Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inscribing delegate without file #3451

Merged
merged 17 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename to new
  • Loading branch information
raphjaph committed Apr 9, 2024
commit b210a3d459a8888af88ad4d95ee707c0309906a4
19 changes: 5 additions & 14 deletions src/inscriptions/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ pub struct Inscription {
}

impl Inscription {
#[cfg(test)]
pub(crate) fn new(content_type: Option<Vec<u8>>, body: Option<Vec<u8>>) -> Self {
Self {
content_type,
body,
..default()
}
}

pub(crate) fn from(
pub(crate) fn new(
chain: Chain,
compress: bool,
delegate: Option<InscriptionId>,
Expand Down Expand Up @@ -778,7 +769,7 @@ mod tests {

write!(file, "foo").unwrap();

let inscription = Inscription::from(
let inscription = Inscription::new(
Chain::Mainnet,
false,
None,
Expand All @@ -793,7 +784,7 @@ mod tests {

assert_eq!(inscription.pointer, None);

let inscription = Inscription::from(
let inscription = Inscription::new(
Chain::Mainnet,
false,
None,
Expand All @@ -808,7 +799,7 @@ mod tests {

assert_eq!(inscription.pointer, Some(Vec::new()));

let inscription = Inscription::from(
let inscription = Inscription::new(
Chain::Mainnet,
false,
None,
Expand All @@ -823,7 +814,7 @@ mod tests {

assert_eq!(inscription.pointer, Some(vec![1]));

let inscription = Inscription::from(
let inscription = Inscription::new(
Chain::Mainnet,
false,
None,
Expand Down
57 changes: 48 additions & 9 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3165,7 +3165,12 @@ mod tests {
3,
0,
0,
Inscription::new(None, Some("hello".as_bytes().into())).to_witness(),
Inscription {
content_type: None,
body: Some("hello".as_bytes().into()),
..default()
}
.to_witness(),
)],
..default()
});
Expand Down Expand Up @@ -4013,7 +4018,11 @@ mod tests {
fn content_response_no_content() {
assert_eq!(
Server::content_response(
Inscription::new(Some("text/plain".as_bytes().to_vec()), None),
Inscription {
content_type: Some("text/plain".as_bytes().to_vec()),
body: None,
..default()
},
AcceptEncoding::default(),
&ServerConfig::default(),
)
Expand All @@ -4025,7 +4034,11 @@ mod tests {
#[test]
fn content_response_with_content() {
let (headers, body) = Server::content_response(
Inscription::new(Some("text/plain".as_bytes().to_vec()), Some(vec![1, 2, 3])),
Inscription {
content_type: Some("text/plain".as_bytes().to_vec()),
body: Some(vec![1, 2, 3]),
..default()
},
AcceptEncoding::default(),
&ServerConfig::default(),
)
Expand All @@ -4039,7 +4052,11 @@ mod tests {
#[test]
fn content_security_policy_no_origin() {
let (headers, _) = Server::content_response(
Inscription::new(Some("text/plain".as_bytes().to_vec()), Some(vec![1, 2, 3])),
Inscription {
content_type: Some("text/plain".as_bytes().to_vec()),
body: Some(vec![1, 2, 3]),
..default()
},
AcceptEncoding::default(),
&ServerConfig::default(),
)
Expand All @@ -4055,7 +4072,11 @@ mod tests {
#[test]
fn content_security_policy_with_origin() {
let (headers, _) = Server::content_response(
Inscription::new(Some("text/plain".as_bytes().to_vec()), Some(vec![1, 2, 3])),
Inscription {
content_type: Some("text/plain".as_bytes().to_vec()),
body: Some(vec![1, 2, 3]),
..default()
},
AcceptEncoding::default(),
&ServerConfig {
csp_origin: Some("https://ordinals.com".into()),
Expand Down Expand Up @@ -4146,7 +4167,11 @@ mod tests {
#[test]
fn content_response_no_content_type() {
let (headers, body) = Server::content_response(
Inscription::new(None, Some(Vec::new())),
Inscription {
content_type: None,
body: Some(Vec::new()),
..default()
},
AcceptEncoding::default(),
&ServerConfig::default(),
)
Expand All @@ -4160,7 +4185,11 @@ mod tests {
#[test]
fn content_response_bad_content_type() {
let (headers, body) = Server::content_response(
Inscription::new(Some("\n".as_bytes().to_vec()), Some(Vec::new())),
Inscription {
content_type: Some("\n".as_bytes().to_vec()),
body: Some(Vec::new()),
..Default::default()
},
AcceptEncoding::default(),
&ServerConfig::default(),
)
Expand Down Expand Up @@ -4510,7 +4539,12 @@ mod tests {
1,
0,
0,
Inscription::new(Some("foo/bar".as_bytes().to_vec()), None).to_witness(),
Inscription {
content_type: Some("foo/bar".as_bytes().to_vec()),
body: None,
..default()
}
.to_witness(),
)],
..default()
});
Expand Down Expand Up @@ -4539,7 +4573,12 @@ mod tests {
1,
0,
0,
Inscription::new(Some("image/png".as_bytes().to_vec()), None).to_witness(),
Inscription {
content_type: Some("image/png".as_bytes().to_vec()),
body: None,
..default()
}
.to_witness(),
)],
..default()
});
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Inscribe {
}],
dry_run: self.shared.dry_run,
etching: None,
inscriptions: vec![Inscription::from(
inscriptions: vec![Inscription::new(
chain,
self.shared.compress,
self.delegate,
Expand Down
6 changes: 5 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ impl From<InscriptionTemplate> for Inscription {
}

pub(crate) fn inscription(content_type: &str, body: impl AsRef<[u8]>) -> Inscription {
Inscription::new(Some(content_type.into()), Some(body.as_ref().into()))
Inscription {
content_type: Some(content_type.into()),
body: Some(body.as_ref().into()),
..default()
}
}

pub(crate) fn inscription_id(n: u32) -> InscriptionId {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/batch/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl File {
}
}

inscriptions.push(Inscription::from(
inscriptions.push(Inscription::new(
wallet.chain(),
compress,
entry.delegate,
Expand Down