Skip to content

Commit

Permalink
Make find command print satpoints instead of outpoints (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 21, 2022
1 parent cc18dd3 commit 4b62e7e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 6 additions & 8 deletions src/command/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
12 changes: 10 additions & 2 deletions tests/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ 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()
}

#[test]
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()
}

0 comments on commit 4b62e7e

Please sign in to comment.