Merge branch '102-fix-blockchain-add-token-support-for-blockchaininmemory' into 'development'

Resolve "fix(Blockchain): Add token support for BlockchainInMemory"

Closes #102

See merge request GeneralProtocols/xo/stack!142
This commit is contained in:
Emergent Reasons
2025-11-03 07:47:15 +00:00
@@ -156,11 +156,19 @@ export class BlockchainInMemory extends BaseBlockchain<BlockHeightPayload> {
); );
} }
// Check if the transaction has a mempool input, if there is one, we need to set the height to -1 to indicate that it uses an unconfirmed input
const hasMempoolInput = tx.getInputs().some((input) => {
const tx = this.transactions.get(binToHex(input.outpointTransactionHash));
if (!tx) return false;
return tx.height <= 0;
});
// Add the transaction. // Add the transaction.
this.addTransaction({ this.addTransaction({
hash: tx.toHash(), hash: tx.toHash(),
transaction: tx, transaction: tx,
height: 0, height: hasMempoolInput ? -1 : 0,
}); });
// Notify our address and transaction subscribers. // Notify our address and transaction subscribers.
@@ -330,10 +338,11 @@ export class BlockchainInMemory extends BaseBlockchain<BlockHeightPayload> {
for (const tx of this.transactions.values()) { for (const tx of this.transactions.values()) {
tx.transaction.getOutputs().forEach((output, outpointIndex) => { tx.transaction.getOutputs().forEach((output, outpointIndex) => {
const utxo: BlockchainUTXO = { const utxo: BlockchainUTXO = {
height: 0, height: tx.height,
utxo: UTXO.from(new Outpoint(tx.hash.toBytes(), outpointIndex), { utxo: UTXO.from(new Outpoint(tx.hash.toBytes(), outpointIndex), {
valueSatoshis: output.valueSatoshis, valueSatoshis: output.valueSatoshis,
lockingBytecode: output.lockingBytecode, lockingBytecode: output.lockingBytecode,
token: output.token,
}), }),
}; };
utxoMap.set(`${tx.hash.toHex()}:${outpointIndex}`, utxo); utxoMap.set(`${tx.hash.toHex()}:${outpointIndex}`, utxo);