From f1ee3ee474f706a96b976d0d682a91bbc1d9cd3e Mon Sep 17 00:00:00 2001 From: tony Date: Tue, 18 Feb 2020 18:38:47 +0300 Subject: [PATCH] read timestamps from new datafeed storage --- src/js/controllers/index.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index f2bbf45e8..8a67eef55 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -172,23 +172,30 @@ angular.module('copayApp.controllers').controller('indexController', function($r if(isCordova) wallet.showCompleteClient(); }); + function readLastTimestamp(cb) { + var db = require('ocore/db.js'); + var data_feeds = require('ocore/data_feeds.js'); + db.query("SELECT timestamp FROM units WHERE is_free=1 ORDER BY timestamp DESC LIMIT 1", function (rows) { + if (rows.length === 0) + return cb(0); + var timestamp = rows[0].timestamp; + if (timestamp) + return cb(timestamp); + data_feeds.readDataFeedValue([configService.TIMESTAMPER_ADDRESS], 'timestamp', null, 0, 1e15, false, 'last', function (objResult) { + cb(objResult.value ? parseInt(objResult.value) : 0); + }); + }); + } + function readLastDateString(cb){ var conf = require('ocore/conf.js'); if (conf.storage !== 'sqlite') return cb(); - var db = require('ocore/db.js'); - db.query( - "SELECT int_value FROM data_feeds CROSS JOIN unit_authors USING(unit) \n\ - WHERE +address=? AND +feed_name='timestamp' \n\ - ORDER BY data_feeds.rowid DESC LIMIT 1", - [configService.TIMESTAMPER_ADDRESS], - function(rows){ - if (rows.length === 0) - return cb(); - var ts = rows[0].int_value; - cb('at '+$filter('date')(ts, 'short')); - } - ); + readLastTimestamp(function(ts){ + if (!ts) + return cb(); + cb('at '+$filter('date')(ts, 'short')); + }); } function readSyncPercent(cb){