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

Check for duplicate satpoints in satpoint mode #3221

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion crates/ordinals/src/sat_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {super::*, bitcoin::transaction::ParseOutPointError};
/// that of the second sat of the genesis block coinbase output is
/// `000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f:0:1`, and
/// so on and so on.
#[derive(Debug, PartialEq, Copy, Clone, Eq, PartialOrd, Ord, Default)]
#[derive(Debug, PartialEq, Copy, Clone, Eq, PartialOrd, Ord, Default, Hash)]
pub struct SatPoint {
pub outpoint: OutPoint,
pub offset: u64,
Expand Down
38 changes: 38 additions & 0 deletions src/wallet/inscribe/batch_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ impl Batchfile {
batchfile.sat.is_none(),
"`sat` cannot be set if in `satpoints` mode"
);

ensure!(
batchfile.satpoint.is_none(),
"`satpoint cannot be set if in `satpoints` mode"
);

let mut seen = HashSet::new();
for entry in batchfile.inscriptions.iter() {
let satpoint = entry.satpoint.unwrap_or_default();
if !seen.insert(satpoint) {
bail!("duplicate satpoint {}", satpoint);
}
}
}

Ok(batchfile)
Expand Down Expand Up @@ -319,4 +328,33 @@ inscriptions:
"`postage` cannot be set if in `satpoints` mode"
);
}

#[test]
fn batchfile_no_duplicate_satpoints() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: satpoints
inscriptions:
- file: inscription.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
- file: tulip.png
satpoint: 5fddcbdc3eb21a93e8dd1dd3f9087c3677f422b82d5ba39a6b1ec37338154af6:0:0
- file: meow.wav
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
- file: inscription_1.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"duplicate satpoint bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0"
);
}
}
Loading