From d396cdd0fd4e0f1413cbd26ee7a3cfbd59922e18 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 6 Jan 2017 21:14:11 -0800 Subject: [PATCH] constants: minor. --- lib/http/rpc.js | 8 ++++---- lib/net/common.js | 4 ++-- lib/protocol/consensus.js | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index fa3b75de..3935e363 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -33,7 +33,7 @@ var Logger = require('../node/logger'); var IP = require('../utils/ip'); var encoding = require('../utils/encoding'); var consensus = require('../protocol/consensus'); -var USER_VERSION = require('../../package.json').version; +var pkg = require('../../package.json'); /** * RPC @@ -324,7 +324,7 @@ RPC.prototype.getinfo = co(function* getinfo(args) { balance = yield this.wallet.getBalance(); return { - version: USER_VERSION, + version: pkg.version, protocolversion: this.pool.protoVersion, walletversion: 0, balance: Amount.btc(balance.unconfirmed, true), @@ -377,7 +377,7 @@ RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args) { throw new RPCError('getnetworkinfo'); return { - version: USER_VERSION, + version: pkg.version, subversion: this.pool.userAgent, protocolversion: this.pool.protoVersion, localservices: this.pool.address.services, @@ -2728,7 +2728,7 @@ RPC.prototype.dumpwallet = co(function* dumpwallet(args) { file = toString(args[0]); time = util.date(); out = [ - util.fmt('# Wallet Dump created by BCoin %s', USER_VERSION), + util.fmt('# Wallet Dump created by BCoin %s', pkg.version), util.fmt('# * Created on %s', time), util.fmt('# * Best block at time of backup was %d (%s),', this.chain.height, this.chain.tip.rhash()), diff --git a/lib/net/common.js b/lib/net/common.js index d7a031b6..0a60ae82 100644 --- a/lib/net/common.js +++ b/lib/net/common.js @@ -7,7 +7,7 @@ 'use strict'; -var USER_VERSION = require('../../package.json').version; +var pkg = require('../../package.json'); /** * Default protocol version. @@ -85,7 +85,7 @@ exports.REQUIRED_SERVICES = 0 * @default */ -exports.USER_AGENT = '/bcoin:' + USER_VERSION + '/'; +exports.USER_AGENT = '/bcoin:' + pkg.version + '/'; /** * Max message size (~4mb with segwit, formerly 2mb) diff --git a/lib/protocol/consensus.js b/lib/protocol/consensus.js index 2a3e01e5..27a14ff1 100644 --- a/lib/protocol/consensus.js +++ b/lib/protocol/consensus.js @@ -27,6 +27,28 @@ exports.COIN = 100000000; exports.MAX_MONEY = 21000000 * exports.COIN; +/** + * Base block subsidy (consensus). + * Note to shitcoin implementors: if you + * increase this to anything greater than + * 33 bits, getReward will have to be + * modified to handle the shifts. + * @const {Amount} + * @default + */ + +exports.BASE_REWARD = 50 * exports.COIN; + +/** + * Half base block subsidy. Required to + * calculate the reward properly (with + * only 32 bit shifts available). + * @const {Amount} + * @default + */ + +exports.HALF_REWARD = Math.floor(exports.BASE_REWARD / 2); + /** * Maximum block base size (consensus). * @const {Number} @@ -302,7 +324,7 @@ exports.getReward = function getReward(height, interval) { // cheat. We only start halving once the // halvings are at least 1. if (halvings === 0) - return 5000000000; + return exports.BASE_REWARD; - return 2500000000 >>> (halvings - 1); + return exports.HALF_REWARD >>> (halvings - 1); };