Mercurial > hg > bitcoin
changeset 3197:b63a5263d11a draft
Bug fix: sendrawtransaction was not relaying properly
author | Gavin Andresen <gavinandresen@gmail.com> |
---|---|
date | Thu, 12 Jul 2012 19:46:24 -0400 |
parents | a77ec339a5ba |
children | c4d7950c8790 6d3c73a7c883 2b044778b85f 322c07b5f42b |
files | src/rpcrawtransaction.cpp |
diffstat | 1 files changed, 23 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -10,6 +10,7 @@ #include "db.h" #include "init.h" #include "main.h" +#include "net.h" #include "wallet.h" using namespace std; @@ -454,17 +455,29 @@ 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"); + uint256 hashTx = tx.GetHash(); - SyncWithWallets(tx, NULL, true); + // See if the transaction is already in a block + // or in the memory pool: + CTransaction existingTx; + uint256 hashBlock = 0; + if (GetTransaction(hashTx, existingTx, hashBlock)) + { + if (hashBlock != 0) + throw JSONRPCError(-5, string("transaction already in block ")+hashBlock.GetHex()); + // Not in block, but already in the memory pool; will drop + // through to re-relay it. + } + else + { + // push to local node + CTxDB txdb("r"); + if (!tx.AcceptToMemoryPool(txdb)) + throw JSONRPCError(-22, "TX rejected"); - // relay to network - CInv inv(MSG_TX, tx.GetHash()); - RelayInventory(inv); + SyncWithWallets(tx, NULL, true); + } + RelayMessage(CInv(MSG_TX, hashTx), tx); - return tx.GetHash().GetHex(); + return hashTx.GetHex(); }