api: more method renames. legacy support. docs.
This commit is contained in:
parent
6ad621cace
commit
f9d960ca23
@ -732,7 +732,7 @@ Usage: `bcoin.chain([options])`
|
|||||||
is one.
|
is one.
|
||||||
- __getHeight(block/hash)__ - Return block height based on hash or block.
|
- __getHeight(block/hash)__ - Return block height based on hash or block.
|
||||||
- __getNextBlock(block/hash)__ - Return next block hash 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).
|
- __height()__ - Return height of chain tip (`-1` if genesis block is not present).
|
||||||
- __currentTarget()__ - Return the current target in compact form.
|
- __currentTarget()__ - Return the current target in compact form.
|
||||||
- __target(last, [block])__ - Return the target (compact form) necessary for
|
- __target(last, [block])__ - Return the target (compact form) necessary for
|
||||||
@ -1333,7 +1333,7 @@ Usage:
|
|||||||
- __createScripthash(s)__ - Compile a scripthash script from `s`.
|
- __createScripthash(s)__ - Compile a scripthash script from `s`.
|
||||||
- __getRedeem(s)__ - Grab an deserialize redeem script from input script.
|
- __getRedeem(s)__ - Grab an deserialize redeem script from input script.
|
||||||
- __getType(s)__ - Return standard output script type. `unknown` if unknown.
|
- __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.
|
- __isLocktime(s)__ - Returns true if script is a checklocktimeverify script.
|
||||||
- __getLockTime(s)__ - Return locktime value pushed onto the stack if
|
- __getLockTime(s)__ - Return locktime value pushed onto the stack if
|
||||||
checklocktimeverify is used.
|
checklocktimeverify is used.
|
||||||
|
|||||||
@ -270,7 +270,7 @@ Chain.prototype.add = function add(block, peer) {
|
|||||||
// add it current to orphans and break.
|
// add it current to orphans and break.
|
||||||
if (prevHeight == null) {
|
if (prevHeight == null) {
|
||||||
this.orphan.count++;
|
this.orphan.count++;
|
||||||
this.orphan.size += block.size();
|
this.orphan.size += block.getSize();
|
||||||
this.orphan.map[prevHash] = block;
|
this.orphan.map[prevHash] = block;
|
||||||
this.orphan.bmap[hash] = block;
|
this.orphan.bmap[hash] = block;
|
||||||
code = Chain.codes.newOrphan;
|
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.bmap[block.hash('hex')];
|
||||||
delete this.orphan.map[hash];
|
delete this.orphan.map[hash];
|
||||||
this.orphan.count--;
|
this.orphan.count--;
|
||||||
this.orphan.size -= block.size();
|
this.orphan.size -= block.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failsafe for large orphan chains. Do not
|
// Failsafe for large orphan chains. Do not
|
||||||
@ -601,23 +601,29 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) {
|
|||||||
return entry.next.hash;
|
return entry.next.hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.size = function size() {
|
Chain.prototype.getSize = function getSize() {
|
||||||
return this.db.count();
|
return this.db.count();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Legacy
|
||||||
|
Chain.prototype.size = Chain.prototype.getSize;
|
||||||
|
|
||||||
Chain.prototype.height = function height() {
|
Chain.prototype.height = function height() {
|
||||||
if (!this.tip)
|
if (!this.tip)
|
||||||
return -1;
|
return -1;
|
||||||
return this.tip.height;
|
return this.tip.height;
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.currentTarget = function currentTarget() {
|
Chain.prototype.getCurrentTarget = function getCurrentTarget() {
|
||||||
if (!this.tip)
|
if (!this.tip)
|
||||||
return utils.toCompact(network.powLimit);
|
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 powLimit = utils.toCompact(network.powLimit);
|
||||||
var ts, first, i;
|
var ts, first, i;
|
||||||
|
|
||||||
@ -652,6 +658,9 @@ Chain.prototype.target = function target(last, block) {
|
|||||||
return this.retarget(last, first);
|
return this.retarget(last, first);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Legacy
|
||||||
|
Chain.prototype.target = Chain.prototype.getTarget;
|
||||||
|
|
||||||
Chain.prototype.retarget = function retarget(last, first) {
|
Chain.prototype.retarget = function retarget(last, first) {
|
||||||
var powTargetTimespan = new bn(network.powTargetTimespan);
|
var powTargetTimespan = new bn(network.powTargetTimespan);
|
||||||
var actualTimespan, target;
|
var actualTimespan, target;
|
||||||
@ -710,7 +719,6 @@ Chain.prototype.fromJSON = function fromJSON(json) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var BLOCK_SIZE = 112;
|
var BLOCK_SIZE = 112;
|
||||||
// var BLOCK_SIZE = 116;
|
|
||||||
|
|
||||||
function ChainDB(chain, options) {
|
function ChainDB(chain, options) {
|
||||||
if (!(this instanceof ChainDB))
|
if (!(this instanceof ChainDB))
|
||||||
@ -1246,14 +1254,11 @@ ChainBlock.prototype.toRaw = function toRaw() {
|
|||||||
utils.writeU32(res, this.bits, 72);
|
utils.writeU32(res, this.bits, 72);
|
||||||
utils.writeU32(res, this.nonce, 76);
|
utils.writeU32(res, this.nonce, 76);
|
||||||
utils.copy(this.chainwork.toArray('be', 32), res, 80);
|
utils.copy(this.chainwork.toArray('be', 32), res, 80);
|
||||||
// utils.copy(utils.checksum(res.slice(0, 112)), res, 112);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
ChainBlock.fromRaw = function fromRaw(chain, height, p) {
|
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, {
|
return new ChainBlock(chain, {
|
||||||
height: height,
|
height: height,
|
||||||
hash: utils.toHex(utils.dsha256(p.slice(0, 80))),
|
hash: utils.toHex(utils.dsha256(p.slice(0, 80))),
|
||||||
|
|||||||
@ -171,7 +171,7 @@ Miner.prototype.addTX = function addTX(tx) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Deliver me from the block size debate, please
|
// 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;
|
return;
|
||||||
|
|
||||||
// Add the tx to our block
|
// 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);
|
ts = Math.max(utils.now(), this.last.ts + 1);
|
||||||
|
|
||||||
// Find target
|
// Find target
|
||||||
target = this.chain.target(this.last, ts);
|
target = this.chain.getTarget(this.last, ts);
|
||||||
|
|
||||||
// Create a coinbase
|
// Create a coinbase
|
||||||
coinbase = bcoin.tx();
|
coinbase = bcoin.tx();
|
||||||
@ -223,7 +223,7 @@ Miner.prototype.createBlock = function createBlock(tx) {
|
|||||||
seq: 0xffffffff
|
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');
|
throw new Error('Coinbase script is too large');
|
||||||
|
|
||||||
coinbase.addOutput({
|
coinbase.addOutput({
|
||||||
|
|||||||
@ -1209,19 +1209,22 @@ script.isStandard = function isStandard(s) {
|
|||||||
if (m < 1 || m > n)
|
if (m < 1 || m > n)
|
||||||
return false;
|
return false;
|
||||||
} else if (script.isNulldata(s)) {
|
} else if (script.isNulldata(s)) {
|
||||||
if (script.size(s) > constants.script.maxOpReturnBytes)
|
if (script.getSize(s) > constants.script.maxOpReturnBytes)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return type != null;
|
return type != null;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.size = function size(s) {
|
script.getSize = function getSize(s) {
|
||||||
if (s._raw)
|
if (s._raw)
|
||||||
return s._raw.length;
|
return s._raw.length;
|
||||||
return script.encode(s).length;
|
return script.encode(s).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Legacy
|
||||||
|
script.size = script.getSize;
|
||||||
|
|
||||||
script.isEncoded = function isEncoded(s) {
|
script.isEncoded = function isEncoded(s) {
|
||||||
var i, b;
|
var i, b;
|
||||||
|
|
||||||
|
|||||||
@ -1275,13 +1275,13 @@ TX.prototype.isStandard = function isStandard() {
|
|||||||
if (this.version > constants.tx.version || this.version < 1)
|
if (this.version > constants.tx.version || this.version < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this.size() > constants.tx.maxSize)
|
if (this.getSize() > constants.tx.maxSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
|
|
||||||
if (script.size(input.script) > 1650)
|
if (script.getSize(input.script) > 1650)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!bcoin.script.isPushOnly(input.script))
|
if (!bcoin.script.isPushOnly(input.script))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user