diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 30c1a4ddf..20005697e 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -6256,7 +6256,7 @@ namespace PocketDb from Transactions r join Transactions p indexed by Transactions_Type_Last_String2_Height - on p.Type in (200,201,202) + on p.Type in = 200 and p.Last = 1 and p.String2 = r.String3 and p.Height > 0 @@ -6294,7 +6294,7 @@ namespace PocketDb and rna.Id = na.Id and rna.Last = 1 - where r.Type in (200,201,202) + where r.Type in = 200 and r.Hash = r.String2 -- Only orig and r.Height = ? and r.String3 is not null @@ -6342,14 +6342,65 @@ namespace PocketDb { ShortTxType::Money, { R"sql( -- Incoming money - select + select distinct (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Money) + R"sql(')TP, t.Hash, t.Type, - i.AddressHash, - t.Height as Height, + null, + o.TxHeight as Height, t.BlockNum as BlockNum, - o.Value, + null, + null, + null, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i indexed by TxOutputs_SpentTxHash + where i.SpentTxHash = t.Hash + ), + ( + select json_group_array(json_object( + 'Value', oo.Value, + 'AddressHash', oo.AddressHash, + 'ScriptPubKey', oo.ScriptPubKey, + 'Account', json_object( + 'Lang', pna.String1, + 'Name', pna.String2, + 'Avatar', pna.String3, + 'Rep', ifnull(rna.Value,0) + ) + )) + from TxOutputs oo indexed by TxOutputs_TxHash_AddressHash_Value + left join Transactions na indexed by Transactions_Type_Last_String1_String2_Height + on na.Type = 100 + and na.Last = 1 + and na.String1 = oo.AddressHash + left join Payload pna + on pna.TxHash = na.Hash + left join Ratings rna indexed by Ratings_Type_Id_Last_Height + on rna.Type = 0 + and rna.Id = na.Id + and rna.Last = 1 + where oo.TxHash = t.Hash + and oo.TxHeight = t.Height + order by oo.Number + ), + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, null, null, null, @@ -6371,18 +6422,13 @@ namespace PocketDb join Transactions t indexed by Transactions_Hash_Type_Height on t.Hash = o.TxHash - and t.Type in (1,2,3) -- 1 default money transfer, 2 coinbase, 3 coinstake + and t.Type in (1,2,3) and t.Height > ? and (t.Height < ? or (t.Height = ? and t.BlockNum < ?)) - join TxOutputs i indexed by TxOutputs_SpentTxHash - on i.SpentTxHash = o.TxHash - and i.Number = (select min(ii.Number) from TxOutputs ii where ii.SpentTxHash = o.TxHash) - and i.AddressHash != o.AddressHash -- TODO (brangr, lostystyg): exclude coinstake first transaction - where o.AddressHash = ? and o.TxHeight > ? - and o.TxHeight < ? + and o.TxHeight <= ? )sql", [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ TryBindStatementInt64(stmt, i++, queryParams.heightMin); @@ -6407,9 +6453,16 @@ namespace PocketDb t.BlockNum as BlockNum, null, null, + null, + null, + null, + null, + null, + null, + null, + p.String1, p.String2, p.String3, - p.String4, ifnull(r.Value,0), null, null, @@ -6421,16 +6474,30 @@ namespace PocketDb null, null, null, + null, + null, + null, + null, + null, + null, + null, + null, + null, null from Transactions t indexed by Transactions_Type_Last_String2_Height + left join Transactions tLast indexed by Transactions_Type_Last_String1_Height_Id + on tLast.Type = 100 + and tLast.Last = 1 + and tLast.String1 = t.String1 + left join Payload p - on p.TxHash = t.Hash + on p.TxHash = tLast.Hash left join Ratings r indexed by Ratings_Type_Id_Last_Height on r.Type = 0 - and r.Id = t.Id + and r.Id = tLast.Id and r.Last = 1 where t.Type = 100 @@ -6457,45 +6524,65 @@ namespace PocketDb a.Hash, a.Type, a.String1, - orig.Height as Height, + a.Height as Height, a.BlockNum as BlockNum, null, + a.String2, + a.String3, + null, + null, + null, pa.String1, + a.String4, + a.String5, + paa.String1, paa.String2, paa.String3, - paa.String4, ifnull(ra.Value,0), + null, c.Hash, c.Type, null, c.Height, c.BlockNum, null, + c.String2, + null, + null, + null, + null, pc.String1, null, null, null, + null, + null, + null, null - from Transactions c indexed by Transactions_Type_Last_String1_String2_Height -- My comments + from Transactions c indexed by Transactions_Type_Last_String1_Height_Id -- My comments left join Payload pc on pc.TxHash = c.Hash join Transactions a indexed by Transactions_Type_Last_String5_Height -- Other answers - on a.Type in (204, 205) and a.Last = 1 + on a.Type in (204, 205) and a.Last in (0,1) and a.Height > ? and (a.Height < ? or (a.Height = ? and a.BlockNum < ?)) and a.String5 = c.String2 and a.String1 != c.String1 + and a.Hash = a.String2 - join Transactions orig indexed by Transactions_Hash_Height - on orig.Hash = a.String2 + left join Transactions aLast indexed by Transactions_Type_Last_String2_Height + on aLast.Type in (204,205) + and aLast.Last = 1 + and aLast.String2 = a.Hash + and aLast.Height > 0 left join Payload pa - on pa.TxHash = a.Hash + on pa.TxHash = aLast.Hash - left join Transactions aa + left join Transactions aa indexed by Transactions_Type_Last_String1_Height_Id on aa.Type = 100 and aa.Last = 1 and aa.String1 = a.String1 @@ -6510,9 +6597,9 @@ namespace PocketDb and ra.Last = 1 where c.Type in (204, 205) - and c.Last = 1 - and c.String1 = ? - and c.Height > 0 + and c.Last = 1 + and c.String1 = ? + and c.Height > 0 )sql", [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ TryBindStatementInt64(stmt, i++, queryParams.heightMin); @@ -6533,44 +6620,81 @@ namespace PocketDb c.String1, c.Height as Height, c.BlockNum as BlockNum, - oc.Value, + null, + c.String2, + null, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = c.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = c.Hash + and o.TxHeight = c.Height + order by o.Number + ), pc.String1, + null, + null, + pac.String1, pac.String2, pac.String3, - pac.String4, ifnull(rac.Value,0), + null, p.Hash, p.Type, null, p.Height, p.BlockNum, null, + p.String2, + null, + null, + null, + null, + pp.String2, + null, + null, null, null, null, null, null - from Transactions p indexed by Transactions_String1_Last_Height + from Transactions p indexed by Transactions_Type_Last_String1_Height_Id join Transactions c indexed by Transactions_Type_Last_String3_Height - on c.Type in (204,205) - and c.Last = 1 + on c.Type = 204 + and c.Last in (0,1) and c.String3 = p.String2 and c.String1 != p.String1 - and c.Hash = c.String2 and c.String4 is null and c.String5 is null and c.Height > ? and (c.Height < ? or (c.Height = ? and c.BlockNum < ?)) - left join TxOutputs oc indexed by TxOutputs_TxHash_AddressHash_Value - on oc.TxHash = c.Hash and oc.AddressHash = p.String1 and oc.AddressHash != c.String1 + left join Transactions cLast indexed by Transactions_Type_Last_String2_Height + on cLast.Type in (204,205) + and cLast.Last = 1 + and cLast.String2 = c.Hash + and cLast.Height > 0 left join Payload pc - on pC.TxHash = c.Hash + on pC.TxHash = cLast.Hash - join Transactions ac -- accounts of commentators + join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id on ac.String1 = c.String1 and ac.Last = 1 and ac.Type = 100 @@ -6584,6 +6708,9 @@ namespace PocketDb and rac.Id = ac.Id and rac.Last = 1 + left join Payload pp + on pp.TxHash = p.Hash + where p.Type in (200,201,202) and p.Last = 1 and p.Height > 0 @@ -6610,9 +6737,16 @@ namespace PocketDb subs.BlockNum as BlockNum, null, null, + null, + null, + null, + null, + null, + null, + null, + pu.String1, pu.String2, pu.String3, - pu.String4, ifnull(ru.Value,0), null, null, @@ -6624,11 +6758,20 @@ namespace PocketDb null, null, null, + null, + null, + null, + null, + null, + null, + null, + null, + null, null - from Transactions subs --indexed by Transactions_Type_Last_String2_Height + from Transactions subs indexed by Transactions_Type_Last_String2_Height - join Transactions u --indexed by Transactions_Type_Last_String1_Height_Id + join Transactions u indexed by Transactions_Type_Last_String1_Height_Id on u.Type in (100) and u.Last = 1 and u.String1 = subs.String1 @@ -6642,8 +6785,8 @@ namespace PocketDb and ru.Id = u.Id and ru.Last = 1 - where subs.Type in (302, 303) -- Ignoring unsubscribers? - and subs.Last = 1 + where subs.Type in (302, 303, 304) -- Ignoring unsubscribers? + and subs.Last in (0,1) and subs.String2 = ? and subs.Height > ? and (subs.Height < ? or (subs.Height = ? and subs.BlockNum < ?)) @@ -6667,19 +6810,35 @@ namespace PocketDb s.String1, s.Height as Height, s.BlockNum as BlockNum, + null, + null, + null, s.Int1, null, + null, + null, + null, + null, + pacs.String1, pacs.String2, pacs.String3, - pacs.String4, ifnull(racs.Value,0), + null, c.Hash, c.Type, null, - c.Height, -- TODO (losty): original? + c.Height, c.BlockNum, null, + c.String2, + c.String3, + null, + null, + null, ps.String1, + c.String4, + c.String5, + null, null, null, null, @@ -6694,8 +6853,13 @@ namespace PocketDb and s.Height > ? and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) + left join Transactions cLast indexed by Transactions_Type_Last_String2_Height + on cLast.Type in (204,205) + and cLast.Last = 1 + and cLast.String2 = c.String2 + left join Payload ps - on ps.TxHash = c.Hash + on ps.TxHash = cLast.Hash join Transactions acs on acs.Type = 100 @@ -6711,8 +6875,8 @@ namespace PocketDb and racs.Id = acs.Id and racs.Last = 1 - where c.Type in (204,205) - and c.Last = 1 + where c.Type in (204) + and c.Last in (0,1) and c.Height > 0 and c.String1 = ? )sql", @@ -6735,25 +6899,41 @@ namespace PocketDb s.String1, s.Height as Height, s.BlockNum as BlockNum, + null, + null, + null, s.Int1, null, + null, + null, + null, + null, + pacs.String1, pacs.String2, pacs.String3, - pacs.String4, ifnull(racs.Value,0), + null, c.Hash, c.Type, null, - c.Height, -- TODO (losty): original? + c.Height, c.BlockNum, null, + c.String2, + null, + null, + null, + null, pc.String2, null, null, null, + null, + null, + null, null - from Transactions c indexed by Transactions_Type_Last_String1_Height_Id + from Transactions c indexed by Transactions_Type_String1_Height_Time_Int1 join Transactions s indexed by Transactions_Type_Last_String2_Height on s.Type = 300 @@ -6762,8 +6942,13 @@ namespace PocketDb and s.Height > ? and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) + left join Transactions cLast indexed by Transactions_Type_Last_String2_Height + on cLast.Type = c.Type + and cLast.Last = 1 + and cLast.String2 = c.String2 + left join Payload pc - on pc.TxHash = c.Hash + on pc.TxHash = cLast.Hash join Transactions acs on acs.Type = 100 @@ -6780,7 +6965,7 @@ namespace PocketDb and racs.Last = 1 where c.Type in (200, 201, 202) - and c.Last = 1 + and c.Hash = c.String2 -- orig and c.Height > 0 and c.String1 = ? )sql", @@ -6804,12 +6989,28 @@ namespace PocketDb c.Height as Height, c.BlockNum as BlockNum, null, + c.String2, + null, + null, + null, + null, p.String2, + null, + null, + pac.String1, pac.String2, pac.String3, - pac.String4, ifnull(rac.Value,0), - null, -- TODO (losty): probably reposts here? + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, null, null, null, @@ -6825,16 +7026,21 @@ namespace PocketDb join Transactions c indexed by Transactions_Type_Last_String1_Height_Id -- content for private subscribers on c.Type in (200,201,202) - and c.Last = 1 -- TODO (losty): last = 1 and c.Hash = c.String2 ????? + and c.Last in (0,1) and c.String1 = subs.String2 - -- and c.Hash = c.String2 -- TODO (losty): Only first content record + and c.Hash = c.String2 -- orig and c.Height > ? and (c.Height < ? or (c.Height = ? and c.BlockNum < ?)) + left join Transactions cLast indexed by Transactions_Type_Last_String2_Height + on cLast.Type = c.Type + and cLast.Last = 1 + and cLast.String2 = c.String2 + left join Payload p - on p.TxHash = c.Hash - - join Transactions ac + on p.TxHash = cLast.Hash + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id on ac.Type = 100 and ac.Last = 1 and ac.String1 = c.String1 @@ -6847,7 +7053,7 @@ namespace PocketDb on rac.Type = 0 and rac.Id = ac.Id and rac.Last = 1 - + where subs.Type = 303 and subs.Last = 1 and subs.Height > 0 @@ -6872,39 +7078,75 @@ namespace PocketDb tBoost.String1, tBoost.Height as Height, tBoost.BlockNum as BlockNum, - tBoost.Int1, null, + null, + null, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = tBoost.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = tBoost.Hash + and o.TxHeight = tBoost.Height + order by o.Number + ), + null, + null, + null, + pac.String1, pac.String2, pac.String3, - pac.String4, ifnull(rac.Value,0), + null, tContent.Hash, tContent.Type, null, tContent.Height, tContent.BlockNum, null, + tContent.String2, + null, + null, + null, + null, pContent.String2, null, null, null, + null, + null, + null, null from Transactions tBoost indexed by Transactions_Type_Last_Height_Id join Transactions tContent indexed by Transactions_Type_Last_String1_String2_Height on tContent.Type in (200,201,202) - and tContent.Last in (0,1) - and tContent.Height > 0 + and tContent.Last = 1 and tContent.String1 = ? and tContent.String2 = tBoost.String2 + and tContent.Height > 0 + left join Payload pContent on pContent.TxHash = tContent.Hash - - join Transactions ac - on ac.String1 = tBoost.String1 - and ac.Type = 100 + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.Type = 100 and ac.Last = 1 + and ac.String1 = tBoost.String1 and ac.Height > 0 left join Payload pac @@ -6937,42 +7179,64 @@ namespace PocketDb r.Hash, r.Type, r.String1, - r.Height as Height, -- TODO (losty): orig height maybe??? + r.Height as Height, r.BlockNum as BlockNum, null, + r.String2, + null, + null, + null, + null, pr.String2, + null, + null, + par.String1, par.String2, par.String3, - par.String4, ifnull(rar.Value,0), + null, p.Hash, p.Type, null, p.Height, p.BlockNum, null, + p.String2, + null, + null, + null, + null, pp.String2, null, null, null, + null, + null, + null, null from Transactions p indexed by Transactions_Type_Last_String1_Height_Id - join Payload pp - on pp.TxHash = p.Hash + left join Payload pp + on pp.TxHash = p.Hash join Transactions r indexed by Transactions_Type_Last_String3_Height - on r.Type in (200,201,202) - and r.Last = 1 + on r.Type = 200 + and r.Last in (0,1) + and r.Hash = r.String2 and r.String3 = p.String2 and r.Height > ? and (r.Height < ? or (r.Height = ? and r.BlockNum < ?)) + left join Transactions rLast indexed by Transactions_Type_Last_String2_Height + on rLast.Type = r.Type + and rLast.Last = 1 + and rLast.String2 = r.String2 + left join Payload pr - on pr.TxHash = r.Hash + on pr.TxHash = rLast.Hash - join Transactions ar + left join Transactions ar indexed by Transactions_Type_Last_String1_Height_Id on ar.Type = 100 and ar.Last = 1 and ar.String1 = r.String1 @@ -6986,7 +7250,7 @@ namespace PocketDb and rar.Id = ar.Id and rar.Last = 1 - where p.Type in (200,201,202) + where p.Type = 200 and p.Last = 1 and p.Height > 0 and p.String1 = ? @@ -7195,10 +7459,10 @@ namespace PocketDb join Transactions p indexed by Transactions_Type_Last_String1_String2_Height on p.String2 = r.String3 and p.Last = 1 - and p.Type in (200,201,202) + and p.Type = 200 and p.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) - where r.Type in (200,201,202) + where r.Type = 200 and r.Last in (0,1) and r.Hash = r.String2 -- Only orig and r.Height between ? and ? diff --git a/src/pocketdb/web/PocketRpc.cpp b/src/pocketdb/web/PocketRpc.cpp index 951afc170..d2fcab1f5 100644 --- a/src/pocketdb/web/PocketRpc.cpp +++ b/src/pocketdb/web/PocketRpc.cpp @@ -69,7 +69,7 @@ static const CRPCCommand commands[] = {"contents", "getcontents", &GetContents, {"address"}}, {"contents", "getrandomcontents", &GetRandomContents, {}}, {"contents", "getcontentactions", &GetContentActions, {"contentHash"}}, - // {"contents", "getevents", &GetEvents, {"address", "height", "blockNum", "filters"}}, + {"contents", "getevents", &GetEvents, {"address", "height", "blockNum", "filters"}}, {"contents", "getactivities", &GetActivities, {"address", "height", "blockNum", "filters"}}, {"contents", "getnotifications", &GetNotifications, {"height", "filters"}}, {"contents", "getnotificationssummary", &GetNotificationsSummary, {"addresses", "height", "filters"}},