diff --git a/README.md b/README.md index 9a23ec9a89..a9e20dc08d 100644 --- a/README.md +++ b/README.md @@ -72,14 +72,17 @@ If the coinbase transaction underpays the block subsidy or fees, those satoshis, along with their ordinal numbers, are destroyed and taken out of circulation. -The `find` command, as of yet unfinished, gives the current outpoint containing +The `find` command, as of yet unfinished, gives the current satpoint containing the satoshi with a given ordinal at a given height: ``` $ ord find --blocksdir ~/.bicoin/blocks 0 0 -4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0 +4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0 ``` +A satpoint is an outpoint, that is to say a transaction ID and output index, +followed by the offset into the output itself, and gives the position of the +satoshi within a particular output. ## Traits diff --git a/src/command/find.rs b/src/command/find.rs index 9190f432d8..a9a42cd14a 100644 --- a/src/command/find.rs +++ b/src/command/find.rs @@ -5,19 +5,17 @@ pub(crate) fn run(blocksdir: Option<&Path>, ordinal: Ordinal, at_height: u64) -> let height = ordinal.height().n(); assert!(height < 100); - assert!(at_height == height); + assert!(height == at_height); let block = index.block(height)?; - let position = ordinal.subsidy_position(); - - let mut ordinal = 0; - for (i, output) in block.txdata[0].output.iter().enumerate() { - if ordinal + output.value >= position { - println!("{}:{}", block.txdata[0].txid(), i); + let mut offset = ordinal.subsidy_position(); + for (index, output) in block.txdata[0].output.iter().enumerate() { + if output.value > offset { + println!("{}:{index}:{offset}", block.txdata[0].txid()); break; } - ordinal += output.value; + offset -= output.value; } Ok(()) diff --git a/tests/find.rs b/tests/find.rs index f1a7fe7b9e..70a829d425 100644 --- a/tests/find.rs +++ b/tests/find.rs @@ -4,7 +4,15 @@ use super::*; fn first_satoshi() -> Result { Test::new()? .args(&["find", "--blocksdir", "blocks", "0", "0"]) - .expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0\n") + .expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0\n") + .run() +} + +#[test] +fn second_satoshi() -> Result { + Test::new()? + .args(&["find", "--blocksdir", "blocks", "1", "0"]) + .expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:1\n") .run() } @@ -12,6 +20,6 @@ fn first_satoshi() -> Result { fn first_satoshi_of_second_block() -> Result { Test::new()? .args(&["find", "--blocksdir", "blocks", "5000000000", "1"]) - .expected_stdout("e5fb252959bdc7727c80296dbc53e1583121503bb2e266a609ebc49cf2a74c1d:0\n") + .expected_stdout("e5fb252959bdc7727c80296dbc53e1583121503bb2e266a609ebc49cf2a74c1d:0:0\n") .run() }