Permalink
Browse files

Relay OP_RETURN TxOut as standard transaction type

  • Loading branch information...
Tranz5 committed Jul 30, 2014
1 parent a9c4540 commit 1fc06a72c2214abd4ee0fe2644fca2f8617989ac
Showing with 30 additions and 7 deletions.
  1. +12 −1 src/main.cpp
  2. +1 −1 src/rpcrawtransaction.cpp
  3. +14 −3 src/script.cpp
  4. +3 −2 src/script.h
@@ -362,14 +362,25 @@ bool CTransaction::IsStandard() const
if (fEnforceCanonical && !txin.scriptSig.HasCanonicalPushes())
return false;
}
unsigned int nDataOut = 0;
txnouttype whichType;
BOOST_FOREACH(const CTxOut& txout, vout) {
if (!::IsStandard(txout.scriptPubKey))
if (!::IsStandard(txout.scriptPubKey, whichType))
return false;
if (whichType == TX_NULL_DATA)
nDataOut++;
if (txout.nValue == 0)
return false;
if (fEnforceCanonical && !txout.scriptPubKey.HasCanonicalPushes())
return false;
}
// only one OP_RETURN txout is permitted
if (nDataOut > 1) {
return false;
}
return true;
}
@@ -29,7 +29,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out)
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired))
{
out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD)));
out.push_back(Pair("type", GetTxnOutputType(type)));
return;
}
@@ -102,6 +102,7 @@ const char* GetTxnOutputType(txnouttype t)
case TX_PUBKEYHASH: return "pubkeyhash";
case TX_SCRIPTHASH: return "scripthash";
case TX_MULTISIG: return "multisig";
case TX_NULL_DATA: return "nulldata";
}
return NULL;
}
@@ -1224,7 +1225,7 @@ bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CSc
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
{
// Templates
static map<txnouttype, CScript> mTemplates;
static multimap<txnouttype, CScript> mTemplates;
if (mTemplates.empty())
{
// Standard tx, sender provides pubkey, receiver adds signature
@@ -1235,6 +1236,9 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
// Sender provides N pubkeys, receivers provides M signatures
mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
// Empty, provably prunable, data-carrying output
mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN));
}
// Shortcut for pay-to-script-hash, which are more constrained than the other types:
@@ -1381,6 +1385,7 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
switch (whichTypeRet)
{
case TX_NONSTANDARD:
case TX_NULL_DATA:
return false;
case TX_PUBKEY:
keyID = CPubKey(vSolutions[0]).GetID();
@@ -1411,6 +1416,7 @@ int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned c
switch (t)
{
case TX_NONSTANDARD:
case TX_NULL_DATA:
return -1;
case TX_PUBKEY:
return 1;
@@ -1426,10 +1432,9 @@ int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned c
return -1;
}
bool IsStandard(const CScript& scriptPubKey)
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
{
vector<valtype> vSolutions;
txnouttype whichType;
if (!Solver(scriptPubKey, whichType, vSolutions))
return false;
@@ -1488,6 +1493,7 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
switch (whichType)
{
case TX_NONSTANDARD:
case TX_NULL_DATA:
return false;
case TX_PUBKEY:
keyID = CPubKey(vSolutions[0]).GetID();
@@ -1586,6 +1592,10 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto
vector<valtype> vSolutions;
if (!Solver(scriptPubKey, typeRet, vSolutions))
return false;
if (typeRet == TX_NULL_DATA){
// This is data, not addresses
return false;
}
if (typeRet == TX_MULTISIG)
{
@@ -1776,6 +1786,7 @@ static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo,
switch (txType)
{
case TX_NONSTANDARD:
case TX_NULL_DATA:
// Don't know anything about this, assume bigger one is correct:
if (sigs1.size() >= sigs2.size())
return PushAll(sigs1);
@@ -37,7 +37,8 @@ enum txnouttype
TX_PUBKEY,
TX_PUBKEYHASH,
TX_SCRIPTHASH,
TX_MULTISIG
TX_MULTISIG,
TX_NULL_DATA
};
class CNoDestination {
@@ -593,7 +594,7 @@ class CScript : public std::vector<unsigned char>
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType);
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
bool IsStandard(const CScript& scriptPubKey);
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector<CKeyID> &vKeys);
bool IsMine(const CKeyStore& keystore, const CTxDestination &dest);

0 comments on commit 1fc06a7

Please sign in to comment.