Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
IPC fetch needs to special case _balance
Browse files Browse the repository at this point in the history
Fixes #34. Based on how Zilliqa/scilla#1007
goes, we may want to remove this special handling and
communicate `accept` directly to the blockchain.
  • Loading branch information
vaivaswatha committed Jun 24, 2021
1 parent 62d583a commit c30106c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libScillaRTL/ScillaBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace bmp = boost::multiprecision;

namespace ScillaRTL {

SafeUint128 TransitionState::getCurBal() const { return Balance; }

void TransitionState::processMessage(std::string OutType, Json::Value &M) {
if (OutJ.empty()) {
OutJ[OutType] = Json::arrayValue;
Expand Down Expand Up @@ -431,6 +433,18 @@ void *_fetch_field(ScillaExecImpl *SJ, const char *Name,
const ScillaTypes::Typ *T, int32_t NumIdx,
const uint8_t *Indices, int32_t FetchVal) {

if (std::string(Name) == "_balance") {
// TODO: This is inefficient, making two copies. It also allocates
// memory on every read of `_balance`. For better ideas, see
// https://github.com/Zilliqa/scilla-compiler/issues/73. On the other hand,
// because of https://github.com/Zilliqa/scilla/issues/1007,
// we may want to get rid of this special handling altogether.
size_t S = sizeof(ScillaTypes::Uint128);
auto BalMem = SJ->OM.allocBytes(S);
auto BalRaw = static_cast<ScillaTypes::Uint128>(SJ->TS->getCurBal());
std::memcpy(BalMem, BalRaw.buf, S);
return BalMem;
}
return fetchFieldHelper(SJ, std::string(), Name, T, NumIdx, Indices,
FetchVal);
}
Expand Down
1 change: 1 addition & 0 deletions libScillaRTL/ScillaBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TransitionState {
void processSend(Json::Value &M);
void processEvent(Json::Value &M);
void processAccept();
SafeUint128 getCurBal() const;
const uint64_t CurBlock;

// Returns the output of the transition execution. Destroys *this*.
Expand Down

0 comments on commit c30106c

Please sign in to comment.