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

Function ExGetBlockTimestamp

src/vm/luavm/lmylib.cpp:2194–2227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2192}
2193
2194int32_t ExGetBlockTimestamp(lua_State *L) {
2195 CLuaVMRunEnv* pLuaVMRunEnv = GetVmRunEnvByContext(L);
2196 int32_t height = 0;
2197 if (!GetDataInt(L,height))
2198 return RetFalse("ExGetBlockTimestamp para err1");
2199
2200 // only support to get current block time
2201 if (height != 0) {
2202 LogPrint(BCLog::LUAVM, "[ERROR]ExGetBlockTimestamp(), the input height=%d must be 0\n", height);
2203 return 0;
2204 }
2205
2206 LUA_BurnFuncCall(L, FUEL_CALL_GetBlockTimestamp, BURN_VER_R2);
2207
2208 CLuaVMContext &vmContext = pLuaVMRunEnv->GetContext();
2209 auto featureForkVersion = GetFeatureForkVersion(vmContext.height);
2210
2211 lua_Integer blockTime = 0;
2212 if (featureForkVersion >= MAJOR_VER_R2) {
2213 blockTime = vmContext.block_time;
2214 }else { //MAJOR_VER_R1
2215 // compact with old data
2216 blockTime = vmContext.prev_block_time;
2217 }
2218
2219 if (!lua_checkstack(L, sizeof(lua_Integer))) {
2220 LogPrint(BCLog::LUAVM, "[ERROR]ExGetBlockTimestamp(), lua stack overflow! input_height=%d, curBlockHeight=%d\n",
2221 height, vmContext.height);
2222 return 0;
2223 }
2224
2225 lua_pushinteger(L, blockTime);
2226 return 1;
2227}
2228
2229
2230int32_t ExLimitedRequire(lua_State *L) {

Callers

nothing calls this directly

Calls 6

GetVmRunEnvByContextFunction · 0.85
GetDataIntFunction · 0.85
RetFalseFunction · 0.85
GetFeatureForkVersionFunction · 0.85
lua_checkstackFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected