diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2017-02-02 22:15:55 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2017-06-05 23:09:01 +0000 |
commit | 578ec80d4fcef6be48acf45185d1248bb62bfdbf (patch) | |
tree | 560b516c5943e28ed75852e8717b474b3b166a99 /src | |
parent | 9fec4da0bec93a49798b5f5e92cf76e900759ee4 (diff) |
RPC: rawtransaction: Add RBF support for createrawtransaction
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/client.cpp | 1 | ||||
-rw-r--r-- | src/rpc/rawtransaction.cpp | 23 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index a3a692c14d..ec27e55f02 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -86,6 +86,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "createrawtransaction", 0, "inputs" }, { "createrawtransaction", 1, "outputs" }, { "createrawtransaction", 2, "locktime" }, + { "createrawtransaction", 3, "optintorbf" }, { "signrawtransaction", 1, "prevtxs" }, { "signrawtransaction", 2, "privkeys" }, { "sendrawtransaction", 1, "allowhighfees" }, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index e27c2a77c7..07a7ef34e2 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -289,9 +289,9 @@ UniValue verifytxoutproof(const JSONRPCRequest& request) UniValue createrawtransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) + if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) throw std::runtime_error( - "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n" + "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime ) ( optintorbf )\n" "\nCreate a transaction spending the given inputs and creating new outputs.\n" "Outputs can be addresses or data.\n" "Returns hex-encoded raw transaction.\n" @@ -315,6 +315,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request) " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" + "4. optintorbf (boolean, optional, default=false) Allow this transaction to be replaced by a transaction with higher fees\n" "\nResult:\n" "\"transaction\" (string) hex string of the transaction\n" @@ -341,6 +342,8 @@ UniValue createrawtransaction(const JSONRPCRequest& request) rawTx.nLockTime = nLockTime; } + bool rbfOptIn = request.params.size() > 3 ? request.params[3].isTrue() : false; + for (unsigned int idx = 0; idx < inputs.size(); idx++) { const UniValue& input = inputs[idx]; const UniValue& o = input.get_obj(); @@ -354,16 +357,26 @@ UniValue createrawtransaction(const JSONRPCRequest& request) if (nOutput < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); - uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max()); + uint32_t nSequence; + if (rbfOptIn) { + nSequence = std::numeric_limits<uint32_t>::max() - 2; + } else if (rawTx.nLockTime) { + nSequence = std::numeric_limits<uint32_t>::max() - 1; + } else { + nSequence = std::numeric_limits<uint32_t>::max(); + } // set the sequence number if passed in the parameters object const UniValue& sequenceObj = find_value(o, "sequence"); if (sequenceObj.isNum()) { int64_t seqNr64 = sequenceObj.get_int64(); - if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max()) + if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range"); - else + } else if (seqNr64 <= std::numeric_limits<uint32_t>::max() - 2 && request.params.size() > 3 && request.params[3].isFalse()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number contradicts optintorbf option"); + } else { nSequence = (uint32_t)seqNr64; + } } CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence); |