aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-07-12 19:46:24 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-07-12 19:55:54 -0400
commit771ffb5e28a75bf2a99283b3a9c7c40dc0f7907d (patch)
tree5fca13386f49e332d150e8f41934a97398a0aa8e
parent4a7d53ee23cafb3eb0064f4a050d843c5833f8a7 (diff)
Bug fix: sendrawtransaction was not relaying properly
-rw-r--r--src/rpcrawtransaction.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp
index 63c2dfe0ac..8ffe4844c6 100644
--- 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 @@ Value sendrawtransaction(const Array& params, bool fHelp)
catch (std::exception &e) {
throw JSONRPCError(-22, "TX decode failed");
}
+ uint256 hashTx = tx.GetHash();
- // push to local node
- CTxDB txdb("r");
- if (!tx.AcceptToMemoryPool(txdb))
- throw JSONRPCError(-22, "TX rejected");
-
- 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();
}