Browse Source

Add parse-accounts script. Put segwit info in account placeholder name.

master
meriadec 7 years ago
parent
commit
1f61e3ef81
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 63
      scripts/parse-accounts.js
  2. 2
      src/internals/accounts/scanAccountsOnDevice.js

63
scripts/parse-accounts.js

@ -0,0 +1,63 @@
// Utility to human-read the accounts.json file
// You have to pass it in parameter, because the location
// differ depending on the OS.
const {
formatCurrencyUnit,
getCryptoCurrencyById,
} = require('@ledgerhq/live-common/lib/helpers/currencies')
const chalk = require('chalk')
const padStart = require('lodash/padStart')
const padEnd = require('lodash/padEnd')
const { argv } = process
const [, , FILE_PATH] = argv
if (!FILE_PATH) {
console.log(`You need to specify a file`)
process.exit(1)
}
const { data: wrappedAccounts } = require(FILE_PATH) // eslint-disable-line
const str = wrappedAccounts
.map(({ data: account }) => {
const currency = getCryptoCurrencyById(account.currencyId)
const unit = currency.units[0]
const headline = `${account.isSegwit ? '[SEGWIT]' : '[NOT SEGWIT]'} ${account.name} | ${
account.id
} | ${account.path} | balance: ${formatCurrencyUnit(unit, account.balance, {
showCode: true,
alwaysShowSign: true,
})}`
return [
headline,
headline
.split('')
.map(() => '-')
.join(''),
account.operations
.map(op => {
const opType = op.amount < 0 ? 'SEND' : 'RECEIVE'
return [
padEnd(opType, 8),
op.date.substr(0, 10),
chalk[opType === 'SEND' ? 'red' : 'green'](
padStart(
formatCurrencyUnit(unit, op.amount, {
showCode: true,
alwaysShowSign: true,
}),
15,
),
),
op.hash,
].join(' ')
})
.join('\n'),
].join('\n')
})
.join('\n\n')
console.log(str)

2
src/internals/accounts/scanAccountsOnDevice.js

@ -217,7 +217,7 @@ async function buildAccountRaw({
xpub,
path: accountPath,
walletPath,
name: `Account ${accountIndex}`, // TODO: placeholder name?
name: `Account ${accountIndex}${isSegwit ? ' (segwit)' : ''}`, // TODO: placeholder name?
isSegwit,
address: bitcoinAddress,
addresses,

Loading…
Cancel
Save