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',
|
||||
'reconnectDelay'
|
||||
].forEach(function(k) {
|
||||
if (typeof opts[k] === 'undefined')
|
||||
throw new Error('missing required option for Wallet: ' + k);
|
||||
preconditions.checkArgument(typeof opts[k] !== 'undefined',
|
||||
'missing required option for Wallet: ' + k);
|
||||
self[k] = opts[k];
|
||||
});
|
||||
if (copayConfig.forceNetwork && this.getNetworkName() !== copayConfig.networkName)
|
||||
throw new Error('Network forced to ' + copayConfig.networkName +
|
||||
preconditions.checkArgument(!copayConfig.forceNetwork || this.getNetworkName() === copayConfig.networkName,
|
||||
'Network forced to ' + copayConfig.networkName +
|
||||
' 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.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin);
|
||||
|
||||
|
||||
this.name = opts.name;
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
|
@ -56,6 +52,7 @@ function Wallet(opts) {
|
|||
this.registeredPeerIds = [];
|
||||
this.addressBook = opts.addressBook || {};
|
||||
this.publicKey = this.privateKey.publicHex;
|
||||
this.lastTimestamp = opts.lastTimestamp || undefined;
|
||||
|
||||
this.paymentRequests = opts.paymentRequests || {};
|
||||
|
||||
|
@ -540,6 +537,7 @@ Wallet.prototype.toObj = function() {
|
|||
txProposals: this.txProposals.toObj(),
|
||||
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
||||
addressBook: this.addressBook,
|
||||
lastTimestamp: this.lastTimestamp,
|
||||
};
|
||||
|
||||
return walletObj;
|
||||
|
@ -579,6 +577,8 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
|||
networkName: this.networkName,
|
||||
});
|
||||
|
||||
opts.lastTimestamp = o.lastTimestamp;
|
||||
|
||||
opts.storage = storage;
|
||||
opts.network = network;
|
||||
opts.blockchain = blockchain;
|
||||
|
|
|
@ -23,6 +23,7 @@ var preconditions = require('preconditions').singleton();
|
|||
*/
|
||||
|
||||
function Network(opts) {
|
||||
preconditions.checkArgument(opts);
|
||||
var self = this;
|
||||
opts = opts || {};
|
||||
this.maxPeers = opts.maxPeers || 12;
|
||||
|
@ -121,6 +122,7 @@ Network.prototype._addConnectedCopayer = function(copayerId) {
|
|||
|
||||
Network.prototype.getKey = function() {
|
||||
if (!this.key) {
|
||||
preconditions.checkState(this.privkey);
|
||||
var key = new bitcore.Key();
|
||||
key.private = new Buffer(this.privkey, 'hex');
|
||||
key.regenerateSync();
|
||||
|
|
Loading…
Reference in New Issue