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

Function check_contract_proto

src/Chain/libraries/glua/thinkyoung_lua_lib.cpp:1854–2072  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1852 }
1853
1854 bool check_contract_proto(lua_State *L, Proto *proto, char *error, std::list<Proto*> *parents)
1855 {
1856 // for all sub function in proto, check whether the contract bytecode meet our provision
1857 int i, proto_size = proto->sizep;
1858 // int const_size = proto->sizek;
1859 int localvar_size = proto->sizelocvars;
1860 int upvalue_size = proto->sizeupvalues;
1861
1862 if (localvar_size > LUA_FUNCTION_MAX_LOCALVARS_COUNT)
1863 {
1864 lcompile_error_set(L, error, "too many local vars in function, limit is %d", LUA_FUNCTION_MAX_LOCALVARS_COUNT);
1865 return false;
1866 }
1867
1868 std::list<std::string> localvars;
1869 for (i = 0; i < localvar_size; i++)
1870 {
1871 // int startpc = proto->locvars[i].startpc;
1872 // int endpc = proto->locvars[i].endpc;
1873 std::string localvarname(getstr(proto->locvars[i].varname));
1874 }
1875
1876 std::list<std::tuple<std::string, int, int>> upvalues;
1877 for (i = 0; i < upvalue_size; i++)
1878 {
1879 std::string upvalue_name(UPVALNAME_OF_PROTO(proto, i));
1880 int instack = proto->upvalues[i].instack;
1881 int idx = proto->upvalues[i].idx;
1882 upvalues.push_back(std::make_tuple(upvalue_name, instack, idx));
1883 }
1884
1885
1886 const Instruction* code = proto->code;
1887 int pc;
1888 int code_size = proto->sizecode;
1889
1890 bool is_importing_contract = false;
1891 bool is_importing_contract_address = false;
1892
1893 for (pc = 0; pc < code_size; pc++)
1894 {
1895 Instruction i = code[pc];
1896 OpCode o = GET_OPCODE(i);
1897 int a = GETARG_A(i);
1898 int b = GETARG_B(i);
1899 int c = GETARG_C(i);
1900 int ax = GETARG_Ax(i);
1901 int bx = GETARG_Bx(i);
1902 int sbx = GETARG_sBx(i);
1903 int line = getfuncline(proto, pc);
1904
1905 if(is_importing_contract)
1906 {
1907 is_importing_contract = false;
1908 // 检查接下来是否是LOADK常量字符串且这个合约名存在
1909 if(getOpMode(o) == OP_LOADK)
1910 {
1911 int idx = MYK(INDEXK(bx));

Callers 4

searcher_thinkyoungFunction · 0.85
GTESTFunction · 0.85

Calls 9

upval_defined_in_parentFunction · 0.85
make_tupleFunction · 0.50
push_backMethod · 0.45
check_contract_existMethod · 0.45
sizeMethod · 0.45
rbeginMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected