Browse Source

minimize need of the device in sign and broadcast

master
Gaëtan Renaudeau 7 years ago
parent
commit
4d9826fec4
  1. 27
      src/commands/libcoreSignAndBroadcast.js

27
src/commands/libcoreSignAndBroadcast.js

@ -152,15 +152,11 @@ export async function doSignAndBroadcast({
onSigned: () => void,
onOperationBroadcasted: (optimisticOp: $Exact<OperationRaw>) => void,
}): Promise<void> {
let njsAccount
const signedTransaction = await withDevice(deviceId)(async transport => {
const hwApp = new Btc(transport)
const { walletName } = accountIdHelper.decode(account.id)
const njsWallet = await core.getWallet(walletName)
if (isCancelled()) return null
njsAccount = await njsWallet.getAccount(account.index)
if (isCancelled()) return null
if (isCancelled()) return
const njsAccount = await njsWallet.getAccount(account.index)
if (isCancelled()) return
const bitcoinLikeAccount = njsAccount.asBitcoinLikeAccount()
const njsWalletCurrency = njsWallet.getCurrency()
const amount = core.createAmount(njsWalletCurrency, transaction.amount)
@ -175,26 +171,27 @@ export async function doSignAndBroadcast({
transactionBuilder.setFeesPerByte(fees)
const builded = await transactionBuilder.build()
if (isCancelled()) return null
const sigHashType = Buffer.from(
njsWalletCurrency.bitcoinLikeNetworkParameters.SigHash,
).toString('hex')
if (isCancelled()) return
const sigHashType = Buffer.from(njsWalletCurrency.bitcoinLikeNetworkParameters.SigHash).toString(
'hex',
)
const hasTimestamp = !!njsWalletCurrency.bitcoinLikeNetworkParameters.UsesTimestampedTransaction
// TODO: const timestampDelay = njsWalletCurrency.bitcoinLikeNetworkParameters.TimestampDelay
const currency = getCryptoCurrencyById(account.currencyId)
return signTransaction({
hwApp,
const signedTransaction = await withDevice(deviceId)(async transport =>
signTransaction({
hwApp: new Btc(transport),
currencyId: account.currencyId,
transaction: builded,
sigHashType: parseInt(sigHashType, 16),
supportsSegwit: !!currency.supportsSegwit,
isSegwit: isSegwitAccount(account),
hasTimestamp,
})
})
}),
)
if (!signedTransaction || isCancelled() || !njsAccount) return
onSigned()

Loading…
Cancel
Save