From 22de68dffc1e94c5b06b7e512140c42290cb4f5d Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 24 Oct 2013 04:32:35 -0400 Subject: [PATCH 1/2] Relay OP_RETURN TxOut as standard transaction type Also fix decoderawtransaction to not show reqSigs or addresses for nulldata txouts. (Previous version also left reqSigs uninitialized mistakenly) --- src/rpcrawtransaction.cpp | 2 +- src/script.cpp | 12 +++++++----- src/test/transaction_tests.cpp | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index d5bd39cb..cb571947 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -29,7 +29,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { - out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); + out.push_back(Pair("type", GetTxnOutputType(type))); return; } diff --git a/src/script.cpp b/src/script.cpp index 63f63279..ec9e9d61 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1195,7 +1195,7 @@ bool CheckSig(vector vchSig, const vector &vchPubK bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector >& vSolutionsRet) { // Templates - static map mTemplates; + static multimap mTemplates; if (mTemplates.empty()) { // Standard tx, sender provides pubkey, receiver adds signature @@ -1209,6 +1209,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector vSolutions; if (!Solver(scriptPubKey, typeRet, vSolutions)) return false; - if (typeRet == TX_NULL_DATA) - return true; + if (typeRet == TX_NULL_DATA){ + // This is data, not addresses + return false; + } if (typeRet == TX_MULTISIG) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index d68ead1c..c6bc2e8a 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -282,11 +282,24 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"); BOOST_CHECK(!IsStandardTx(t, reason)); - // Only one TX_NULL_DATA permitted + // TX_NULL_DATA w/o PUSHDATA + t.vout.resize(1); + t.vout[0].scriptPubKey = CScript() << OP_RETURN; + BOOST_CHECK(IsStandardTx(t, reason)); + + // Only one TX_NULL_DATA permitted in all cases t.vout.resize(2); t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"); t.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"); BOOST_CHECK(!IsStandardTx(t, reason)); + + t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"); + t.vout[1].scriptPubKey = CScript() << OP_RETURN; + BOOST_CHECK(!IsStandardTx(t, reason)); + + t.vout[0].scriptPubKey = CScript() << OP_RETURN; + t.vout[1].scriptPubKey = CScript() << OP_RETURN; + BOOST_CHECK(!IsStandardTx(t, reason)); } BOOST_AUTO_TEST_SUITE_END() From 005609539b2184a474ffe9ebfe883984c900a3fb Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 24 Oct 2013 04:52:16 -0400 Subject: [PATCH 2/2] Show short scriptPubKeys correctly Previously bitcoin-qt's -debug transaction info was showing CTxOut([error]) It is valid for a scriptPubKey to be any size, for example simply OP_RETURN is valid and can be used to destroy a TXOUT to mining fees. --- src/core.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 99b5c664..5512f81b 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -63,8 +63,6 @@ uint256 CTxOut::GetHash() const std::string CTxOut::ToString() const { - if (scriptPubKey.size() < 6) - return "CTxOut(error)"; return strprintf("CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); }