MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ExQueryAccountBalanceFunc

Function ExQueryAccountBalanceFunc

src/vm/luavm/lmylib.cpp:1141–1174  ·  view source on GitHub ↗

*bool QueryAccountBalance(const uint8_t* const account,Int64* const pBalance) * 这个函数式从中间层传了一个参数过来: * 1.第一个是 账户id,六个字节 */

Source from the content-addressed store, hash-verified

1139 * 1.第一个是 账户id,六个字节
1140 */
1141int32_t ExQueryAccountBalanceFunc(lua_State *L) {
1142 vector<std::shared_ptr<vector<uint8_t>>> retdata;
1143 if (!GetArray(L, retdata) || retdata.size() != 1 ||
1144 !(retdata.at(0).get()->size() == 6 || retdata.at(0).get()->size() == 34)) {
1145 return RetFalse("ExQueryAccountBalanceFunc para err1");
1146 }
1147
1148 CLuaVMRunEnv *pVmRunEnv = GetVmRunEnv(L);
1149 if (nullptr == pVmRunEnv) {
1150 return RetFalse("pVmRunEnv is nullptr");
1151 }
1152
1153 LUA_BurnFuncCall(L, FUEL_ACCOUNT_GET_VALUE, BURN_VER_R2);
1154 CKeyID addrKeyId;
1155 if (!GetKeyId(pVmRunEnv, *retdata.at(0).get(), addrKeyId)) {
1156 return RetFalse("ExQueryAccountBalanceFunc para err2");
1157 }
1158
1159 CUserID uid(addrKeyId);
1160 int32_t len = 0;
1161 shared_ptr<CAccount> spAccount = pVmRunEnv->GetAccount(uid);
1162 if (!spAccount) {
1163 LogPrint(BCLog::LUAVM, "[ERROR] The account not exist! address=%s\n", uid.ToDebugString());
1164 return 0;
1165 }
1166
1167 uint64_t nbalance = spAccount->GetToken(SYMB::WICC).free_amount;
1168 CDataStream tep(SER_DISK, CLIENT_VERSION);
1169 tep << nbalance;
1170 vector<uint8_t> TMP(tep.begin(), tep.end());
1171 len = RetRstToLua(L, TMP);
1172
1173 return len;
1174}
1175
1176/**
1177 *uint32_t GetTxConfirmHeight(const void * const txid)

Callers

nothing calls this directly

Calls 13

GetArrayFunction · 0.85
RetFalseFunction · 0.85
GetVmRunEnvFunction · 0.85
GetKeyIdFunction · 0.85
RetRstToLuaFunction · 0.85
atMethod · 0.80
ToDebugStringMethod · 0.80
GetTokenMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45
GetAccountMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected