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

Function GetDataTableWriteDataDB

src/vm/luavm/lmylib.cpp:1289–1333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1287}
1288
1289static bool GetDataTableWriteDataDB(lua_State *L, vector<std::shared_ptr<std::vector<uint8_t>>> &ret) {
1290 //取写数据库的key value
1291 if (!lua_istable(L, -1)) {
1292 LogPrint(BCLog::LUAVM, "GetDataTableWriteDataDB is not table\n");
1293 return false;
1294 }
1295 uint16_t len = 0;
1296 vector<uint8_t> vBuf;
1297 //取key
1298 string key = "";
1299 if (!(getStringInTable(L, (char *)"key", key))) {
1300 LogPrint(BCLog::LUAVM, "key get fail\n");
1301 return false;
1302 } else {
1303 // LogPrint(BCLog::LUAVM, "key:%s\n", key);
1304 }
1305 vBuf.clear();
1306 for (size_t i = 0; i < key.size(); i++) {
1307 vBuf.insert(vBuf.end(), key.at(i));
1308 }
1309 ret.insert(ret.end(), std::make_shared<vector<uint8_t>>(vBuf.begin(), vBuf.end()));
1310
1311 //取value的长度
1312 double doubleValue = 0;
1313 if (!(getNumberInTable(L, (char *)"length", doubleValue))) {
1314 LogPrint(BCLog::LUAVM, "length get fail\n");
1315 return false;
1316 } else {
1317 len = (uint16_t)doubleValue;
1318 // LogPrint(BCLog::LUAVM, "len =%d\n", len);
1319 }
1320 if ((len > 0) && (len <= LUA_C_BUFFER_SIZE)) {
1321 if (!getArrayInTable(L, (char *)"value", len, vBuf)) {
1322 LogPrint(BCLog::LUAVM, "value is not table\n");
1323 return false;
1324 } else {
1325 // LogPrint(BCLog::LUAVM, "value:%s\n", HexStr(vBuf).c_str());
1326 ret.insert(ret.end(), std::make_shared<vector<uint8_t>>(vBuf.begin(), vBuf.end()));
1327 }
1328 return true;
1329 } else {
1330 LogPrint(BCLog::LUAVM, "len overflow\n");
1331 return false;
1332 }
1333}
1334
1335/**
1336 *bool WriteDataDB(const void* const key,const uint8_t keylen,const void * const value,const uint16_t valuelen,const uint32_t time)

Callers 2

ExWriteDataDBFuncFunction · 0.85
ExModifyDataDBFuncFunction · 0.85

Calls 9

getStringInTableFunction · 0.85
getNumberInTableFunction · 0.85
getArrayInTableFunction · 0.85
atMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected