aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-05-23 16:21:25 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-05-23 16:21:25 -0400
commit976c08b68a516514b7d987ea7dd3ec59ca166ba0 (patch)
treef0ccd128d914f7dd1bb41d96e31b982785c61d7a /src/bitcoinrpc.cpp
parent7a99821377eb46a1cc8b0115daf3af01ddb26a16 (diff)
downloadbitcoin-976c08b68a516514b7d987ea7dd3ec59ca166ba0.tar.xz
JSON-RPC: Add 'sendrawtx' op, for sending pre-built TX's to network
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 24fa97588c..8f4fb93a5a 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -2217,6 +2217,40 @@ Value getblock(const Array& params, bool fHelp)
(params.size() > 1) ? params[1].get_obj() : emptyobj);
}
+Value sendrawtx(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() < 1 || params.size() > 1)
+ throw runtime_error(
+ "sendrawtx <hex string>\n"
+ "Submits raw transaction (serialized, hex-encoded) to local node and network.");
+
+ // parse hex string from parameter
+ vector<unsigned char> txData(ParseHex(params[0].get_str()));
+ CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
+ CTransaction tx;
+
+ // deserialize binary data stream
+ try {
+ ssData >> tx;
+ }
+ catch (std::exception &e) {
+ throw JSONRPCError(-22, "TX decode failed");
+ }
+
+ // push to local node
+ CTxDB txdb("r");
+ if (!tx.AcceptToMemoryPool(txdb))
+ throw JSONRPCError(-22, "TX rejected");
+
+ SyncWithWallets(tx, NULL, true);
+
+ // relay to network
+ CInv inv(MSG_TX, tx.GetHash());
+ RelayInventory(inv);
+
+ return true;
+}
+
@@ -2280,6 +2314,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listsinceblock", &listsinceblock, false },
{ "dumpprivkey", &dumpprivkey, false },
{ "importprivkey", &importprivkey, false },
+ { "sendrawtx", &sendrawtx, false },
};
CRPCTable::CRPCTable()