From ed6b1e9072aed009d6060f2d06358f7810f49910 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 19 Apr 2016 11:46:10 -0700 Subject: [PATCH] rename methods. --- lib/bcoin/block.js | 20 ++++++++++---------- lib/bcoin/chaindb.js | 4 ++-- lib/bcoin/coin.js | 14 +++++++------- lib/bcoin/coins.js | 4 ++-- lib/bcoin/hd.js | 16 +++++++++++----- lib/bcoin/headers.js | 4 ++-- lib/bcoin/http/client.js | 4 ++-- lib/bcoin/input.js | 18 +++++++++--------- lib/bcoin/keypair.js | 4 ++-- lib/bcoin/merkleblock.js | 4 ++-- lib/bcoin/mtx.js | 18 +++++++++--------- lib/bcoin/output.js | 10 +++++----- lib/bcoin/script.js | 8 ++++---- lib/bcoin/tx.js | 16 ++++++++-------- lib/bcoin/wallet.js | 4 ++-- lib/bcoin/walletdb.js | 4 ++-- 16 files changed, 79 insertions(+), 73 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 67c5cc27..c433c797 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -554,12 +554,12 @@ Block.prototype.toJSON = function toJSON() { * for passing to the Block constructor). */ -Block._fromJSON = function _fromJSON(json) { +Block.parseJSON = function parseJSON(json) { assert.equal(json.type, 'block'); json.prevBlock = utils.revHex(json.prevBlock); json.merkleRoot = utils.revHex(json.merkleRoot); json.txs = json.txs.map(function(tx) { - return bcoin.tx._fromJSON(tx); + return bcoin.tx.parseJSON(tx); }); return json; }; @@ -571,7 +571,7 @@ Block._fromJSON = function _fromJSON(json) { */ Block.fromJSON = function fromJSON(json) { - return new Block(Block._fromJSON(json)); + return new Block(Block.parseJSON(json)); }; /** @@ -598,15 +598,15 @@ Block.prototype.toRaw = function toRaw(enc) { * @returns {Object} A "naked" block object. */ -Block._fromRaw = function _fromRaw(data, enc, type) { +Block.parseRaw = function parseRaw(data, enc, type) { if (enc === 'hex') data = new Buffer(data, 'hex'); if (type === 'merkleblock') - return bcoin.merkleblock._fromRaw(data); + return bcoin.merkleblock.parseRaw(data); if (type === 'headers') - return bcoin.headers._fromRaw(data); + return bcoin.headers.parseRaw(data); return bcoin.protocol.parser.parseBlock(data); }; @@ -621,12 +621,12 @@ Block._fromRaw = function _fromRaw(data, enc, type) { Block.fromRaw = function fromRaw(data, enc, type) { if (type === 'merkleblock') - return bcoin.merkleblock.fromRaw(data); + return bcoin.merkleblock.fromRaw(data, enc); if (type === 'headers') - return bcoin.headers.fromRaw(data); + return bcoin.headers.fromRaw(data, enc); - return new Block(Block._fromRaw(data, enc)); + return new Block(Block.parseRaw(data, enc)); }; /** @@ -662,7 +662,7 @@ Block.prototype.toCompact = function toCompact() { * @returns {NakedBlock} - A "naked" block object with a `hashes` vector. */ -Block.fromCompact = function fromCompact(buf) { +Block.parseCompact = function parseCompact(buf) { var p = new BufferReader(buf); var hashes = []; var version = p.readU32(); // Technically signed diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index c8009f7a..52715430 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -1441,7 +1441,7 @@ ChainDB.prototype.getBlock = function getBlock(hash, callback) { return callback(); try { - block = bcoin.block.fromCompact(data); + block = bcoin.block.parseCompact(data); } catch (e) { return callback(e); } @@ -1596,7 +1596,7 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { return callback(); try { - compact = bcoin.block.fromCompact(compact); + compact = bcoin.block.parseCompact(compact); } catch (e) { return callback(e); } diff --git a/lib/bcoin/coin.js b/lib/bcoin/coin.js index 709aa349..61c4ec76 100644 --- a/lib/bcoin/coin.js +++ b/lib/bcoin/coin.js @@ -163,12 +163,12 @@ Coin.prototype.toJSON = function toJSON() { * for passing to the Coin constructor). */ -Coin._fromJSON = function _fromJSON(json) { +Coin.parseJSON = function parseJSON(json) { return { version: json.version, height: json.height, value: utils.satoshi(json.value), - script: bcoin.script._fromRaw(json.script, 'hex')), + script: bcoin.script.parseRaw(json.script, 'hex')), coinbase: json.coinbase, hash: json.hash ? utils.revHex(json.hash) : null, index: json.index @@ -182,7 +182,7 @@ Coin._fromJSON = function _fromJSON(json) { */ Coin.fromJSON = function fromJSON(json) { - return new Coin(Coin._fromJSON(json)); + return new Coin(Coin.parseJSON(json)); }; /** @@ -207,7 +207,7 @@ Coin.prototype.toRaw = function toRaw(enc) { * @returns {NakedCoin} A "naked" coin object. */ -Coin._fromRaw = function _fromRaw(data, enc) { +Coin.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -224,7 +224,7 @@ Coin._fromRaw = function _fromRaw(data, enc) { */ Coin.fromRaw = function fromRaw(data, enc) { - return new Coin(Coin._fromRaw(data, enc)); + return new Coin(Coin.parseRaw(data, enc)); }; /** @@ -250,7 +250,7 @@ Coin.prototype.toExtended = function toExtended(enc) { * @returns {NakedCoin} - A "naked" coin object. */ -Coin._fromExtended = function _fromExtended(data, enc) { +Coin.parseExtended = function parseExtended(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -268,7 +268,7 @@ Coin._fromExtended = function _fromExtended(data, enc) { */ Coin.fromExtended = function fromExtended(data, enc) { - return new Coin(Coin._fromExtended(data, enc)); + return new Coin(Coin.parseExtended(data, enc)); }; /** diff --git a/lib/bcoin/coins.js b/lib/bcoin/coins.js index 2188ad35..4d1d954d 100644 --- a/lib/bcoin/coins.js +++ b/lib/bcoin/coins.js @@ -237,7 +237,7 @@ Coins.toRaw = function toRaw(tx) { * @returns {Object} A "naked" coins object. */ -Coins._fromRaw = function _fromRaw(buf) { +Coins.parseRaw = function parseRaw(buf) { var tx = { outputs: [] }; var p = new BufferReader(buf); var coinCount, i, coin; @@ -271,7 +271,7 @@ Coins._fromRaw = function _fromRaw(buf) { */ Coins.fromRaw = function fromRaw(buf, hash) { - return new Coins(Coins._fromRaw(buf), hash); + return new Coins(Coins.parseRaw(buf), hash); }; return Coins; diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 8e1a54ab..655e49ca 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -797,12 +797,10 @@ HDPrivateKey.prototype.toJSON = function toJSON(passphrase) { /** * Handle a deserialized JSON HDPrivateKey object. * @param {Object} json - * @returns {Object} A "naked" HDPrivateKey (a - * plain javascript object which is suitable - * for passing to the HDPrivateKey constructor). + * @returns {Object} A "naked" HDPrivateKey. */ -HDPrivateKey._fromJSON = function _fromJSON(json, passphrase) { +HDPrivateKey.parseJSON = function parseJSON(json, passphrase) { var data = {}; assert.equal(json.v, 1); @@ -850,7 +848,7 @@ HDPrivateKey._fromJSON = function _fromJSON(json, passphrase) { HDPrivateKey.fromJSON = function fromJSON(json, passphrase) { var key; - json = HDPrivateKey._fromJSON(json, passphrase); + json = HDPrivateKey.parseJSON(json, passphrase); if (json.xprivkey) { key = HDPrivateKey.fromBase58(json.xprivkey); @@ -1077,6 +1075,14 @@ HDPublicKey.prototype.derivePath = function derivePath(path) { HDPublicKey.prototype.toJSON = HDPrivateKey.prototype.toJSON; +/** + * Handle a deserialized JSON HDPublicKey object. + * @param {Object} json + * @returns {Object} A "naked" HDPublicKey. + */ + +HDPublicKey.parseJSON = HDPrivateKey.parseJSON; + /** * Instantiate an HDPrivateKey from a jsonified key object. * @method diff --git a/lib/bcoin/headers.js b/lib/bcoin/headers.js index 03a02e42..21ec65b7 100644 --- a/lib/bcoin/headers.js +++ b/lib/bcoin/headers.js @@ -124,7 +124,7 @@ Headers.prototype.toRaw = function toRaw(enc) { * @returns {NakedBlock} A "naked" headers object. */ -Headers._fromRaw = function _fromRaw(data, enc) { +Headers.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -139,7 +139,7 @@ Headers._fromRaw = function _fromRaw(data, enc) { */ Headers.fromRaw = function fromRaw(data, enc) { - return new Headers(Headers._fromRaw(data, enc)); + return new Headers(Headers.parseRaw(data, enc)); }; /** diff --git a/lib/bcoin/http/client.js b/lib/bcoin/http/client.js index 5ba31609..7852b6b6 100644 --- a/lib/bcoin/http/client.js +++ b/lib/bcoin/http/client.js @@ -330,7 +330,7 @@ HTTPClient.prototype.getWallet = function getWallet(id, passphrase, callback) { return callback(err); try { - json = bcoin.wallet._fromJSON(json, passphrase); + json = bcoin.wallet.parseJSON(json, passphrase); } catch (e) { return callback(e); } @@ -356,7 +356,7 @@ HTTPClient.prototype.createWallet = function createWallet(options, callback) { return callback(err); try { - json = bcoin.wallet._fromJSON(json, options.passphrase); + json = bcoin.wallet.parseJSON(json, options.passphrase); } catch (e) { return callback(e); } diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index 8bd6565f..ad66a488 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -277,15 +277,15 @@ Input.prototype.toJSON = function toJSON() { * for passing to the Input constructor). */ -Input._fromJSON = function _fromJSON(json) { +Input.parseJSON = function parseJSON(json) { return { prevout: { hash: utils.revHex(json.prevout.hash), index: json.prevout.index }, - coin: json.coin ? bcoin.coin._fromJSON(json.coin) : null, - script: bcoin.script._fromRaw(json.script, 'hex'), - witness: bcoin.witness._fromRaw(json.witness, 'hex'), + coin: json.coin ? bcoin.coin.parseJSON(json.coin) : null, + script: bcoin.script.parseRaw(json.script, 'hex'), + witness: bcoin.witness.parseRaw(json.witness, 'hex'), sequence: json.sequence }; }; @@ -297,7 +297,7 @@ Input._fromJSON = function _fromJSON(json) { */ Input.fromJSON = function fromJSON(json) { - return new Input(Input._fromJSON(json)); + return new Input(Input.parseJSON(json)); }; /** @@ -322,7 +322,7 @@ Input.prototype.toRaw = function toRaw(enc) { * @returns {NakedInput} A "naked" input object. */ -Input._fromRaw = function _fromRaw(data, enc) { +Input.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -339,7 +339,7 @@ Input._fromRaw = function _fromRaw(data, enc) { */ Input.fromRaw = function fromRaw(data, enc) { - return new Input(Input._fromRaw(data, enc)); + return new Input(Input.parseRaw(data, enc)); }; /** @@ -371,7 +371,7 @@ Input.prototype.toExtended = function toExtended(enc) { * @returns {NakedInput} - A "naked" input object. */ -Input._fromExtended = function _fromExtended(data, enc) { +Input.parseExtended = function parseExtended(data, enc) { var input, p; if (enc === 'hex') @@ -395,7 +395,7 @@ Input._fromExtended = function _fromExtended(data, enc) { */ Input.fromExtended = function fromExtended(data, enc) { - return new Input(Input._fromExtended(data, enc)); + return new Input(Input.parseExtended(data, enc)); }; /** diff --git a/lib/bcoin/keypair.js b/lib/bcoin/keypair.js index d6810bab..aae24f9b 100644 --- a/lib/bcoin/keypair.js +++ b/lib/bcoin/keypair.js @@ -225,7 +225,7 @@ KeyPair.prototype.toJSON = function toJSON(passphrase) { * for passing to the KeyPair constructor). */ -KeyPair._fromJSON = function _fromJSON(json, passphrase) { +KeyPair.parseJSON = function parseJSON(json, passphrase) { var privateKey, publicKey; assert.equal(json.v, 1); @@ -259,7 +259,7 @@ KeyPair._fromJSON = function _fromJSON(json, passphrase) { */ KeyPair.fromJSON = function fromJSON(json, passphrase) { - return new KeyPair(KeyPair._fromJSON(json, passphrase)); + return new KeyPair(KeyPair.parseJSON(json, passphrase)); }; return KeyPair; diff --git a/lib/bcoin/merkleblock.js b/lib/bcoin/merkleblock.js index 5d59a9ab..4f5fb68d 100644 --- a/lib/bcoin/merkleblock.js +++ b/lib/bcoin/merkleblock.js @@ -275,7 +275,7 @@ MerkleBlock.prototype.toRaw = function toRaw(enc) { * @returns {NakedBlock} A "naked" headers object. */ -MerkleBlock._fromRaw = function _fromRaw(data, enc) { +MerkleBlock.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -290,7 +290,7 @@ MerkleBlock._fromRaw = function _fromRaw(data, enc) { */ MerkleBlock.fromRaw = function fromRaw(data, enc) { - return new MerkleBlock(MerkleBlock._fromRaw(data, enc)); + return new MerkleBlock(MerkleBlock.parseRaw(data, enc)); }; /** diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index b1708898..f233ab8f 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -1327,45 +1327,45 @@ MTX.prototype.setLocktime = function setLocktime(locktime) { }; /** - * @see TX._fromJSON + * @see TX.parseJSON */ -MTX._fromJSON = bcoin.tx._fromJSON; +MTX.parseJSON = bcoin.tx.parseJSON; /** * @see TX.fromJSON */ MTX.fromJSON = function fromJSON(json) { - return new MTX(MTX._fromJSON(json)); + return new MTX(MTX.parseJSON(json)); }; /** - * @see TX._fromRaw + * @see TX.parseRaw */ -MTX._fromRaw = bcoin.tx._fromRaw; +MTX.parseRaw = bcoin.tx.parseRaw; /** * @see TX.fromRaw */ MTX.fromRaw = function fromRaw(data, enc) { - return new MTX(MTX._fromRaw(data, enc)); + return new MTX(MTX.parseRaw(data, enc)); }; /** - * @see TX._fromExtended + * @see TX.parseExtended */ -MTX._fromExtended = bcoin.tx._fromExtended; +MTX.parseExtended = bcoin.tx.parseExtended; /** * @see TX.fromExtended */ MTX.fromExtended = function fromExtended(data, enc) { - return new MTX(MTX._fromExtended(data, enc)); + return new MTX(MTX.parseExtended(data, enc)); }; /** diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index 6320dea3..d9484802 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -152,10 +152,10 @@ Output.prototype.toJSON = function toJSON() { * for passing to the Output constructor). */ -Output._fromJSON = function _fromJSON(json) { +Output.parseJSON = function parseJSON(json) { return { value: utils.satoshi(json.value), - script: bcoin.script._fromRaw(json.script, 'hex')) + script: bcoin.script.parseRaw(json.script, 'hex')) }; }; @@ -166,7 +166,7 @@ Output._fromJSON = function _fromJSON(json) { */ Output.fromJSON = function fromJSON(json) { - return new Output(Output._fromJSON(json)); + return new Output(Output.parseJSON(json)); }; /** @@ -191,7 +191,7 @@ Output.prototype.toRaw = function toRaw(enc) { * @returns {NakedOutput} A "naked" output object. */ -Output._fromRaw = function _fromRaw(data, enc) { +Output.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -208,7 +208,7 @@ Output._fromRaw = function _fromRaw(data, enc) { */ Output.fromRaw = function fromRaw(data, enc) { - return new Output(Output._fromRaw(data, enc)); + return new Output(Output.parseRaw(data, enc)); }; /** diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index f0587673..4ec3178b 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -218,7 +218,7 @@ Witness.prototype.toRaw = function toRaw(enc) { * @returns {Object} Naked witness object. */ -Witness._fromRaw = function _fromRaw(data, enc) { +Witness.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -233,7 +233,7 @@ Witness._fromRaw = function _fromRaw(data, enc) { */ Witness.fromRaw = function fromRaw(data, enc) { - return new Witness(Witness._fromRaw(data, enc)); + return new Witness(Witness.parseRaw(data, enc)); }; /** @@ -4066,7 +4066,7 @@ Script.sign = function sign(msg, key, type) { * @returns {Object} Naked script object. */ -Script._fromRaw = function _fromRaw(data, enc) { +Script.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -4081,7 +4081,7 @@ Script._fromRaw = function _fromRaw(data, enc) { */ Script.fromRaw = function fromRaw(data, enc) { - return new Script(Script._fromRaw(data, enc)); + return new Script(Script.parseRaw(data, enc)); }; /** diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index c37d2317..3285b897 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1615,7 +1615,7 @@ TX.prototype.toJSON = function toJSON() { * for passing to the TX constructor). */ -TX._fromJSON = function fromJSON(json) { +TX.parseJSON = function fromJSON(json) { assert.equal(json.type, 'tx'); return { block: json.block ? utils.revHex(json.block) : null, @@ -1626,10 +1626,10 @@ TX._fromJSON = function fromJSON(json) { changeIndex: json.changeIndex || -1, version: json.version, inputs: json.inputs.map(function(input) { - return bcoin.input._fromJSON(input); + return bcoin.input.parseJSON(input); }), outputs: json.outputs.map(function(output) { - return bcoin.output._fromJSON(output); + return bcoin.output.parseJSON(output); }), locktime: json.locktime }; @@ -1644,7 +1644,7 @@ TX._fromJSON = function fromJSON(json) { TX.fromJSON = function fromJSON(json) { assert.equal(json.type, 'tx'); - return new TX(TX._fromJSON(json)); + return new TX(TX.parseJSON(json)); }; /** @@ -1670,7 +1670,7 @@ TX.prototype.toRaw = function toRaw(enc) { * @returns {NakedTX} A "naked" transaction object. */ -TX._fromRaw = function _fromRaw(data, enc) { +TX.parseRaw = function parseRaw(data, enc) { if (enc === 'hex') data = new Buffer(data, 'hex'); @@ -1685,7 +1685,7 @@ TX._fromRaw = function _fromRaw(data, enc) { */ TX.fromRaw = function fromRaw(data, enc) { - return new bcoin.tx(TX._fromRaw(data, enc)); + return new bcoin.tx(TX.parseRaw(data, enc)); }; /** @@ -1748,7 +1748,7 @@ TX.prototype.toExtended = function toExtended(saveCoins) { * @returns {NakedTX} - A "naked" transaction object. */ -TX._fromExtended = function _fromExtended(buf, saveCoins) { +TX.parseExtended = function parseExtended(buf, saveCoins) { var p = new BufferReader(buf); var tx, coinCount, coin, i; @@ -1803,7 +1803,7 @@ TX._fromExtended = function _fromExtended(buf, saveCoins) { */ TX.fromExtended = function fromExtended(buf, saveCoins) { - return new TX(TX._fromExtended(buf, saveCoins)); + return new TX(TX.parseExtended(buf, saveCoins)); }; /** diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index da84ed05..9b47a670 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -1625,7 +1625,7 @@ Wallet.prototype.toJSON = function toJSON() { * @throws Error on bad decrypt */ -Wallet._fromJSON = function _fromJSON(json, passphrase) { +Wallet.parseJSON = function parseJSON(json, passphrase) { assert.equal(json.v, 3); assert.equal(json.name, 'wallet'); @@ -1659,7 +1659,7 @@ Wallet._fromJSON = function _fromJSON(json, passphrase) { */ Wallet.fromJSON = function fromJSON(json, passphrase) { - return new Wallet(Wallet._fromJSON(json, passphrase)); + return new Wallet(Wallet.parseJSON(json, passphrase)); }; Wallet._syncDepth = function _syncDepth(json, options) { diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index 946b4349..94ead451 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -527,7 +527,7 @@ WalletDB.prototype.get = function get(id, passphrase, callback) { return callback(); try { - options = bcoin.wallet._fromJSON(options, passphrase); + options = bcoin.wallet.parseJSON(options, passphrase); options.provider = new Provider(self); wallet = new bcoin.wallet(options); } catch (e) { @@ -668,7 +668,7 @@ WalletDB.prototype.ensure = function ensure(id, options, callback) { assert(json); try { - options = bcoin.wallet._fromJSON(json, options.passphrase); + options = bcoin.wallet.parseJSON(json, options.passphrase); options.provider = new Provider(self); wallet = new bcoin.wallet(options); } catch (e) {