block and tx methods.
This commit is contained in:
parent
0d7929136a
commit
e7d0ea81f9
@ -517,13 +517,13 @@ Block.reward = function reward(height) {
|
||||
return reward;
|
||||
};
|
||||
|
||||
Block.prototype.getReward = function getReward() {
|
||||
Block.prototype._getReward = function _getReward() {
|
||||
var reward, base, fee, height;
|
||||
|
||||
if (this._reward)
|
||||
return this._reward;
|
||||
|
||||
base = Block.reward(this.height);
|
||||
base = Block.reward(this.getHeight());
|
||||
|
||||
if (this.txs.length === 0 || !this.txs[0].isCoinbase()) {
|
||||
return this._reward = {
|
||||
@ -555,6 +555,18 @@ Block.prototype.getReward = function getReward() {
|
||||
};
|
||||
};
|
||||
|
||||
Block.prototype.getBaseReward = function getBaseReward() {
|
||||
return this._getReward().base;
|
||||
};
|
||||
|
||||
Block.prototype.getReward = function getReward() {
|
||||
return this._getReward().reward;
|
||||
};
|
||||
|
||||
Block.prototype.getFee = function getFee() {
|
||||
return this._getReward().fee;
|
||||
};
|
||||
|
||||
Block.prototype.getEntry = function getEntry() {
|
||||
if (!this.chain)
|
||||
return;
|
||||
@ -564,7 +576,14 @@ Block.prototype.getEntry = function getEntry() {
|
||||
Block.prototype.isOrphan = function isOrphan() {
|
||||
if (!this.chain)
|
||||
return true;
|
||||
return this.chain.hasBlock(this.prevBlock);
|
||||
return !this.chain.hasBlock(this.prevBlock);
|
||||
};
|
||||
|
||||
Block.prototype.getCoinbase = function getCoinbase() {
|
||||
var tx = this.txs[0];
|
||||
if (!tx || !tx.isCoinbase())
|
||||
return;
|
||||
return tx;
|
||||
};
|
||||
|
||||
Block.prototype.__defineGetter__('chain', function() {
|
||||
@ -584,18 +603,15 @@ Block.prototype.__defineGetter__('nextBlock', function() {
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('reward', function() {
|
||||
return this.getReward().reward;
|
||||
return this.getReward();
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('fee', function() {
|
||||
return this.getReward().fee;
|
||||
return this.getFee();
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('coinbase', function() {
|
||||
var tx = this.txs[0];
|
||||
if (!tx || !tx.isCoinbase())
|
||||
return;
|
||||
return tx;
|
||||
return this.getCoinbase();
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('entry', function() {
|
||||
@ -613,10 +629,10 @@ Block.prototype.inspect = function inspect() {
|
||||
delete copy._chain;
|
||||
copy.hash = this.hash('hex');
|
||||
copy.rhash = this.rhash;
|
||||
copy.height = this.height;
|
||||
copy.nextBlock = this.nextBlock;
|
||||
copy.reward = utils.btc(this.reward);
|
||||
copy.fee = utils.btc(this.fee);
|
||||
copy.height = this.getHeight();
|
||||
copy.nextBlock = this.getNextBlock();
|
||||
copy.reward = utils.btc(this.getReward());
|
||||
copy.fee = utils.btc(this.getFee());
|
||||
copy.date = new Date((copy.ts || 0) * 1000).toISOString();
|
||||
return copy;
|
||||
};
|
||||
|
||||
@ -1386,6 +1386,10 @@ TX.prototype.getConfirmations = function getConfirmations() {
|
||||
return top - height + 1;
|
||||
};
|
||||
|
||||
TX.prototype.getValue = function getValue() {
|
||||
return this.funds('out');
|
||||
};
|
||||
|
||||
TX.prototype.__defineGetter__('chain', function() {
|
||||
return this._chain || bcoin.chain.global;
|
||||
});
|
||||
@ -1405,7 +1409,7 @@ TX.prototype.__defineGetter__('fee', function() {
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('value', function() {
|
||||
return this.funds('out');
|
||||
return this.getValue();
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('height', function() {
|
||||
@ -1416,6 +1420,10 @@ TX.prototype.__defineGetter__('confirmations', function() {
|
||||
return this.getConfirmations();
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('priority', function() {
|
||||
return this.getPriority();
|
||||
});
|
||||
|
||||
TX.prototype.inspect = function inspect() {
|
||||
var copy = bcoin.tx(this);
|
||||
copy.__proto__ = null;
|
||||
@ -1427,11 +1435,14 @@ TX.prototype.inspect = function inspect() {
|
||||
copy.hash = this.hash('hex');
|
||||
copy.rhash = this.rhash;
|
||||
copy.rblock = this.rblock;
|
||||
copy.value = utils.btc(this.value);
|
||||
copy.fee = utils.btc(this.fee);
|
||||
copy.height = this.height;
|
||||
copy.confirmations = this.confirmations;
|
||||
copy.value = utils.btc(this.getValue());
|
||||
copy.fee = utils.btc(this.getFee());
|
||||
copy.height = this.getHeight();
|
||||
copy.confirmations = this.getConfirmations();
|
||||
copy.priority = this.getPriority().toString(10);
|
||||
copy.date = new Date((copy.ts || 0) * 1000).toISOString();
|
||||
if (copy.hardFee)
|
||||
copy.hardFee = utils.btc(copy.hardFee);
|
||||
return copy;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user