Browse Source

IsStandard() check for CScripts: only relay/include in blocks CScripts we can understand.

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@197 1a98c847-1fd6-4fd8-948a-caf3550aa51b
0.8
gavinandresen 14 years ago
parent
commit
a206a23980
  1. 20
      main.cpp
  2. 11
      main.h
  3. 7
      script.cpp
  4. 16
      script.h
  5. 2
      serialize.h
  6. 4
      sha256.cpp

20
main.cpp

@ -572,7 +572,7 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet"); return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet");
// Rather not work on nonstandard transactions // Rather not work on nonstandard transactions
if (GetSigOpCount() > 2 || ::GetSerializeSize(*this, SER_NETWORK) < 100) if (!IsStandard() || GetSigOpCount() > 2 || ::GetSerializeSize(*this, SER_NETWORK) < 100)
return error("AcceptToMemoryPool() : nonstandard transaction"); return error("AcceptToMemoryPool() : nonstandard transaction");
// Do we already have it? // Do we already have it?
@ -2567,15 +2567,17 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
else if (strCommand == "checkorder") else if (strCommand == "checkorder")
{ {
uint256 hashReply; uint256 hashReply;
CWalletTx order; vRecv >> hashReply;
vRecv >> hashReply >> order;
if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0") if (!GetBoolArg("-allowreceivebyip"))
{ {
pfrom->PushMessage("reply", hashReply, (int)2, string("")); pfrom->PushMessage("reply", hashReply, (int)2, string(""));
return true; return true;
} }
CWalletTx order;
vRecv >> order;
/// we have a chance to check the order here /// we have a chance to check the order here
// Keep giving the same key to the same ip until they use it // Keep giving the same key to the same ip until they use it
@ -2592,16 +2594,18 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
else if (strCommand == "submitorder") else if (strCommand == "submitorder")
{ {
uint256 hashReply; uint256 hashReply;
CWalletTx wtxNew; vRecv >> hashReply;
vRecv >> hashReply >> wtxNew;
wtxNew.fFromMe = false;
if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0") if (!GetBoolArg("-allowreceivebyip"))
{ {
pfrom->PushMessage("reply", hashReply, (int)2); pfrom->PushMessage("reply", hashReply, (int)2);
return true; return true;
} }
CWalletTx wtxNew;
vRecv >> wtxNew;
wtxNew.fFromMe = false;
// Broadcast // Broadcast
if (!wtxNew.AcceptWalletTransaction()) if (!wtxNew.AcceptWalletTransaction())
{ {

11
main.h

@ -499,6 +499,17 @@ public:
return n; return n;
} }
bool IsStandard() const
{
foreach(const CTxIn& txin, vin)
if (!txin.scriptSig.IsPushOnly())
return error("nonstandard txin: %s", txin.scriptSig.ToString().c_str());
foreach(const CTxOut& txout, vout)
if (!::IsStandard(txout.scriptPubKey))
return error("nonstandard txout: %s", txout.scriptPubKey.ToString().c_str());
return true;
}
bool IsMine() const bool IsMine() const
{ {
foreach(const CTxOut& txout, vout) foreach(const CTxOut& txout, vout)

7
script.cpp

@ -1076,6 +1076,13 @@ bool Solver(const CScript& scriptPubKey, uint256 hash, int nHashType, CScript& s
} }
bool IsStandard(const CScript& scriptPubKey)
{
vector<pair<opcodetype, valtype> > vSolution;
return Solver(scriptPubKey, vSolution);
}
bool IsMine(const CScript& scriptPubKey) bool IsMine(const CScript& scriptPubKey)
{ {
CScript scriptSig; CScript scriptSig;

16
script.h

@ -597,6 +597,21 @@ public:
} }
bool IsPushOnly() const
{
const_iterator pc = begin();
while (pc < end())
{
opcodetype opcode;
if (!GetOp(pc, opcode))
return false;
if (opcode > OP_16)
return false;
}
return true;
}
uint160 GetBitcoinAddressHash160() const uint160 GetBitcoinAddressHash160() const
{ {
opcodetype opcode; opcodetype opcode;
@ -684,6 +699,7 @@ public:
uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
bool IsStandard(const CScript& scriptPubKey);
bool IsMine(const CScript& scriptPubKey); bool IsMine(const CScript& scriptPubKey);
bool ExtractPubKey(const CScript& scriptPubKey, bool fMineOnly, vector<unsigned char>& vchPubKeyRet); bool ExtractPubKey(const CScript& scriptPubKey, bool fMineOnly, vector<unsigned char>& vchPubKeyRet);
bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret); bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret);

2
serialize.h

@ -25,7 +25,7 @@ class CDataStream;
class CAutoFile; class CAutoFile;
static const unsigned int MAX_SIZE = 0x02000000; static const unsigned int MAX_SIZE = 0x02000000;
static const int VERSION = 31704; static const int VERSION = 31705;
static const char* pszSubVer = ""; static const char* pszSubVer = "";

4
sha256.cpp

@ -1,8 +1,8 @@
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2010 Nils Schneider
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php. // file license.txt or http://www.opensource.org/licenses/mit-license.php.
// tcatm's 4-way 128-bit SSE2 SHA-256 // 4-way 128-bit SSE2 SHA-256
#ifdef FOURWAYSSE2 #ifdef FOURWAYSSE2

Loading…
Cancel
Save