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

Function lua_common_open_contract

src/Chain/libraries/glua/lauxlib.cpp:2130–2164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2128}
2129
2130std::shared_ptr<GluaModuleByteStream> lua_common_open_contract(lua_State *L, const char *name, char *error)
2131{
2132 std::string namestr(name);
2133 if (glua::util::starts_with(namestr, ADDRESS_CONTRACT_PREFIX))
2134 {
2135 std::string pointer_str = namestr.substr(strlen(ADDRESS_CONTRACT_PREFIX), namestr.length() - strlen(ADDRESS_CONTRACT_PREFIX));
2136 std::string address;
2137 std::stringstream(pointer_str) >> address;
2138 auto stream = global_glua_chain_api->open_contract_by_address(L, address.c_str());
2139 if (stream && stream->contract_level != CONTRACT_LEVEL_FOREVER && (stream->contract_name.length() < 1 || stream->contract_state == CONTRACT_STATE_DELETED))
2140 {
2141 auto start_contract_address = thinkyoung::lua::lib::get_starting_contract_address(L);
2142 if (start_contract_address.length()>0 && stream->contract_name.length() < 1 && std::string(address) == start_contract_address)
2143 {
2144 return stream;
2145 }
2146 lerror_set(L, error, "only active and upgraded contract %s can be imported by others", namestr.c_str());
2147 return nullptr;
2148 }
2149 else
2150 return stream;
2151 }
2152 else if (glua::util::starts_with(namestr, STREAM_CONTRACT_PREFIX))
2153 {
2154 std::string p_str = namestr.substr(strlen(STREAM_CONTRACT_PREFIX), namestr.length() - strlen(STREAM_CONTRACT_PREFIX));
2155 intptr_t p;
2156 std::stringstream(p_str) >> p;
2157 auto stream = std::make_shared<GluaModuleByteStream>(*(GluaModuleByteStream*)p);
2158 return stream;
2159 }
2160 else
2161 {
2162 return global_glua_chain_api->open_contract(L, name);
2163 }
2164}
2165
2166LUALIB_API bool luaL_is_bytecode_file(lua_State *L, const char *filename)
2167{

Callers 1

searcher_thinkyoungFunction · 0.85

Calls 9

stringstreamClass · 0.85
starts_withFunction · 0.70
stringClass · 0.50
substrMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
open_contractMethod · 0.45

Tested by

no test coverage detected