wallet/bcoin: refactor exposure.
This commit is contained in:
parent
425b8780f7
commit
99a7eb5fa5
@ -28,7 +28,7 @@ const node = new Node({
|
||||
logFile: true,
|
||||
logConsole: true,
|
||||
logLevel: 'debug',
|
||||
db: 'leveldb',
|
||||
memory: false,
|
||||
workers: true,
|
||||
listen: true,
|
||||
loader: require
|
||||
|
||||
@ -25,115 +25,107 @@ const bcoin = exports;
|
||||
*/
|
||||
|
||||
bcoin.set = function set(network) {
|
||||
bcoin.network.set(network);
|
||||
bcoin.Network.set(network);
|
||||
return bcoin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache all necessary modules.
|
||||
*/
|
||||
|
||||
bcoin.cache = function cache() {
|
||||
;
|
||||
};
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
/*
|
||||
// Blockchain
|
||||
bcoin.blockchain = require('./blockchain');
|
||||
bcoin.chain = require('./blockchain/chain');
|
||||
bcoin.chaindb = require('./blockchain/chaindb');
|
||||
bcoin.chainentry = require('./blockchain/chainentry');
|
||||
bcoin.Chain = require('./blockchain/chain');
|
||||
bcoin.ChainEntry = require('./blockchain/chainentry');
|
||||
*/
|
||||
|
||||
// BTC
|
||||
bcoin.btc = require('./btc');
|
||||
bcoin.amount = require('./btc/amount');
|
||||
bcoin.uri = require('./btc/uri');
|
||||
bcoin.Amount = require('./btc/amount');
|
||||
bcoin.URI = require('./btc/uri');
|
||||
|
||||
// Coins
|
||||
bcoin.coins = require('./coins');
|
||||
bcoin.coinview = require('./coins/coinview');
|
||||
bcoin.Coins = require('./coins/coins');
|
||||
bcoin.CoinEntry = require('./coins/coinentry');
|
||||
bcoin.CoinView = require('./coins/coinview');
|
||||
|
||||
// HD
|
||||
bcoin.hd = require('./hd');
|
||||
bcoin.HDPrivateKey = require('./hd/private');
|
||||
bcoin.HDPublicKey = require('./hd/public');
|
||||
bcoin.Mnemonic = require('./hd/mnemonic');
|
||||
|
||||
/*
|
||||
// Mempool
|
||||
bcoin.txmempool = require('./mempool');
|
||||
bcoin.fees = require('./mempool/fees');
|
||||
bcoin.mempool = require('./mempool/mempool');
|
||||
bcoin.mempoolentry = require('./mempool/mempoolentry');
|
||||
bcoin.mempool = require('./mempool');
|
||||
bcoin.Fees = require('./mempool/fees');
|
||||
bcoin.Mempool = require('./mempool/mempool');
|
||||
bcoin.MempoolEntry = require('./mempool/mempoolentry');
|
||||
|
||||
// Miner
|
||||
bcoin.mining = require('./mining');
|
||||
bcoin.miner = require('./mining/miner');
|
||||
bcoin.template = require('./mining/template');
|
||||
bcoin.Miner = require('./mining/miner');
|
||||
|
||||
// Net
|
||||
bcoin.net = require('./net');
|
||||
bcoin.bip150 = require('./net/bip150');
|
||||
bcoin.bip151 = require('./net/bip151');
|
||||
bcoin.bip152 = require('./net/bip152');
|
||||
bcoin.netaddress = require('./net/netaddress');
|
||||
bcoin.packets = require('./net/packets');
|
||||
bcoin.peer = require('./net/peer');
|
||||
bcoin.pool = require('./net/pool');
|
||||
bcoin.Peer = require('./net/peer');
|
||||
bcoin.Pool = require('./net/pool');
|
||||
|
||||
// Node
|
||||
bcoin.node = require('./node');
|
||||
bcoin.fullnode = require('./node/fullnode');
|
||||
bcoin.spvnode = require('./node/spvnode');
|
||||
bcoin.Node = require('./node/node');
|
||||
bcoin.FullNode = require('./node/fullnode');
|
||||
bcoin.SPVNode = require('./node/spvnode');
|
||||
*/
|
||||
|
||||
// Primitives
|
||||
bcoin.primitives = require('./primitives');
|
||||
bcoin.address = require('./primitives/address');
|
||||
bcoin.block = require('./primitives/block');
|
||||
bcoin.coin = require('./primitives/coin');
|
||||
bcoin.headers = require('./primitives/headers');
|
||||
bcoin.input = require('./primitives/input');
|
||||
bcoin.invitem = require('./primitives/invitem');
|
||||
bcoin.keyring = require('./primitives/keyring');
|
||||
bcoin.merkleblock = require('./primitives/merkleblock');
|
||||
bcoin.mtx = require('./primitives/mtx');
|
||||
bcoin.outpoint = require('./primitives/outpoint');
|
||||
bcoin.output = require('./primitives/output');
|
||||
bcoin.tx = require('./primitives/tx');
|
||||
bcoin.Address = require('./primitives/address');
|
||||
bcoin.Block = require('./primitives/block');
|
||||
bcoin.Coin = require('./primitives/coin');
|
||||
bcoin.Headers = require('./primitives/headers');
|
||||
bcoin.Input = require('./primitives/input');
|
||||
bcoin.InvItem = require('./primitives/invitem');
|
||||
bcoin.KeyRing = require('./primitives/keyring');
|
||||
bcoin.MerkleBlock = require('./primitives/merkleblock');
|
||||
bcoin.MTX = require('./primitives/mtx');
|
||||
bcoin.Outpoint = require('./primitives/outpoint');
|
||||
bcoin.Output = require('./primitives/output');
|
||||
bcoin.TX = require('./primitives/tx');
|
||||
|
||||
// Protocol
|
||||
bcoin.protocol = require('./protocol');
|
||||
bcoin.consensus = require('./protocol/consensus');
|
||||
bcoin.errors = require('./protocol/errors');
|
||||
bcoin.network = require('./protocol/network');
|
||||
bcoin.Network = require('./protocol/network');
|
||||
bcoin.networks = require('./protocol/networks');
|
||||
bcoin.policy = require('./protocol/policy');
|
||||
bcoin.timedata = require('./protocol/timedata');
|
||||
|
||||
// Script
|
||||
bcoin.txscript = require('./script');
|
||||
bcoin.opcode = require('./script/opcode');
|
||||
bcoin.program = require('./script/program');
|
||||
bcoin.script = require('./script/script');
|
||||
bcoin.scriptnum = require('./script/scriptnum');
|
||||
bcoin.sigcache = require('./script/sigcache');
|
||||
bcoin.stack = require('./script/stack');
|
||||
bcoin.witness = require('./script/witness');
|
||||
bcoin.script = require('./script');
|
||||
bcoin.Opcode = require('./script/opcode');
|
||||
bcoin.Program = require('./script/program');
|
||||
bcoin.Script = require('./script/script');
|
||||
bcoin.ScriptNum = require('./script/scriptnum');
|
||||
bcoin.SigCache = require('./script/sigcache');
|
||||
bcoin.Stack = require('./script/stack');
|
||||
bcoin.Witness = require('./script/witness');
|
||||
|
||||
// Utils
|
||||
bcoin.utils = require('./utils');
|
||||
bcoin.co = require('./utils/co');
|
||||
bcoin.lock = require('./utils/lock');
|
||||
bcoin.util = require('./utils/util');
|
||||
|
||||
/*
|
||||
// Wallet
|
||||
bcoin.wallet = require('./wallet');
|
||||
bcoin.path = require('./wallet/path');
|
||||
bcoin.walletkey = require('./wallet/walletkey');
|
||||
bcoin.walletdb = require('./wallet/walletdb');
|
||||
bcoin.WalletDB = require('./wallet/walletdb');
|
||||
|
||||
// Workers
|
||||
bcoin.workers = require('./workers');
|
||||
bcoin.workerpool = require('./workers/workerpool');
|
||||
bcoin.WorkerPool = require('./workers/workerpool');
|
||||
*/
|
||||
|
||||
// Package Info
|
||||
bcoin.pkg = require('./pkg');
|
||||
|
||||
122
lib/bcoin.js
122
lib/bcoin.js
@ -28,7 +28,7 @@ const bcoin = exports;
|
||||
*/
|
||||
|
||||
bcoin.define = function define(name, path) {
|
||||
let cache;
|
||||
let cache = null;
|
||||
Object.defineProperty(bcoin, name, {
|
||||
get() {
|
||||
if (!cache)
|
||||
@ -44,131 +44,103 @@ bcoin.define = function define(name, path) {
|
||||
*/
|
||||
|
||||
bcoin.set = function set(network) {
|
||||
bcoin.network.set(network);
|
||||
bcoin.Network.set(network);
|
||||
return bcoin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache all necessary modules.
|
||||
*/
|
||||
|
||||
bcoin.cache = function cache() {
|
||||
bcoin.blockchain;
|
||||
bcoin.btc;
|
||||
bcoin.coins;
|
||||
bcoin.crypto;
|
||||
bcoin.hd;
|
||||
bcoin.http;
|
||||
bcoin.txmempool;
|
||||
bcoin.mining;
|
||||
bcoin.net;
|
||||
bcoin.node;
|
||||
bcoin.primitives;
|
||||
bcoin.protocol;
|
||||
bcoin.txscript;
|
||||
bcoin.utils;
|
||||
bcoin.wallet;
|
||||
bcoin.workers;
|
||||
bcoin.pkg;
|
||||
};
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
// Blockchain
|
||||
bcoin.define('blockchain', './blockchain');
|
||||
bcoin.define('chain', './blockchain/chain');
|
||||
bcoin.define('chaindb', './blockchain/chaindb');
|
||||
bcoin.define('chainentry', './blockchain/chainentry');
|
||||
bcoin.define('Chain', './blockchain/chain');
|
||||
bcoin.define('ChainEntry', './blockchain/chainentry');
|
||||
|
||||
// BTC
|
||||
bcoin.define('btc', './btc');
|
||||
bcoin.define('amount', './btc/amount');
|
||||
bcoin.define('uri', './btc/uri');
|
||||
bcoin.define('Amount', './btc/amount');
|
||||
bcoin.define('URI', './btc/uri');
|
||||
|
||||
// Coins
|
||||
bcoin.define('coins', './coins');
|
||||
bcoin.define('coinview', './coins/coinview');
|
||||
bcoin.define('Coins', './coins/coins');
|
||||
bcoin.define('CoinEntry', './coins/coinentry');
|
||||
bcoin.define('CoinView', './coins/coinview');
|
||||
|
||||
// HD
|
||||
bcoin.define('hd', './hd');
|
||||
bcoin.define('HDPrivateKey', './hd/private');
|
||||
bcoin.define('HDPublicKey', './hd/public');
|
||||
bcoin.define('Mnemonic', './hd/mnemonic');
|
||||
|
||||
// Mempool
|
||||
bcoin.define('txmempool', './mempool');
|
||||
bcoin.define('fees', './mempool/fees');
|
||||
bcoin.define('mempool', './mempool/mempool');
|
||||
bcoin.define('mempoolentry', './mempool/mempoolentry');
|
||||
bcoin.define('mempool', './mempool');
|
||||
bcoin.define('Fees', './mempool/fees');
|
||||
bcoin.define('Mempool', './mempool/mempool');
|
||||
bcoin.define('MempoolEntry', './mempool/mempoolentry');
|
||||
|
||||
// Miner
|
||||
bcoin.define('mining', './mining');
|
||||
bcoin.define('miner', './mining/miner');
|
||||
bcoin.define('template', './mining/template');
|
||||
bcoin.define('Miner', './mining/miner');
|
||||
|
||||
// Net
|
||||
bcoin.define('net', './net');
|
||||
bcoin.define('bip150', './net/bip150');
|
||||
bcoin.define('bip151', './net/bip151');
|
||||
bcoin.define('bip152', './net/bip152');
|
||||
bcoin.define('netaddress', './net/netaddress');
|
||||
bcoin.define('packets', './net/packets');
|
||||
bcoin.define('peer', './net/peer');
|
||||
bcoin.define('pool', './net/pool');
|
||||
bcoin.define('Peer', './net/peer');
|
||||
bcoin.define('Pool', './net/pool');
|
||||
|
||||
// Node
|
||||
bcoin.define('node', './node');
|
||||
bcoin.define('fullnode', './node/fullnode');
|
||||
bcoin.define('spvnode', './node/spvnode');
|
||||
bcoin.define('Node', './node/node');
|
||||
bcoin.define('FullNode', './node/fullnode');
|
||||
bcoin.define('SPVNode', './node/spvnode');
|
||||
|
||||
// Primitives
|
||||
bcoin.define('primitives', './primitives');
|
||||
bcoin.define('address', './primitives/address');
|
||||
bcoin.define('block', './primitives/block');
|
||||
bcoin.define('coin', './primitives/coin');
|
||||
bcoin.define('headers', './primitives/headers');
|
||||
bcoin.define('input', './primitives/input');
|
||||
bcoin.define('invitem', './primitives/invitem');
|
||||
bcoin.define('keyring', './primitives/keyring');
|
||||
bcoin.define('merkleblock', './primitives/merkleblock');
|
||||
bcoin.define('mtx', './primitives/mtx');
|
||||
bcoin.define('outpoint', './primitives/outpoint');
|
||||
bcoin.define('output', './primitives/output');
|
||||
bcoin.define('tx', './primitives/tx');
|
||||
bcoin.define('Address', './primitives/address');
|
||||
bcoin.define('Block', './primitives/block');
|
||||
bcoin.define('Coin', './primitives/coin');
|
||||
bcoin.define('Headers', './primitives/headers');
|
||||
bcoin.define('Input', './primitives/input');
|
||||
bcoin.define('InvItem', './primitives/invitem');
|
||||
bcoin.define('KeyRing', './primitives/keyring');
|
||||
bcoin.define('MerkleBlock', './primitives/merkleblock');
|
||||
bcoin.define('MTX', './primitives/mtx');
|
||||
bcoin.define('Outpoint', './primitives/outpoint');
|
||||
bcoin.define('Output', './primitives/output');
|
||||
bcoin.define('TX', './primitives/tx');
|
||||
|
||||
// Protocol
|
||||
bcoin.define('protocol', './protocol');
|
||||
bcoin.define('consensus', './protocol/consensus');
|
||||
bcoin.define('errors', './protocol/errors');
|
||||
bcoin.define('network', './protocol/network');
|
||||
bcoin.define('Network', './protocol/network');
|
||||
bcoin.define('networks', './protocol/networks');
|
||||
bcoin.define('policy', './protocol/policy');
|
||||
bcoin.define('timedata', './protocol/timedata');
|
||||
|
||||
// Script
|
||||
bcoin.define('txscript', './script');
|
||||
bcoin.define('opcode', './script/opcode');
|
||||
bcoin.define('program', './script/program');
|
||||
bcoin.define('script', './script/script');
|
||||
bcoin.define('scriptnum', './script/scriptnum');
|
||||
bcoin.define('sigcache', './script/sigcache');
|
||||
bcoin.define('stack', './script/stack');
|
||||
bcoin.define('witness', './script/witness');
|
||||
bcoin.define('script', './script');
|
||||
bcoin.define('Opcode', './script/opcode');
|
||||
bcoin.define('Program', './script/program');
|
||||
bcoin.define('Script', './script/script');
|
||||
bcoin.define('ScriptNum', './script/scriptnum');
|
||||
bcoin.define('SigCache', './script/sigcache');
|
||||
bcoin.define('Stack', './script/stack');
|
||||
bcoin.define('Witness', './script/witness');
|
||||
|
||||
// Utils
|
||||
bcoin.define('utils', './utils');
|
||||
bcoin.define('co', './utils/co');
|
||||
bcoin.define('lock', './utils/lock');
|
||||
bcoin.define('util', './utils/util');
|
||||
|
||||
// Wallet
|
||||
bcoin.define('wallet', './wallet');
|
||||
bcoin.define('path', './wallet/path');
|
||||
bcoin.define('walletkey', './wallet/walletkey');
|
||||
bcoin.define('walletdb', './wallet/walletdb');
|
||||
bcoin.define('Path', './wallet/path');
|
||||
bcoin.define('WalletKey', './wallet/walletkey');
|
||||
bcoin.define('WalletDB', './wallet/walletdb');
|
||||
|
||||
// Workers
|
||||
bcoin.define('workers', './workers');
|
||||
bcoin.define('workerpool', './workers/workerpool');
|
||||
bcoin.define('WorkerPool', './workers/workerpool');
|
||||
|
||||
// Package Info
|
||||
bcoin.define('pkg', './pkg');
|
||||
|
||||
@ -447,7 +447,7 @@ class HTTP extends Server {
|
||||
const start = valid.i32(0, -1);
|
||||
const end = valid.i32(1, -1);
|
||||
|
||||
return await this.chain.getHashes(start, end);
|
||||
return this.chain.getHashes(start, end);
|
||||
});
|
||||
|
||||
socket.hook('add filter', (...args) => {
|
||||
|
||||
@ -13,7 +13,7 @@ const Chain = require('../blockchain/chain');
|
||||
const Pool = require('../net/pool');
|
||||
const Node = require('./node');
|
||||
const HTTP = require('./http');
|
||||
const RPC = require('../rpc');
|
||||
const RPC = require('./rpc');
|
||||
|
||||
/**
|
||||
* SPV Node
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
* @const {String}
|
||||
*/
|
||||
|
||||
exports.version = 'v1.0.0-beta.14';
|
||||
exports.version = 'v1.0.0-beta.16';
|
||||
|
||||
/**
|
||||
* Repository URL.
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
exports.Account = require('./account');
|
||||
exports.Client = require('./client');
|
||||
exports.common = require('./common');
|
||||
exports.HTTPServer = require('./http');
|
||||
exports.HTTP = require('./http');
|
||||
exports.layout = require('./layout');
|
||||
exports.MasterKey = require('./masterkey');
|
||||
exports.NodeClient = require('./nodeclient');
|
||||
@ -21,7 +21,7 @@ exports.Path = require('./path');
|
||||
exports.plugin = require('./plugin');
|
||||
exports.records = require('./records');
|
||||
exports.RPC = require('./rpc');
|
||||
exports.server = require('./server');
|
||||
exports.Node = require('./node');
|
||||
exports.TXDB = require('./txdb');
|
||||
exports.WalletDB = require('./walletdb');
|
||||
exports.Wallet = require('./wallet');
|
||||
|
||||
@ -68,6 +68,7 @@ class WalletDB extends EventEmitter {
|
||||
this.wallets = new Map();
|
||||
this.depth = 0;
|
||||
this.rescanning = false;
|
||||
this.filterSent = false;
|
||||
|
||||
// Wallet read lock.
|
||||
this.readLock = new MapLock();
|
||||
@ -125,6 +126,10 @@ class WalletDB extends EventEmitter {
|
||||
}
|
||||
});
|
||||
|
||||
this.client.on('disconnect', async () => {
|
||||
this.filterSent = false;
|
||||
});
|
||||
|
||||
this.client.bind('block connect', async (entry, txs) => {
|
||||
try {
|
||||
await this.addBlock(entry, txs);
|
||||
@ -519,6 +524,7 @@ class WalletDB extends EventEmitter {
|
||||
this.logger.info('Sending filter to server (%dmb).',
|
||||
this.filter.size / 8 / (1 << 20));
|
||||
|
||||
this.filterSent = true;
|
||||
return this.client.setFilter(this.filter);
|
||||
}
|
||||
|
||||
@ -530,6 +536,8 @@ class WalletDB extends EventEmitter {
|
||||
*/
|
||||
|
||||
addFilter(data) {
|
||||
if (!this.filterSent)
|
||||
return undefined;
|
||||
return this.client.addFilter(data);
|
||||
}
|
||||
|
||||
@ -540,6 +548,8 @@ class WalletDB extends EventEmitter {
|
||||
*/
|
||||
|
||||
resetFilter() {
|
||||
if (!this.filterSent)
|
||||
return undefined;
|
||||
return this.client.resetFilter();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user