Skip to content

Commit 5dc18d0

Browse files
author
Alexander Avramenko
committed
Accurate new state handling, both value and hash
1 parent ebca9e1 commit 5dc18d0

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

api/src/apihandler.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,23 @@ bool APIHandler::updateSmartCachesTransaction(csdb::Transaction trxn, cs::Sequen
10551055
}
10561056

10571057
HashState res;
1058-
{ // signal to end waiting for a transaction
1058+
res.hash = cs::Zero::hash;
1059+
std::string newStateStr;
1060+
if (trxn.user_field_ids().count(cs::trx_uf::new_state::RetVal) > 0) {
1061+
res.retVal = trxn.user_field(cs::trx_uf::new_state::RetVal).template value<std::string>();
1062+
}
1063+
1064+
general::Variant var;
1065+
if (!res.retVal.empty()) {
1066+
std::string tmp = res.retVal;
1067+
var = deserialize<general::Variant>(std::move(tmp));
1068+
}
1069+
1070+
if (trxn.user_field_ids().count(cs::trx_uf::new_state::Value) > 0) {
1071+
// new_state value, not hash!
1072+
newStateStr = trxn.user_field(cs::trx_uf::new_state::Value).template value<std::string>();
1073+
}
1074+
else { // signal to end waiting for a transaction
10591075
auto hashStateInst(lockedReference(this->hashStateSL));
10601076
(*hashStateInst)[target_pk].updateHash([&](const HashState& oldHash) {
10611077
auto newHashStr = trxn.user_field(cs::trx_uf::new_state::Hash).template value<std::string>();
@@ -1068,16 +1084,18 @@ bool APIHandler::updateSmartCachesTransaction(csdb::Transaction trxn, cs::Sequen
10681084
});
10691085
}
10701086

1071-
if (res.hash != cs::Zero::hash) { // update tokens
1087+
if (!newStateStr.empty() || res.hash != cs::Zero::hash) { // update tokens
10721088
auto caller_pk = s_blockchain.getAddressByType(execTrans.source(), BlockChain::AddressType::PublicKey);
10731089

10741090
if (is_smart_deploy(smart))
10751091
tm.checkNewDeploy(target_pk, caller_pk, smart);
10761092

1077-
// state also will be updated in update_smart_state_slot()
1078-
std::string newState = cs::SmartContracts::get_contract_state(s_blockchain, target_pk);
1079-
if (!newState.empty())
1080-
tm.checkNewState(target_pk, caller_pk, smart, newState);
1093+
if (newStateStr.empty()) {
1094+
newStateStr = cs::SmartContracts::get_contract_state(s_blockchain, target_pk);
1095+
}
1096+
if (!newStateStr.empty()) {
1097+
tm.checkNewState(target_pk, caller_pk, smart, newStateStr);
1098+
}
10811099
}
10821100
}
10831101
}

api/src/tokens.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ void TokensMaster::updateTokenChaches(const csdb::Address& addr, const std::stri
252252
[&retBalance](const std::string& balance) { retBalance = balance; });
253253

254254
if (!std::all_of(retBalance.begin(), retBalance.end(), [](char ch) { return (isdigit(ch) || ch == '.'); })) {
255+
csdebug() << "executor returns balance as " << retBalance;
255256
retBalance = "0";
256-
cserror() << "executor return text balance!";
257257
}
258258
return retBalance;
259259
};

0 commit comments

Comments
 (0)