Skip to content

Commit

Permalink
Merge pull request #2624 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
hughy authored Nov 20, 2022
2 parents de27e51 + 9a31509 commit 22e9f8c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.53",
"version": "0.1.54",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -56,7 +56,7 @@
"dependencies": {
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.17",
"@ironfish/sdk": "0.0.30",
"@ironfish/sdk": "0.0.31",
"@oclif/core": "1.16.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
52 changes: 44 additions & 8 deletions ironfish-cli/src/commands/accounts/repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default class Repair extends IronfishCommand {

this.log(`Repairing wallet for account ${account.name}`)

this.log('Repairing expired transactions')
await this.repairTransactions(account, node.wallet.walletDb, node.chain)

this.log('Repairing balance')
await this.repairBalance(account, node.wallet.walletDb, node.chain)

Expand Down Expand Up @@ -69,6 +72,36 @@ export default class Repair extends IronfishCommand {
throw new Error('Could not find an account to repair.')
}

private async repairTransactions(
account: Account,
walletDb: WalletDB,
chain: Blockchain,
): Promise<void> {
let unexpiredTransactions = 0

for await (const transactionValue of account.getTransactions()) {
const expirationSequence = transactionValue.transaction.expirationSequence()
const transactionHash = transactionValue.transaction.hash()

const isExpired =
!transactionValue.sequence &&
chain.verifier.isExpiredSequence(expirationSequence, chain.head.sequence)

const pendingTransactionHash = await walletDb.pendingTransactionHashes.get([
account.prefix,
[expirationSequence, transactionHash],
])

if (isExpired && !pendingTransactionHash) {
unexpiredTransactions++

await account.expireTransaction(transactionValue.transaction)
}
}

this.log(`Repaired ${unexpiredTransactions} expired transactions stuck in unexpired state.`)
}

private async repairBalance(
account: Account,
walletDb: WalletDB,
Expand Down Expand Up @@ -105,21 +138,24 @@ export default class Repair extends IronfishCommand {
...decryptedNoteValue,
spent: true,
})
} else if (
!spent &&
!chain.verifier.isExpiredSequence(
transactionValue.transaction.expirationSequence(),
chain.head.sequence,
)
) {
} else if (!spent) {
const isExpired =
!transactionValue.sequence &&
chain.verifier.isExpiredSequence(
transactionValue.transaction.expirationSequence(),
chain.head.sequence,
)

if (decryptedNoteValue.spent) {
await walletDb.saveDecryptedNote(account, decryptedNoteValue.hash, {
...decryptedNoteValue,
spent: false,
})
}

unconfirmedBalance += decryptedNoteValue.note.value()
if (!isExpired) {
unconfirmedBalance += decryptedNoteValue.note.value()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ironfish/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/sdk",
"version": "0.0.30",
"version": "0.0.31",
"description": "SDK for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down

0 comments on commit 22e9f8c

Please sign in to comment.