Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// })
// console.log(accounts)
try {
console.log(`> Creating transport`)
const transport = await CommNodeHid.open(device.path)
// transport.setDebugMode(true)
console.log(`> Instanciate BTC app`)
const hwApp = new Btc(transport)
console.log(`> Get currency`)
const currency = await getCurrency('bitcoin_testnet')
console.log(`> Create wallet`)
const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')
console.log(`> Create account`)
const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)
console.log(`> Sync account`)
if (CREATE) {
await syncAccount(account)
}
console.log(`> Create transaction`)
const transaction = await createTransaction(wallet, account)
const signedTransaction = await signTransaction(hwApp, transaction)
await account.asBitcoinLikeAccount().broadcastRawTransaction(signedTransaction)
// console.log(signedTransaction);
async function getOrCreateWallet(currencyId) {
try {
const wallet = await getWallet(currencyId)
return wallet
} catch (err) {
const currency = await getCurrency(currencyId)
const wallet = await createWallet(currencyId, currency)
return wallet
}
}