forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
bcoin.js
310 lines (280 loc) · 7.91 KB
/
bcoin.js
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*!
* bcoin.js - a javascript bitcoin library.
* Copyright (c) 2014-2015, Fedor Indutny (MIT License).
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
*/
/* eslint prefer-arrow-callback: "off" */
'use strict';
/**
* A bcoin "environment" which exposes all
* constructors for primitives, the blockchain,
* mempool, wallet, etc. It also exposes a
* global worker pool.
*
* @exports bcoin
* @type {Object}
*
* @property {Function} bn - See {@url https://github.com/indutny/bn.js}.
* @property {Object} elliptic - See {@url https://github.com/indutny/elliptic}.
*
* @property {Object} bip70 - See {@link module:bip70}.
*
* @property {Object} blockchain - See {@link module:blockchain}.
* @property {Function} chain - See {@link module:blockchain.Chain}.
* @property {Function} chaindb - See {@link module:blockchain.ChainDB}.
* @property {Function} chainentry - See {@link module:blockchain.ChainEntry}.
*
* @property {Object} btc
* @property {Function} amount
* @property {Function} uri
*
* @property {Object} coins
* @property {Function} coinview
*
* @property {Object} crypto
* @property {Object} secp256k1
* @property {Object} schnorr
*
* @property {Object} db
* @property {Object} ldb
*
* @property {Object} hd
*
* @property {Object} http
* @property {Object} rpc
*
* @property {Object} txmempool
* @property {Object} fees
* @property {Object} mempool
* @property {Object} mempoolentry
*
* @property {Object} mining
* @property {Object} miner
* @property {Object} minerblock
*
* @property {Object} net
* @property {Object} bip150
* @property {Object} bip151
* @property {Object} bip152
* @property {Object} dns
* @property {Object} packets
* @property {Object} peer
* @property {Object} pool
* @property {Object} tcp
*
* @property {Object} node
* @property {Object} config
* @property {Object} fullnode
* @property {Object} logger
* @property {Object} spvnode
*
* @property {Object} primitives
* @property {Object} address
* @property {Object} block
* @property {Object} coin
* @property {Object} headers
* @property {Object} input
* @property {Object} invitem
* @property {Object} keyring
* @property {Object} merkleblock
* @property {Object} mtx
* @property {Object} netaddress
* @property {Object} outpoint
* @property {Object} output
* @property {Object} tx
*
* @property {Object} protocol
* @property {Object} consensus
* @property {Object} errors
* @property {Object} network
* @property {Object} networks
* @property {Object} policy
* @property {Object} timedata
*
* @property {Object} txscript
* @property {Object} opcodes
* @property {Object} program
* @property {Object} script
* @property {Object} sigcache
* @property {Object} stack
* @property {Object} witness
*
* @property {Object} utils
* @property {Object} base32
* @property {Object} base58
* @property {Object} bloom
* @property {Object} co
* @property {Object} encoding
* @property {Object} lock
* @property {Object} reader
* @property {Object} staticwriter
* @property {Object} util
* @property {Object} writer
*
* @property {Object} wallet
* @property {Object} path
* @property {Object} walletkey
* @property {Object} walletdb
*
* @property {Object} workers
* @property {Object} workerpool
*/
const bcoin = exports;
/**
* Define a module for lazy loading.
* @param {String} name
* @param {String} path
*/
bcoin.define = function define(name, path) {
let cache;
Object.defineProperty(bcoin, name, {
get() {
if (!cache)
cache = require(path);
return cache;
}
});
};
/**
* Set the default network.
* @param {String} network
*/
bcoin.set = function set(network) {
bcoin.network.set(network);
return bcoin;
};
/**
* Cache all necessary modules.
*/
bcoin.cache = function cache() {
bcoin.bip70;
bcoin.blockchain;
bcoin.btc;
bcoin.coins;
bcoin.crypto;
bcoin.db;
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
*/
// Horrible BIP
bcoin.define('bip70', './bip70');
// Blockchain
bcoin.define('blockchain', './blockchain');
bcoin.define('chain', './blockchain/chain');
bcoin.define('chaindb', './blockchain/chaindb');
bcoin.define('chainentry', './blockchain/chainentry');
// BTC
bcoin.define('btc', './btc');
bcoin.define('amount', './btc/amount');
bcoin.define('uri', './btc/uri');
// Coins
bcoin.define('coins', './coins');
bcoin.define('coinview', './coins/coinview');
// Crypto
bcoin.define('crypto', './crypto');
bcoin.define('bn', './crypto/bn');
bcoin.define('secp256k1', './crypto/secp256k1');
bcoin.define('schnorr', './crypto/schnorr');
// DB
bcoin.define('db', './db');
bcoin.define('ldb', './db/ldb');
// HD
bcoin.define('hd', './hd');
// HTTP
bcoin.define('http', './http');
bcoin.define('rpc', './http/rpc');
// Mempool
bcoin.define('txmempool', './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');
// Net
bcoin.define('net', './net');
bcoin.define('bip150', './net/bip150');
bcoin.define('bip151', './net/bip151');
bcoin.define('bip152', './net/bip152');
bcoin.define('dns', './net/dns');
bcoin.define('packets', './net/packets');
bcoin.define('peer', './net/peer');
bcoin.define('pool', './net/pool');
bcoin.define('tcp', './net/tcp');
// Node
bcoin.define('node', './node');
bcoin.define('config', './node/config');
bcoin.define('fullnode', './node/fullnode');
bcoin.define('logger', './node/logger');
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('netaddress', './primitives/netaddress');
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('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');
// Utils
bcoin.define('utils', './utils');
bcoin.define('base32', './utils/base32');
bcoin.define('base58', './utils/base58');
bcoin.define('bloom', './utils/bloom');
bcoin.define('co', './utils/co');
bcoin.define('encoding', './utils/encoding');
bcoin.define('int64', './utils/int64');
bcoin.define('lock', './utils/lock');
bcoin.define('reader', './utils/reader');
bcoin.define('staticwriter', './utils/staticwriter');
bcoin.define('util', './utils/util');
bcoin.define('writer', './utils/writer');
// Wallet
bcoin.define('wallet', './wallet');
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');
// Package Info
bcoin.define('pkg', './pkg');