Skip to content
Snippets Groups Projects
Commit 30bd4fee authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #362 Added reception time on pending transactions

parent f3187ad0
No related branches found
No related tags found
No related merge requests found
......@@ -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 *() {
......
......@@ -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);
};
......
......@@ -329,6 +329,7 @@ dtos.TxOfHistory = {
"outputs": [String],
"comment": String,
"locktime": String,
"received": Number,
"signatures": [String],
"hash": String,
"block_number": Number,
......
......@@ -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"
],
......
......@@ -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(){
......
......@@ -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();
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment