From 2a43d23f959c63c67018d6791b70e94b832cdeef Mon Sep 17 00:00:00 2001 From: TheLazieR Yip Date: Fri, 20 Jan 2017 06:00:47 +0700 Subject: [PATCH] Enable sendrawtransaction to send IS (#1271) * Enable sendrawtransaction to send IS * InstantSend as optional for sendrawtransaction --- src/rpcrawtransaction.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index f9573800e..fdca27903 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -24,6 +24,7 @@ #include "txmempool.h" #include "uint256.h" #include "utilstrencodings.h" +#include "instantx.h" #ifdef ENABLE_WALLET #include "wallet/wallet.h" #endif @@ -810,14 +811,15 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) UniValue sendrawtransaction(const UniValue& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 2) + if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( - "sendrawtransaction \"hexstring\" ( allowhighfees )\n" + "sendrawtransaction \"hexstring\" ( allowhighfees instantsend )\n" "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n" "\nAlso see createrawtransaction and signrawtransaction calls.\n" "\nArguments:\n" "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n" - "2. allowhighfees (boolean, optional, default=false) Allow high fees\n" + "2. allowhighfees (boolean, optional, default=false) Allow high fees\n" + "3. instantsend (boolean, optional, default=false) Use InstantSend to send this transaction\n" "\nResult:\n" "\"hex\" (string) The transaction hash in hex\n" "\nExamples:\n" @@ -832,7 +834,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) ); LOCK(cs_main); - RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)); + RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)(UniValue::VBOOL)); // parse hex string from parameter CTransaction tx; @@ -844,6 +846,10 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) if (params.size() > 1) fOverrideFees = params[1].get_bool(); + bool fInstantSend = false; + if (params.size() > 2) + fInstantSend = params[2].get_bool(); + CCoinsViewCache &view = *pcoinsTip; const CCoins* existingCoins = view.AccessCoins(hashTx); bool fHaveMempool = mempool.exists(hashTx); @@ -865,6 +871,13 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) } else if (fHaveChain) { throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); } + if (fInstantSend) { + if (!IsInstantSendTxValid(tx)) { + throw JSONRPCError(RPC_TRANSACTION_ERROR, "Not a valid InstantSend transaction"); + } + mapLockRequestAccepted.insert(make_pair(hashTx, tx)); + CreateTxLockCandidate(tx); + } RelayTransaction(tx); return hashTx.GetHex();