bit-history

This commit is contained in:
Ivan Socolsky 2015-02-22 23:26:21 -03:00
parent 036cc88ba8
commit 3b83dc095f
6 changed files with 67 additions and 10 deletions

View File

@ -15,6 +15,7 @@ program
.command('reject <txpId> [reason]', 'reject a transaction proposal')
.command('broadcast <txpId>', 'broadcast a transaction proposal to the Bitcoin network')
.command('rm <txpId>', 'remove a transaction proposal')
.command('history', 'list of past incoming and outgoing transactions')
.command('export', 'export wallet critical data')
.command('import', 'import wallet critical data')
.command('confirm', 'show copayer\'s data for confirmation')

38
bit-wallet/bit-history Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env node
var _ = require('lodash');
var fs = require('fs');
var moment = require('moment');
var program = require('commander');
var Utils = require('./cli-utils');
program = Utils.configureCommander(program);
program
.parse(process.argv);
var args = program.args;
var client = Utils.getClient(program);
var txData;
client.getTxHistory({}, function (err, txs) {
if (_.isEmpty(txs))
return;
console.log("* TX History:")
_.each(txs, function(tx) {
var time = moment().fromNow(tx.time);
switch (tx.action) {
case 'received':
console.log("\t%s: <= %s", time, Utils.renderAmount(tx.amount));
break;
case 'sent':
console.log("\t%s: %s => %s", time, Utils.renderAmount(tx.amount), tx.addressTo);
break;
case 'moved':
console.log("\t%s: == %s", time, Utils.renderAmount(tx.amount));
break;
}
});
});

View File

@ -36,6 +36,7 @@ function _decryptMessage(message, encryptingKey) {
};
function _processTxps(txps, encryptingKey) {
if (!txps) return;
_.each([].concat(txps), function(txp) {
txp.encryptedMessage = txp.message;
txp.message = _decryptMessage(txp.message, encryptingKey);
@ -482,10 +483,6 @@ API.prototype.getMainAddresses = function(opts, cb) {
});
};
API.prototype.history = function(limit, cb) {
};
API.prototype.getBalance = function(cb) {
var self = this;
@ -591,8 +588,10 @@ API.prototype.parseTxProposals = function(txData, cb) {
}, function(err, wcd) {
if (err) return cb(err);
<< << << < HEAD
var txps = txData.txps;
_processTxps(txps, wcd.sharedEncryptingKey);
_processTxps(txps, wcd.sharedEncryptingKey); === === =
_processTxps(txps, data.sharedEncryptingKey); >>> >>> > bit - history
var fake = _.any(txps, function(txp) {
return (!Verifier.checkTxProposal(wcd, txp));

View File

@ -268,6 +268,7 @@ ExpressApp.start = function(opts) {
server.getTxHistory({}, function(err, txs) {
if (err) return returnError(err, res, req);
res.json(txs);
res.end();
});
});
});

View File

@ -80,8 +80,7 @@ WalletService.getInstanceWithAuth = function(opts, cb) {
if (!copayer) return cb(new ClientError('NOTAUTHORIZED', 'Copayer not found'));
var pubKey = opts.readOnly ? copayer.roPubKey : copayer.rwPubKey;
var isValid = server._verifySignature(opts.message, opts.signature,
pubKey);
var isValid = server._verifySignature(opts.message, opts.signature, pubKey);
if (!isValid)
return cb(new ClientError('NOTAUTHORIZED', 'Invalid signature'));
@ -324,6 +323,20 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) {
WalletService.prototype._getBlockExplorer = function(provider, network) {
var url;
function getTransactionsInsight(url, addresses, cb) {
var request = require('request');
request({
method: "POST",
url: url + '/api/addrs/txs',
json: {
addrs: [].concat(addresses).join(',')
}
}, function(err, res, body) {
if (err || res.statusCode != 200) return cb(err || res);
return cb(null, body);
});
};
if (this.blockExplorer)
return this.blockExplorer;
@ -339,7 +352,9 @@ WalletService.prototype._getBlockExplorer = function(provider, network) {
url = 'https://test-insight.bitpay.com:443'
break;
}
return new Explorers.Insight(url, network);
var bc = new Explorers.Insight(url, network);
bc.getTransactions = _.bind(getTransactionsInsight, bc, url);
return bc;
break;
}
};
@ -874,7 +889,7 @@ WalletService.prototype._normalizeTxHistory = function(txs) {
txid: tx.txid,
confirmations: tx.confirmations,
fees: parseInt((tx.fees * 1e8).toFixed(0)),
minedTs: !_.isNaN(tx.time) ? tx.time * 1000 : undefined,
time: !_.isNaN(tx.time) ? tx.time : Math.floor(Date.now() / 1000),
inputs: inputs,
outputs: outputs,
};
@ -937,7 +952,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
var proposal = indexedProposals[tx.txid];
if (proposal) {
tx.message = proposal.message;
tx.actions = proposal.actions;
tx.actions = _.map(proposal.actions, function(action) {
return _.pick(action, ['createdOn', 'type', 'copayerId', 'copayerName', 'comment']);
});
// tx.sentTs = proposal.sentTs;
// tx.merchant = proposal.merchant;
//tx.paymentAckMemo = proposal.paymentAckMemo;

View File

@ -29,6 +29,7 @@
"levelup": "^0.19.0",
"lodash": "*",
"mocha-lcov-reporter": "0.0.1",
"moment": "^2.9.0",
"morgan": "*",
"npmlog": "^0.1.1",
"preconditions": "^1.0.7",