|
|
@ -28,6 +28,10 @@ Storage.prototype.fetchWallet = function (id, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.storeWallet = function (wallet, cb) { |
|
|
|
this.db.put('wallet-' + wallet.id, wallet, cb); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.fetchTx = function (walletId, txProposalId, cb) { |
|
|
|
this.db.get('wallet-' + walletId + '-txp-' + txProposalId, function (err, data) { |
|
|
|
if (err) { |
|
|
@ -38,12 +42,20 @@ Storage.prototype.fetchTx = function (walletId, txProposalId, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.storeWallet = function (wallet, cb) { |
|
|
|
this.db.put('wallet-' + wallet.id, wallet, cb); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.storeAddress = function (walletId, address, cb) { |
|
|
|
this.db.put('wallet-' + walletId + '-address-' + address.address, address, cb); |
|
|
|
Storage.prototype.fetchTxs = function (walletId, cb) { |
|
|
|
var txs = []; |
|
|
|
var key = 'wallet-' + walletId + '-txp-'; |
|
|
|
this.db.createReadStream({ gte: key, lt: key + '~' }) |
|
|
|
.on('data', function (data) { |
|
|
|
txs.push(TxProposal.fromObj(data.value)); |
|
|
|
}) |
|
|
|
.on('error', function (err) { |
|
|
|
if (err.notFound) return cb(); |
|
|
|
return cb(err); |
|
|
|
}) |
|
|
|
.on('end', function () { |
|
|
|
return cb(null, txs); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.storeTx = function (walletId, txp, cb) { |
|
|
@ -66,22 +78,12 @@ Storage.prototype.fetchAddresses = function (walletId, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Storage.prototype.fetchTxs = function (walletId, cb) { |
|
|
|
var txs = []; |
|
|
|
var key = 'wallet-' + walletId + '-txp-'; |
|
|
|
this.db.createReadStream({ gte: key, lt: key + '~' }) |
|
|
|
.on('data', function (data) { |
|
|
|
txs.push(TxProposal.fromObj(data.value)); |
|
|
|
}) |
|
|
|
.on('error', function (err) { |
|
|
|
if (err.notFound) return cb(); |
|
|
|
return cb(err); |
|
|
|
}) |
|
|
|
.on('end', function () { |
|
|
|
return cb(null, txs); |
|
|
|
}); |
|
|
|
Storage.prototype.storeAddress = function (walletId, address, cb) { |
|
|
|
this.db.put('wallet-' + walletId + '-address-' + address.address, address, cb); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Storage.prototype._dump = function (cb) { |
|
|
|
this.db.readStream() |
|
|
|
.on('data', console.log) |
|
|
|