refactor: more moving.
This commit is contained in:
parent
69d0320faa
commit
75430cae8b
@ -11,7 +11,7 @@ var AsyncObject = require('../utils/async');
|
||||
var Network = require('../protocol/network');
|
||||
var Logger = require('../node/logger');
|
||||
var ChainDB = require('./chaindb');
|
||||
var constants = require('../protocol/constants');
|
||||
var common = require('./common');
|
||||
var consensus = require('../protocol/consensus');
|
||||
var util = require('../utils/util');
|
||||
var Locker = require('../utils/locker');
|
||||
@ -498,8 +498,8 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
|
||||
active = yield this.isActive(prev, deployments.csv);
|
||||
if (active) {
|
||||
state.flags |= Script.flags.VERIFY_CHECKSEQUENCEVERIFY;
|
||||
state.lockFlags |= constants.lockFlags.VERIFY_SEQUENCE;
|
||||
state.lockFlags |= constants.lockFlags.MEDIAN_TIME_PAST;
|
||||
state.lockFlags |= common.lockFlags.VERIFY_SEQUENCE;
|
||||
state.lockFlags |= common.lockFlags.MEDIAN_TIME_PAST;
|
||||
}
|
||||
|
||||
// Segregrated witness is now usable (bip141 - segnet4)
|
||||
@ -2045,7 +2045,7 @@ Chain.prototype.isActive = co(function* isActive(prev, deployment) {
|
||||
|
||||
state = yield this.getState(prev, deployment);
|
||||
|
||||
return state === constants.thresholdStates.ACTIVE;
|
||||
return state === common.thresholdStates.ACTIVE;
|
||||
});
|
||||
|
||||
/**
|
||||
@ -2061,7 +2061,7 @@ Chain.prototype.isActive = co(function* isActive(prev, deployment) {
|
||||
Chain.prototype.getState = co(function* getState(prev, deployment) {
|
||||
var period = this.network.minerWindow;
|
||||
var threshold = this.network.activationThreshold;
|
||||
var thresholdStates = constants.thresholdStates;
|
||||
var thresholdStates = common.thresholdStates;
|
||||
var bit = deployment.bit;
|
||||
var compute = [];
|
||||
var i, entry, count, state, cached;
|
||||
@ -2180,13 +2180,13 @@ Chain.prototype.computeBlockVersion = co(function* computeBlockVersion(prev) {
|
||||
deployment = this.network.deploys[i];
|
||||
state = yield this.getState(prev, deployment);
|
||||
|
||||
if (state === constants.thresholdStates.LOCKED_IN
|
||||
|| state === constants.thresholdStates.STARTED) {
|
||||
if (state === common.thresholdStates.LOCKED_IN
|
||||
|| state === common.thresholdStates.STARTED) {
|
||||
version |= 1 << deployment.bit;
|
||||
}
|
||||
}
|
||||
|
||||
version |= constants.versionbits.TOP_BITS;
|
||||
version |= consensus.VERSION_TOP_BITS;
|
||||
version >>>= 0;
|
||||
|
||||
return version;
|
||||
@ -2226,7 +2226,7 @@ Chain.prototype.verifyFinal = co(function* verifyFinal(prev, tx, flags) {
|
||||
if (tx.locktime < consensus.LOCKTIME_THRESHOLD)
|
||||
return tx.isFinal(height, -1);
|
||||
|
||||
if (flags & constants.lockFlags.MEDIAN_TIME_PAST) {
|
||||
if (flags & common.lockFlags.MEDIAN_TIME_PAST) {
|
||||
ts = yield prev.getMedianTimeAsync();
|
||||
return tx.isFinal(height, ts);
|
||||
}
|
||||
@ -2249,7 +2249,7 @@ Chain.prototype.getLocks = co(function* getLocks(prev, tx, view, flags) {
|
||||
var granularity = consensus.SEQUENCE_GRANULARITY;
|
||||
var disableFlag = consensus.SEQUENCE_DISABLE_FLAG;
|
||||
var typeFlag = consensus.SEQUENCE_TYPE_FLAG;
|
||||
var hasFlag = flags & constants.lockFlags.VERIFY_SEQUENCE;
|
||||
var hasFlag = flags & common.lockFlags.VERIFY_SEQUENCE;
|
||||
var nextHeight = this.height + 1;
|
||||
var minHeight = -1;
|
||||
var minTime = -1;
|
||||
@ -2328,7 +2328,7 @@ function DeploymentState() {
|
||||
|
||||
this.flags = Script.flags.MANDATORY_VERIFY_FLAGS;
|
||||
this.flags &= ~Script.flags.VERIFY_P2SH;
|
||||
this.lockFlags = constants.lockFlags.MANDATORY_LOCKTIME_FLAGS;
|
||||
this.lockFlags = common.lockFlags.MANDATORY_LOCKTIME_FLAGS;
|
||||
this.bip34 = false;
|
||||
}
|
||||
|
||||
@ -2374,7 +2374,7 @@ DeploymentState.prototype.hasCLTV = function hasCLTV() {
|
||||
*/
|
||||
|
||||
DeploymentState.prototype.hasMTP = function hasMTP() {
|
||||
return (this.lockFlags & constants.lockFlags.MEDIAN_TIME_PAST) !== 0;
|
||||
return (this.lockFlags & common.lockFlags.MEDIAN_TIME_PAST) !== 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var Network = require('../protocol/network');
|
||||
var constants = require('../protocol/constants');
|
||||
var consensus = require('../protocol/consensus');
|
||||
var util = require('../utils/util');
|
||||
var crypto = require('../crypto/crypto');
|
||||
@ -370,8 +369,8 @@ ChainEntry.prototype.isHistorical = function isHistorical() {
|
||||
*/
|
||||
|
||||
ChainEntry.prototype.hasUnknown = function hasUnknown() {
|
||||
var bits = this.version & constants.versionbits.TOP_MASK;
|
||||
var topBits = constants.versionbits.TOP_BITS;
|
||||
var bits = this.version & consensus.VERSION_TOP_MASK;
|
||||
var topBits = consensus.VERSION_TOP_BITS;
|
||||
|
||||
if ((bits >>> 0) !== topBits)
|
||||
return false;
|
||||
@ -386,8 +385,8 @@ ChainEntry.prototype.hasUnknown = function hasUnknown() {
|
||||
*/
|
||||
|
||||
ChainEntry.prototype.hasBit = function hasBit(bit) {
|
||||
var bits = this.version & constants.versionbits.TOP_MASK;
|
||||
var topBits = constants.versionbits.TOP_BITS;
|
||||
var bits = this.version & consensus.VERSION_TOP_MASK;
|
||||
var topBits = consensus.VERSION_TOP_BITS;
|
||||
var mask = 1 << bit;
|
||||
return (bits >>> 0) === topBits && (this.version & mask) !== 0;
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* constants.js - bitcoin constants for bcoin
|
||||
* common.js - bitcoin constants for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
@ -35,32 +35,6 @@ exports.lockFlags.STANDARD_LOCKTIME_FLAGS = 0
|
||||
| exports.lockFlags.VERIFY_SEQUENCE
|
||||
| exports.lockFlags.MEDIAN_TIME_PAST;
|
||||
|
||||
/**
|
||||
* Versionbits constants.
|
||||
* @enum {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
exports.versionbits = {
|
||||
/**
|
||||
* What block version to use for new blocks (pre versionbits)
|
||||
*/
|
||||
|
||||
LAST_OLD_BLOCK_VERSION: 4,
|
||||
|
||||
/**
|
||||
* What bits to set in version for versionbits blocks
|
||||
*/
|
||||
|
||||
TOP_BITS: 0x20000000,
|
||||
|
||||
/**
|
||||
* What bitmask determines whether versionbits is in use
|
||||
*/
|
||||
|
||||
TOP_MASK: 0xe0000000
|
||||
};
|
||||
|
||||
/**
|
||||
* Threshold states for versionbits
|
||||
* @enum {Number}
|
||||
@ -12,7 +12,7 @@ var util = require('../utils/util');
|
||||
var co = require('../utils/co');
|
||||
var crypto = require('../crypto/crypto');
|
||||
var assert = require('assert');
|
||||
var constants = require('../protocol/constants');
|
||||
var common = require('../blockchain/common');
|
||||
var ec = require('../crypto/ec');
|
||||
var Amount = require('../btc/amount');
|
||||
var NetAddress = require('../primitives/netaddress');
|
||||
@ -631,19 +631,19 @@ RPC.prototype._getBIP9Softforks = co(function* _getBIP9Softforks() {
|
||||
state = yield this.chain.getState(tip, deployment);
|
||||
|
||||
switch (state) {
|
||||
case constants.thresholdStates.DEFINED:
|
||||
case common.thresholdStates.DEFINED:
|
||||
state = 'defined';
|
||||
break;
|
||||
case constants.thresholdStates.STARTED:
|
||||
case common.thresholdStates.STARTED:
|
||||
state = 'started';
|
||||
break;
|
||||
case constants.thresholdStates.LOCKED_IN:
|
||||
case common.thresholdStates.LOCKED_IN:
|
||||
state = 'locked_in';
|
||||
break;
|
||||
case constants.thresholdStates.ACTIVE:
|
||||
case common.thresholdStates.ACTIVE:
|
||||
state = 'active';
|
||||
break;
|
||||
case constants.thresholdStates.FAILED:
|
||||
case common.thresholdStates.FAILED:
|
||||
state = 'failed';
|
||||
break;
|
||||
}
|
||||
@ -984,7 +984,7 @@ RPC.prototype.getmempoolinfo = co(function* getmempoolinfo(args) {
|
||||
size: this.mempool.totalTX,
|
||||
bytes: this.mempool.getSize(),
|
||||
usage: this.mempool.getSize(),
|
||||
maxmempool: constants.mempool.MAX_MEMPOOL_SIZE,
|
||||
maxmempool: this.mempool.maxSize,
|
||||
mempoolminfee: Amount.btc(this.mempool.minRelay, true)
|
||||
};
|
||||
});
|
||||
@ -1612,19 +1612,19 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
||||
name = deploy.name;
|
||||
|
||||
switch (state) {
|
||||
case constants.thresholdStates.DEFINED:
|
||||
case constants.thresholdStates.FAILED:
|
||||
case common.thresholdStates.DEFINED:
|
||||
case common.thresholdStates.FAILED:
|
||||
break;
|
||||
case constants.thresholdStates.LOCKED_IN:
|
||||
case common.thresholdStates.LOCKED_IN:
|
||||
block.version |= 1 << deploy.bit;
|
||||
case constants.thresholdStates.STARTED:
|
||||
case common.thresholdStates.STARTED:
|
||||
vbavailable[name] = deploy.bit;
|
||||
if (rules) {
|
||||
if (rules.indexOf(name) === -1 && !deploy.force)
|
||||
block.version &= ~(1 << deploy.bit);
|
||||
}
|
||||
break;
|
||||
case constants.thresholdStates.ACTIVE:
|
||||
case common.thresholdStates.ACTIVE:
|
||||
if (rules) {
|
||||
if (rules.indexOf(name) === -1 && !deploy.force)
|
||||
throw new RPCError('Client must support ' + name + '.');
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var AsyncObject = require('../utils/async');
|
||||
var constants = require('../protocol/constants');
|
||||
var common = require('../blockchain/common');
|
||||
var policy = require('../protocol/policy');
|
||||
var util = require('../utils/util');
|
||||
var co = require('../utils/co');
|
||||
@ -692,7 +692,7 @@ Mempool.prototype.addTX = co(function* addTX(tx) {
|
||||
*/
|
||||
|
||||
Mempool.prototype._addTX = co(function* _addTX(tx) {
|
||||
var lockFlags = constants.lockFlags.STANDARD_LOCKTIME_FLAGS;
|
||||
var lockFlags = common.lockFlags.STANDARD_LOCKTIME_FLAGS;
|
||||
var hash = tx.hash('hex');
|
||||
var ret = new VerifyResult();
|
||||
var entry, view, missing;
|
||||
@ -831,7 +831,7 @@ Mempool.prototype._addTX = co(function* _addTX(tx) {
|
||||
|
||||
Mempool.prototype.verify = co(function* verify(entry, view) {
|
||||
var height = this.chain.height + 1;
|
||||
var lockFlags = constants.lockFlags.STANDARD_LOCKTIME_FLAGS;
|
||||
var lockFlags = common.lockFlags.STANDARD_LOCKTIME_FLAGS;
|
||||
var flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
||||
var ret = new VerifyResult();
|
||||
var tx = entry.tx;
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var constants = require('../protocol/constants');
|
||||
var policy = require('../protocol/policy');
|
||||
var util = require('../utils/util');
|
||||
var Script = require('../script/script');
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
var assert = require('assert');
|
||||
var Network = require('../protocol/network');
|
||||
var networks = require('../protocol/networks');
|
||||
var encoding = require('../script/encoding');
|
||||
var enc = require('../utils/encoding');
|
||||
var common = require('../script/common');
|
||||
var encoding = require('../utils/encoding');
|
||||
var util = require('../utils/util');
|
||||
var crypto = require('../crypto/crypto');
|
||||
var BufferReader = require('../utils/reader');
|
||||
@ -38,7 +38,7 @@ function Address(options) {
|
||||
if (!(this instanceof Address))
|
||||
return new Address(options);
|
||||
|
||||
this.hash = enc.ZERO_HASH160;
|
||||
this.hash = encoding.ZERO_HASH160;
|
||||
this.type = Address.types.PUBKEYHASH;
|
||||
this.version = -1;
|
||||
this.network = Network.primary;
|
||||
@ -52,14 +52,14 @@ function Address(options) {
|
||||
* @enum {Number}
|
||||
*/
|
||||
|
||||
Address.types = encoding.types;
|
||||
Address.types = common.types;
|
||||
|
||||
/**
|
||||
* Address types by value.
|
||||
* @const {RevMap}
|
||||
*/
|
||||
|
||||
Address.typesByVal = encoding.typesByVal;
|
||||
Address.typesByVal = common.typesByVal;
|
||||
|
||||
/**
|
||||
* Inject properties from options object.
|
||||
@ -134,7 +134,7 @@ Address.prototype.verifyNetwork = function verifyNetwork(network) {
|
||||
*/
|
||||
|
||||
Address.prototype.getType = function getType() {
|
||||
return encoding.typesByVal[this.type].toLowerCase();
|
||||
return Address.typesByVal[this.type].toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -67,6 +67,24 @@ exports.MAX_BLOCK_SIGOPS = 1000000 / 50;
|
||||
|
||||
exports.MAX_BLOCK_SIGOPS_COST = 80000;
|
||||
|
||||
/**
|
||||
* What bits to set in version
|
||||
* for versionbits blocks.
|
||||
* @const {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
exports.VERSION_TOP_BITS = 0x20000000;
|
||||
|
||||
/**
|
||||
* What bitmask determines whether
|
||||
* versionbits is in use.
|
||||
* @const {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
exports.VERSION_TOP_MASK = 0xe0000000;
|
||||
|
||||
/**
|
||||
* Number of blocks before a coinbase
|
||||
* spend can occur (consensus).
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
var assert = require('assert');
|
||||
var util = require('../utils/util');
|
||||
var networks = require('./networks');
|
||||
var constants = require('./constants');
|
||||
var consensus = require('./consensus');
|
||||
var TimeData = require('./timedata');
|
||||
|
||||
/**
|
||||
@ -44,7 +44,7 @@ function Network(options) {
|
||||
this.minerWindow = options.minerWindow;
|
||||
this.deployments = options.deployments;
|
||||
this.deploys = options.deploys;
|
||||
this.unknownBits = ~constants.versionbits.TOP_MASK;
|
||||
this.unknownBits = ~consensus.VERSION_TOP_MASK;
|
||||
this.keyPrefix = options.keyPrefix;
|
||||
this.addressPrefix = options.addressPrefix;
|
||||
this.requireStandard = options.requireStandard;
|
||||
@ -100,7 +100,7 @@ Network.prototype._init = function _init() {
|
||||
bits |= 1 << deployment.bit;
|
||||
}
|
||||
|
||||
bits |= constants.versionbits.TOP_MASK;
|
||||
bits |= consensus.VERSION_TOP_MASK;
|
||||
|
||||
this.unknownBits = ~bits;
|
||||
};
|
||||
|
||||
@ -10,10 +10,10 @@
|
||||
var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var util = require('../utils/util');
|
||||
var encoding = require('./encoding');
|
||||
var common = require('./common');
|
||||
var BufferReader = require('../utils/reader');
|
||||
var StaticWriter = require('../utils/staticwriter');
|
||||
var opcodes = encoding.opcodes;
|
||||
var opcodes = common.opcodes;
|
||||
|
||||
/**
|
||||
* A simple struct which contains
|
||||
@ -274,7 +274,7 @@ Opcode.fromPush = function fromPush(data) {
|
||||
*/
|
||||
|
||||
Opcode.fromNumber = function fromNumber(num) {
|
||||
return Opcode.fromData(encoding.array(num));
|
||||
return Opcode.fromData(common.array(num));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -346,7 +346,7 @@ Opcode.fromSymbol = function fromSymbol(name) {
|
||||
if (!util.startsWith(name, 'OP_'))
|
||||
name = 'OP_' + name;
|
||||
|
||||
op = encoding.opcodes[name];
|
||||
op = common.opcodes[name];
|
||||
assert(op != null, 'Unknown opcode.');
|
||||
|
||||
return Opcode.fromOp(op);
|
||||
|
||||
@ -9,8 +9,8 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../utils/util');
|
||||
var encoding = require('./encoding');
|
||||
var scriptTypes = encoding.types;
|
||||
var common = require('./common');
|
||||
var scriptTypes = common.types;
|
||||
|
||||
/**
|
||||
* Witness Program
|
||||
@ -96,7 +96,7 @@ Program.prototype.inspect = function inspect() {
|
||||
return '<Program:'
|
||||
+ ' version=' + this.version
|
||||
+ ' data=' + this.data.toString('hex')
|
||||
+ ' type=' + encoding.typesByVal[this.getType()].toLowerCase()
|
||||
+ ' type=' + common.typesByVal[this.getType()].toLowerCase()
|
||||
+ '>';
|
||||
};
|
||||
|
||||
|
||||
@ -20,16 +20,16 @@ var Program = require('./program');
|
||||
var Opcode = require('./opcode');
|
||||
var Stack = require('./stack');
|
||||
var sigcache = require('./sigcache');
|
||||
var encoding = require('./encoding');
|
||||
var enc = require('../utils/encoding');
|
||||
var common = require('./common');
|
||||
var encoding = require('../utils/encoding');
|
||||
var ec = require('../crypto/ec');
|
||||
var Address = require('../primitives/address');
|
||||
var opcodes = encoding.opcodes;
|
||||
var scriptTypes = encoding.types;
|
||||
var ScriptError = encoding.ScriptError;
|
||||
var STACK_TRUE = encoding.STACK_TRUE;
|
||||
var STACK_FALSE = encoding.STACK_FALSE;
|
||||
var STACK_NEGATE = encoding.STACK_NEGATE;
|
||||
var opcodes = common.opcodes;
|
||||
var scriptTypes = common.types;
|
||||
var ScriptError = common.ScriptError;
|
||||
var STACK_TRUE = common.STACK_TRUE;
|
||||
var STACK_FALSE = common.STACK_FALSE;
|
||||
var STACK_NEGATE = common.STACK_NEGATE;
|
||||
|
||||
/**
|
||||
* Represents a input or output script.
|
||||
@ -60,21 +60,21 @@ function Script(options) {
|
||||
* @default
|
||||
*/
|
||||
|
||||
Script.opcodes = encoding.opcodes;
|
||||
Script.opcodes = common.opcodes;
|
||||
|
||||
/**
|
||||
* Opcodes by value.
|
||||
* @const {RevMap}
|
||||
*/
|
||||
|
||||
Script.opcodesByVal = encoding.opcodesByVal;
|
||||
Script.opcodesByVal = common.opcodesByVal;
|
||||
|
||||
/**
|
||||
* Script and locktime flags. See {@link VerifyFlags}.
|
||||
* @enum {Number}
|
||||
*/
|
||||
|
||||
Script.flags = encoding.flags;
|
||||
Script.flags = common.flags;
|
||||
|
||||
/**
|
||||
* Sighash Types.
|
||||
@ -82,28 +82,28 @@ Script.flags = encoding.flags;
|
||||
* @default
|
||||
*/
|
||||
|
||||
Script.hashType = encoding.hashType;
|
||||
Script.hashType = common.hashType;
|
||||
|
||||
/**
|
||||
* Sighash types by value.
|
||||
* @const {RevMap}
|
||||
*/
|
||||
|
||||
Script.hashTypeByVal = encoding.hashTypeByVal;
|
||||
Script.hashTypeByVal = common.hashTypeByVal;
|
||||
|
||||
/**
|
||||
* Output script types.
|
||||
* @enum {Number}
|
||||
*/
|
||||
|
||||
Script.types = encoding.types;
|
||||
Script.types = common.types;
|
||||
|
||||
/**
|
||||
* Output script types by value.
|
||||
* @const {RevMap}
|
||||
*/
|
||||
|
||||
Script.typesByVal = encoding.typesByVal;
|
||||
Script.typesByVal = common.typesByVal;
|
||||
|
||||
/**
|
||||
* Getter to retrieve code length.
|
||||
@ -302,7 +302,7 @@ Script.prototype.inspect = function inspect() {
|
||||
*/
|
||||
|
||||
Script.prototype.toString = function toString() {
|
||||
return encoding.formatCode(this.code);
|
||||
return common.formatCode(this.code);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -312,7 +312,7 @@ Script.prototype.toString = function toString() {
|
||||
*/
|
||||
|
||||
Script.prototype.toASM = function toASM(decode) {
|
||||
return encoding.formatASM(this.code, decode);
|
||||
return common.formatASM(this.code, decode);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1432,7 +1432,7 @@ Script.bool = function bool(value) {
|
||||
*/
|
||||
|
||||
Script.num = function num(value, flags, size) {
|
||||
return encoding.num(value, flags, size);
|
||||
return common.num(value, flags, size);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1449,7 +1449,7 @@ Script.num = function num(value, flags, size) {
|
||||
*/
|
||||
|
||||
Script.array = function(value) {
|
||||
return encoding.array(value);
|
||||
return common.array(value);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1978,7 +1978,7 @@ Script.prototype.getSize = function getSize() {
|
||||
*/
|
||||
|
||||
Script.prototype.getVarSize = function getVarSize() {
|
||||
return enc.sizeVarBytes(this.raw);
|
||||
return encoding.sizeVarBytes(this.raw);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2736,7 +2736,7 @@ Script.prototype.set = function set(i, data) {
|
||||
*/
|
||||
|
||||
Script.isHash = function isHash(hash) {
|
||||
return encoding.isHash(hash);
|
||||
return common.isHash(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2747,7 +2747,7 @@ Script.isHash = function isHash(hash) {
|
||||
*/
|
||||
|
||||
Script.isKey = function isKey(key) {
|
||||
return encoding.isKey(key);
|
||||
return common.isKey(key);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2758,7 +2758,7 @@ Script.isKey = function isKey(key) {
|
||||
*/
|
||||
|
||||
Script.isSignature = function isSignature(sig) {
|
||||
return encoding.isSignature(sig);
|
||||
return common.isSignature(sig);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2768,7 +2768,7 @@ Script.isSignature = function isSignature(sig) {
|
||||
*/
|
||||
|
||||
Script.isDummy = function isDummy(data) {
|
||||
return encoding.isDummy(data);
|
||||
return common.isDummy(data);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2807,7 +2807,7 @@ Script.validateKey = function validateKey(key, flags, version) {
|
||||
*/
|
||||
|
||||
Script.isCompressedEncoding = function isCompressedEncoding(key) {
|
||||
return encoding.isCompressedEncoding(key);
|
||||
return common.isCompressedEncoding(key);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2817,7 +2817,7 @@ Script.isCompressedEncoding = function isCompressedEncoding(key) {
|
||||
*/
|
||||
|
||||
Script.isKeyEncoding = function isKeyEncoding(key) {
|
||||
return encoding.isKeyEncoding(key);
|
||||
return common.isKeyEncoding(key);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2870,7 +2870,7 @@ Script.validateSignature = function validateSignature(sig, flags) {
|
||||
*/
|
||||
|
||||
Script.isSignatureEncoding = function isSignatureEncoding(sig) {
|
||||
return encoding.isSignatureEncoding(sig);
|
||||
return common.isSignatureEncoding(sig);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../utils/util');
|
||||
var ec = require('../crypto/ec');
|
||||
var assert = require('assert');
|
||||
|
||||
/**
|
||||
* Signature cache.
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var encoding = require('./encoding');
|
||||
var common = require('./common');
|
||||
|
||||
/**
|
||||
* Represents the stack of a Script during execution.
|
||||
@ -25,10 +25,26 @@ function Stack(items) {
|
||||
this.items = items || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter to retrieve items length.
|
||||
* @function
|
||||
* @name length(get)
|
||||
* @memberof Stack#
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Stack.prototype.__defineGetter__('length', function() {
|
||||
return this.items.length;
|
||||
});
|
||||
|
||||
/**
|
||||
* Setter to set items length.
|
||||
* @function
|
||||
* @name length(set)
|
||||
* @memberof Stack#
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Stack.prototype.__defineSetter__('length', function(length) {
|
||||
return this.items.length = length;
|
||||
});
|
||||
@ -48,7 +64,7 @@ Stack.prototype.inspect = function inspect() {
|
||||
*/
|
||||
|
||||
Stack.prototype.toString = function toString() {
|
||||
return encoding.formatStack(this.items);
|
||||
return common.formatStack(this.items);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -58,7 +74,7 @@ Stack.prototype.toString = function toString() {
|
||||
*/
|
||||
|
||||
Stack.prototype.toASM = function toASM(decode) {
|
||||
return encoding.formatStackASM(this.items, decode);
|
||||
return common.formatStackASM(this.items, decode);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -11,17 +11,17 @@ var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var util = require('../utils/util');
|
||||
var Script = require('./script');
|
||||
var encoding = require('./encoding');
|
||||
var enc = require('../utils/encoding');
|
||||
var common = require('./common');
|
||||
var encoding = require('../utils/encoding');
|
||||
var Opcode = require('./opcode');
|
||||
var BufferReader = require('../utils/reader');
|
||||
var StaticWriter = require('../utils/staticwriter');
|
||||
var Address = require('../primitives/address');
|
||||
var Stack = require('./stack');
|
||||
var opcodes = encoding.opcodes;
|
||||
var scriptTypes = encoding.types;
|
||||
var STACK_FALSE = encoding.STACK_FALSE;
|
||||
var STACK_NEGATE = encoding.STACK_NEGATE;
|
||||
var opcodes = common.opcodes;
|
||||
var scriptTypes = common.types;
|
||||
var STACK_FALSE = common.STACK_FALSE;
|
||||
var STACK_NEGATE = common.STACK_NEGATE;
|
||||
|
||||
/**
|
||||
* Refers to the witness field of segregated witness transactions.
|
||||
@ -146,7 +146,7 @@ Witness.prototype.inspect = function inspect() {
|
||||
*/
|
||||
|
||||
Witness.prototype.toString = function toString() {
|
||||
return encoding.formatStack(this.items);
|
||||
return common.formatStack(this.items);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -156,7 +156,7 @@ Witness.prototype.toString = function toString() {
|
||||
*/
|
||||
|
||||
Witness.prototype.toASM = function toASM(decode) {
|
||||
return encoding.formatStackASM(this.items, decode);
|
||||
return common.formatStackASM(this.items, decode);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -226,8 +226,8 @@ Witness.prototype.isPubkeyInput = function isPubkeyInput() {
|
||||
|
||||
Witness.prototype.isPubkeyhashInput = function isPubkeyhashInput() {
|
||||
return this.items.length === 2
|
||||
&& encoding.isSignatureEncoding(this.items[0])
|
||||
&& encoding.isKeyEncoding(this.items[1]);
|
||||
&& common.isSignatureEncoding(this.items[0])
|
||||
&& common.isKeyEncoding(this.items[1]);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -331,7 +331,7 @@ Witness.prototype.getSize = function getSize() {
|
||||
|
||||
for (i = 0; i < this.items.length; i++) {
|
||||
item = this.items[i];
|
||||
size += enc.sizeVarBytes(item);
|
||||
size += encoding.sizeVarBytes(item);
|
||||
}
|
||||
|
||||
return size;
|
||||
@ -344,7 +344,7 @@ Witness.prototype.getSize = function getSize() {
|
||||
*/
|
||||
|
||||
Witness.prototype.getVarSize = function getVarSize() {
|
||||
return enc.sizeVarint(this.items.length) + this.getSize();
|
||||
return encoding.sizeVarint(this.items.length) + this.getSize();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -500,7 +500,7 @@ Witness.prototype.getNumber = function getNumber(i) {
|
||||
var item = this.items[i];
|
||||
if (!item || item.length > 5)
|
||||
return;
|
||||
return encoding.num(item, encoding.flags.VERIFY_NONE, 5);
|
||||
return common.num(item, common.flags.VERIFY_NONE, 5);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -559,7 +559,7 @@ Witness.encodeItem = function encodeItem(data) {
|
||||
}
|
||||
|
||||
if (BN.isBN(data))
|
||||
return encoding.array(data);
|
||||
return common.array(data);
|
||||
|
||||
if (typeof data === 'string')
|
||||
return new Buffer(data, 'utf8');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user