From 26eb8f00fd7f43bcacb9c1130e1c44667962c5e4 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Mon, 6 Nov 2023 14:28:54 +0800 Subject: [PATCH] wip --- src/dfi/rpc_accounts.cpp | 49 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index e366613a12a..92acd5dd337 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -2198,11 +2198,54 @@ UniValue transferdomain(const JSONRPCRequest &request) { EnsureWalletIsUnlocked(pwallet); - RPCTypeCheck(request.params, {UniValue::VARR}, false); - UniValue srcDstArray(UniValue::VARR); - srcDstArray = request.params[0].get_array(); + if (!request.params[0].isArray()) { + auto defineDomain = [](CTxDestination &dest) { + if (dest.index() == WitV0KeyHashType || dest.index() == PKHashType) { + return VMDomain::DVM; + } else if (dest.index() == WitV16KeyEthHashType) { + return VMDomain::EVM; + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unsupport domain provided"); + } + }; + + if (request.params[0].isNull()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "\"src\" is required"); + } + std::string src = request.params[0].get_str(); + CTxDestination srcDest = DecodeDestination(src); + + if (request.params[1].isNull()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "\"dst\" is required"); + } + std::string dst = request.params[1].get_str(); + CTxDestination dstDest = DecodeDestination(dst); + + if (request.params[2].isNull()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "\"amount\" is required"); + } + std::string amount = request.params[2].get_str(); + + VMDomain srcDomainType = defineDomain(srcDest); + VMDomain dstDomainType = defineDomain(dstDest); + UniValue elem(UniValue::VOBJ); + elem.pushKV("src", src); + elem.pushKV("amount", amount); + elem.pushKV("domain", static_cast(srcDomainType)); + elem.pushKV("dst", dst); + elem.pushKV("amount", amount); + elem.pushKV("domain", static_cast(dstDomainType)); + + if (!request.params[3].isNull()) { + elem.pushKV("nonce", request.params[3].get_int()); + } + srcDstArray.push_back(elem); + } else { + RPCTypeCheck(request.params, {UniValue::VARR}, false); + srcDstArray = request.params[0].get_array(); + } CrossBoundaryResult result; CTransferDomainMessage msg;