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

Function ExDeleteDataDBFunc

src/vm/luavm/lmylib.cpp:1381–1415  ·  view source on GitHub ↗

*bool DeleteDataDB(const void* const key,const uint8_t keylen) * 这个函数式从中间层传了一个参数过来: * 1.第一个是 key值 */

Source from the content-addressed store, hash-verified

1379 * 1.第一个是 key值
1380 */
1381int32_t ExDeleteDataDBFunc(lua_State *L) {
1382 vector<std::shared_ptr < vector<uint8_t> > > retdata;
1383
1384 if (!GetDataString(L, retdata) || retdata.size() != 1) {
1385 LogPrint(BCLog::LUAVM, "ExDeleteDataDBFunc key err1");
1386 return RetFalse(string(__FUNCTION__) + "para err !");
1387 }
1388 string key = string((*retdata.at(0)).begin(), (*retdata.at(0)).end());
1389
1390 CLuaVMRunEnv* pVmRunEnv = GetVmRunEnv(L);
1391 if (nullptr == pVmRunEnv) {
1392 return RetFalse("pVmRunEnv is nullptr");
1393 }
1394
1395 CRegID contractRegId = pVmRunEnv->GetContractRegID();
1396 CContractDBCache *scriptDB = pVmRunEnv->GetScriptDB();
1397
1398 bool flag = true;
1399 string oldValue;
1400 // TODO: get old data when set data ??
1401 scriptDB->GetContractData(contractRegId, key, oldValue);
1402
1403 if (!scriptDB->EraseContractData(contractRegId, key)) {
1404 LogPrint(BCLog::LUAVM, "ExDeleteDataDBFunc EraseContractData railed, key:%s!\n", HexStr(*retdata.at(0)));
1405 lua_BurnStoreUnchanged(L, key.size(), oldValue.size(), BURN_VER_R2);
1406 flag = false;
1407 } else {
1408 lua_BurnStoreSet(L, key.size(), oldValue.size(), 0, BURN_VER_R2);
1409 }
1410 #ifdef TRACE_LUAVM_CONTRACT_DATA
1411 LogPrint(BCLog::LUAVM, "DeleteData(), contract_regid=%s, key=%s, key_hex=%s, old_value=%s, old_value_hex=%s\n",
1412 contractRegId.ToString(), key, HexStr(key), oldValue, HexStr(oldValue));
1413 #endif//TRACE_LUAVM_CONTRACT_DATA
1414 return RetRstBooleanToLua(L, flag);
1415}
1416
1417/**
1418 *uint16_t ReadDataValueDB(const void* const key,const uint8_t keylen, void* const value,uint16_t const maxbuffer)

Callers

nothing calls this directly

Calls 15

GetDataStringFunction · 0.85
RetFalseFunction · 0.85
GetVmRunEnvFunction · 0.85
HexStrFunction · 0.85
lua_BurnStoreUnchangedFunction · 0.85
lua_BurnStoreSetFunction · 0.85
RetRstBooleanToLuaFunction · 0.85
atMethod · 0.80
GetScriptDBMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected