| 2067 | } |
| 2068 | |
| 2069 | LUA_API int lua_execute_contract_api(lua_State *L, const char *contract_name, |
| 2070 | const char *api_name, const char *arg1, std::string *result_json_string) |
| 2071 | { |
| 2072 | auto contract_address = thinkyoung::lua::lib::malloc_managed_string(L, CONTRACT_ID_MAX_LENGTH + 1); |
| 2073 | memset(contract_address, 0x0, CONTRACT_ID_MAX_LENGTH + 1); |
| 2074 | size_t address_size = 0; |
| 2075 | global_glua_chain_api->get_contract_address_by_name(L, contract_name, contract_address, &address_size); |
| 2076 | if (address_size > 0) |
| 2077 | { |
| 2078 | GluaStateValue value; |
| 2079 | value.string_value = contract_address; |
| 2080 | thinkyoung::lua::lib::set_lua_state_value(L, STARTING_CONTRACT_ADDRESS, value, LUA_STATE_VALUE_STRING); |
| 2081 | } |
| 2082 | |
| 2083 | lua_createtable(L, 0, 0); |
| 2084 | lua_setglobal(L, "last_return"); |
| 2085 | |
| 2086 | /* |
| 2087 | lua_pushcfunction(L, lua_real_execute_contract_api); |
| 2088 | lua_pushstring(L, contract_name); |
| 2089 | lua_pushstring(L, api_name); |
| 2090 | if (nullptr != arg1) |
| 2091 | lua_pushstring(L, arg1); |
| 2092 | |
| 2093 | // FIXME: 这里看能不能不需要这样调用而是直接调用 |
| 2094 | int status = lua_pcall(L, nullptr != arg1 ? 3 : 2, 1, 0); |
| 2095 | */ |
| 2096 | int status = lua_real_execute_contract_api(L, contract_name, api_name, arg1); |
| 2097 | |
| 2098 | if (lua_gettop(L) < 1) |
| 2099 | return LUA_ERRRUN; |
| 2100 | int result = lua_toboolean(L, -1); |
| 2101 | if (result>0 && result_json_string) |
| 2102 | { |
| 2103 | // FIXME |
| 2104 | lua_getglobal(L, "last_return"); |
| 2105 | auto last_return_value_json = luaL_tojsonstring(L, -1, nullptr); |
| 2106 | auto last_return_value_json_string = std::string(last_return_value_json); |
| 2107 | lua_pop(L, 1); |
| 2108 | *result_json_string = last_return_value_json_string; |
| 2109 | } |
| 2110 | if(result) |
| 2111 | result = luaL_commit_storage_changes(L); |
| 2112 | return result > 0 ? LUA_OK : LUA_ERRRUN; |
| 2113 | } |
| 2114 | |
| 2115 | LUA_API int lua_execute_contract_api_by_address(lua_State *L, const char *address, |
| 2116 | const char *api_name, const char *arg1, std::string *result_json_string) |
no test coverage detected