diff --git a/browser/wsproxy.js b/browser/wsproxy.js index 2588b448..5fce0994 100644 --- a/browser/wsproxy.js +++ b/browser/wsproxy.js @@ -39,7 +39,7 @@ function WSProxy(options) { this.init(); } -util.inherits(WSProxy, EventEmitter); +Object.setPrototypeOf(WSProxy.prototype, EventEmitter.prototype); WSProxy.prototype.init = function init() { this.io.on('error', (err) => { diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 56ca0bcb..4610fabd 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -86,7 +86,7 @@ function Chain(options) { this.db = new ChainDB(this); } -util.inherits(Chain, AsyncObject); +Object.setPrototypeOf(Chain.prototype, AsyncObject.prototype); /** * Open the chain, wait for the database to load. diff --git a/lib/http/base.js b/lib/http/base.js index a1dd0e9a..3af24188 100644 --- a/lib/http/base.js +++ b/lib/http/base.js @@ -50,7 +50,7 @@ function HTTPBase(options) { this._init(); } -util.inherits(HTTPBase, AsyncObject); +Object.setPrototypeOf(HTTPBase.prototype, AsyncObject.prototype); /** * Initialize server. @@ -1218,7 +1218,7 @@ function Request(req, res, url) { this.init(req, res, url); } -util.inherits(Request, EventEmitter); +Object.setPrototypeOf(Request.prototype, EventEmitter.prototype); Request.prototype.init = function init(req, res, url) { assert(req); @@ -1369,7 +1369,7 @@ function Response(req, res) { this.init(req, res); } -util.inherits(Response, EventEmitter); +Object.setPrototypeOf(Response.prototype, EventEmitter.prototype); Response.prototype.init = function init(req, res) { assert(req); @@ -1535,7 +1535,7 @@ function WebSocket(socket, ctx) { this.init(); } -util.inherits(WebSocket, EventEmitter); +Object.setPrototypeOf(WebSocket.prototype, EventEmitter.prototype); WebSocket.prototype.init = function init() { const socket = this.socket; diff --git a/lib/http/client.js b/lib/http/client.js index 48e1e935..6d7c6d15 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -10,7 +10,6 @@ const Network = require('../protocol/network'); const AsyncObject = require('../utils/asyncobject'); const RPCClient = require('./rpcclient'); -const util = require('../utils/util'); const request = require('./request'); /** @@ -43,7 +42,7 @@ function HTTPClient(options) { this.rpc = new RPCClient(options); } -util.inherits(HTTPClient, AsyncObject); +Object.setPrototypeOf(HTTPClient.prototype, AsyncObject.prototype); /** * Open the client, wait for socket to connect. diff --git a/lib/http/rpc.js b/lib/http/rpc.js index e133c5cd..a146fb34 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -75,7 +75,7 @@ function RPC(node) { this.init(); } -util.inherits(RPC, RPCBase); +Object.setPrototypeOf(RPC.prototype, RPCBase.prototype); RPC.prototype.init = function init() { this.add('stop', this.stop); diff --git a/lib/http/rpcbase.js b/lib/http/rpcbase.js index 987924b5..038c1550 100644 --- a/lib/http/rpcbase.js +++ b/lib/http/rpcbase.js @@ -8,7 +8,6 @@ const assert = require('assert'); const EventEmitter = require('events'); -const util = require('../utils/util'); const Lock = require('../utils/lock'); const Logger = require('../node/logger'); @@ -30,7 +29,7 @@ function RPCBase() { this.locker = new Lock(); } -util.inherits(RPCBase, EventEmitter); +Object.setPrototypeOf(RPCBase.prototype, EventEmitter.prototype); /** * RPC errors. @@ -312,7 +311,7 @@ function RPCError(code, msg) { Error.captureStackTrace(this, RPCError); } -util.inherits(RPCError, Error); +Object.setPrototypeOf(RPCError.prototype, Error.prototype); /* * Expose diff --git a/lib/http/rpcclient.js b/lib/http/rpcclient.js index 75e869e6..c8a498bd 100644 --- a/lib/http/rpcclient.js +++ b/lib/http/rpcclient.js @@ -8,7 +8,6 @@ const Network = require('../protocol/network'); const request = require('./request'); -const util = require('../utils/util'); /** * Bcoin RPC client. @@ -93,7 +92,7 @@ function RPCError(msg, code) { Error.captureStackTrace(this, RPCError); } -util.inherits(RPCError, Error); +Object.setPrototypeOf(RPCError.prototype, Error.prototype); /* * Expose diff --git a/lib/http/server.js b/lib/http/server.js index a68cf252..e21b855a 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -55,7 +55,7 @@ function HTTPServer(options) { this.init(); } -util.inherits(HTTPServer, HTTPBase); +Object.setPrototypeOf(HTTPServer.prototype, HTTPBase.prototype); /** * Initialize routes. diff --git a/lib/http/wallet.js b/lib/http/wallet.js index a79847c1..8111ff99 100644 --- a/lib/http/wallet.js +++ b/lib/http/wallet.js @@ -10,7 +10,6 @@ const assert = require('assert'); const EventEmitter = require('events'); const Network = require('../protocol/network'); -const util = require('../utils/util'); const Client = require('./client'); /** @@ -53,7 +52,7 @@ function HTTPWallet(options) { this._init(); } -util.inherits(HTTPWallet, EventEmitter); +Object.setPrototypeOf(HTTPWallet.prototype, EventEmitter.prototype); /** * Initialize the wallet. diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 7c7c9ff2..e7ce9b49 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -95,7 +95,7 @@ function Mempool(options) { this.txIndex = new TXIndex(); } -util.inherits(Mempool, AsyncObject); +Object.setPrototypeOf(Mempool.prototype, AsyncObject.prototype); /** * Open the chain, wait for the database to load. diff --git a/lib/mining/cpuminer.js b/lib/mining/cpuminer.js index 0ea901eb..6bb7cda5 100644 --- a/lib/mining/cpuminer.js +++ b/lib/mining/cpuminer.js @@ -44,7 +44,7 @@ function CPUMiner(miner) { this._init(); } -util.inherits(CPUMiner, AsyncObject); +Object.setPrototypeOf(CPUMiner.prototype, AsyncObject.prototype); /** * Nonce range interval. diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 21c680a1..6b19a254 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -46,7 +46,7 @@ function Miner(options) { this.init(); } -util.inherits(Miner, AsyncObject); +Object.setPrototypeOf(Miner.prototype, AsyncObject.prototype); /** * Open the miner, wait for the chain and mempool to load. diff --git a/lib/net/bip150.js b/lib/net/bip150.js index 36206165..1251ddb4 100644 --- a/lib/net/bip150.js +++ b/lib/net/bip150.js @@ -11,7 +11,6 @@ const assert = require('assert'); const path = require('path'); const EventEmitter = require('events'); -const util = require('../utils/util'); const co = require('../utils/co'); const digest = require('../crypto/digest'); const random = require('../crypto/random'); @@ -87,7 +86,7 @@ function BIP150(bip151, host, outbound, db, key) { this._init(); } -util.inherits(BIP150, EventEmitter); +Object.setPrototypeOf(BIP150.prototype, EventEmitter.prototype); /** * Initialize BIP150. diff --git a/lib/net/bip151.js b/lib/net/bip151.js index 50938f1b..cdfa2020 100644 --- a/lib/net/bip151.js +++ b/lib/net/bip151.js @@ -329,7 +329,7 @@ function BIP151(cipher) { this.bip150 = null; } -util.inherits(BIP151, EventEmitter); +Object.setPrototypeOf(BIP151.prototype, EventEmitter.prototype); /** * Cipher list. diff --git a/lib/net/bip152.js b/lib/net/bip152.js index f2e44d72..28e42f28 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -59,7 +59,7 @@ function CompactBlock(options) { this.fromOptions(options); } -util.inherits(CompactBlock, AbstractBlock); +Object.setPrototypeOf(CompactBlock.prototype, AbstractBlock.prototype); /** * Inject properties from options object. diff --git a/lib/net/packets.js b/lib/net/packets.js index de225b70..c1702512 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -180,7 +180,7 @@ function VersionPacket(options) { this.fromOptions(options); } -util.inherits(VersionPacket, Packet); +Object.setPrototypeOf(VersionPacket.prototype, Packet.prototype); VersionPacket.prototype.cmd = 'version'; VersionPacket.prototype.type = exports.types.VERSION; @@ -366,7 +366,7 @@ function VerackPacket() { Packet.call(this); } -util.inherits(VerackPacket, Packet); +Object.setPrototypeOf(VerackPacket.prototype, Packet.prototype); VerackPacket.prototype.cmd = 'verack'; VerackPacket.prototype.type = exports.types.VERACK; @@ -410,7 +410,7 @@ function PingPacket(nonce) { this.nonce = nonce || null; } -util.inherits(PingPacket, Packet); +Object.setPrototypeOf(PingPacket.prototype, Packet.prototype); PingPacket.prototype.cmd = 'ping'; PingPacket.prototype.type = exports.types.PING; @@ -506,7 +506,7 @@ function PongPacket(nonce) { this.nonce = nonce || encoding.ZERO_U64; } -util.inherits(PongPacket, Packet); +Object.setPrototypeOf(PongPacket.prototype, Packet.prototype); PongPacket.prototype.cmd = 'pong'; PongPacket.prototype.type = exports.types.PONG; @@ -595,7 +595,7 @@ function GetAddrPacket() { Packet.call(this); } -util.inherits(GetAddrPacket, Packet); +Object.setPrototypeOf(GetAddrPacket.prototype, Packet.prototype); GetAddrPacket.prototype.cmd = 'getaddr'; GetAddrPacket.prototype.type = exports.types.GETADDR; @@ -639,7 +639,7 @@ function AddrPacket(items) { this.items = items || []; } -util.inherits(AddrPacket, Packet); +Object.setPrototypeOf(AddrPacket.prototype, Packet.prototype); AddrPacket.prototype.cmd = 'addr'; AddrPacket.prototype.type = exports.types.ADDR; @@ -735,7 +735,7 @@ function InvPacket(items) { this.items = items || []; } -util.inherits(InvPacket, Packet); +Object.setPrototypeOf(InvPacket.prototype, Packet.prototype); InvPacket.prototype.cmd = 'inv'; InvPacket.prototype.type = exports.types.INV; @@ -842,7 +842,7 @@ function GetDataPacket(items) { InvPacket.call(this, items); } -util.inherits(GetDataPacket, InvPacket); +Object.setPrototypeOf(GetDataPacket.prototype, InvPacket.prototype); GetDataPacket.prototype.cmd = 'getdata'; GetDataPacket.prototype.type = exports.types.GETDATA; @@ -884,7 +884,7 @@ function NotFoundPacket(items) { InvPacket.call(this, items); } -util.inherits(NotFoundPacket, InvPacket); +Object.setPrototypeOf(NotFoundPacket.prototype, InvPacket.prototype); NotFoundPacket.prototype.cmd = 'notfound'; NotFoundPacket.prototype.type = exports.types.NOTFOUND; @@ -932,7 +932,7 @@ function GetBlocksPacket(locator, stop) { this.stop = stop || null; } -util.inherits(GetBlocksPacket, Packet); +Object.setPrototypeOf(GetBlocksPacket.prototype, Packet.prototype); GetBlocksPacket.prototype.cmd = 'getblocks'; GetBlocksPacket.prototype.type = exports.types.GETBLOCKS; @@ -1042,7 +1042,7 @@ function GetHeadersPacket(locator, stop) { GetBlocksPacket.call(this, locator, stop); } -util.inherits(GetHeadersPacket, GetBlocksPacket); +Object.setPrototypeOf(GetHeadersPacket.prototype, GetBlocksPacket.prototype); GetHeadersPacket.prototype.cmd = 'getheaders'; GetHeadersPacket.prototype.type = exports.types.GETHEADERS; @@ -1086,7 +1086,7 @@ function HeadersPacket(items) { this.items = items || []; } -util.inherits(HeadersPacket, Packet); +Object.setPrototypeOf(HeadersPacket.prototype, Packet.prototype); HeadersPacket.prototype.cmd = 'headers'; HeadersPacket.prototype.type = exports.types.HEADERS; @@ -1185,7 +1185,7 @@ function SendHeadersPacket() { Packet.call(this); } -util.inherits(SendHeadersPacket, Packet); +Object.setPrototypeOf(SendHeadersPacket.prototype, Packet.prototype); SendHeadersPacket.prototype.cmd = 'sendheaders'; SendHeadersPacket.prototype.type = exports.types.SENDHEADERS; @@ -1232,7 +1232,7 @@ function BlockPacket(block, witness) { this.witness = witness || false; } -util.inherits(BlockPacket, Packet); +Object.setPrototypeOf(BlockPacket.prototype, Packet.prototype); BlockPacket.prototype.cmd = 'block'; BlockPacket.prototype.type = exports.types.BLOCK; @@ -1334,7 +1334,7 @@ function TXPacket(tx, witness) { this.witness = witness || false; } -util.inherits(TXPacket, Packet); +Object.setPrototypeOf(TXPacket.prototype, Packet.prototype); TXPacket.prototype.cmd = 'tx'; TXPacket.prototype.type = exports.types.TX; @@ -1442,7 +1442,7 @@ function RejectPacket(options) { this.fromOptions(options); } -util.inherits(RejectPacket, Packet); +Object.setPrototypeOf(RejectPacket.prototype, Packet.prototype); /** * Reject codes. Note that `internal` and higher @@ -1729,7 +1729,7 @@ function MempoolPacket() { Packet.call(this); } -util.inherits(MempoolPacket, Packet); +Object.setPrototypeOf(MempoolPacket.prototype, Packet.prototype); MempoolPacket.prototype.cmd = 'mempool'; MempoolPacket.prototype.type = exports.types.MEMPOOL; @@ -1772,7 +1772,7 @@ function FilterLoadPacket(filter) { this.filter = filter || new Bloom(); } -util.inherits(FilterLoadPacket, Packet); +Object.setPrototypeOf(FilterLoadPacket.prototype, Packet.prototype); FilterLoadPacket.prototype.cmd = 'filterload'; FilterLoadPacket.prototype.type = exports.types.FILTERLOAD; @@ -1874,7 +1874,7 @@ function FilterAddPacket(data) { this.data = data || DUMMY; } -util.inherits(FilterAddPacket, Packet); +Object.setPrototypeOf(FilterAddPacket.prototype, Packet.prototype); FilterAddPacket.prototype.cmd = 'filteradd'; FilterAddPacket.prototype.type = exports.types.FILTERADD; @@ -1954,7 +1954,7 @@ function FilterClearPacket() { Packet.call(this); } -util.inherits(FilterClearPacket, Packet); +Object.setPrototypeOf(FilterClearPacket.prototype, Packet.prototype); FilterClearPacket.prototype.cmd = 'filterclear'; FilterClearPacket.prototype.type = exports.types.FILTERCLEAR; @@ -1988,7 +1988,7 @@ function MerkleBlockPacket(block) { this.block = block || new MerkleBlock(); } -util.inherits(MerkleBlockPacket, Packet); +Object.setPrototypeOf(MerkleBlockPacket.prototype, Packet.prototype); MerkleBlockPacket.prototype.cmd = 'merkleblock'; MerkleBlockPacket.prototype.type = exports.types.MERKLEBLOCK; @@ -2071,7 +2071,7 @@ function FeeFilterPacket(rate) { this.rate = rate || 0; } -util.inherits(FeeFilterPacket, Packet); +Object.setPrototypeOf(FeeFilterPacket.prototype, Packet.prototype); FeeFilterPacket.prototype.cmd = 'feefilter'; FeeFilterPacket.prototype.type = exports.types.FEEFILTER; @@ -2167,7 +2167,7 @@ function SendCmpctPacket(mode, version) { this.version = version || 1; } -util.inherits(SendCmpctPacket, Packet); +Object.setPrototypeOf(SendCmpctPacket.prototype, Packet.prototype); SendCmpctPacket.prototype.cmd = 'sendcmpct'; SendCmpctPacket.prototype.type = exports.types.SENDCMPCT; @@ -2275,7 +2275,7 @@ function CmpctBlockPacket(block, witness) { this.witness = witness || false; } -util.inherits(CmpctBlockPacket, Packet); +Object.setPrototypeOf(CmpctBlockPacket.prototype, Packet.prototype); CmpctBlockPacket.prototype.cmd = 'cmpctblock'; CmpctBlockPacket.prototype.type = exports.types.CMPCTBLOCK; @@ -2374,7 +2374,7 @@ function GetBlockTxnPacket(request) { this.request = request || new bip152.TXRequest(); } -util.inherits(GetBlockTxnPacket, Packet); +Object.setPrototypeOf(GetBlockTxnPacket.prototype, Packet.prototype); GetBlockTxnPacket.prototype.cmd = 'getblocktxn'; GetBlockTxnPacket.prototype.type = exports.types.GETBLOCKTXN; @@ -2470,7 +2470,7 @@ function BlockTxnPacket(response, witness) { this.witness = witness || false; } -util.inherits(BlockTxnPacket, Packet); +Object.setPrototypeOf(BlockTxnPacket.prototype, Packet.prototype); BlockTxnPacket.prototype.cmd = 'blocktxn'; BlockTxnPacket.prototype.type = exports.types.BLOCKTXN; @@ -2572,7 +2572,7 @@ function EncinitPacket(publicKey, cipher) { this.cipher = cipher || 0; } -util.inherits(EncinitPacket, Packet); +Object.setPrototypeOf(EncinitPacket.prototype, Packet.prototype); EncinitPacket.prototype.cmd = 'encinit'; EncinitPacket.prototype.type = exports.types.ENCINIT; @@ -2667,7 +2667,7 @@ function EncackPacket(publicKey) { this.publicKey = publicKey || encoding.ZERO_KEY; } -util.inherits(EncackPacket, Packet); +Object.setPrototypeOf(EncackPacket.prototype, Packet.prototype); EncackPacket.prototype.cmd = 'encack'; EncackPacket.prototype.type = exports.types.ENCACK; @@ -2760,7 +2760,7 @@ function AuthChallengePacket(hash) { this.hash = hash || encoding.ZERO_HASH; } -util.inherits(AuthChallengePacket, Packet); +Object.setPrototypeOf(AuthChallengePacket.prototype, Packet.prototype); AuthChallengePacket.prototype.cmd = 'authchallenge'; AuthChallengePacket.prototype.type = exports.types.AUTHCHALLENGE; @@ -2853,7 +2853,7 @@ function AuthReplyPacket(signature) { this.signature = signature || encoding.ZERO_SIG64; } -util.inherits(AuthReplyPacket, Packet); +Object.setPrototypeOf(AuthReplyPacket.prototype, Packet.prototype); AuthReplyPacket.prototype.cmd = 'authreply'; AuthReplyPacket.prototype.type = exports.types.AUTHREPLY; @@ -2946,7 +2946,7 @@ function AuthProposePacket(hash) { this.hash = hash || encoding.ZERO_HASH; } -util.inherits(AuthProposePacket, Packet); +Object.setPrototypeOf(AuthProposePacket.prototype, Packet.prototype); AuthProposePacket.prototype.cmd = 'authpropose'; AuthProposePacket.prototype.type = exports.types.AUTHPROPOSE; @@ -3042,7 +3042,7 @@ function UnknownPacket(cmd, data) { this.data = data; } -util.inherits(UnknownPacket, Packet); +Object.setPrototypeOf(UnknownPacket.prototype, Packet.prototype); UnknownPacket.prototype.type = exports.types.UNKNOWN; diff --git a/lib/net/parser.js b/lib/net/parser.js index 96535d58..2a0ddfb5 100644 --- a/lib/net/parser.js +++ b/lib/net/parser.js @@ -40,7 +40,7 @@ function Parser(network) { this.header = null; } -util.inherits(Parser, EventEmitter); +Object.setPrototypeOf(Parser.prototype, EventEmitter.prototype); /** * Emit an error. diff --git a/lib/net/peer.js b/lib/net/peer.js index e719286d..ea4f5055 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -146,7 +146,7 @@ function Peer(options) { this._init(); } -util.inherits(Peer, EventEmitter); +Object.setPrototypeOf(Peer.prototype, EventEmitter.prototype); /** * Max output bytes buffered before diff --git a/lib/net/pool.js b/lib/net/pool.js index cfd92317..e12f2f55 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -119,7 +119,7 @@ function Pool(options) { this._init(); }; -util.inherits(Pool, AsyncObject); +Object.setPrototypeOf(Pool.prototype, AsyncObject.prototype); /** * Discovery interval for UPNP and DNS seeds. @@ -4189,7 +4189,7 @@ function BroadcastItem(pool, msg) { this.jobs = []; } -util.inherits(BroadcastItem, EventEmitter); +Object.setPrototypeOf(BroadcastItem.prototype, EventEmitter.prototype); /** * Add a job to be executed on ack, timeout, or reject. diff --git a/lib/net/proxysocket.js b/lib/net/proxysocket.js index f6949acd..80f91641 100644 --- a/lib/net/proxysocket.js +++ b/lib/net/proxysocket.js @@ -36,7 +36,7 @@ function ProxySocket(uri) { this._init(); } -util.inherits(ProxySocket, EventEmitter); +Object.setPrototypeOf(ProxySocket.prototype, EventEmitter.prototype); ProxySocket.prototype._init = function _init() { this.socket.on('info', (info) => { diff --git a/lib/net/socks.js b/lib/net/socks.js index 2a21b5c7..e0282fa5 100644 --- a/lib/net/socks.js +++ b/lib/net/socks.js @@ -42,7 +42,7 @@ function SOCKS() { this.proxied = false; } -util.inherits(SOCKS, EventEmitter); +Object.setPrototypeOf(SOCKS.prototype, EventEmitter.prototype); SOCKS.states = { INIT: 0, @@ -553,7 +553,7 @@ function Proxy(host, port, user, pass) { this.ops = []; } -util.inherits(Proxy, EventEmitter); +Object.setPrototypeOf(Proxy.prototype, EventEmitter.prototype); Proxy.prototype.connect = async function connect(port, host) { assert(!this.socket, 'Already connected.'); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 0ad663a1..7be09415 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -7,8 +7,6 @@ 'use strict'; -const util = require('../utils/util'); -const Node = require('./node'); const Chain = require('../blockchain/chain'); const Fees = require('../mempool/fees'); const Mempool = require('../mempool/mempool'); @@ -16,6 +14,7 @@ const Pool = require('../net/pool'); const Miner = require('../mining/miner'); const HTTPServer = require('../http/server'); const RPC = require('../http/rpc'); +const Node = require('./node'); /** * Respresents a fullnode complete with a @@ -157,7 +156,7 @@ function FullNode(options) { this._init(); } -util.inherits(FullNode, Node); +Object.setPrototypeOf(FullNode.prototype, Node.prototype); /** * Initialize the node. diff --git a/lib/node/node.js b/lib/node/node.js index 9e9d7f86..4615be3e 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -59,7 +59,7 @@ function Node(options) { this.init(); } -util.inherits(Node, AsyncObject); +Object.setPrototypeOf(Node.prototype, AsyncObject.prototype); /** * Initialize options. diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index ab852fba..eb96fc9d 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -7,13 +7,12 @@ 'use strict'; -const util = require('../utils/util'); const Lock = require('../utils/lock'); -const Node = require('./node'); const Chain = require('../blockchain/chain'); const Pool = require('../net/pool'); const HTTPServer = require('../http/server'); const RPC = require('../http/rpc'); +const Node = require('./node'); /** * Create an spv node which only maintains @@ -104,7 +103,7 @@ function SPVNode(options) { this._init(); } -util.inherits(SPVNode, Node); +Object.setPrototypeOf(SPVNode.prototype, Node.prototype); /** * Initialize the node. diff --git a/lib/primitives/block.js b/lib/primitives/block.js index 937aec2a..09bda2e2 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -45,7 +45,7 @@ function Block(options) { this.fromOptions(options); } -util.inherits(Block, AbstractBlock); +Object.setPrototypeOf(Block.prototype, AbstractBlock.prototype); /** * Inject properties from options object. diff --git a/lib/primitives/coin.js b/lib/primitives/coin.js index 6a32d420..f4c5101a 100644 --- a/lib/primitives/coin.js +++ b/lib/primitives/coin.js @@ -49,7 +49,7 @@ function Coin(options) { this.fromOptions(options); } -util.inherits(Coin, Output); +Object.setPrototypeOf(Coin.prototype, Output.prototype); /** * Inject options into coin. diff --git a/lib/primitives/headers.js b/lib/primitives/headers.js index 2c5ce7fc..ecbda889 100644 --- a/lib/primitives/headers.js +++ b/lib/primitives/headers.js @@ -30,7 +30,7 @@ function Headers(options) { this.parseOptions(options); } -util.inherits(Headers, AbstractBlock); +Object.setPrototypeOf(Headers.prototype, AbstractBlock.prototype); /** * Do non-contextual verification on the headers. diff --git a/lib/primitives/memblock.js b/lib/primitives/memblock.js index c72f0e67..fb91ec68 100644 --- a/lib/primitives/memblock.js +++ b/lib/primitives/memblock.js @@ -7,11 +7,10 @@ 'use strict'; -const util = require('../utils/util'); const AbstractBlock = require('./abstractblock'); const Block = require('./block'); -const Script = require('../script/script'); const Headers = require('./headers'); +const Script = require('../script/script'); const BufferReader = require('../utils/reader'); const DUMMY = Buffer.alloc(0); @@ -45,7 +44,7 @@ function MemBlock() { this._raw = DUMMY; } -util.inherits(MemBlock, AbstractBlock); +Object.setPrototypeOf(MemBlock.prototype, AbstractBlock.prototype); /** * Test whether the block is a memblock. diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index 8800e115..0d7b094e 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -43,7 +43,7 @@ function MerkleBlock(options) { this.fromOptions(options); } -util.inherits(MerkleBlock, AbstractBlock); +Object.setPrototypeOf(MerkleBlock.prototype, AbstractBlock.prototype); /** * Inject properties from options object. diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index f41c66cd..f81fd308 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -56,7 +56,7 @@ function MTX(options) { this.fromOptions(options); } -util.inherits(MTX, TX); +Object.setPrototypeOf(MTX.prototype, TX.prototype); /** * Inject properties from options object. @@ -1818,7 +1818,7 @@ function FundingError(msg, available, required) { Error.captureStackTrace(this, FundingError); } -util.inherits(FundingError, Error); +Object.setPrototypeOf(FundingError.prototype, Error.prototype); /* * Helpers diff --git a/lib/protocol/errors.js b/lib/protocol/errors.js index bafdc6ec..765e4356 100644 --- a/lib/protocol/errors.js +++ b/lib/protocol/errors.js @@ -12,7 +12,6 @@ */ const assert = require('assert'); -const util = require('../utils/util'); /** * An error thrown during verification. Can be either @@ -57,7 +56,7 @@ function VerifyError(msg, code, reason, score, malleated) { Error.captureStackTrace(this, VerifyError); } -util.inherits(VerifyError, Error); +Object.setPrototypeOf(VerifyError.prototype, Error.prototype); /* * Expose diff --git a/lib/protocol/timedata.js b/lib/protocol/timedata.js index 8d8a30e7..ddefcc14 100644 --- a/lib/protocol/timedata.js +++ b/lib/protocol/timedata.js @@ -40,7 +40,7 @@ function TimeData(limit) { this.checked = false; } -util.inherits(TimeData, EventEmitter); +Object.setPrototypeOf(TimeData.prototype, EventEmitter.prototype); /** * Add time data. diff --git a/lib/script/common.js b/lib/script/common.js index 72fbb45a..0fb0186c 100644 --- a/lib/script/common.js +++ b/lib/script/common.js @@ -834,4 +834,4 @@ exports.ScriptError = function ScriptError(code, op, ip) { Error.captureStackTrace(this, ScriptError); }; -util.inherits(exports.ScriptError, Error); +Object.setPrototypeOf(exports.ScriptError.prototype, Error.prototype); diff --git a/lib/utils/asyncobject.js b/lib/utils/asyncobject.js index 1ee2286a..3e306f42 100644 --- a/lib/utils/asyncobject.js +++ b/lib/utils/asyncobject.js @@ -8,7 +8,6 @@ const assert = require('assert'); const EventEmitter = require('events'); -const util = require('./util'); const Lock = require('./lock'); /** @@ -34,7 +33,7 @@ function AsyncObject() { this.loaded = false; } -util.inherits(AsyncObject, EventEmitter); +Object.setPrototypeOf(AsyncObject.prototype, EventEmitter.prototype); /** * Open the object (recallable). diff --git a/lib/utils/encoding.js b/lib/utils/encoding.js index c46e8aac..c5e56e06 100644 --- a/lib/utils/encoding.js +++ b/lib/utils/encoding.js @@ -12,7 +12,6 @@ */ const BN = require('bn.js'); -const util = require('./util'); const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; const encoding = exports; @@ -1038,7 +1037,7 @@ encoding.EncodingError = function EncodingError(offset, reason) { Error.captureStackTrace(this, EncodingError); }; -util.inherits(encoding.EncodingError, Error); +Object.setPrototypeOf(encoding.EncodingError.prototype, Error.prototype); /* * Helpers diff --git a/lib/utils/protoreader.js b/lib/utils/protoreader.js index 8a34f128..28bb9c57 100644 --- a/lib/utils/protoreader.js +++ b/lib/utils/protoreader.js @@ -7,7 +7,6 @@ 'use strict'; const assert = require('assert'); -const util = require('../utils/util'); const BufferReader = require('../utils/reader'); /* @@ -36,7 +35,7 @@ function ProtoReader(data, zeroCopy) { BufferReader.call(this, data, zeroCopy); } -util.inherits(ProtoReader, BufferReader); +Object.setPrototypeOf(ProtoReader.prototype, BufferReader.prototype); ProtoReader.prototype.readVarint = function _readVarint() { const {size, value} = readVarint(this.data, this.offset); diff --git a/lib/utils/protowriter.js b/lib/utils/protowriter.js index aaa8ad60..5950d227 100644 --- a/lib/utils/protowriter.js +++ b/lib/utils/protowriter.js @@ -11,7 +11,6 @@ */ const assert = require('assert'); -const util = require('../utils/util'); const BufferWriter = require('../utils/writer'); /* @@ -40,7 +39,7 @@ function ProtoWriter() { BufferWriter.call(this); } -util.inherits(ProtoWriter, BufferWriter); +Object.setPrototypeOf(ProtoWriter.prototype, BufferWriter.prototype); ProtoWriter.prototype.writeVarint = function _writeVarint(num) { const size = sizeVarint(num); diff --git a/lib/utils/util.js b/lib/utils/util.js index 3d57d481..bb955f88 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -509,21 +509,6 @@ util.mb = function mb(size) { return Math.floor(size / 1024 / 1024); }; -/** - * Inheritance. - * @param {Function} child - Constructor to inherit. - * @param {Function} parent - Parent constructor. - */ - -util.inherits = function inherits(child, parent) { - child.super_ = parent; - Object.setPrototypeOf(child.prototype, parent.prototype); - Object.defineProperty(child.prototype, 'constructor', { - value: child, - enumerable: false - }); -}; - /** * Find index of a buffer in an array of buffers. * @param {Buffer[]} items diff --git a/lib/utils/validator.js b/lib/utils/validator.js index 3ec7d5f9..3603eb20 100644 --- a/lib/utils/validator.js +++ b/lib/utils/validator.js @@ -689,7 +689,7 @@ function ValidationError(key, type) { Error.captureStackTrace(this, ValidationError); } -util.inherits(ValidationError, Error); +Object.setPrototypeOf(ValidationError.prototype, Error.prototype); /* * Expose diff --git a/lib/wallet/client.js b/lib/wallet/client.js index 04c74c54..e5281f92 100644 --- a/lib/wallet/client.js +++ b/lib/wallet/client.js @@ -44,7 +44,7 @@ function WalletClient(options) { this.socket = null; } -util.inherits(WalletClient, AsyncObject); +Object.setPrototypeOf(WalletClient.prototype, AsyncObject.prototype); /** * Open the client, wait for socket to connect. diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 0c650b85..6f60391e 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -52,7 +52,7 @@ function HTTPServer(options) { this.init(); } -util.inherits(HTTPServer, HTTPBase); +Object.setPrototypeOf(HTTPServer.prototype, HTTPBase.prototype); /** * Attach to server. diff --git a/lib/wallet/nodeclient.js b/lib/wallet/nodeclient.js index 17e3a721..d28cca2e 100644 --- a/lib/wallet/nodeclient.js +++ b/lib/wallet/nodeclient.js @@ -6,7 +6,6 @@ 'use strict'; -const util = require('../utils/util'); const AsyncObject = require('../utils/asyncobject'); /** @@ -30,7 +29,7 @@ function NodeClient(node) { this._init(); } -util.inherits(NodeClient, AsyncObject); +Object.setPrototypeOf(NodeClient.prototype, AsyncObject.prototype); /** * Initialize the client. diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js index 8c5218ad..4d13174e 100644 --- a/lib/wallet/rpc.js +++ b/lib/wallet/rpc.js @@ -54,7 +54,7 @@ function RPC(wdb) { this.init(); } -util.inherits(RPC, RPCBase); +Object.setPrototypeOf(RPC.prototype, RPCBase.prototype); RPC.prototype.init = function init() { this.add('help', this.help); diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index be7faefc..5a506311 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -95,7 +95,7 @@ function Wallet(db, options) { this.fromOptions(options); } -util.inherits(Wallet, EventEmitter); +Object.setPrototypeOf(Wallet.prototype, EventEmitter.prototype); /** * Inject properties from options object. diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index a89fd5be..0dd42a7e 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -101,7 +101,7 @@ function WalletDB(options) { this._init(); } -util.inherits(WalletDB, AsyncObject); +Object.setPrototypeOf(WalletDB.prototype, AsyncObject.prototype); /** * Database layout. diff --git a/lib/wallet/walletkey.js b/lib/wallet/walletkey.js index 008561be..92152339 100644 --- a/lib/wallet/walletkey.js +++ b/lib/wallet/walletkey.js @@ -7,7 +7,6 @@ 'use strict'; -const util = require('../utils/util'); const Address = require('../primitives/address'); const KeyRing = require('../primitives/keyring'); const Path = require('./path'); @@ -35,7 +34,7 @@ function WalletKey(options, network) { this.index = -1; } -util.inherits(WalletKey, KeyRing); +Object.setPrototypeOf(WalletKey.prototype, KeyRing.prototype); /** * Instantiate key ring from options. diff --git a/lib/workers/child-browser.js b/lib/workers/child-browser.js index aac029c1..8e10f85d 100644 --- a/lib/workers/child-browser.js +++ b/lib/workers/child-browser.js @@ -8,7 +8,6 @@ const assert = require('assert'); const EventEmitter = require('events'); -const util = require('../utils/util'); /** * Represents a child process. @@ -27,7 +26,7 @@ function Child(file) { this.init(file); } -util.inherits(Child, EventEmitter); +Object.setPrototypeOf(Child.prototype, EventEmitter.prototype); /** * Test whether child process support is available. diff --git a/lib/workers/child.js b/lib/workers/child.js index 6b1430aa..02aad7f1 100644 --- a/lib/workers/child.js +++ b/lib/workers/child.js @@ -9,7 +9,6 @@ const EventEmitter = require('events'); const path = require('path'); const cp = require('child_process'); -const util = require('../utils/util'); const children = new Set(); let exitBound = false; @@ -33,7 +32,7 @@ function Child(file) { this.init(file); } -util.inherits(Child, EventEmitter); +Object.setPrototypeOf(Child.prototype, EventEmitter.prototype); /** * Test whether child process support is available. diff --git a/lib/workers/master.js b/lib/workers/master.js index 7303d860..9cc109f6 100644 --- a/lib/workers/master.js +++ b/lib/workers/master.js @@ -38,7 +38,7 @@ function Master() { this.init(); } -util.inherits(Master, EventEmitter); +Object.setPrototypeOf(Master.prototype, EventEmitter.prototype); /** * Initialize master. Bind events. diff --git a/lib/workers/packets.js b/lib/workers/packets.js index 0cba880d..ba0503b5 100644 --- a/lib/workers/packets.js +++ b/lib/workers/packets.js @@ -11,7 +11,6 @@ */ const assert = require('assert'); -const util = require('../utils/util'); const BufferReader = require('../utils/reader'); const encoding = require('../utils/encoding'); const Script = require('../script/script'); @@ -79,7 +78,7 @@ function EnvPacket(env) { this.json = JSON.stringify(this.env); } -util.inherits(EnvPacket, Packet); +Object.setPrototypeOf(EnvPacket.prototype, Packet.prototype); EnvPacket.prototype.cmd = packetTypes.ENV; @@ -110,7 +109,7 @@ function EventPacket(items) { this.json = JSON.stringify(this.items); } -util.inherits(EventPacket, Packet); +Object.setPrototypeOf(EventPacket.prototype, Packet.prototype); EventPacket.prototype.cmd = packetTypes.EVENT; @@ -140,7 +139,7 @@ function LogPacket(text) { this.text = text || ''; } -util.inherits(LogPacket, Packet); +Object.setPrototypeOf(LogPacket.prototype, Packet.prototype); LogPacket.prototype.cmd = packetTypes.LOG; @@ -169,7 +168,7 @@ function ErrorPacket(error) { this.error = error || new Error(); } -util.inherits(ErrorPacket, Packet); +Object.setPrototypeOf(ErrorPacket.prototype, Packet.prototype); ErrorPacket.prototype.cmd = packetTypes.ERROR; @@ -249,7 +248,7 @@ function ErrorResultPacket(error) { ErrorPacket.call(this, error); } -util.inherits(ErrorResultPacket, ErrorPacket); +Object.setPrototypeOf(ErrorResultPacket.prototype, ErrorPacket.prototype); ErrorResultPacket.prototype.cmd = packetTypes.ERRORRESULT; @@ -265,7 +264,7 @@ function CheckPacket(tx, view, flags) { this.flags = flags != null ? flags : null; } -util.inherits(CheckPacket, Packet); +Object.setPrototypeOf(CheckPacket.prototype, Packet.prototype); CheckPacket.prototype.cmd = packetTypes.CHECK; @@ -303,7 +302,7 @@ function CheckResultPacket(error) { this.error = error || null; } -util.inherits(CheckResultPacket, Packet); +Object.setPrototypeOf(CheckResultPacket.prototype, Packet.prototype); CheckResultPacket.prototype.cmd = packetTypes.CHECKRESULT; @@ -379,7 +378,7 @@ function SignPacket(tx, rings, type) { this.type = type != null ? type : 1; } -util.inherits(SignPacket, Packet); +Object.setPrototypeOf(SignPacket.prototype, Packet.prototype); SignPacket.prototype.cmd = packetTypes.SIGN; @@ -441,7 +440,7 @@ function SignResultPacket(total, witness, script) { this.witness = witness || []; } -util.inherits(SignResultPacket, Packet); +Object.setPrototypeOf(SignResultPacket.prototype, Packet.prototype); SignResultPacket.prototype.cmd = packetTypes.SIGNRESULT; @@ -524,7 +523,7 @@ function CheckInputPacket(tx, index, coin, flags) { this.flags = flags != null ? flags : null; } -util.inherits(CheckInputPacket, Packet); +Object.setPrototypeOf(CheckInputPacket.prototype, Packet.prototype); CheckInputPacket.prototype.cmd = packetTypes.CHECKINPUT; @@ -574,7 +573,9 @@ function CheckInputResultPacket(error) { CheckResultPacket.call(this, error); } -util.inherits(CheckInputResultPacket, CheckResultPacket); +Object.setPrototypeOf( + CheckInputResultPacket.prototype, + CheckResultPacket.prototype); CheckInputResultPacket.prototype.cmd = packetTypes.CHECKINPUTRESULT; @@ -599,7 +600,7 @@ function SignInputPacket(tx, index, coin, ring, type) { this.type = type != null ? type : 1; } -util.inherits(SignInputPacket, Packet); +Object.setPrototypeOf(SignInputPacket.prototype, Packet.prototype); SignInputPacket.prototype.cmd = packetTypes.SIGNINPUT; @@ -652,7 +653,7 @@ function SignInputResultPacket(value, witness, script) { this.witness = witness || null; } -util.inherits(SignInputResultPacket, Packet); +Object.setPrototypeOf(SignInputResultPacket.prototype, Packet.prototype); SignInputResultPacket.prototype.cmd = packetTypes.SIGNINPUTRESULT; @@ -706,7 +707,7 @@ function ECVerifyPacket(msg, sig, key) { this.key = key || null; } -util.inherits(ECVerifyPacket, Packet); +Object.setPrototypeOf(ECVerifyPacket.prototype, Packet.prototype); ECVerifyPacket.prototype.cmd = packetTypes.ECVERIFY; @@ -743,7 +744,7 @@ function ECVerifyResultPacket(value) { this.value = value; } -util.inherits(ECVerifyResultPacket, Packet); +Object.setPrototypeOf(ECVerifyResultPacket.prototype, Packet.prototype); ECVerifyResultPacket.prototype.cmd = packetTypes.ECVERIFYRESULT; @@ -773,7 +774,7 @@ function ECSignPacket(msg, key) { this.key = key || null; } -util.inherits(ECSignPacket, Packet); +Object.setPrototypeOf(ECSignPacket.prototype, Packet.prototype); ECSignPacket.prototype.cmd = packetTypes.ECSIGN; @@ -807,7 +808,7 @@ function ECSignResultPacket(sig) { this.sig = sig; } -util.inherits(ECSignResultPacket, Packet); +Object.setPrototypeOf(ECSignResultPacket.prototype, Packet.prototype); ECSignResultPacket.prototype.cmd = packetTypes.ECSIGNRESULT; @@ -839,7 +840,7 @@ function MinePacket(data, target, min, max) { this.max = max != null ? max : -1; } -util.inherits(MinePacket, Packet); +Object.setPrototypeOf(MinePacket.prototype, Packet.prototype); MinePacket.prototype.cmd = packetTypes.MINE; @@ -874,7 +875,7 @@ function MineResultPacket(nonce) { this.nonce = nonce != null ? nonce : -1; } -util.inherits(MineResultPacket, Packet); +Object.setPrototypeOf(MineResultPacket.prototype, Packet.prototype); MineResultPacket.prototype.cmd = packetTypes.MINERESULT; @@ -910,7 +911,7 @@ function ScryptPacket(passwd, salt, N, r, p, len) { this.len = len != null ? len : -1; } -util.inherits(ScryptPacket, Packet); +Object.setPrototypeOf(ScryptPacket.prototype, Packet.prototype); ScryptPacket.prototype.cmd = packetTypes.SCRYPT; @@ -953,7 +954,7 @@ function ScryptResultPacket(key) { this.key = key || null; } -util.inherits(ScryptResultPacket, Packet); +Object.setPrototypeOf(ScryptResultPacket.prototype, Packet.prototype); ScryptResultPacket.prototype.cmd = packetTypes.SCRYPTRESULT; diff --git a/lib/workers/parent-browser.js b/lib/workers/parent-browser.js index 5c811135..2eb865e7 100644 --- a/lib/workers/parent-browser.js +++ b/lib/workers/parent-browser.js @@ -8,7 +8,6 @@ const assert = require('assert'); const EventEmitter = require('events'); -const util = require('../utils/util'); /** * Represents the parent process. @@ -26,7 +25,7 @@ function Parent() { this.init(); } -util.inherits(Parent, EventEmitter); +Object.setPrototypeOf(Parent.prototype, EventEmitter.prototype); /** * Initialize master (web workers). diff --git a/lib/workers/parent.js b/lib/workers/parent.js index 77dc6ed8..c0868680 100644 --- a/lib/workers/parent.js +++ b/lib/workers/parent.js @@ -7,7 +7,6 @@ 'use strict'; const EventEmitter = require('events'); -const util = require('../utils/util'); /** * Represents the parent process. @@ -24,7 +23,7 @@ function Parent() { this.init(); } -util.inherits(Parent, EventEmitter); +Object.setPrototypeOf(Parent.prototype, EventEmitter.prototype); /** * Initialize master (node.js). diff --git a/lib/workers/parser.js b/lib/workers/parser.js index f9c9672f..b70a2908 100644 --- a/lib/workers/parser.js +++ b/lib/workers/parser.js @@ -9,7 +9,6 @@ const assert = require('assert'); const EventEmitter = require('events'); -const util = require('../utils/util'); const packets = require('./packets'); /** @@ -30,7 +29,7 @@ function Parser() { this.total = 0; } -util.inherits(Parser, EventEmitter); +Object.setPrototypeOf(Parser.prototype, EventEmitter.prototype); Parser.prototype.feed = function feed(data) { this.total += data.length; diff --git a/lib/workers/workerpool.js b/lib/workers/workerpool.js index 8d62e1b0..05ce36d8 100644 --- a/lib/workers/workerpool.js +++ b/lib/workers/workerpool.js @@ -51,7 +51,7 @@ function WorkerPool(options) { this.set(options); } -util.inherits(WorkerPool, EventEmitter); +Object.setPrototypeOf(WorkerPool.prototype, EventEmitter.prototype); /** * Set worker pool options. @@ -378,7 +378,7 @@ function Worker(file) { this.init(); } -util.inherits(Worker, EventEmitter); +Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype); /** * Initialize worker. Bind to events.