Use define immutable helper
This commit is contained in:
parent
d941ed4438
commit
e57d02c03c
|
@ -74,19 +74,10 @@ function Address(data, network, type) {
|
||||||
info.network = info.network || Networks.get(network) || Networks.defaultNetwork;
|
info.network = info.network || Networks.get(network) || Networks.defaultNetwork;
|
||||||
info.type = info.type || type || Address.PayToPublicKeyHash;
|
info.type = info.type || type || Address.PayToPublicKeyHash;
|
||||||
|
|
||||||
Object.defineProperty(this, 'hashBuffer', {
|
JSUtil.defineImmutable(this, {
|
||||||
configurable: false,
|
hashBuffer: info.hashBuffer,
|
||||||
value: info.hashBuffer
|
network: info.network,
|
||||||
});
|
type: info.type
|
||||||
|
|
||||||
Object.defineProperty(this, 'network', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.network
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'type', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.type
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -215,6 +215,7 @@ BlockHeader.prototype._getHash = function hash() {
|
||||||
var idProperty = {
|
var idProperty = {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writeable: false,
|
writeable: false,
|
||||||
|
enumerable: true,
|
||||||
/**
|
/**
|
||||||
* @returns {string} - The big endian hash buffer of the header
|
* @returns {string} - The big endian hash buffer of the header
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -358,9 +358,9 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) {
|
||||||
/* jshint maxstatements: 20 */
|
/* jshint maxstatements: 20 */
|
||||||
|
|
||||||
HDPrivateKey._validateBufferArguments(arg);
|
HDPrivateKey._validateBufferArguments(arg);
|
||||||
Object.defineProperty(this, '_buffers', {
|
|
||||||
configurable: false,
|
JSUtil.defineImmutable(this, {
|
||||||
value: arg
|
_buffers: arg
|
||||||
});
|
});
|
||||||
|
|
||||||
var sequence = [
|
var sequence = [
|
||||||
|
|
|
@ -297,9 +297,8 @@ HDPublicKey.prototype._buildFromBuffers = function (arg) {
|
||||||
|
|
||||||
HDPublicKey._validateBufferArguments(arg);
|
HDPublicKey._validateBufferArguments(arg);
|
||||||
|
|
||||||
Object.defineProperty(this, '_buffers', {
|
JSUtil.defineImmutable(this, {
|
||||||
configurable: false,
|
_buffers: arg
|
||||||
value: arg
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var sequence = [
|
var sequence = [
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var $ = require('./util/preconditions');
|
var $ = require('./util/preconditions');
|
||||||
var BufferUtil = require('./util/buffer');
|
var BufferUtil = require('./util/buffer');
|
||||||
|
var JSUtil = require('./util/js');
|
||||||
|
|
||||||
function Opcode(num) {
|
function Opcode(num) {
|
||||||
if (!(this instanceof Opcode)) {
|
if (!(this instanceof Opcode)) {
|
||||||
|
@ -19,9 +20,8 @@ function Opcode(num) {
|
||||||
throw new TypeError('Unrecognized num type: "' + typeof(num) + '" for Opcode');
|
throw new TypeError('Unrecognized num type: "' + typeof(num) + '" for Opcode');
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(this, 'num', {
|
JSUtil.defineImmutable(this, {
|
||||||
configurable: false,
|
num: value
|
||||||
value: value
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -57,23 +57,15 @@ var PrivateKey = function PrivateKey(data, network) {
|
||||||
throw new TypeError('Must specify the network ("livenet" or "testnet")');
|
throw new TypeError('Must specify the network ("livenet" or "testnet")');
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(this, 'bn', {
|
JSUtil.defineImmutable(this, {
|
||||||
configurable: false,
|
bn: info.bn,
|
||||||
value: info.bn
|
compressed: info.compressed,
|
||||||
});
|
network: info.network
|
||||||
|
|
||||||
Object.defineProperty(this, 'compressed', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.compressed
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'network', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.network
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(this, 'publicKey', {
|
Object.defineProperty(this, 'publicKey', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
|
enumerable: true,
|
||||||
get: this.toPublicKey.bind(this)
|
get: this.toPublicKey.bind(this)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -52,23 +52,13 @@ var PublicKey = function PublicKey(data, extra) {
|
||||||
// validation
|
// validation
|
||||||
info.point.validate();
|
info.point.validate();
|
||||||
|
|
||||||
Object.defineProperty(this, 'point', {
|
JSUtil.defineImmutable(this, {
|
||||||
configurable: false,
|
point: info.point,
|
||||||
value: info.point
|
compressed: info.compressed,
|
||||||
});
|
network: info.network || Network.defaultNetwork
|
||||||
|
|
||||||
Object.defineProperty(this, 'compressed', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.compressed
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'network', {
|
|
||||||
configurable: false,
|
|
||||||
value: info.network || Network.defaultNetwork
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,7 @@ function Input(params) {
|
||||||
Object.defineProperty(Input.prototype, 'script', {
|
Object.defineProperty(Input.prototype, 'script', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writeable: false,
|
writeable: false,
|
||||||
|
enumerable: true,
|
||||||
get: function() {
|
get: function() {
|
||||||
if (!this._script) {
|
if (!this._script) {
|
||||||
this._script = new Script(this._scriptBuffer);
|
this._script = new Script(this._scriptBuffer);
|
||||||
|
|
|
@ -20,6 +20,7 @@ function Output(params) {
|
||||||
Object.defineProperty(Output.prototype, 'script', {
|
Object.defineProperty(Output.prototype, 'script', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writeable: false,
|
writeable: false,
|
||||||
|
enumerable: true,
|
||||||
get: function() {
|
get: function() {
|
||||||
if (!this._script) {
|
if (!this._script) {
|
||||||
this._script = new Script(this._scriptBuffer);
|
this._script = new Script(this._scriptBuffer);
|
||||||
|
@ -31,6 +32,7 @@ Object.defineProperty(Output.prototype, 'script', {
|
||||||
Object.defineProperty(Output.prototype, 'satoshis', {
|
Object.defineProperty(Output.prototype, 'satoshis', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writeable: true,
|
writeable: true,
|
||||||
|
enumerable: true,
|
||||||
get: function() {
|
get: function() {
|
||||||
return this._satoshis.toNumber();
|
return this._satoshis.toNumber();
|
||||||
},
|
},
|
||||||
|
|
|
@ -81,6 +81,7 @@ Transaction.shallowCopy = function(transaction) {
|
||||||
var hashProperty = {
|
var hashProperty = {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
writeable: false,
|
writeable: false,
|
||||||
|
enumerable: true,
|
||||||
get: function() {
|
get: function() {
|
||||||
return new BufferReader(this._getHash()).readReverse().toString('hex');
|
return new BufferReader(this._getHash()).readReverse().toString('hex');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue