add network to wallet file + check on open
This commit is contained in:
parent
e354e6d377
commit
85030f00ab
2 changed files with 21 additions and 4 deletions
|
|
@ -20,7 +20,7 @@ function Wallet(opts) {
|
||||||
['storage', 'network', 'blockchain',
|
['storage', 'network', 'blockchain',
|
||||||
'requiredCopayers', 'totalCopayers', 'spendUnconfirmed',
|
'requiredCopayers', 'totalCopayers', 'spendUnconfirmed',
|
||||||
'publicKeyRing', 'txProposals', 'privateKey', 'version',
|
'publicKeyRing', 'txProposals', 'privateKey', 'version',
|
||||||
'reconnectDelay'
|
'reconnectDelay', 'networkName'
|
||||||
].forEach(function(k) {
|
].forEach(function(k) {
|
||||||
if (typeof opts[k] === 'undefined')
|
if (typeof opts[k] === 'undefined')
|
||||||
throw new Error('missing required option for Wallet: ' + k);
|
throw new Error('missing required option for Wallet: ' + k);
|
||||||
|
|
@ -181,6 +181,7 @@ Wallet.prototype._optsToObj = function() {
|
||||||
requiredCopayers: this.requiredCopayers,
|
requiredCopayers: this.requiredCopayers,
|
||||||
totalCopayers: this.totalCopayers,
|
totalCopayers: this.totalCopayers,
|
||||||
reconnectDelay: this.reconnectDelay,
|
reconnectDelay: this.reconnectDelay,
|
||||||
|
networkName: this.networkName,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
netKey: this.netKey,
|
netKey: this.netKey,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ function WalletFactory(config, version) {
|
||||||
this.network = new Network(config.network);
|
this.network = new Network(config.network);
|
||||||
this.blockchain = new Blockchain(config.blockchain);
|
this.blockchain = new Blockchain(config.blockchain);
|
||||||
|
|
||||||
this.networkName = config.networkName;
|
this.networkName = config.networkName;
|
||||||
this.verbose = config.verbose;
|
this.verbose = config.verbose;
|
||||||
this.walletDefaults = config.wallet;
|
this.walletDefaults = config.wallet;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletFactory.prototype.log = function(){
|
WalletFactory.prototype.log = function(){
|
||||||
|
|
@ -115,6 +115,7 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
|
|
||||||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||||
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
||||||
|
opts.networkName = opts.networkName || this.networkName;
|
||||||
opts.requiredCopayers = requiredCopayers;
|
opts.requiredCopayers = requiredCopayers;
|
||||||
opts.totalCopayers = totalCopayers;
|
opts.totalCopayers = totalCopayers;
|
||||||
opts.version = opts.version || this.version;
|
opts.version = opts.version || this.version;
|
||||||
|
|
@ -139,6 +140,20 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WalletFactory.prototype._checkNetwork = function(inNetworkName) {
|
||||||
|
if( this.networkName !== inNetworkName ) {
|
||||||
|
throw new Error('This Wallet is configured for '
|
||||||
|
+ inNetworkName
|
||||||
|
+ ' while currently Copay is configured for: '
|
||||||
|
+ this.networkName
|
||||||
|
+ '. Check your settings.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WalletFactory.prototype.open = function(walletId, opts) {
|
WalletFactory.prototype.open = function(walletId, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.id = walletId;
|
opts.id = walletId;
|
||||||
|
|
@ -148,6 +163,7 @@ WalletFactory.prototype.open = function(walletId, opts) {
|
||||||
var w = this.read(walletId);
|
var w = this.read(walletId);
|
||||||
if (w) {
|
if (w) {
|
||||||
this._checkVersion(w.version);
|
this._checkVersion(w.version);
|
||||||
|
this._checkNetwork(w.networkName);
|
||||||
w.store();
|
w.store();
|
||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue