| 2192 | } |
| 2193 | |
| 2194 | int32_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 | |
| 2230 | int32_t ExLimitedRequire(lua_State *L) { |
nothing calls this directly
no test coverage detected