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

Function SubmitOrderTx

src/rpc/rpcdex.cpp:233–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231} // namespace RPC_PARAM
232
233Object SubmitOrderTx(const CKeyID &txKeyid, const DexOperatorDetail &operatorDetail,
234 shared_ptr<CDEXOrderBaseTx> &pOrderBaseTx) {
235
236 if (!pWalletMain->HasKey(txKeyid)) {
237 throw JSONRPCError(RPC_WALLET_ERROR, "tx user address not found in wallet");
238 }
239 const uint256 txHash = pOrderBaseTx->GetHash();
240 if (!pWalletMain->Sign(txKeyid, txHash, pOrderBaseTx->signature)) {
241 throw JSONRPCError(RPC_WALLET_ERROR, "Sign failed");
242 }
243
244 shared_ptr<CBaseTx> pBaseTx = static_pointer_cast<CBaseTx>(pOrderBaseTx);
245 if (pOrderBaseTx->has_operator_config) {
246 CAccount operatorAccount = RPC_PARAM::GetUserAccount(*pCdMan->pAccountCache, operatorDetail.fee_receiver_regid);
247 const CKeyID &operatorKeyid = operatorAccount.keyid;
248 if (!pWalletMain->HasKey(operatorKeyid)) {
249 CDataStream ds(SER_DISK, CLIENT_VERSION);
250 ds << pBaseTx;
251 throw JSONRPCError(RPC_WALLET_ERROR, strprintf("dex operator address not found in wallet! "
252 "tx_raw_with_sign=%s", HexStr(ds.begin(), ds.end())));
253 }
254 if (!pWalletMain->Sign(operatorKeyid, txHash, pOrderBaseTx->operator_signature)) {
255 throw JSONRPCError(RPC_WALLET_ERROR, "Sign failed");
256 }
257 }
258
259 CValidationState state;
260 if (!pWalletMain->CommitTx(pBaseTx.get(), state))
261 throw JSONRPCError(RPC_WALLET_ERROR,
262 strprintf("CommitTx failed: code=%d, reason=%s", state.GetRejectCode(),
263 state.GetRejectReason()));
264
265 Object obj;
266 obj.push_back( Pair("txid", pBaseTx->GetHash().GetHex()) );
267
268 return obj;
269}
270
271static void CheckDexId0BeforeV3(uint64_t dexId, int32_t height) {
272 if (dexId != 0)

Callers 4

submitdexbuylimitordertxFunction · 0.85

Calls 14

JSONRPCErrorFunction · 0.85
HexStrFunction · 0.85
PairClass · 0.85
CommitTxMethod · 0.80
GetRejectCodeMethod · 0.80
GetRejectReasonMethod · 0.80
push_backMethod · 0.80
HasKeyMethod · 0.45
GetHashMethod · 0.45
SignMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected