Skip to content

Commit

Permalink
Process saved transaction inputs and outputs against current UTXO state
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Oct 29, 2024
1 parent 77d6760 commit e0b4d13
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- fixed: (ADA) Fixed a bug in Blockfrost response handling that caused an error when processing successful non-JSON responses.
- fixed: (ADA) Re-spending UTXO race condition.
- fixed: Possible to send polkadot currencies to `0x` addresses

## 4.26.1 (2024-10-14)
Expand Down
32 changes: 32 additions & 0 deletions src/cardano/CardanoEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,38 @@ export class CardanoEngine extends CurrencyEngine<
return edgeTransaction
}

async saveTx(edgeTransaction: EdgeTransaction): Promise<void> {
await super.saveTx(edgeTransaction)

const tx = Cardano.Transaction.from_hex(edgeTransaction.signedTx)
const txHash = Cardano.hash_transaction(tx.body()).to_hex()
const txJson = tx.to_js_value()

// Filter out spent utxos:
const vouts = new Set(
txJson.body.inputs.map(input => `${input.transaction_id}_${input.index}`)
)
this.utxos = this.utxos.filter(utxo => {
return !vouts.has(`${utxo.tx_hash}_${utxo.tx_index}`)
})

// Add new utxos that our own:
const ownAddress = this.walletInfo.keys.bech32Address
txJson.body.outputs.forEach((output, index) => {
if (output.address === ownAddress) {
// Skip over multiasset outputs (we don't support spending from them):
if (output.amount.multiasset != null) return

this.utxos.push({
asset_list: [],
tx_hash: txHash,
tx_index: index,
value: output.amount.coin
})
}
})
}

async signTx(
edgeTransaction: EdgeTransaction,
privateKeys: JsonObject
Expand Down

0 comments on commit e0b4d13

Please sign in to comment.