*bool QueryAccountBalance(const uint8_t* const account,Int64* const pBalance) * 这个函数式从中间层传了一个参数过来: * 1.第一个是 账户id,六个字节 */
| 1139 | * 1.第一个是 账户id,六个字节 |
| 1140 | */ |
| 1141 | int32_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) |
nothing calls this directly
no test coverage detected