Skip to content

Commit

Permalink
fix tx shield creation error handling (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone authored Mar 7, 2024
1 parent 64e6794 commit b70b035
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
11 changes: 8 additions & 3 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,14 @@ async function send(address, amount, useShieldInputs) {
transferAmount.value = '';
// Create and send the TX
await wallet.createAndSendTransaction(getNetwork(), address, nValue, {
useShieldInputs,
});
try {
await wallet.createAndSendTransaction(getNetwork(), address, nValue, {
useShieldInputs,
});
} catch (e) {
console.error(e);
createAlert('warning', e);
}
}
/**
Expand Down
41 changes: 26 additions & 15 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Database } from './database.js';
import { RECEIVE_TYPES } from './contacts-book.js';
import { Account } from './accounts.js';
import { fAdvancedMode } from './settings.js';
import { bytesToHex, hexToBytes, startBatch } from './utils.js';
import { bytesToHex, hexToBytes, sleep, startBatch } from './utils.js';
import { strHardwareName } from './ledger.js';
import { UTXO_WALLET_STATE } from './mempool.js';
import { getEventEmitter } from './event_bus.js';
Expand Down Expand Up @@ -1025,20 +1025,31 @@ export class Wallet {

const value =
transaction.shieldOutput[0]?.value || transaction.vout[0].value;
const { hex } = await this.#shield.createTransaction({
address:
transaction.shieldOutput[0]?.address ||
this.getAddressesFromScript(transaction.vout[0].script)
.addresses[0],
amount: value,
blockHeight: getNetwork().cachedBlockCount,
useShieldInputs: transaction.vin.length === 0,
utxos: this.#getUTXOsForShield(),
transparentChangeAddress: this.getNewAddress(1)[0],
});
clearInterval(periodicFunction);
getEventEmitter().emit('shield-transaction-creation-update', 0.0, true);
return transaction.fromHex(hex);
try {
const { hex } = await this.#shield.createTransaction({
address:
transaction.shieldOutput[0]?.address ||
this.getAddressesFromScript(transaction.vout[0].script)
.addresses[0],
amount: value,
blockHeight: getNetwork().cachedBlockCount,
useShieldInputs: transaction.vin.length === 0,
utxos: this.#getUTXOsForShield(),
transparentChangeAddress: this.getNewAddress(1)[0],
});
return transaction.fromHex(hex);
} catch (e) {
// sleep a full period of periodicFunction
await sleep(500);
throw new Error(e);
} finally {
clearInterval(periodicFunction);
getEventEmitter().emit(
'shield-transaction-creation-update',
0.0,
true
);
}
}

/**
Expand Down

0 comments on commit b70b035

Please sign in to comment.