* Add missing cache key to sample config.
[electrum-server.git] / patches / bitcoinrpc.cpp.diff
1 diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
2 index 6e2eac5..8b60ebf 100644
3 --- a/src/bitcoinrpc.cpp
4 +++ b/src/bitcoinrpc.cpp
5 @@ -1355,7 +1355,43 @@ Value gettransaction(const Array& params, bool fHelp)
6      return entry;
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);
28 +    CTransaction tx;
29 +    ss >> tx;
30 +    CInv inv(MSG_TX, tx.GetHash());
31 +    if(! tx.AcceptToMemoryPool(true)) throw JSONRPCError(-4, "Transaction not accepted to memory pool.");
32 +    CDataStream msg(rawtx);
33 +    RelayMessage(inv, msg);
34 +    return tx.GetHash().GetHex();
35 +  }
36 + catch (std::exception& e)
37 +   {
38 +     throw JSONRPCError(-4, "Exception while parsing the transaction data.");
39 +   }
40 +
41 +}
42 +
43 +
44  
45 +  
46  Value backupwallet(const Array& params, bool fHelp)
47  {
48      if (fHelp || params.size() != 1)
49 @@ -1850,6 +1886,7 @@ pair<string, rpcfn_type> pCallTable[] =
50      make_pair("settxfee",               &settxfee),
51      make_pair("getmemorypool",          &getmemorypool),
52      make_pair("listsinceblock",        &listsinceblock),
53 +    make_pair("importtransaction",      &importtransaction),
54  };
55  map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
56