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

1004
yarn.lock

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