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

Function luavm_executecontract

src/rpc/rpcvm.cpp:257–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257Value luavm_executecontract(const Array& params, bool fHelp) {
258 if (fHelp || params.size() < 2 || params.size() > 4) {
259 throw runtime_error(
260 "luavm_executecontract \"addr\" \"app_id\" [\"arguments\"] [symbol:amount:unit]\n"
261 "\nexecute the existed contract in vm simulator, and then returns the execution status.\n"
262 "\nArguments:\n"
263 "1.\"addr\": (string required) contract owner address from this wallet\n"
264 "2.\"app_id\": (string required) regid of app account\n"
265 "3.\"arguments\": (string, optional) contract method invoke content (Hex encode required)\n"
266 "4.\"symbol:amount:unit\": (string:numeric:string, optional) amount of coin to send to app account\n"
267 "\nResult vm execute detail\n"
268 "\nResult:\n"
269 "\nExamples:\n"
270 + HelpExampleCli("luavm_executecontract","\"100-3\" \"20-3\"")
271 + "\nAs json rpc call\n"
272 + HelpExampleRpc("luavm_executecontract", "\"100-3\", \"20-3"));
273 }
274
275 const CUserID &txUid = RPC_PARAM::ParseUserIdByAddr(params[0]);
276 const CUserID &appUid = RPC_PARAM::GetUserId(params[1]);
277 vector<uint8_t> arguments;
278 if (params.size() > 2) {
279 arguments = ParseHex(params[2].get_str());
280 }
281 const ComboMoney cbAmount = RPC_PARAM::GetComboMoney(params, 3, ComboMoney(SYMB::WICC, 0, COIN_UNIT::SAWI));
282
283 auto spCw = std::make_shared<CCacheWrapper>(pCdMan);
284 CBlockIndex *pTip = chainActive.Tip();
285 const auto &bpRegid = GetBlockBpRegid(*chainActive.TipBlock());
286 HeightType height = pTip->height + 1;
287 uint32_t txIndex = 1;
288 uint32_t fuelRate = GetElementForBurn(pTip);
289 uint32_t blockTime = pTip->GetBlockTime();
290 uint32_t prevBlockTime = pTip->pprev != nullptr ? pTip->pprev->GetBlockTime() : pTip->GetBlockTime();
291 vector<CReceipt> receipts;
292
293 const TokenSymbol &feeSymbol = SYMB::WICC;
294 uint64_t minFee = 0;
295 if (!GetTxMinFee(*spCw, LCONTRACT_INVOKE_TX, height, feeSymbol, minFee))
296 throw JSONRPCError(RPC_INTERNAL_ERROR, "Get tx min fee failed");
297
298 uint64_t fees = minFee + 100000 * COIN; // give the enough fee to execute contract
299
300 CAccount txAccount;
301 if (!spCw->accountCache.GetAccount(txUid, txAccount)) {
302 if (txUid.is<CKeyID>()) {
303 txAccount.keyid = txUid.get<CKeyID>();
304 } else if (txUid.is<CPubKey>()) {
305 txAccount.owner_pubkey = txUid.get<CPubKey>();
306 txAccount.keyid = txAccount.owner_pubkey.GetKeyId();
307 } else {
308 throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("txUid=%s does not have account", txUid.ToString()));
309 }
310 }
311
312 if (txAccount.regid.IsEmpty()) {
313 txAccount.regid = CRegID(height, txIndex);
314 }

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHexFunction · 0.85
GetComboMoneyFunction · 0.85
ComboMoneyClass · 0.85
GetElementForBurnFunction · 0.85
GetTxMinFeeFunction · 0.85
JSONRPCErrorFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
PairClass · 0.85
TipMethod · 0.80
TipBlockMethod · 0.80

Tested by

no test coverage detected