Browse Source

Merge pull request #166 from rude9/1.0.0

1.0.0
patch-2
Matias Alejo Garcia 7 years ago
committed by GitHub
parent
commit
2b451cc59e
  1. 8
      lib/address.js
  2. 10
      lib/transaction/transaction.js
  3. 6
      test/address.js
  4. 5
      test/networks.js

8
lib/address.js

@ -195,10 +195,14 @@ Address._transformBuffer = function(buffer, network, type) {
throw new TypeError('Address buffers must be exactly 21 bytes.');
}
network = Networks.get(network);
var networkObj = Networks.get(network);
var bufferVersion = Address._classifyFromVersion(buffer);
if (!bufferVersion.network || (network && network !== bufferVersion.network)) {
if (network && !networkObj) {
throw new TypeError('Unknown network');
}
if (!bufferVersion.network || (networkObj && networkObj !== bufferVersion.network)) {
throw new TypeError('Address has mismatched network type.');
}

10
lib/transaction/transaction.js

@ -393,13 +393,13 @@ Transaction.prototype.fromObject = function fromObject(arg) {
Transaction.prototype._checkConsistency = function(arg) {
if (!_.isUndefined(this._changeIndex)) {
$.checkState(this._changeScript);
$.checkState(this.outputs[this._changeIndex]);
$.checkState(this._changeScript, 'Change script is expected.');
$.checkState(this.outputs[this._changeIndex], 'Change index points to undefined output.');
$.checkState(this.outputs[this._changeIndex].script.toString() ===
this._changeScript.toString());
this._changeScript.toString(), 'Change output has an unexpected script.');
}
if (arg && arg.hash) {
$.checkState(arg.hash === this.hash, 'Hash in object does not match transaction hash');
$.checkState(arg.hash === this.hash, 'Hash in object does not match transaction hash.');
}
};
@ -1050,7 +1050,7 @@ Transaction.prototype.removeInput = function(txId, outputIndex) {
* @return {Transaction} this, for chaining
*/
Transaction.prototype.sign = function(privateKey, sigtype) {
$.checkState(this.hasAllUtxoInfo());
$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.');
var self = this;
if (_.isArray(privateKey)) {
_.each(privateKey, function(privateKey) {

6
test/address.js

@ -250,6 +250,12 @@ describe('Address', function() {
Address.fromString(str, Networks.livenet).toString().should.equal(str);
});
it('should throw with bad network param', function() {
(function(){
Address.fromString(str, 'somenet');
}).should.throw('Unknown network');
});
it('should error because of unrecognized data format', function() {
(function() {
return new Address(new Error());

5
test/networks.js

@ -89,7 +89,10 @@ describe('Networks', function() {
networks.add(custom);
var network = networks.get(undefined);
should.not.exist(network);
networks.remove(custom);
var somenet = networks.get('somenet');
should.exist(somenet);
somenet.name.should.equal('somenet');
networks.remove(somenet);
});
var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey'];

Loading…
Cancel
Save