@@ -777,25 +777,23 @@ Value sendrawtransaction(const Array& params, bool fHelp)
777
777
}
778
778
uint256 hashTx = tx.GetHash ();
779
779
780
- bool fHave = false ;
781
780
CCoinsViewCache &view = *pcoinsTip;
782
781
CCoins existingCoins;
783
- {
784
- fHave = view.GetCoins (hashTx, existingCoins);
785
- if (!fHave ) {
786
- // push to local node
787
- CValidationState state;
788
- if (!AcceptToMemoryPool (mempool, state, tx, false , NULL , !fOverrideFees ))
789
- throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " TX rejected" ); // TODO: report validation state
782
+ bool fHaveMempool = mempool.exists (hashTx);
783
+ bool fHaveChain = view.GetCoins (hashTx, existingCoins) && existingCoins.nHeight < 1000000000 ;
784
+ if (!fHaveMempool && !fHaveChain ) {
785
+ // push to local node and sync with wallets
786
+ CValidationState state;
787
+ if (AcceptToMemoryPool (mempool, state, tx, false , NULL , !fOverrideFees ))
788
+ SyncWithWallets (hashTx, tx, NULL );
789
+ else {
790
+ if (state.IsInvalid ())
791
+ throw JSONRPCError (RPC_TRANSACTION_REJECTED, strprintf (" %i: %s" , state.GetRejectCode (), state.GetRejectReason ()));
792
+ else
793
+ throw JSONRPCError (RPC_TRANSACTION_ERROR, state.GetRejectReason ());
790
794
}
791
- }
792
- if (fHave ) {
793
- if (existingCoins.nHeight < 1000000000 )
794
- throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " transaction already in block chain" );
795
- // Not in block, but already in the memory pool; will drop
796
- // through to re-relay it.
797
- } else {
798
- SyncWithWallets (hashTx, tx, NULL );
795
+ } else if (fHaveChain ) {
796
+ throw JSONRPCError (RPC_TRANSACTION_ALREADY_IN_CHAIN, " transaction already in block chain" );
799
797
}
800
798
RelayTransaction (tx, hashTx);
801
799
0 commit comments