diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 5883a3fb..707b1862 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1532,13 +1532,15 @@ RPC.prototype._template = co(function* _template(version, coinbase, rules) { }); RPC.prototype.__template = co(function* _template(version, coinbase, rules) { + var mutable = ['time', 'transactions', 'prevblock']; var txs = []; var txIndex = {}; + var vbavailable = {}; + var vbrules = []; var attempt = yield this._getAttempt(false); var block = attempt.block; var i, j, tx, deps, input, dep, output, raw, rwhash; - var keys, vbavailable, vbrules, mutable, template; - var id, deployment, state; + var template, name, deployment, state; for (i = 1; i < block.txs.length; i++) { tx = block.txs[i]; @@ -1569,18 +1571,13 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { }); } - keys = Object.keys(this.network.deployments); - vbavailable = {}; - vbrules = []; - mutable = ['time', 'transactions', 'prevblock']; - if (version >= 2) mutable.push('version/force'); - for (i = 0; i < keys.length; i++) { - id = keys[i]; - deployment = this.network.deployments[id]; - state = yield this.chain.getState(this.chain.tip, id); + for (i = 0; i < this.network.deploys.length; i++) { + deployment = this.network.deploys[i]; + state = yield this.chain.getState(this.chain.tip, deployment); + name = deployment.name; switch (state) { case constants.thresholdStates.DEFINED: @@ -1589,17 +1586,17 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { case constants.thresholdStates.LOCKED_IN: block.version |= 1 << deployment.bit; case constants.thresholdStates.STARTED: - vbavailable[id] = deployment.bit; + vbavailable[name] = deployment.bit; if (rules) { - if (rules.indexOf(id) === -1 && !deployment.force) + if (rules.indexOf(name) === -1 && !deployment.force) block.version &= ~(1 << deployment.bit); } break; case constants.thresholdStates.ACTIVE: - vbrules.push(id); + vbrules.push(name); if (rules) { - if (rules.indexOf(id) === -1 && !deployment.force) - throw new RPCError('Client must support ' + id + '.'); + if (rules.indexOf(name) === -1 && !deployment.force) + throw new RPCError('Client must support ' + name + '.'); } break; }