Merge pull request #911 from yemel/fix/enumerate-properties

Use defineImmutable helper
This commit is contained in:
Esteban Ordano 2015-01-08 14:29:21 -05:00
commit c98f4dd8e5
10 changed files with 26 additions and 49 deletions

View File

@ -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;

View File

@ -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
*/

View File

@ -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 = [

View File

@ -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 = [

View File

@ -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;

View File

@ -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)
});

View File

@ -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;
};
/**

View File

@ -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);

View File

@ -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();
},

View File

@ -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');
}