add block.reward. add coinbase data to into. failsafe for getFee.
This commit is contained in:
parent
fdc11b76b2
commit
f68750991d
@ -7,6 +7,7 @@
|
||||
var bcoin = require('../bcoin');
|
||||
var utils = bcoin.utils;
|
||||
var constants = bcoin.protocol.constants;
|
||||
var network = bcoin.protocol.network;
|
||||
|
||||
/**
|
||||
* Block
|
||||
@ -299,6 +300,26 @@ Block.prototype.__defineGetter__('rhash', function() {
|
||||
return utils.revHex(this.hash('hex'));
|
||||
});
|
||||
|
||||
Block.reward = function reward(height) {
|
||||
var halvings = height / network.halvingInterval | 0;
|
||||
var reward;
|
||||
|
||||
if (height < 0)
|
||||
return utils.satoshi('0.0');
|
||||
|
||||
if (halvings >= 64)
|
||||
return utils.satoshi('0.0');
|
||||
|
||||
reward = utils.satoshi('50.0');
|
||||
reward.iushrn(halvings);
|
||||
|
||||
return reward;
|
||||
};
|
||||
|
||||
Block.prototype.__defineGetter__('reward', function() {
|
||||
return Block.reward(this.height);
|
||||
});
|
||||
|
||||
Block.prototype.inspect = function inspect() {
|
||||
var copy = bcoin.block(this, this.subtype);
|
||||
copy.__proto__ = null;
|
||||
|
||||
@ -115,7 +115,7 @@ Input.getData = function getData(input) {
|
||||
addr: '[unknown]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
@ -125,17 +125,20 @@ Input.getData = function getData(input) {
|
||||
}
|
||||
|
||||
if (+input.out.hash === 0) {
|
||||
data = bcoin.script.coinbase(input.script);
|
||||
return {
|
||||
type: 'coinbase',
|
||||
side: 'input',
|
||||
coinbase: data,
|
||||
height: data.height || -1,
|
||||
sig: null,
|
||||
pub: null,
|
||||
hash: '[coinbase]',
|
||||
addr: '[coinbase]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
text: null,
|
||||
flags: data.flags,
|
||||
text: data.text,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
seq: input.seq,
|
||||
@ -173,7 +176,7 @@ Input.getData = function getData(input) {
|
||||
addr: '[unknown]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
@ -195,7 +198,7 @@ Input.getData = function getData(input) {
|
||||
addr: addr,
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
@ -260,7 +263,7 @@ Input.getData = function getData(input) {
|
||||
addr: '[unknown]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
|
||||
@ -88,7 +88,7 @@ Output.getData = function getData(output) {
|
||||
addr: addr,
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: output.value,
|
||||
script: s,
|
||||
@ -109,7 +109,7 @@ Output.getData = function getData(output) {
|
||||
addr: addr,
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: output.value,
|
||||
script: s,
|
||||
@ -143,7 +143,7 @@ Output.getData = function getData(output) {
|
||||
})
|
||||
},
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: output.value,
|
||||
script: s,
|
||||
@ -171,7 +171,7 @@ Output.getData = function getData(output) {
|
||||
addrs: null
|
||||
},
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: output.value,
|
||||
script: s,
|
||||
@ -191,7 +191,7 @@ Output.getData = function getData(output) {
|
||||
addr: '[colored]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: ret,
|
||||
flags: ret,
|
||||
text: utils.array2utf8(ret),
|
||||
value: output.value,
|
||||
script: s,
|
||||
@ -209,7 +209,7 @@ Output.getData = function getData(output) {
|
||||
addr: '[unknown]',
|
||||
multisig: null,
|
||||
redeem: null,
|
||||
data: null,
|
||||
flags: null,
|
||||
text: null,
|
||||
value: new bn(0),
|
||||
script: s,
|
||||
|
||||
@ -80,6 +80,8 @@ main.checkpoints.tsLastCheckpoint = 1397080064;
|
||||
main.checkpoints.txsLastCheckpoint = 36544669;
|
||||
main.checkpoints.txsPerDay = 60000.0;
|
||||
|
||||
main.halvingInterval = 210000;
|
||||
|
||||
// http://blockexplorer.com/b/0
|
||||
// http://blockexplorer.com/rawblock/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
|
||||
main.genesis = {
|
||||
@ -153,6 +155,8 @@ testnet.checkpoints.tsLastCheckpoint = 1338180505;
|
||||
testnet.checkpoints.txsLastCheckpoint = 16341;
|
||||
testnet.checkpoints.txsPerDay = 300;
|
||||
|
||||
testnet.halvingInterval = 210000;
|
||||
|
||||
// http://blockexplorer.com/testnet/b/0
|
||||
// http://blockexplorer.com/testnet/rawblock/000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
|
||||
testnet.genesis = {
|
||||
|
||||
@ -795,6 +795,9 @@ TX.prototype._recalculateFee = function recalculateFee() {
|
||||
};
|
||||
|
||||
TX.prototype.getFee = function getFee() {
|
||||
if (this.funds('in').cmp(this.funds('out')) < 0)
|
||||
return new bn(0);
|
||||
|
||||
return this.funds('in').sub(this.funds('out'));
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user