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

Function ExTransferSomeAsset

src/vm/luavm/lmylib.cpp:2112–2192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2110}
2111
2112int32_t ExTransferSomeAsset(lua_State *L) {
2113 vector<std::shared_ptr < vector<uint8_t> > > retdata;
2114
2115 CAssetOperate tempAsset;
2116 uint32_t size = ::GetSerializeSize(tempAsset, SER_NETWORK, PROTOCOL_VERSION);
2117
2118 if (!GetDataTableAssetOperate(L, -1, retdata) || retdata.size() != 2 || (retdata.at(1).get()->size() % size) != 0 ||
2119 retdata.at(0).get()->size() != 34)
2120 return RetFalse(string(__FUNCTION__) + "para err !");
2121
2122 CLuaVMRunEnv* pVmRunEnv = GetVmRunEnv(L);
2123 if (nullptr == pVmRunEnv)
2124 return RetFalse("pVmRunEnv is nullptr");
2125
2126 CDataStream ss(*retdata.at(1), SER_DISK, CLIENT_VERSION);
2127 CAssetOperate assetOp;
2128 ss >> assetOp;
2129
2130 vector<uint8_t> sendKey;
2131 vector<uint8_t> recvKey;
2132
2133 CRegID sendRegID = pVmRunEnv->GetTxAccountRegId();
2134 CKeyID SendKeyID = sendRegID.GetKeyId(*pVmRunEnv->GetAccountCache());
2135 string addr = SendKeyID.ToAddress();
2136 sendKey.assign(addr.c_str(), addr.c_str() + addr.length());
2137
2138 recvKey.assign(retdata.at(0).get()->begin(), retdata.at(0).get()->end());
2139
2140 std::string recvaddr( recvKey.begin(), recvKey.end() );
2141 if (addr == recvaddr) {
2142 LogPrint(BCLog::LUAVM, "%s\n", "send addr and recv addr is same !");
2143 return RetFalse(string(__FUNCTION__)+"send addr and recv addr is same !");
2144 }
2145
2146 CKeyID RecvKeyID;
2147 bool bValid = GetKeyId(pVmRunEnv, recvKey, RecvKeyID);
2148 if (!bValid) {
2149 LogPrint(BCLog::LUAVM, "%s\n", "recv addr is not valid !");
2150 return RetFalse(string(__FUNCTION__)+"recv addr is not valid !");
2151 }
2152
2153 uint64_t uTransferMoney = assetOp.GetUint64Value();
2154 if (0 == uTransferMoney)
2155 return RetFalse(string(__FUNCTION__) + " Transfer Money is not valid !");
2156
2157 int32_t height = assetOp.GetHeight();
2158 if (height < 0)
2159 return RetFalse(string(__FUNCTION__) + " outHeight is not valid !");
2160
2161 int32_t i = 0;
2162 CAppFundOperate op;
2163 vector<uint8_t> vtag = assetOp.GetFundTagV();
2164 op.fundTagLen = vtag.size();
2165
2166 for (i = 0; i < op.fundTagLen; i++) {
2167 op.vFundTag[i] = vtag[i];
2168 }
2169

Callers

nothing calls this directly

Calls 15

GetSerializeSizeFunction · 0.85
GetDataTableAssetOperateFunction · 0.85
RetFalseFunction · 0.85
GetVmRunEnvFunction · 0.85
GetKeyIdFunction · 0.85
RetRstBooleanToLuaFunction · 0.85
atMethod · 0.80
GetAccountCacheMethod · 0.80
ToAddressMethod · 0.80
InsertOutAPPOperteMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected