rename methods.

This commit is contained in:
Christopher Jeffrey 2016-04-19 11:46:10 -07:00
parent 63a9c44762
commit ed6b1e9072
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
16 changed files with 79 additions and 73 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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));
};
/**

View File

@ -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;

View File

@ -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

View File

@ -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));
};
/**

View File

@ -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);
}

View File

@ -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));
};
/**

View File

@ -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;

View File

@ -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));
};
/**

View File

@ -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));
};
/**

View File

@ -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));
};
/**

View File

@ -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));
};
/**

View File

@ -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));
};
/**

View File

@ -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) {

View File

@ -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) {