Mercurial > hg > bitcoin
changeset 2676:264ca7bc2a8b draft
JSON-RPC: Add 'sendrawtx' op, for sending pre-built TX's to network
author | Jeff Garzik <jgarzik@exmulti.com> |
---|---|
date | Wed, 23 May 2012 16:21:25 -0400 |
parents | dab1bd565628 |
children | 6434b1393146 |
files | src/bitcoinrpc.cpp src/main.cpp src/main.h |
diffstat | 3 files changed, 37 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2217,6 +2217,40 @@ (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 @@ { "listsinceblock", &listsinceblock, false }, { "dumpprivkey", &dumpprivkey, false }, { "importprivkey", &importprivkey, false }, + { "sendrawtx", &sendrawtx, false }, }; CRPCTable::CRPCTable()
--- a/src/main.cpp +++ b/src/main.cpp @@ -109,7 +109,7 @@ } // make sure all wallets know about the given transaction, in the given block -void static SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false) +void SyncWithWallets(const CTransaction& tx, const CBlock* pblock, bool fUpdate) { BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) pwallet->AddToWalletIfInvolvingMe(tx, pblock, fUpdate);
--- a/src/main.h +++ b/src/main.h @@ -81,6 +81,7 @@ void RegisterWallet(CWallet* pwalletIn); void UnregisterWallet(CWallet* pwalletIn); +void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false); bool ProcessBlock(CNode* pfrom, CBlock* pblock); bool CheckDiskSpace(uint64 nAdditionalBytes=0); FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode="rb");