diff --git a/app/lib/dal/sqliteDAL/MetaDAL.js b/app/lib/dal/sqliteDAL/MetaDAL.js index 3e3954eb4113e728d915e1ca5485e9bcab462009..7a4a8a38ab6209664dc0efc39ff0befe6856edbe 100644 --- a/app/lib/dal/sqliteDAL/MetaDAL.js +++ b/app/lib/dal/sqliteDAL/MetaDAL.js @@ -28,7 +28,8 @@ function MetaDAL(db) { let migrations = { 0: 'BEGIN; COMMIT;', - 1: 'BEGIN; COMMIT;' + 1: 'BEGIN; COMMIT;', + 2: 'BEGIN; ALTER TABLE txs ADD COLUMN received INTEGER NULL; COMMIT;' }; this.init = () => co(function *() { diff --git a/app/lib/dal/sqliteDAL/TxsDAL.js b/app/lib/dal/sqliteDAL/TxsDAL.js index ef36c0b21956549fabed36fb7b48813dd89811cf..05b278fb01763bba785e915de76e59f4aebc81ad 100644 --- a/app/lib/dal/sqliteDAL/TxsDAL.js +++ b/app/lib/dal/sqliteDAL/TxsDAL.js @@ -4,6 +4,7 @@ var Q = require('q'); var co = require('co'); +var moment = require('moment'); var AbstractSQLite = require('./AbstractSQLite'); module.exports = TxsDAL; @@ -24,6 +25,7 @@ function TxsDAL(db) { 'currency', 'comment', 'locktime', + 'received', 'time', 'written', 'removed', @@ -99,11 +101,13 @@ function TxsDAL(db) { }; this.addPending = (tx) => { + tx.received = moment().unix(); tx.written = false; tx.removed = false; tx.hash = tx.getHash(true); tx.recipients = tx.outputs.map(function(out) { - return out.match('(.*):')[1]; + let recipent = out.match('SIG\\((.*)\\)'); + return (recipent && recipent[1]) || 'UNKNOWN'; }); return this.saveEntity(tx); }; diff --git a/app/lib/streams/dtos.js b/app/lib/streams/dtos.js index 3e297b5d765fa8b0757f6250984995c09040d829..1971dcb406a896623d6d61959773983d117f71c2 100644 --- a/app/lib/streams/dtos.js +++ b/app/lib/streams/dtos.js @@ -329,6 +329,7 @@ dtos.TxOfHistory = { "outputs": [String], "comment": String, "locktime": String, + "received": Number, "signatures": [String], "hash": String, "block_number": Number, diff --git a/doc/HTTP_API.md b/doc/HTTP_API.md index 886b1afaf3735dd66839e9b31ae06aa666a8d457..8dcfecdc221893363ccd8825ab24386fe9e8a02e 100644 --- a/doc/HTTP_API.md +++ b/doc/HTTP_API.md @@ -1375,6 +1375,7 @@ The full transaction history for the given `pubkey` "sent": [ { "version": 2, + "received": null, "issuers": [ "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ], @@ -1397,6 +1398,7 @@ The full transaction history for the given `pubkey` "received": [ { "version": 2, + "received": null, "issuers": [ "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ], @@ -1417,6 +1419,7 @@ The full transaction history for the given `pubkey` }, { "version": 2, + "received": null, "issuers": [ "J78bPUvLjxmjaEkdjxWLeENQtcfXm7iobqB49uT1Bgp3" ], @@ -1439,6 +1442,7 @@ The full transaction history for the given `pubkey` "sending": [ { "version": 2, + "received": 1459691641, "issuers": [ "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ], @@ -1459,6 +1463,7 @@ The full transaction history for the given `pubkey` "receiving": [ { "version": 2, + "received": 1459691641, "issuers": [ "2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX" ], diff --git a/test/dal/dal.js b/test/dal/dal.js index 6e64cc3b28bc0cee18cdf4305cbff7a3110e5736..6909f5d0ac8d686a274eac59b9e9b37c4164177c 100644 --- a/test/dal/dal.js +++ b/test/dal/dal.js @@ -173,7 +173,7 @@ describe("DAL", function(){ it('should have DB version 2', () => co(function *() { let version = yield fileDAL.getDBVersion(); should.exist(version); - version.should.equal(2); + version.should.equal(3); })); it('should have no peer in a first time', function(){ diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index 996d589b9cf6b6d1f80eb82083f2b4789ffe60e7..b844f68b16164617c1628db49af67e0b316ab961 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -8,6 +8,8 @@ var constants = require('../../app/lib/constants'); var node = require('./tools/node'); var user = require('./tools/user'); var unit = require('./tools/unit'); +var http = require('./tools/http'); +var rp = require('request-promise'); var MEMORY_MODE = true; describe("Testing transactions", function() { @@ -40,6 +42,11 @@ describe("Testing transactions", function() { yield node2.commitP(); yield node2.commitP(); yield tic.sendP(51, toc); + yield http.expectAnswer(rp('http://127.0.0.1:9998/tx/history/DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', { json: true }), function(res) { + res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo'); + res.should.have.property('history').property('pending').length(1); + res.history.pending[0].should.have.property('received').be.a.Number; + }); yield node2.commitP(); }); });