|
@ -102,7 +102,7 @@ CopayServer.prototype._runLocked = function (walletId, cb, task) { |
|
|
|
|
|
|
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err || !wallet) return cb(err); |
|
|
if (err) return cb(err); |
|
|
if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb('Copayer already in wallet'); |
|
|
if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb('Copayer already in wallet'); |
|
|
if (wallet.copayers.length == wallet.n) return cb('Wallet full'); |
|
|
if (wallet.copayers.length == wallet.n) return cb('Wallet full'); |
|
|
// TODO: validate copayer's extended public key using the public key from this wallet
|
|
|
// TODO: validate copayer's extended public key using the public key from this wallet
|
|
@ -142,7 +142,7 @@ CopayServer.prototype._doCreateAddress = function (pkr, index, isChange) { |
|
|
|
|
|
|
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err || !wallet) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
var index = wallet.addressIndex++; |
|
|
var index = wallet.addressIndex++; |
|
|
self.storage.storeWallet(wallet, function (err) { |
|
|
self.storage.storeWallet(wallet, function (err) { |
|
@ -251,7 +251,7 @@ CopayServer.prototype.createTx = function (opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err || !wallet) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
self._getUtxos({ walletId: wallet.id }, function (err, utxos) { |
|
|
self._getUtxos({ walletId: wallet.id }, function (err, utxos) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
@ -277,7 +277,7 @@ CopayServer.prototype.createTx = function (opts, cb) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
CopayServer.prototype._broadcastTx = function (rawTx, cb) { |
|
|
CopayServer.prototype._broadcastTx = function (rawTx, cb) { |
|
|
// TODO: this should attempt to broadcast _all_ accepted txps?
|
|
|
// TODO: this should attempt to broadcast _all_ accepted and not-yet broadcasted (status=='accepted') txps?
|
|
|
cb = cb || function () {}; |
|
|
cb = cb || function () {}; |
|
|
|
|
|
|
|
|
throw 'not implemented'; |
|
|
throw 'not implemented'; |
|
@ -295,7 +295,7 @@ CopayServer.prototype.signTx = function (opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err || !wallet) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
self.fetchTx(wallet.id, opts.txProposalId, function (err, txp) { |
|
|
self.fetchTx(wallet.id, opts.txProposalId, function (err, txp) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
@ -336,7 +336,17 @@ CopayServer.prototype.signTx = function (opts, cb) { |
|
|
CopayServer.prototype.getPendingTxs = function (opts, cb) { |
|
|
CopayServer.prototype.getPendingTxs = function (opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
throw 'not implemented'; |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
|
|
|
self.storage.fetchTxs(wallet.id, function (err, txps) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
|
|
|
var pending = _.filter(txps, { status: 'pending' }); |
|
|
|
|
|
|
|
|
|
|
|
return cb(null, pending); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|