Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /*! * account.js - Multisig wallets' account * Copyright (c) 2018, The Bcoin Developers (MIT License). * https://github.com/bcoin-org/bcoin */ 'use strict'; const assert = require('bsert'); const {Account} = require('bcoin').wallet; const custom = require('./utils/inspect'); /** * Account object for multisig * for formatting. * @alias module:multisig.Account */ class MultisigAccount { constructor(account) { this.account = null; this.fromAccount(account); } fromAccount(account) { assert(account, 'MultisigAccount needs account.'); assert(account.type === Account.types.MULTISIG, 'Account needs to be multisig'); assert(account.watchOnly === true, 'Account needs to be watchOnly'); this.account = account; } /** * Get public keys. * @returns {bcoin#HDPublicKey[]} */ getPublicKeys() { const keys = [this.account.accountKey]; return keys.concat(this.account.keys); } /** * Get current receive address. * @returns {Address} */ receiveAddress() { const key = this.account.receiveKey(); if (!key) return null; return key.getAddress(); } /** * Get current change address. * @returns {Address} */ changeAddress() { const key = this.account.changeKey(); if (!key) return null; return key.getAddress(); } /** * Get current nested address. * @returns {Address} */ nestedAddress() { const key = this.account.nestedKey(); if (!key) return null; return key.getAddress(); } createReceive(b) { return this.account.createReceive(b); } createChange(b) { return this.account.createChange(b); } createNested(b) { return this.account.createNested(b); } /** * Derive path * @param {Path} path */ derivePath(path) { return this.account.deriveKey(path.branch, path.index); } /** * Create MultisigAccount from bcoin Account. * @param {bcoin#Account} * @returns {MultisigAccount} */ static fromAccount(account) { return new MultisigAccount(account); } [custom]() { return this.toJSON(); } /** * Convert account to JSON. * @returns {Object} */ toJSON() { return this.getJSON(); } /** * Convert the account to an object suitable for * serialization. * @param {Balance} [balance] * @returns {Object} */ getJSON(balance) { const network = this.account.network; const keys = this.account.keys; const receive = this.receiveAddress(); const change = this.changeAddress(); const nested = this.nestedAddress(); return { name: this.account.name, initialized: this.account.initialized, witness: this.account.witness, watchOnly: true, type: 'multisig', m: this.account.m, n: this.account.n, accountIndex: this.account.accountIndex, receiveDepth: this.account.receiveDepth, changeDepth: this.account.changeDepth, nestedDepth: this.account.nestedDepth, lookahead: this.account.lookahead, receiveAddress: receive ? receive.toString(network) : null, changeAddress: change ? change.toString(network) : null, nestedAddress: nested ? nested.toString(network) : null, accountKey: this.account.accountKey.toBase58(network), keys: keys.map(key => key.toBase58(network)), balance: balance ? balance.toJSON(true) : null }; } } module.exports = MultisigAccount; |