add block.reward. add coinbase data to into. failsafe for getFee.

This commit is contained in:
Christopher Jeffrey 2015-12-23 05:33:21 -08:00
parent fdc11b76b2
commit f68750991d
5 changed files with 43 additions and 12 deletions

View File

@ -7,6 +7,7 @@
var bcoin = require('../bcoin'); var bcoin = require('../bcoin');
var utils = bcoin.utils; var utils = bcoin.utils;
var constants = bcoin.protocol.constants; var constants = bcoin.protocol.constants;
var network = bcoin.protocol.network;
/** /**
* Block * Block
@ -299,6 +300,26 @@ Block.prototype.__defineGetter__('rhash', function() {
return utils.revHex(this.hash('hex')); 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() { Block.prototype.inspect = function inspect() {
var copy = bcoin.block(this, this.subtype); var copy = bcoin.block(this, this.subtype);
copy.__proto__ = null; copy.__proto__ = null;

View File

@ -115,7 +115,7 @@ Input.getData = function getData(input) {
addr: '[unknown]', addr: '[unknown]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: new bn(0), value: new bn(0),
script: s, script: s,
@ -125,17 +125,20 @@ Input.getData = function getData(input) {
} }
if (+input.out.hash === 0) { if (+input.out.hash === 0) {
data = bcoin.script.coinbase(input.script);
return { return {
type: 'coinbase', type: 'coinbase',
side: 'input', side: 'input',
coinbase: data,
height: data.height || -1,
sig: null, sig: null,
pub: null, pub: null,
hash: '[coinbase]', hash: '[coinbase]',
addr: '[coinbase]', addr: '[coinbase]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: data.flags,
text: null, text: data.text,
value: new bn(0), value: new bn(0),
script: s, script: s,
seq: input.seq, seq: input.seq,
@ -173,7 +176,7 @@ Input.getData = function getData(input) {
addr: '[unknown]', addr: '[unknown]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: new bn(0), value: new bn(0),
script: s, script: s,
@ -195,7 +198,7 @@ Input.getData = function getData(input) {
addr: addr, addr: addr,
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: new bn(0), value: new bn(0),
script: s, script: s,
@ -260,7 +263,7 @@ Input.getData = function getData(input) {
addr: '[unknown]', addr: '[unknown]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: new bn(0), value: new bn(0),
script: s, script: s,

View File

@ -88,7 +88,7 @@ Output.getData = function getData(output) {
addr: addr, addr: addr,
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: output.value, value: output.value,
script: s, script: s,
@ -109,7 +109,7 @@ Output.getData = function getData(output) {
addr: addr, addr: addr,
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: output.value, value: output.value,
script: s, script: s,
@ -143,7 +143,7 @@ Output.getData = function getData(output) {
}) })
}, },
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: output.value, value: output.value,
script: s, script: s,
@ -171,7 +171,7 @@ Output.getData = function getData(output) {
addrs: null addrs: null
}, },
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: output.value, value: output.value,
script: s, script: s,
@ -191,7 +191,7 @@ Output.getData = function getData(output) {
addr: '[colored]', addr: '[colored]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: ret, flags: ret,
text: utils.array2utf8(ret), text: utils.array2utf8(ret),
value: output.value, value: output.value,
script: s, script: s,
@ -209,7 +209,7 @@ Output.getData = function getData(output) {
addr: '[unknown]', addr: '[unknown]',
multisig: null, multisig: null,
redeem: null, redeem: null,
data: null, flags: null,
text: null, text: null,
value: new bn(0), value: new bn(0),
script: s, script: s,

View File

@ -80,6 +80,8 @@ main.checkpoints.tsLastCheckpoint = 1397080064;
main.checkpoints.txsLastCheckpoint = 36544669; main.checkpoints.txsLastCheckpoint = 36544669;
main.checkpoints.txsPerDay = 60000.0; main.checkpoints.txsPerDay = 60000.0;
main.halvingInterval = 210000;
// http://blockexplorer.com/b/0 // http://blockexplorer.com/b/0
// http://blockexplorer.com/rawblock/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f // http://blockexplorer.com/rawblock/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
main.genesis = { main.genesis = {
@ -153,6 +155,8 @@ testnet.checkpoints.tsLastCheckpoint = 1338180505;
testnet.checkpoints.txsLastCheckpoint = 16341; testnet.checkpoints.txsLastCheckpoint = 16341;
testnet.checkpoints.txsPerDay = 300; testnet.checkpoints.txsPerDay = 300;
testnet.halvingInterval = 210000;
// http://blockexplorer.com/testnet/b/0 // http://blockexplorer.com/testnet/b/0
// http://blockexplorer.com/testnet/rawblock/000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 // http://blockexplorer.com/testnet/rawblock/000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
testnet.genesis = { testnet.genesis = {

View File

@ -795,6 +795,9 @@ TX.prototype._recalculateFee = function recalculateFee() {
}; };
TX.prototype.getFee = function getFee() { 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')); return this.funds('in').sub(this.funds('out'));
}; };