diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-05-24 09:14:04 -0700 |
---|---|---|
committer | Jeff Garzik <jgarzik@exmulti.com> | 2012-05-24 09:14:04 -0700 |
commit | ec9c9021336c5c0b6a7c0ad3cc4f8d563fe65f56 (patch) | |
tree | 59181b4ed7839ecf940cd33d1bed93c74a8223b6 /src | |
parent | 8e154e4d742530f0836a4e5fedd2b086f51499eb (diff) | |
parent | 976c08b68a516514b7d987ea7dd3ec59ca166ba0 (diff) |
Merge pull request #1383 from jgarzik/rawtx
JSON-RPC: Add 'sendrawtx' op, for sending pre-built TX's to network
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 35 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/main.h | 1 |
3 files changed, 37 insertions, 1 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() diff --git a/src/main.cpp b/src/main.cpp index 9e20ca6261..96718cf181 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,7 +109,7 @@ void static EraseFromWallets(uint256 hash) } // 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); diff --git a/src/main.h b/src/main.h index c0fe63a32a..29c9a8bce3 100644 --- a/src/main.h +++ b/src/main.h @@ -81,6 +81,7 @@ class CTxIndex; 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"); |