Skip to content

Commit e7fbdfd

Browse files
committed
Fix spending htlc output in api server
1 parent 6a8917e commit e7fbdfd

File tree

5 files changed

+387
-5
lines changed

5 files changed

+387
-5
lines changed

api-server/scanner-lib/src/blockchain_state/mod.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,16 @@ async fn update_tables_from_transaction_inputs<T: ApiServerStorageWrite>(
13141314
)
13151315
.await;
13161316
}
1317-
TxOutput::Htlc(_, _) => {} // TODO(HTLC)
1317+
TxOutput::Htlc(_, htlc) => {
1318+
let address =
1319+
Address::<Destination>::new(&chain_config, htlc.spend_key)
1320+
.expect("Unable to encode destination");
1321+
1322+
address_transactions
1323+
.entry(address.clone())
1324+
.or_default()
1325+
.insert(tx.get_id());
1326+
}
13181327
TxOutput::LockThenTransfer(output_value, destination, _)
13191328
| TxOutput::Transfer(output_value, destination) => {
13201329
let address = Address::<Destination>::new(&chain_config, destination)
@@ -1729,7 +1738,27 @@ async fn update_tables_from_transaction_outputs<T: ApiServerStorageWrite>(
17291738
.expect("Unable to set locked utxo");
17301739
}
17311740
}
1732-
TxOutput::Htlc(_, _) => {} // TODO(HTLC)
1741+
TxOutput::Htlc(output_value, htlc) => {
1742+
let address = Address::<Destination>::new(&chain_config, htlc.spend_key.clone())
1743+
.expect("Unable to encode destination");
1744+
1745+
address_transactions.entry(address.clone()).or_default().insert(transaction_id);
1746+
1747+
let token_decimals = match output_value {
1748+
OutputValue::Coin(_) | OutputValue::TokenV0(_) => None,
1749+
OutputValue::TokenV1(token_id, _) => {
1750+
Some(token_decimals(*token_id, &BTreeMap::new(), db_tx).await?.1)
1751+
}
1752+
};
1753+
1754+
let outpoint =
1755+
UtxoOutPoint::new(OutPointSourceId::Transaction(transaction_id), idx as u32);
1756+
let utxo = Utxo::new(output.clone(), token_decimals, false);
1757+
db_tx
1758+
.set_utxo_at_height(outpoint, utxo, address.as_str(), block_height)
1759+
.await
1760+
.expect("Unable to set utxo");
1761+
}
17331762
TxOutput::CreateOrder(_) => {
17341763
// TODO(orders)
17351764
}
@@ -1932,7 +1961,7 @@ fn get_tx_output_destination(txo: &TxOutput) -> Option<&Destination> {
19321961
| TxOutput::Burn(_)
19331962
| TxOutput::DelegateStaking(_, _)
19341963
| TxOutput::DataDeposit(_)
1964+
| TxOutput::Htlc(_, _)
19351965
| TxOutput::CreateOrder(_) => None,
1936-
TxOutput::Htlc(_, _) => None, // TODO(HTLC)
19371966
}
19381967
}

api-server/stack-test-suite/tests/v2/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async fn ok(#[case] seed: Seed) {
157157
"transactions": block.transactions()
158158
.iter()
159159
.zip(tx_additional_data.iter())
160-
.map(|(tx, additinal_data)| tx_to_json(tx.transaction(), additinal_data, tf.chain_config()))
160+
.map(|(tx, additional_data)| tx_to_json(tx.transaction(), additional_data, tf.chain_config()))
161161
.collect::<Vec<_>>(),
162162
},
163163
});

0 commit comments

Comments
 (0)