api: more method renames. legacy support. docs.

This commit is contained in:
Christopher Jeffrey 2016-02-01 11:57:40 -08:00
parent 6ad621cace
commit f9d960ca23
5 changed files with 27 additions and 19 deletions

View File

@ -732,7 +732,7 @@ Usage: `bcoin.chain([options])`
is one.
- __getHeight(block/hash)__ - Return block height based on hash or block.
- __getNextBlock(block/hash)__ - Return next block hash based on hash or block.
- __size()__ - Number of blocks in the chain (different from height).
- __getSize()__ - Number of blocks in the chain (different from height).
- __height()__ - Return height of chain tip (`-1` if genesis block is not present).
- __currentTarget()__ - Return the current target in compact form.
- __target(last, [block])__ - Return the target (compact form) necessary for
@ -1333,7 +1333,7 @@ Usage:
- __createScripthash(s)__ - Compile a scripthash script from `s`.
- __getRedeem(s)__ - Grab an deserialize redeem script from input script.
- __getType(s)__ - Return standard output script type. `unknown` if unknown.
- __size(s)__ - Return script size in bytes.
- __getSize(s)__ - Return script size in bytes.
- __isLocktime(s)__ - Returns true if script is a checklocktimeverify script.
- __getLockTime(s)__ - Return locktime value pushed onto the stack if
checklocktimeverify is used.

View File

@ -270,7 +270,7 @@ Chain.prototype.add = function add(block, peer) {
// add it current to orphans and break.
if (prevHeight == null) {
this.orphan.count++;
this.orphan.size += block.size();
this.orphan.size += block.getSize();
this.orphan.map[prevHash] = block;
this.orphan.bmap[hash] = block;
code = Chain.codes.newOrphan;
@ -390,7 +390,7 @@ Chain.prototype.add = function add(block, peer) {
delete this.orphan.bmap[block.hash('hex')];
delete this.orphan.map[hash];
this.orphan.count--;
this.orphan.size -= block.size();
this.orphan.size -= block.getSize();
}
// Failsafe for large orphan chains. Do not
@ -601,23 +601,29 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) {
return entry.next.hash;
};
Chain.prototype.size = function size() {
Chain.prototype.getSize = function getSize() {
return this.db.count();
};
// Legacy
Chain.prototype.size = Chain.prototype.getSize;
Chain.prototype.height = function height() {
if (!this.tip)
return -1;
return this.tip.height;
};
Chain.prototype.currentTarget = function currentTarget() {
Chain.prototype.getCurrentTarget = function getCurrentTarget() {
if (!this.tip)
return utils.toCompact(network.powLimit);
return this.target(this.tip);
return this.getTarget(this.tip);
};
Chain.prototype.target = function target(last, block) {
// Legacy
Chain.prototype.currentTarget = Chain.prototype.getCurrentTarget;
Chain.prototype.getTarget = function getTarget(last, block) {
var powLimit = utils.toCompact(network.powLimit);
var ts, first, i;
@ -652,6 +658,9 @@ Chain.prototype.target = function target(last, block) {
return this.retarget(last, first);
};
// Legacy
Chain.prototype.target = Chain.prototype.getTarget;
Chain.prototype.retarget = function retarget(last, first) {
var powTargetTimespan = new bn(network.powTargetTimespan);
var actualTimespan, target;
@ -710,7 +719,6 @@ Chain.prototype.fromJSON = function fromJSON(json) {
*/
var BLOCK_SIZE = 112;
// var BLOCK_SIZE = 116;
function ChainDB(chain, options) {
if (!(this instanceof ChainDB))
@ -1246,14 +1254,11 @@ ChainBlock.prototype.toRaw = function toRaw() {
utils.writeU32(res, this.bits, 72);
utils.writeU32(res, this.nonce, 76);
utils.copy(this.chainwork.toArray('be', 32), res, 80);
// utils.copy(utils.checksum(res.slice(0, 112)), res, 112);
return res;
};
ChainBlock.fromRaw = function fromRaw(chain, height, p) {
// if (!utils.isEqual(utils.checksum(p.slice(0, 112)), p.slice(112, 116)))
// throw new Error('Bad checksum');
return new ChainBlock(chain, {
height: height,
hash: utils.toHex(utils.dsha256(p.slice(0, 80))),

View File

@ -171,7 +171,7 @@ Miner.prototype.addTX = function addTX(tx) {
return;
// Deliver me from the block size debate, please
if (this.block.size() + tx.size() > constants.blocks.maxSize)
if (this.block.getSize() + tx.getSize() > constants.blocks.maxSize)
return;
// Add the tx to our block
@ -194,7 +194,7 @@ Miner.prototype.createBlock = function createBlock(tx) {
ts = Math.max(utils.now(), this.last.ts + 1);
// Find target
target = this.chain.target(this.last, ts);
target = this.chain.getTarget(this.last, ts);
// Create a coinbase
coinbase = bcoin.tx();
@ -223,7 +223,7 @@ Miner.prototype.createBlock = function createBlock(tx) {
seq: 0xffffffff
});
if (script.size(coinbase.inputs[0].script) > 100)
if (script.getSize(coinbase.inputs[0].script) > 100)
throw new Error('Coinbase script is too large');
coinbase.addOutput({

View File

@ -1209,19 +1209,22 @@ script.isStandard = function isStandard(s) {
if (m < 1 || m > n)
return false;
} else if (script.isNulldata(s)) {
if (script.size(s) > constants.script.maxOpReturnBytes)
if (script.getSize(s) > constants.script.maxOpReturnBytes)
return false;
}
return type != null;
};
script.size = function size(s) {
script.getSize = function getSize(s) {
if (s._raw)
return s._raw.length;
return script.encode(s).length;
};
// Legacy
script.size = script.getSize;
script.isEncoded = function isEncoded(s) {
var i, b;

View File

@ -1275,13 +1275,13 @@ TX.prototype.isStandard = function isStandard() {
if (this.version > constants.tx.version || this.version < 1)
return false;
if (this.size() > constants.tx.maxSize)
if (this.getSize() > constants.tx.maxSize)
return false;
for (i = 0; i < this.inputs.length; i++) {
input = this.inputs[i];
if (script.size(input.script) > 1650)
if (script.getSize(input.script) > 1650)
return false;
if (!bcoin.script.isPushOnly(input.script))