add script type to address

This commit is contained in:
Ivan Socolsky 2015-09-07 17:46:45 -03:00
parent a2dfbc6d86
commit 69ae9a63e7
4 changed files with 12 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -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, {