add network to address model
This commit is contained in:
parent
c7ffacac93
commit
d8524fed2a
|
@ -17,6 +17,7 @@ Address.create = function(opts) {
|
||||||
x.isChange = opts.isChange;
|
x.isChange = opts.isChange;
|
||||||
x.path = opts.path;
|
x.path = opts.path;
|
||||||
x.publicKeys = opts.publicKeys;
|
x.publicKeys = opts.publicKeys;
|
||||||
|
x.network = Bitcore.Address(x.address).toObject().network;
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ Address.fromObj = function(obj) {
|
||||||
x.createdOn = obj.createdOn;
|
x.createdOn = obj.createdOn;
|
||||||
x.address = obj.address;
|
x.address = obj.address;
|
||||||
x.walletId = obj.walletId;
|
x.walletId = obj.walletId;
|
||||||
|
x.network = obj.network;
|
||||||
x.isChange = obj.isChange;
|
x.isChange = obj.isChange;
|
||||||
x.path = obj.path;
|
x.path = obj.path;
|
||||||
x.publicKeys = obj.publicKeys;
|
x.publicKeys = obj.publicKeys;
|
||||||
|
|
|
@ -84,13 +84,12 @@ WalletService.initialize = function(opts, cb) {
|
||||||
|
|
||||||
|
|
||||||
WalletService.shutDown = function(cb) {
|
WalletService.shutDown = function(cb) {
|
||||||
if (initialized) {
|
if (!initialized) return cb();
|
||||||
storage.disconnect(function(err) {
|
storage.disconnect(function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
initialized = false;
|
initialized = false;
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletService.getInstance = function() {
|
WalletService.getInstance = function() {
|
||||||
|
|
|
@ -80,10 +80,16 @@ helpers.getSignedCopayerOpts = function(opts) {
|
||||||
return opts;
|
return opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.createAndJoinWallet = function(m, n, cb) {
|
helpers.createAndJoinWallet = function(m, n, opts, cb) {
|
||||||
|
if (_.isFunction(opts)) {
|
||||||
|
cb = opts;
|
||||||
|
opts = {};
|
||||||
|
}
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
var server = new WalletService();
|
var server = new WalletService();
|
||||||
var copayerIds = [];
|
var copayerIds = [];
|
||||||
var offset = helpers.offset || 0;
|
var offset = opts.offset || 0;
|
||||||
|
|
||||||
var walletOpts = {
|
var walletOpts = {
|
||||||
name: 'a wallet',
|
name: 'a wallet',
|
||||||
|
@ -241,10 +247,7 @@ describe('Wallet service', function() {
|
||||||
WalletService.initialize({
|
WalletService.initialize({
|
||||||
storage: storage,
|
storage: storage,
|
||||||
blockchainExplorer: blockchainExplorer,
|
blockchainExplorer: blockchainExplorer,
|
||||||
}, function() {
|
}, done);
|
||||||
helpers.offset = 0;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
|
@ -673,6 +676,8 @@ describe('Wallet service', function() {
|
||||||
server.createAddress({}, function(err, address) {
|
server.createAddress({}, function(err, address) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
address.should.exist;
|
address.should.exist;
|
||||||
|
address.walletId.should.equal(wallet.id);
|
||||||
|
address.network.should.equal('livenet');
|
||||||
address.address.should.equal('3KxttbKQQPWmpsnXZ3rB4mgJTuLnVR7frg');
|
address.address.should.equal('3KxttbKQQPWmpsnXZ3rB4mgJTuLnVR7frg');
|
||||||
address.isChange.should.be.false;
|
address.isChange.should.be.false;
|
||||||
address.path.should.equal('m/2147483647/0/0');
|
address.path.should.equal('m/2147483647/0/0');
|
||||||
|
@ -2138,8 +2143,9 @@ describe('Wallet service', function() {
|
||||||
async.series([
|
async.series([
|
||||||
|
|
||||||
function(next) {
|
function(next) {
|
||||||
helpers.offset = 1;
|
helpers.createAndJoinWallet(1, 1, {
|
||||||
helpers.createAndJoinWallet(1, 1, function(s, w) {
|
offset: 1
|
||||||
|
}, function(s, w) {
|
||||||
server2 = s;
|
server2 = s;
|
||||||
wallet2 = w;
|
wallet2 = w;
|
||||||
|
|
||||||
|
@ -3057,10 +3063,7 @@ describe('Blockchain monitor', function() {
|
||||||
WalletService.initialize({
|
WalletService.initialize({
|
||||||
storage: storage,
|
storage: storage,
|
||||||
blockchainExplorer: blockchainExplorer,
|
blockchainExplorer: blockchainExplorer,
|
||||||
}, function() {
|
}, done);
|
||||||
helpers.offset = 0;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _ = require('lodash');
|
||||||
|
var chai = require('chai');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var should = chai.should();
|
||||||
|
|
||||||
|
var Address = require('../../lib/model/address');
|
||||||
|
|
||||||
|
describe('Address', function() {
|
||||||
|
it('should create livenet address', function() {
|
||||||
|
var x = Address.create({
|
||||||
|
address: '3KxttbKQQPWmpsnXZ3rB4mgJTuLnVR7frg',
|
||||||
|
walletId: '123',
|
||||||
|
isChange: false,
|
||||||
|
path: 'm/0/1',
|
||||||
|
publicKeys: ['123', '456'],
|
||||||
|
});
|
||||||
|
should.exist(x.createdOn);
|
||||||
|
x.network.should.equal('livenet');
|
||||||
|
});
|
||||||
|
it('should create testnet address', function() {
|
||||||
|
var x = Address.create({
|
||||||
|
address: 'mp5xaa4uBj16DJt1fuA3D9fejHuCzeb7hj',
|
||||||
|
walletId: '123',
|
||||||
|
isChange: false,
|
||||||
|
path: 'm/0/1',
|
||||||
|
publicKeys: ['123', '456'],
|
||||||
|
});
|
||||||
|
x.network.should.equal('testnet');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue