2c3821aaa3c75dfbf3b7cd78875c05002d2c165c
[electrum-server.git] / patches / bitcoin-0.6.2.diff
1 diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
2 index 15bcf1d..1ace361 100644
3 --- a/src/bitcoinrpc.cpp
4 +++ b/src/bitcoinrpc.cpp
5 @@ -1497,6 +1497,43 @@ Value gettransaction(const Array& params, bool fHelp)
6  }
7  
8  
9 +Value importtransaction(const Array& params, bool fHelp)
10 +{
11 +  string hexdump;
12 +  if (fHelp || params.size() != 1 || (hexdump=params[0].get_str()).size()&1)
13 +    throw runtime_error(
14 +            "importtransaction <hexdata>\n"
15 +            "Import an offline transaction to announce it into the network");
16 +
17 +  std::vector<unsigned char> rawtx;
18 +  for (int i=0; i<hexdump.size(); i+=2)
19 +    {
20 +      int v;
21 +      if (sscanf(hexdump.substr(i,2).c_str(), "%x", &v)!=1)
22 +       throw JSONRPCError(-4, "Error in hex data.");
23 +      rawtx.push_back((unsigned char)v);
24 +    }
25 +try
26 +  {
27 +    CDataStream ss(rawtx, SER_NETWORK, PROTOCOL_VERSION);
28 +    CTransaction tx;
29 +    ss >> tx;
30 +    CInv inv(MSG_TX, tx.GetHash());
31 +
32 +    CTxDB txdb("r");
33 +    if(! tx.AcceptToMemoryPool(txdb, true)) throw JSONRPCError(-4, "Transaction not accepted to memory pool.");
34 +    CDataStream msg(rawtx, SER_NETWORK, PROTOCOL_VERSION);
35 +    RelayMessage(inv, msg);
36 +    return tx.GetHash().GetHex();
37 +  }
38 + catch (std::exception& e)
39 +   {
40 +     throw JSONRPCError(-4, "Exception while parsing the transaction data.");
41 +   }
42 +
43 +}
44 +
45 +
46  Value backupwallet(const Array& params, bool fHelp)
47  {
48      if (fHelp || params.size() != 1)
49 @@ -2055,6 +2092,7 @@ static const CRPCCommand vRPCCommands[] =
50      { "listsinceblock",         &listsinceblock,         false },
51      { "dumpprivkey",            &dumpprivkey,            false },
52      { "importprivkey",          &importprivkey,          false },
53 +    { "importtransaction",      &importtransaction,      false },
54  };
55  
56  CRPCTable::CRPCTable()
57 diff --git a/src/main.cpp b/src/main.cpp
58 index 427e435..35da486 100644
59 --- a/src/main.cpp
60 +++ b/src/main.cpp
61 @@ -3160,6 +3160,10 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
62              if (tx.IsCoinBase() || !tx.IsFinal())
63                  continue;
64  
65 +           if (tx.get_electrum_flag())
66 +             continue;
67 +           tx.set_electrum_flag(true);
68 +
69              COrphan* porphan = NULL;
70              double dPriority = 0;
71              BOOST_FOREACH(const CTxIn& txin, tx.vin)
72 @@ -3222,18 +3226,21 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
73  
74              // Size limits
75              unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
76 -            if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN)
77 -                continue;
78 +            //if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN)
79 +            //    continue;
80  
81              // Legacy limits on sigOps:
82              unsigned int nTxSigOps = tx.GetLegacySigOpCount();
83 -            if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
84 -                continue;
85 +            //if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
86 +            //    continue;
87  
88              // Transaction fee required depends on block size
89              bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority));
90              int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, GMF_BLOCK);
91  
92 +            // Electrum server: do not check fees
93 +            nMinFee = 0;
94 +
95              // Connecting shouldn't fail due to dependency on other memory pool transactions
96              // because we're already processing them in order of dependency
97              map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
98 diff --git a/src/main.h b/src/main.h
99 index 262e77e..fb79232 100644
100 --- a/src/main.h
101 +++ b/src/main.h
102 @@ -395,9 +395,20 @@ public:
103      mutable int nDoS;
104      bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
105  
106 +    bool electrum_flag;
107 +
108 +    void set_electrum_flag(bool x){
109 +      electrum_flag = x;
110 +    }
111 +
112 +    bool get_electrum_flag(){
113 +      return electrum_flag;
114 +    }
115 +
116      CTransaction()
117      {
118          SetNull();
119 +       set_electrum_flag(false);
120      }
121  
122      IMPLEMENT_SERIALIZE