MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / GetLuaContractScript

Method GetLuaContractScript

src/rpc/core/rpccommons.cpp:590–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588}
589
590string RPC_PARAM::GetLuaContractScript(const Value &jsonValue) {
591 string filePath = GetAbsolutePath(jsonValue.get_str()).string();
592 if (filePath.empty())
593 throw JSONRPCError(RPC_SCRIPT_FILEPATH_NOT_EXIST, "Lua Script file not exist");
594
595 if (filePath.compare(0, LUA_CONTRACT_LOCATION_PREFIX.size(), LUA_CONTRACT_LOCATION_PREFIX.c_str()) != 0)
596 throw JSONRPCError(RPC_SCRIPT_FILEPATH_INVALID, "Lua Script file not inside /tmp/lua dir or its subdir");
597
598 std::tuple<bool, string> result = CLuaVM::CheckScriptSyntax(filePath.c_str(), chainActive.Height());
599 if (!std::get<0>(result))
600 throw JSONRPCError(RPC_INVALID_PARAMETER, std::get<1>(result));
601
602 bool success = false;
603 string contractScript;
604 do {
605 streampos begin, end;
606 ifstream fin(filePath.c_str(), ios::binary | ios::in);
607 if (!fin)
608 break;
609
610 begin = fin.tellg();
611 fin.seekg(0, ios::end);
612 end = fin.tellg();
613
614 streampos length = end - begin;
615 if (length == 0 || length > MAX_CONTRACT_CODE_SIZE) {
616 fin.close();
617 break;
618 }
619
620 fin.seekg(0, ios::beg);
621 char *buffer = new char[length];
622 fin.read(buffer, length);
623
624 contractScript.assign(buffer, length);
625 free(buffer);
626 fin.close();
627
628 success = true;
629 } while (false);
630
631 if (!success)
632 throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to acquire contract script");
633
634 return contractScript;
635}
636
637uint64_t RPC_PARAM::GetPrice(const Value &jsonValue) {
638 // TODO: check price range??

Callers

nothing calls this directly

Calls 8

GetAbsolutePathFunction · 0.85
JSONRPCErrorFunction · 0.85
compareMethod · 0.80
HeightMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
closeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected