Skip to content

Commit fd818bc

Browse files
committed
Enforce SIP-02 reserved spaces
1 parent 4466a24 commit fd818bc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

protocol/src/constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub struct ChainAnchor {
1616
pub height: u32,
1717
}
1818

19+
pub const RESERVED_SPACES: [&'static [u8]; 3] = [
20+
b"\x07example",
21+
b"\x04test",
22+
b"\x04local",
23+
];
24+
1925
/// The number of blocks between each rollout of new spaces for auction.
2026
pub const ROLLOUT_BLOCK_INTERVAL: u32 = 144;
2127

protocol/src/script.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
validate::RejectParams,
1919
FullSpaceOut,
2020
};
21+
use crate::constants::RESERVED_SPACES;
2122

2223
/// Ways that a script might fail. Not everything is split up as
2324
/// much as it could be; patches welcome if more detailed errors
@@ -32,6 +33,7 @@ use crate::{
3233
#[non_exhaustive]
3334
pub enum ScriptError {
3435
MalformedName,
36+
ReservedName,
3537
Reject(RejectParams),
3638
}
3739

@@ -138,6 +140,10 @@ impl SpaceScript {
138140
}
139141
let name = name.unwrap();
140142

143+
if RESERVED_SPACES.iter().any(|reserved| *reserved == name.as_ref()) {
144+
return Ok(Err(ScriptError::ReservedName));
145+
}
146+
141147
let kind = {
142148
let spacehash = SpaceKey::from(H::hash(name.as_ref()));
143149
let existing = src.get_space_outpoint(&spacehash)?;
@@ -186,6 +192,7 @@ impl core::fmt::Display for ScriptError {
186192

187193
match *self {
188194
MalformedName => f.write_str("malformed name"),
195+
ReservedName => f.write_str("reserved name"),
189196
Reject(_) => f.write_str("rejected"),
190197
}
191198
}

0 commit comments

Comments
 (0)