Enable sendrawtransaction to send IS (#1271)

* Enable sendrawtransaction to send IS

* InstantSend as optional for sendrawtransaction
This commit is contained in:
TheLazieR Yip 2017-01-20 06:00:47 +07:00 committed by UdjinM6
parent a7d172fafd
commit 2a43d23f95

View File

@ -24,6 +24,7 @@
#include "txmempool.h" #include "txmempool.h"
#include "uint256.h" #include "uint256.h"
#include "utilstrencodings.h" #include "utilstrencodings.h"
#include "instantx.h"
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
#include "wallet/wallet.h" #include "wallet/wallet.h"
#endif #endif
@ -810,14 +811,15 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
UniValue sendrawtransaction(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( throw runtime_error(
"sendrawtransaction \"hexstring\" ( allowhighfees )\n" "sendrawtransaction \"hexstring\" ( allowhighfees instantsend )\n"
"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n" "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
"\nAlso see createrawtransaction and signrawtransaction calls.\n" "\nAlso see createrawtransaction and signrawtransaction calls.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"hexstring\" (string, required) The hex string of the raw transaction)\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" "\nResult:\n"
"\"hex\" (string) The transaction hash in hex\n" "\"hex\" (string) The transaction hash in hex\n"
"\nExamples:\n" "\nExamples:\n"
@ -832,7 +834,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
); );
LOCK(cs_main); 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 // parse hex string from parameter
CTransaction tx; CTransaction tx;
@ -844,6 +846,10 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
if (params.size() > 1) if (params.size() > 1)
fOverrideFees = params[1].get_bool(); fOverrideFees = params[1].get_bool();
bool fInstantSend = false;
if (params.size() > 2)
fInstantSend = params[2].get_bool();
CCoinsViewCache &view = *pcoinsTip; CCoinsViewCache &view = *pcoinsTip;
const CCoins* existingCoins = view.AccessCoins(hashTx); const CCoins* existingCoins = view.AccessCoins(hashTx);
bool fHaveMempool = mempool.exists(hashTx); bool fHaveMempool = mempool.exists(hashTx);
@ -865,6 +871,13 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
} else if (fHaveChain) { } else if (fHaveChain) {
throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); 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); RelayTransaction(tx);
return hashTx.GetHex(); return hashTx.GetHex();