Browse Source

Update hw-app-btc, update account sync function

master
meriadec 7 years ago
parent
commit
a0af0a79a6
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 2
      package.json
  2. 33
      src/internals/usb/wallet/scanAccountsOnDevice.js
  3. 1004
      yarn.lock

2
package.json

@ -35,7 +35,7 @@
"webpack-sources": "1.0.1"
},
"dependencies": {
"@ledgerhq/hw-app-btc": "^4.7.3",
"@ledgerhq/hw-app-btc": "^4.11.1",
"@ledgerhq/hw-app-eth": "^4.7.3",
"@ledgerhq/hw-transport": "^4.7.3",
"@ledgerhq/hw-transport-node-hid": "^4.7.6",

33
src/internals/usb/wallet/scanAccountsOnDevice.js

@ -8,7 +8,6 @@
// " `--[]
//
import core from 'ledger-core'
import Btc from '@ledgerhq/hw-app-btc'
import CommNodeHid from '@ledgerhq/hw-transport-node-hid'
@ -19,42 +18,44 @@ type Props = {
currencyId: string,
}
async function getOrCreateWallet(walletPool, currencyId) {
async function getOrCreateWallet(currencyId) {
const core = require('ledger-core')
try {
const wallet = await core.getWallet(walletPool, currencyId)
const wallet = await core.getWallet(currencyId)
return wallet
} catch (err) {
const currency = await core.getCurrency(walletPool, currencyId)
const wallet = await core.createWallet(walletPool, currencyId, currency)
const currency = await core.getCurrency(currencyId)
const wallet = await core.createWallet(currencyId, currency)
return wallet
}
}
async function scanNextAccount(wallet, hwApp, accountIndex = 0) {
console.log(`creating an account with index ${accountIndex}`)
async function scanNextAccount(wallet, hwApp, accountIndex = 0, accounts = []) {
const core = require('ledger-core')
console.log(`>> On index ${accountIndex}...`)
const account = await core.createAccount(wallet, hwApp)
console.log(`synchronizing account ${accountIndex}`)
await core.syncAccount(account)
console.log(`finished sync`)
const utxoCount = await account.asBitcoinLikeAccount().getUTXOCount()
console.log(`utxoCount = ${utxoCount}`)
console.log(`>> Found ${utxoCount} utxos`)
if (utxoCount === 0) {
return accounts
}
accounts.push(account)
return scanNextAccount(wallet, hwApp, accountIndex + 1, accounts)
}
export default async function scanAccountsOnDevice(props: Props): Account[] {
try {
const { devicePath, currencyId } = props
const walletPool = core.createWalletPool()
console.log(`get or create wallet`)
const wallet = await getOrCreateWallet(walletPool, currencyId)
console.log(`open device`)
const wallet = await getOrCreateWallet(currencyId)
const transport = await CommNodeHid.open(devicePath)
console.log(`create app`)
const hwApp = new Btc(transport)
console.log(`scan account`)
console.log(`>> Scanning accounts...`)
const accounts = await scanNextAccount(wallet, hwApp)
console.log(accounts)
return []
} catch (err) {
console.log(err)
return []
}
}

1004
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save