Skip to content

Commit

Permalink
Fiix fee-spent inscription track (ordinals#1971)
Browse files Browse the repository at this point in the history
Assign inscriptions spent as fees to the correct
sat in the coinbase output.

---------

Co-authored-by: Greg Martin <[email protected]>
Co-authored-by: raphjaph <[email protected]>
  • Loading branch information
3 people authored Apr 14, 2023
1 parent 20e2881 commit e928f63
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ mod tests {
}

#[test]
fn fee_spent_inscriptions_are_tracked_correctly() {
fn one_input_fee_spent_inscriptions_are_tracked_correctly() {
for context in Context::configurations() {
context.mine_blocks(1);

Expand Down Expand Up @@ -1623,6 +1623,42 @@ mod tests {
}
}

#[test]
fn two_input_fee_spent_inscriptions_are_tracked_correctly() {
for context in Context::configurations() {
context.mine_blocks(2);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0)],
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);

context.mine_blocks(1);

context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(2, 0, 0), (3, 1, 0)],
fee: 50 * COIN_VALUE,
..Default::default()
});

let coinbase_tx = context.mine_blocks(1)[0].txdata[0].txid();

context.index.assert_inscription_location(
inscription_id,
SatPoint {
outpoint: OutPoint {
txid: coinbase_tx,
vout: 0,
},
offset: 50 * COIN_VALUE,
},
50 * COIN_VALUE,
);
}
}

#[test]
fn inscription_can_be_fee_spent_in_first_transaction() {
for context in Context::configurations() {
Expand Down
2 changes: 1 addition & 1 deletion src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
Ok(self.reward - output_value)
} else {
self.flotsam.extend(inscriptions.map(|flotsam| Flotsam {
offset: self.reward + flotsam.offset,
offset: self.reward + flotsam.offset - output_value,
..flotsam
}));
self.reward += input_value - output_value;
Expand Down

0 comments on commit e928f63

Please sign in to comment.