mirror of https://github.com/BTCPrivate/copay.git
wallet refactor
This commit is contained in:
parent
1c3c7f0bde
commit
28e00b24cc
|
@ -33,20 +33,16 @@ function Wallet(opts) {
|
||||||
'publicKeyRing', 'txProposals', 'privateKey', 'version',
|
'publicKeyRing', 'txProposals', 'privateKey', 'version',
|
||||||
'reconnectDelay'
|
'reconnectDelay'
|
||||||
].forEach(function(k) {
|
].forEach(function(k) {
|
||||||
if (typeof opts[k] === 'undefined')
|
preconditions.checkArgument(typeof opts[k] !== 'undefined',
|
||||||
throw new Error('missing required option for Wallet: ' + k);
|
'missing required option for Wallet: ' + k);
|
||||||
self[k] = opts[k];
|
self[k] = opts[k];
|
||||||
});
|
});
|
||||||
if (copayConfig.forceNetwork && this.getNetworkName() !== copayConfig.networkName)
|
preconditions.checkArgument(!copayConfig.forceNetwork || this.getNetworkName() === copayConfig.networkName,
|
||||||
throw new Error('Network forced to ' + copayConfig.networkName +
|
'Network forced to ' + copayConfig.networkName +
|
||||||
' and tried to create a Wallet with network ' + this.getNetworkName());
|
' and tried to create a Wallet with network ' + this.getNetworkName());
|
||||||
|
|
||||||
this.log('creating ' + opts.requiredCopayers + ' of ' + opts.totalCopayers + ' wallet');
|
|
||||||
|
|
||||||
this.id = opts.id || Wallet.getRandomId();
|
this.id = opts.id || Wallet.getRandomId();
|
||||||
this.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin);
|
this.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin);
|
||||||
|
|
||||||
|
|
||||||
this.name = opts.name;
|
this.name = opts.name;
|
||||||
|
|
||||||
this.verbose = opts.verbose;
|
this.verbose = opts.verbose;
|
||||||
|
@ -56,6 +52,7 @@ function Wallet(opts) {
|
||||||
this.registeredPeerIds = [];
|
this.registeredPeerIds = [];
|
||||||
this.addressBook = opts.addressBook || {};
|
this.addressBook = opts.addressBook || {};
|
||||||
this.publicKey = this.privateKey.publicHex;
|
this.publicKey = this.privateKey.publicHex;
|
||||||
|
this.lastTimestamp = opts.lastTimestamp || undefined;
|
||||||
|
|
||||||
this.paymentRequests = opts.paymentRequests || {};
|
this.paymentRequests = opts.paymentRequests || {};
|
||||||
|
|
||||||
|
@ -540,6 +537,7 @@ Wallet.prototype.toObj = function() {
|
||||||
txProposals: this.txProposals.toObj(),
|
txProposals: this.txProposals.toObj(),
|
||||||
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
||||||
addressBook: this.addressBook,
|
addressBook: this.addressBook,
|
||||||
|
lastTimestamp: this.lastTimestamp,
|
||||||
};
|
};
|
||||||
|
|
||||||
return walletObj;
|
return walletObj;
|
||||||
|
@ -579,6 +577,8 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||||
networkName: this.networkName,
|
networkName: this.networkName,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
opts.lastTimestamp = o.lastTimestamp;
|
||||||
|
|
||||||
opts.storage = storage;
|
opts.storage = storage;
|
||||||
opts.network = network;
|
opts.network = network;
|
||||||
opts.blockchain = blockchain;
|
opts.blockchain = blockchain;
|
||||||
|
|
|
@ -23,6 +23,7 @@ var preconditions = require('preconditions').singleton();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Network(opts) {
|
function Network(opts) {
|
||||||
|
preconditions.checkArgument(opts);
|
||||||
var self = this;
|
var self = this;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.maxPeers = opts.maxPeers || 12;
|
this.maxPeers = opts.maxPeers || 12;
|
||||||
|
@ -121,6 +122,7 @@ Network.prototype._addConnectedCopayer = function(copayerId) {
|
||||||
|
|
||||||
Network.prototype.getKey = function() {
|
Network.prototype.getKey = function() {
|
||||||
if (!this.key) {
|
if (!this.key) {
|
||||||
|
preconditions.checkState(this.privkey);
|
||||||
var key = new bitcore.Key();
|
var key = new bitcore.Key();
|
||||||
key.private = new Buffer(this.privkey, 'hex');
|
key.private = new Buffer(this.privkey, 'hex');
|
||||||
key.regenerateSync();
|
key.regenerateSync();
|
||||||
|
|
Loading…
Reference in New Issue