server.peers rpc
[electrum-server.git] / patches / bitcoinrpc.cpp.diff
1 diff -u -r bitcoin/src/bitcoinrpc.cpp bitcoin-electrum/src/bitcoinrpc.cpp
2 --- bitcoin/src/bitcoinrpc.cpp  2011-12-28 21:23:40.844812872 +0200
3 +++ bitcoin-electrum/src/bitcoinrpc.cpp 2011-12-28 17:31:24.000000000 +0200
4 @@ -1437,6 +1437,38 @@
5      return entry;
6  }
7  
8 +Value importtransaction(const Array& params, bool fHelp)
9 +{
10 +  string hexdump;
11 +  if (fHelp || params.size() != 1 || (hexdump=params[0].get_str()).size()&1)
12 +    throw runtime_error(
13 +            "importtransaction <hexdata>\n"
14 +            "Import an offline transaction to announce it into the network");
15 +
16 +  std::vector<unsigned char> rawtx;
17 +  for (int i=0; i<hexdump.size(); i+=2)
18 +    {
19 +      int v;
20 +      if (sscanf(hexdump.substr(i,2).c_str(), "%x", &v)!=1)
21 +       throw JSONRPCError(-4, "Error in hex data.");
22 +      rawtx.push_back((unsigned char)v);
23 +    }
24 +try
25 +  {
26 +    CDataStream ss(rawtx);
27 +    CTransaction tx;
28 +    ss >> tx;
29 +    CInv inv(MSG_TX, tx.GetHash());
30 +    if(! tx.AcceptToMemoryPool(true)) throw JSONRPCError(-4, "Transaction not accepted to memory pool.");
31 +    CDataStream msg(rawtx);
32 +    RelayMessage(inv, msg);
33 +    return tx.GetHash().GetHex();
34 +  }
35 + catch (std::exception& e)
36 +   {
37 +     throw JSONRPCError(-4, "Exception while parsing the transaction data.");
38 +   }
39 +}
40  
41  Value backupwallet(const Array& params, bool fHelp)
42  {
43 @@ -1950,7 +1982,8 @@
44      make_pair("getmemorypool",          &getmemorypool),
45      make_pair("listsinceblock",         &listsinceblock),
46      make_pair("dumpprivkey",            &dumpprivkey),
47 -    make_pair("importprivkey",          &importprivkey)
48 +    make_pair("importprivkey",          &importprivkey),
49 +    make_pair("importtransaction",     &importtransaction)
50  };
51  map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
52