add more tests and fix some bugs
This commit is contained in:
parent
fabc8aac85
commit
697dea673a
6 changed files with 129 additions and 27 deletions
|
|
@ -241,24 +241,26 @@ PublicKeyRing.prototype.getRedeemScriptMap = function () {
|
|||
return ret;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._checkInPRK = function(inPKR, ignoreId) {
|
||||
PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
|
||||
|
||||
if (!ignoreId && this.walletId !== inPKR.walletId) {
|
||||
throw new Error('inPRK walletId mismatch');
|
||||
throw new Error('inPKR walletId mismatch');
|
||||
}
|
||||
|
||||
if (this.network.name !== inPKR.network.name)
|
||||
throw new Error('inPRK network mismatch');
|
||||
if (this.network.name !== inPKR.network.name) {
|
||||
throw new Error('inPKR network mismatch. Should be '+this.network.name +
|
||||
' and found '+inPKR.network.name);
|
||||
}
|
||||
|
||||
if (
|
||||
this.requiredCopayers && inPKR.requiredCopayers &&
|
||||
(this.requiredCopayers !== inPKR.requiredCopayers))
|
||||
throw new Error('inPRK requiredCopayers mismatch '+this.requiredCopayers+'!='+inPKR.requiredCopayers);
|
||||
throw new Error('inPKR requiredCopayers mismatch '+this.requiredCopayers+'!='+inPKR.requiredCopayers);
|
||||
|
||||
if (
|
||||
this.totalCopayers && inPKR.totalCopayers &&
|
||||
(this.totalCopayers !== inPKR.totalCopayers))
|
||||
throw new Error('inPRK totalCopayers mismatch'+this.totalCopayers+'!='+inPKR.requiredCopayers);
|
||||
throw new Error('inPKR totalCopayers mismatch'+this.totalCopayers+'!='+inPKR.requiredCopayers);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -296,7 +298,7 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
||||
var hasChanged = false;
|
||||
|
||||
this._checkInPRK(inPKR, ignoreId);
|
||||
this._checkInPKR(inPKR, ignoreId);
|
||||
|
||||
if (this.indexes.merge(inPKR.indexes))
|
||||
hasChanged = true;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ function Wallet(opts) {
|
|||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.name = opts.name;
|
||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||
this.networkName = opts.networkName;
|
||||
|
||||
// Renew token every 24hs
|
||||
if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) {
|
||||
|
|
@ -318,7 +319,7 @@ Wallet.prototype.toObj = function() {
|
|||
opts: optsObj,
|
||||
publicKeyRing: this.publicKeyRing.toObj(),
|
||||
txProposals: this.txProposals.toObj(),
|
||||
privateKey: this.privateKey.toObj()
|
||||
privateKey: this.privateKey?this.privateKey.toObj():undefined
|
||||
};
|
||||
|
||||
return walletObj;
|
||||
|
|
@ -459,7 +460,6 @@ Wallet.prototype.sign = function(ntxid, cb) {
|
|||
var txp = self.txProposals.txps[ntxid];
|
||||
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) {
|
||||
if (cb) cb(false);
|
||||
throw new Error('Invalid transaction to sign: '+ntxid);
|
||||
}
|
||||
|
||||
var pkr = self.publicKeyRing;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ var Wallet = require('./Wallet');
|
|||
function WalletFactory(config, version) {
|
||||
var self = this;
|
||||
config = config || {};
|
||||
console.log('asd');
|
||||
|
||||
this.storage = new Storage(config.storage);
|
||||
this.network = new Network(config.network);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue