MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / wait_for_future_random

Method wait_for_future_random

src/Chain/libraries/glua/thinkyoung_lua_api.cpp:711–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

709 }
710
711 uint32_t GluaChainApi::wait_for_future_random(lua_State *L, int next)
712 {
713 thinkyoung::lua::lib::increment_lvm_instructions_executed_count(L, CHAIN_GLUA_API_EACH_INSTRUCTIONS_COUNT - 1);
714 try{
715 thinkyoung::blockchain::TransactionEvaluationState* eval_state_ptr =
716 (thinkyoung::blockchain::TransactionEvaluationState*)
717 (thinkyoung::lua::lib::get_lua_state_value(L, "evaluate_state").pointer_value);
718
719 if (!eval_state_ptr || !eval_state_ptr->_current_state)
720 FC_CAPTURE_AND_THROW(lua_executor_internal_error, (""));
721
722 uint32_t target = eval_state_ptr->_current_state->get_head_block_num() + next;
723 if (target < next)
724 return 0;
725 return target;
726 }
727 catch (fc::exception e)
728 {
729 L->force_stopping = true;
730 L->exit_code = LUA_API_INTERNAL_ERROR;
731 return 0;
732 }
733 }
734 //获取指定块与之前50块的pre_secret hash出的结果,该值在指定块被产出的上一轮出块时就已经确定,而无人可知,无法操控
735 //如果希望使用该值作为随机值,以随机值作为其他数据的选取依据时,需要在目标块被产出前确定要被筛选的数据
736 //如投注彩票,只允许在目标块被产出前投注

Callers 1

wait_for_future_randomFunction · 0.45

Calls 3

get_lua_state_valueFunction · 0.85
get_head_block_numMethod · 0.80

Tested by

no test coverage detected