aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoin-tx.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-06-07 18:25:10 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-06-07 18:25:13 +0200
commit79004d4ae67164d980fdaab4de9d9d467cdb9b88 (patch)
tree7e02c296c5f64dd9ae69d8e07fd926848535b522 /src/bitcoin-tx.cpp
parent22e0b35676230961aeb848a4f5c6b007cb8a43c9 (diff)
parentae357d5ab940dea5e2640361ae17fd8722a93c9f (diff)
downloadbitcoin-79004d4ae67164d980fdaab4de9d9d467cdb9b88.tar.xz
Merge #7957: [RPC][Bitcoin-TX] Add support for sequence number
ae357d5 [Bitcoin-Tx] Add tests for sequence number support (Jonas Schnelli) e59336f [bitcoin-tx] allow to set nSequence number over the in= command (Jonas Schnelli) a946bb6 [RPC] createrawtransaction: add option to set the sequence number per input (Jonas Schnelli)
Diffstat (limited to 'src/bitcoin-tx.cpp')
-rw-r--r--src/bitcoin-tx.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 95d7a085a0..d5e2fc279b 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -71,7 +71,7 @@ static bool AppInitRawTx(int argc, char* argv[])
strUsage = HelpMessageGroup(_("Commands:"));
strUsage += HelpMessageOpt("delin=N", _("Delete input N from TX"));
strUsage += HelpMessageOpt("delout=N", _("Delete output N from TX"));
- strUsage += HelpMessageOpt("in=TXID:VOUT", _("Add input to TX"));
+ strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"));
strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
@@ -181,15 +181,15 @@ static void MutateTxLocktime(CMutableTransaction& tx, const string& cmdVal)
static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
{
+ std::vector<std::string> vStrInputParts;
+ boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
+
// separate TXID:VOUT in string
- size_t pos = strInput.find(':');
- if ((pos == string::npos) ||
- (pos == 0) ||
- (pos == (strInput.size() - 1)))
+ if (vStrInputParts.size()<2)
throw runtime_error("TX input missing separator");
// extract and validate TXID
- string strTxid = strInput.substr(0, pos);
+ string strTxid = vStrInputParts[0];
if ((strTxid.size() != 64) || !IsHex(strTxid))
throw runtime_error("invalid TX input txid");
uint256 txid(uint256S(strTxid));
@@ -198,13 +198,18 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
static const unsigned int maxVout = MAX_BLOCK_SIZE / minTxOutSz;
// extract and validate vout
- string strVout = strInput.substr(pos + 1, string::npos);
+ string strVout = vStrInputParts[1];
int vout = atoi(strVout);
if ((vout < 0) || (vout > (int)maxVout))
throw runtime_error("invalid TX input vout");
+ // extract the optional sequence number
+ uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max();
+ if (vStrInputParts.size() > 2)
+ nSequenceIn = atoi(vStrInputParts[2]);
+
// append to transaction input list
- CTxIn txin(txid, vout);
+ CTxIn txin(txid, vout, CScript(), nSequenceIn);
tx.vin.push_back(txin);
}