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