@@ -219,14 +219,14 @@ general::Amount convertAmount(const csdb::Amount& amount) {
219219api::TransactionId convert_transaction_id (const csdb::TransactionID& trid) {
220220 api::TransactionId result_id;
221221 result_id.index = (uint32_t ) trid.index ();
222- result_id.poolHash = fromByteArray ( trid.pool_hash (). to_binary () );
222+ result_id.poolSeq = trid.pool_seq ( );
223223 result_id.__isset .index = true ;
224- result_id.__isset .poolHash = true ;
224+ result_id.__isset .poolSeq = true ;
225225 return result_id;
226226}
227227
228228csdb::TransactionID convert_transaction_id (const api::TransactionId& trid) {
229- return csdb::TransactionID (csdb::PoolHash::from_binary ( toByteArray ( trid.poolHash )) , trid.index );
229+ return csdb::TransactionID (trid.poolSeq , trid.index );
230230}
231231
232232bool is_smart (const csdb::Transaction& tr) {
@@ -299,7 +299,7 @@ api::SealedTransaction APIHandler::convertTransaction(const csdb::Transaction& t
299299
300300 result.trxn .timeCreation = transaction.get_time ();
301301
302- result.trxn .poolNumber = executor_.loadBlockApi (transaction.id ().pool_hash ()).sequence ();
302+ result.trxn .poolNumber = executor_.loadBlockApi (transaction.id ().pool_seq ()).sequence ();
303303
304304 if (is_smart (transaction)) {
305305 using namespace cs ::trx_uf;
@@ -412,7 +412,7 @@ api::SealedTransaction APIHandler::convertTransaction(const csdb::Transaction& t
412412 if (is_smart (transaction)) {
413413 auto opers = lockedReference (this ->smart_operations );
414414 auto state_id = (*opers)[transaction.id ()].stateTransaction ;
415- if (! state_id.pool_hash (). is_empty ()) {
415+ if (state_id.is_valid ()) {
416416 stateTrx = executor_.loadTransactionApi (state_id);
417417 }
418418 }
@@ -423,7 +423,7 @@ api::SealedTransaction APIHandler::convertTransaction(const csdb::Transaction& t
423423 return result;
424424
425425 // 2) fill ExtraFee for state transaction
426- auto pool = executor_.loadBlockApi (stateTrx.id ().pool_hash ());
426+ auto pool = executor_.loadBlockApi (stateTrx.id ().pool_seq ());
427427 auto transactions = pool.transactions ();
428428 ExtraFee extraFee;
429429 extraFee.transactionId = convert_transaction_id (stateTrx.id ());
@@ -522,8 +522,7 @@ std::vector<api::SealedTransaction> APIHandler::extractTransactions(const csdb::
522522}
523523
524524void APIHandler::TransactionGet (TransactionGetResult& _return, const TransactionId& transactionId) {
525- const csdb::PoolHash poolhash = csdb::PoolHash::from_binary (toByteArray (transactionId.poolHash ));
526- const csdb::TransactionID tmpTransactionId = csdb::TransactionID (poolhash, (transactionId.index ));
525+ const csdb::TransactionID tmpTransactionId = csdb::TransactionID (transactionId.poolSeq , (transactionId.index ));
527526 csdb::Transaction transaction = executor_.loadTransactionApi (tmpTransactionId);
528527 _return.found = transaction.is_valid ();
529528 if (_return.found )
@@ -592,7 +591,7 @@ api::SmartContract APIHandler::fetch_smart_body(const csdb::Transaction& tr) {
592591 if (tr.user_field (0 ).is_valid ())
593592 res.transactionsCount = s_blockchain.getTransactionsCount (tr.target ());
594593
595- auto pool = executor_.loadBlockApi (tr.id ().pool_hash ());
594+ auto pool = executor_.loadBlockApi (tr.id ().pool_seq ());
596595 res.createTime = pool.get_time ();
597596
598597 return res;
@@ -846,38 +845,25 @@ void APIHandler::TransactionFlow(api::TransactionFlowResult& _return, const Tran
846845}
847846
848847void APIHandler::PoolListGet (api::PoolListGetResult& _return, const int64_t offset, const int64_t const_limit) {
849- if (!validatePagination (_return, *this , offset, const_limit)) {
850- return ;
851- }
848+ cs::Sequence limit = limitPage (const_limit);
852849
853850 uint64_t sequence = s_blockchain.getLastSeq ();
854851 if ((uint64_t )offset > sequence) {
855852 return ;
856853 }
857854
858- _return.pools .reserve (const_limit );
855+ _return.pools .reserve (limit );
859856
860- csdb::PoolHash hash;
861- try {
862- hash = s_blockchain.getHashBySequence (sequence - offset);
863- }
864- catch (...) {
865- return ;
866- }
867- if (hash.is_empty ()) {
868- return ;
869- }
870- PoolListGetStable (_return, fromByteArray (hash.to_binary ()), const_limit);
857+ PoolListGetStable (_return, sequence - offset, limit);
871858 _return.count = uint32_t (sequence + 1 );
872859}
873860
874- void APIHandler::PoolTransactionsGet (PoolTransactionsGetResult& _return, const PoolHash& hash , const int64_t offset, const int64_t const_limit) {
861+ void APIHandler::PoolTransactionsGet (PoolTransactionsGetResult& _return, const int64_t sequence , const int64_t offset, const int64_t const_limit) {
875862 // if (!validatePagination(_return, *this, offset, const_limit)) {
876863 // return;
877864 // }
878865 auto limit = limitPage (const_limit);
879- const csdb::PoolHash poolHash = csdb::PoolHash::from_binary (toByteArray (hash));
880- csdb::Pool pool = executor_.loadBlockApi (poolHash);
866+ csdb::Pool pool = executor_.loadBlockApi (cs::Sequence (sequence));
881867
882868 if (pool.is_valid ()) {
883869 _return.transactions = extractTransactions (pool, limit, offset);
@@ -886,14 +872,13 @@ void APIHandler::PoolTransactionsGet(PoolTransactionsGetResult& _return, const P
886872 SetResponseStatus (_return.status , APIRequestStatusType::SUCCESS);
887873}
888874
889- void APIHandler::PoolInfoGet (PoolInfoGetResult& _return, const PoolHash& hash , const int64_t index) {
875+ void APIHandler::PoolInfoGet (PoolInfoGetResult& _return, const int64_t sequence , const int64_t index) {
890876 csunused (index);
891- const csdb::PoolHash poolHash = csdb::PoolHash::from_binary (toByteArray (hash));
892- csdb::Pool pool = executor_.loadBlockApi (poolHash);
877+ csdb::Pool pool = executor_.loadBlockApi (cs::Sequence (sequence));
893878 _return.isFound = pool.is_valid ();
894879
895880 if (_return.isFound ) {
896- _return.pool = convertPool (poolHash );
881+ _return.pool = convertPool (pool );
897882 }
898883
899884 SetResponseStatus (_return.status , APIRequestStatusType::SUCCESS);
@@ -972,7 +957,7 @@ void APIHandler::collect_all_stats_slot(const csdb::Pool& pool) {
972957 periodStats.transactionsCount += (uint32_t )transactionsCount;
973958
974959 for (size_t i = 0 ; i < transactionsCount; ++i) {
975- const auto & transaction = pool.transaction (csdb::TransactionID (pool.hash (), i));
960+ const auto & transaction = pool.transaction (csdb::TransactionID (pool.sequence (), i));
976961
977962#ifdef MONITOR_NODE
978963 if (is_smart (transaction) || is_smart_state (transaction))
@@ -1007,7 +992,7 @@ void APIHandler::collect_all_stats_slot(const csdb::Pool& pool) {
1007992 periodStats.transactionsCount += (uint32_t )transactionsCount;
1008993
1009994 for (size_t i = 0 ; i < transactionsCount; ++i) {
1010- const auto & transaction = pool.transaction (csdb::TransactionID (pool.hash (), i));
995+ const auto & transaction = pool.transaction (csdb::TransactionID (pool.sequence (), i));
1011996
1012997 if (transaction.source () == s_blockchain.getGenesisAddress ())
1013998 continue ;
@@ -1040,7 +1025,7 @@ bool APIHandler::updateSmartCachesTransaction(csdb::Transaction trxn, cs::Sequen
10401025
10411026 if (is_smart_state (trxn)) {
10421027 cs::SmartContractRef scr (trxn.user_field (cs::trx_uf::new_state::RefStart));
1043- csdb::TransactionID trId (scr.hash , scr.transaction );
1028+ csdb::TransactionID trId (scr.sequence , scr.transaction );
10441029 const auto execTrans = solver.smart_contracts ().get_contract_call (trxn);
10451030
10461031 if ((execTrans.is_valid () && is_smart (execTrans)) ||
@@ -1183,37 +1168,40 @@ void APIHandler::GetLastHash(api::PoolHash& _return) {
11831168 return ;
11841169}
11851170
1186- void APIHandler::PoolListGetStable (api::PoolListGetResult& _return, const api::PoolHash& api_hash, const int64_t const_limit) {
1187- auto hash = csdb::PoolHash::from_binary (toByteArray (api_hash));
1171+ void APIHandler::PoolListGetStable (api::PoolListGetResult& _return, const int64_t sequence, const int64_t const_limit) {
11881172 auto limit = limitPage (const_limit);
1189-
1173+ cs::Sequence seq = cs::Sequence (sequence);
1174+ if (seq < 0 ) {
1175+ return ;
1176+ }
1177+ csmeta (csdebug) << " sequence " << seq << " , limit " << limit;
11901178 bool limSet = false ;
11911179
1192- while (limit && !hash.is_empty ()) {
1193- auto cch = poolCache.find (hash);
1194-
1195- if (cch == poolCache.end ()) {
1196- auto pool = executor_.loadBlockApi (hash);
1197- api::Pool apiPool = convertPool (pool);
1198- _return.pools .push_back (apiPool);
1199- poolCache.insert (cch, std::make_pair (hash, apiPool));
1200- hash = pool.previous_hash ();
1201-
1202- if (!limSet) {
1203- _return.count = uint32_t (pool.sequence () + 1 );
1204- limSet = true ;
1180+ while (limit) {
1181+ auto lockedPoolCache = lockedReference (this ->poolCache );
1182+ auto cch = lockedPoolCache->find (seq);
1183+
1184+ if (cch == lockedPoolCache->end ()) {
1185+ auto pool = executor_.loadBlockApi (seq);
1186+ if (pool.is_valid ()) {
1187+ api::Pool apiPool = convertPool (pool);
1188+ _return.pools .push_back (apiPool);
1189+ lockedPoolCache->insert (cch, std::make_pair (seq, apiPool));
1190+ if (!limSet) {
1191+ _return.count = uint32_t (seq + 1 );
1192+ limSet = true ;
1193+ }
12051194 }
12061195 }
12071196 else {
12081197 _return.pools .push_back (cch->second );
1209- hash = csdb::PoolHash::from_binary (toByteArray (cch->second .prevHash ));
1210-
12111198 if (!limSet) {
12121199 _return.count = uint32_t (cch->second .poolNumber + 1 );
12131200 limSet = true ;
12141201 }
12151202 }
12161203
1204+ --seq;
12171205 --limit;
12181206 }
12191207}
@@ -1390,7 +1378,7 @@ void addTokenResult(api::TokenTransfersResult& _return, const csdb::Address& tok
13901378 transfer.amount = TokensMaster::getAmount (smart);
13911379 transfer.initiator = fromByteArray (handler.getAddressByType (tr.source (), BlockChain::AddressType::PublicKey).public_key ());
13921380
1393- transfer.transaction .poolHash = fromByteArray ( tr.id ().pool_hash (). to_binary () );
1381+ transfer.transaction .poolSeq = tr.id ().pool_seq ( );
13941382 transfer.transaction .index = (uint32_t ) tr.id ().index ();
13951383 transfer.time = atoll (pool.user_field (0 ).value <std::string>().c_str ());
13961384 _return.transfers .push_back (transfer);
@@ -1400,7 +1388,7 @@ void addTokenResult(api::TokenTransactionsResult& _return, const csdb::Address&
14001388 const api::SmartContractInvocation& smart, const std::pair<csdb::Address, csdb::Address>&, BlockChain& handler) {
14011389 api::TokenTransaction trans;
14021390 trans.token = fromByteArray (token.public_key ());
1403- trans.transaction .poolHash = fromByteArray ( tr.id ().pool_hash (). to_binary () );
1391+ trans.transaction .poolSeq = tr.id ().pool_seq ( );
14041392 trans.transaction .index = (uint32_t ) tr.id ().index ();
14051393 trans.time = atoll (pool.user_field (0 ).value <std::string>().c_str ());
14061394 trans.initiator = fromByteArray (handler.getAddressByType (tr.source (), BlockChain::AddressType::PublicKey).public_key ());
@@ -1491,7 +1479,7 @@ void APIHandler::iterateOverTokenTransactions(const csdb::Address& addr, const s
14911479 if (is_smart_state (*trIt)) {
14921480 cs::SmartContractRef smart_ref;
14931481 smart_ref.from_user_field (trIt->user_field (cs::trx_uf::new_state::RefStart));
1494- l_id.emplace_back (csdb::TransactionID (smart_ref.hash , smart_ref.transaction ));
1482+ l_id.emplace_back (csdb::TransactionID (smart_ref.sequence , smart_ref.transaction ));
14951483 }
14961484 else if (is_smart (*trIt)) {
14971485 auto it = std::find (l_id.begin (), l_id.end (), trIt->id ());
@@ -1655,8 +1643,7 @@ void APIHandler::TokenTransfersGet(api::TokenTransfersResult& _return, const gen
16551643}
16561644
16571645void APIHandler::TokenTransferGet (api::TokenTransfersResult& _return, const general::Address& token, const TransactionId& id) {
1658- const csdb::PoolHash poolhash = csdb::PoolHash::from_binary (toByteArray (id.poolHash ));
1659- const csdb::TransactionID trxn_id = csdb::TransactionID (poolhash, id.index );
1646+ const csdb::TransactionID trxn_id = csdb::TransactionID (id.poolSeq , id.index );
16601647 const csdb::Transaction trxn = executor_.loadTransactionApi (trxn_id);
16611648 const csdb::Address addr = BlockChain::getAddressFromKey (token);
16621649
@@ -1673,7 +1660,7 @@ void APIHandler::TokenTransferGet(api::TokenTransfersResult& _return, const gene
16731660 return ;
16741661 }
16751662
1676- const auto pool = executor_.loadBlockApi (trxn.id ().pool_hash ());
1663+ const auto pool = executor_.loadBlockApi (trxn.id ().pool_seq ());
16771664 const auto smart = fetch_smart (trxn);
16781665 const auto addr_pk = s_blockchain.getAddressByType (trxn.source (), BlockChain::AddressType::PublicKey);
16791666 const auto addrPair = TokensMaster::getTransferData (addr_pk, smart.method , smart.params );
@@ -1723,24 +1710,23 @@ void APIHandler::TokenTransfersListGet(api::TokenTransfersResult& _return, int64
17231710 }
17241711
17251712 uint64_t totalTransfers = 0 ;
1726- std::multimap<csdb::PoolHash , csdb::Address> tokenTransPools;
1713+ std::multimap<cs::Sequence , csdb::Address> tokenTransPools;
17271714
17281715 tm.loadTokenInfo ({}, [&totalTransfers, &tokenTransPools, this ](const TokensMap& tm, const HoldersMap&) {
17291716 for (auto & t : tm) {
17301717 totalTransfers += t.second .transfersCount ;
1731- tokenTransPools.insert (std::make_pair (s_blockchain.getLastTransaction (t.first ).pool_hash (), t.first ));
1718+ tokenTransPools.insert (std::make_pair (s_blockchain.getLastTransaction (t.first ).pool_seq (), t.first ));
17321719 }
17331720 }, false );
17341721
17351722 _return.count = uint32_t (totalTransfers);
17361723
17371724 std::vector<csdb::Address> tokenAddrs;
1738-
1739- csdb::PoolHash pooh = s_blockchain.getLastNonEmptyBlock ().first ;
1740- while (limit && !pooh.is_empty () && tokenTransPools.size ()) {
1741- auto it = tokenTransPools.find (pooh);
1725+ cs::Sequence seq = s_blockchain.getLastNonEmptyBlock ().first ;
1726+ while (limit && seq != cs::kWrongSequence && tokenTransPools.size ()) {
1727+ auto it = tokenTransPools.find (seq);
17421728 if (it != tokenTransPools.end ()) {
1743- auto pool = executor_.loadBlockApi (pooh );
1729+ auto pool = executor_.loadBlockApi (seq );
17441730
17451731 for (auto & t : pool.transactions ()) {
17461732 if (!is_smart (t)) {
@@ -1763,19 +1749,19 @@ void APIHandler::TokenTransfersListGet(api::TokenTransfersResult& _return, int64
17631749 }
17641750
17651751 do {
1766- const auto lPh = s_blockchain.getPreviousPoolHash (it->second , it->first );
1752+ const auto lPs = s_blockchain.getPreviousPoolSeq (it->second , it->first );
17671753 const auto lAddr = it->second ;
17681754
17691755 tokenTransPools.erase (it);
1770- if (!lPh. is_empty () ) {
1771- tokenTransPools.insert (std::make_pair (lPh , lAddr));
1756+ if (lPs != cs:: kWrongSequence ) {
1757+ tokenTransPools.insert (std::make_pair (lPs , lAddr));
17721758 }
17731759
1774- it = tokenTransPools.find (pooh );
1760+ it = tokenTransPools.find (seq );
17751761 } while (it != tokenTransPools.end ());
17761762 }
17771763
1778- pooh = s_blockchain.getPreviousNonEmptyBlock (pooh ).first ;
1764+ seq = s_blockchain.getPreviousNonEmptyBlock (seq ).first ;
17791765 }
17801766
17811767 tm.loadTokenInfo (tokenAddrs, [&_return](const TokensMap& tm, const HoldersMap&) {
0 commit comments