From 69ae9a63e7955823e27a6e1b679590feb0f9e088 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 7 Sep 2015 17:46:45 -0300 Subject: [PATCH] add script type to address --- lib/model/address.js | 5 ++++- lib/model/copayer.js | 1 + lib/model/wallet.js | 5 ++++- test/integration/server.js | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/model/address.js b/lib/model/address.js index 9f4da97..a286187 100644 --- a/lib/model/address.js +++ b/lib/model/address.js @@ -1,6 +1,7 @@ 'use strict'; -var Bitcore = require('bitcore-wallet-utils').Bitcore; +var WalletUtils = require('bitcore-wallet-utils'); +var Bitcore = WalletUtils.Bitcore; function Address() {}; @@ -17,6 +18,7 @@ Address.create = function(opts) { x.path = opts.path; x.publicKeys = opts.publicKeys; x.network = Bitcore.Address(x.address).toObject().network; + x.type = opts.type || WalletUtils.SCRIPT_TYPES.P2SH; return x; }; @@ -31,6 +33,7 @@ Address.fromObj = function(obj) { x.isChange = obj.isChange; x.path = obj.path; x.publicKeys = obj.publicKeys; + x.type = obj.type || WalletUtils.SCRIPT_TYPES.P2SH; return x; }; diff --git a/lib/model/copayer.js b/lib/model/copayer.js index 0e25001..4fdbb45 100644 --- a/lib/model/copayer.js +++ b/lib/model/copayer.js @@ -85,6 +85,7 @@ Copayer.prototype.createAddress = function(wallet, isChange) { var raw = Address.create(WalletUtils.deriveAddress(wallet.addressType, wallet.publicKeyRing, path, wallet.m, wallet.network)); var address = Address.create(_.extend(raw, { walletId: wallet.id, + type: wallet.addressType, })); address.isChange = isChange; diff --git a/lib/model/wallet.js b/lib/model/wallet.js index 64bb775..a85ae68 100644 --- a/lib/model/wallet.js +++ b/lib/model/wallet.js @@ -150,10 +150,13 @@ Wallet.prototype.isScanning = function() { Wallet.prototype.createAddress = function(isChange) { $.checkState(this.isComplete()); + var self = this; + var path = this.addressManager.getNewAddressPath(isChange); var raw = WalletUtils.deriveAddress(this.addressType, this.publicKeyRing, path, this.m, this.network); var address = Address.create(_.extend(raw, { - walletId: this.id, + walletId: self.id, + type: self.addressType, })); address.isChange = isChange; return address; diff --git a/test/integration/server.js b/test/integration/server.js index 7493742..a6d2282 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1403,6 +1403,7 @@ describe('Wallet service', function() { address.address.should.equal('3BVJZ4CYzeTtawDtgwHvWV5jbvnXtYe97i'); address.isChange.should.be.false; address.path.should.equal('m/2147483647/0/0'); + address.type.should.equal('P2SH'); server.getNotifications({}, function(err, notifications) { should.not.exist(err); var notif = _.find(notifications, { @@ -1449,6 +1450,7 @@ describe('Wallet service', function() { address.address.should.equal('36q2G5FMGvJbPgAVEaiyAsFGmpkhPKwk2r'); address.isChange.should.be.false; address.path.should.equal('m/0/0'); + address.type.should.equal('P2SH'); server.getNotifications({}, function(err, notifications) { should.not.exist(err); var notif = _.find(notifications, { @@ -1515,6 +1517,7 @@ describe('Wallet service', function() { address.address.should.equal('1L3z9LPd861FWQhf3vDn89Fnc9dkdBo2CG'); address.isChange.should.be.false; address.path.should.equal('m/0/0'); + address.type.should.equal('P2PKH'); server.getNotifications({}, function(err, notifications) { should.not.exist(err); var notif = _.find(notifications, {