Skip to content

Commit

Permalink
RPC: getrawtransaction and resendtx improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEADFACE committed Feb 2, 2014
1 parent 51bf76e commit 3a28452
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ void static Inventory(const uint256& hash)
}

// ask wallets to resend their transactions
void ResendWalletTransactions()
void ResendWalletTransactions(bool fForce)
{
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->ResendWalletTransactions();
pwallet->ResendWalletTransactions(fForce);
}


Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash);
uint256 WantedByOrphan(const CBlock* pblockOrphan);
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake);
void StakeMiner(CWallet *pwallet);
void ResendWalletTransactions();
void ResendWalletTransactions(bool fForce=false);

bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);

Expand Down
9 changes: 7 additions & 2 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ Value getrawtransaction(const Array& params, bool fHelp)
fVerbose = (params[1].get_int() != 0);

CTransaction tx;
uint256 hashBlock = 0;
uint256 hashBlock = 0; // trying to find transaction in the blockchain
if (!GetTransaction(hash, tx, hashBlock, true))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
{
if (pwalletMain->mapWallet.count(hash))
tx = (CTransaction)pwalletMain->mapWallet[hash]; // get transaction from wallet
else
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
}

CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << tx;
Expand Down
33 changes: 18 additions & 15 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,23 +911,26 @@ void CWalletTx::RelayWalletTransaction()
}
}

void CWallet::ResendWalletTransactions()
void CWallet::ResendWalletTransactions(bool fForce)
{
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
static int64 nNextTime;
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;
if (!fForce)
{
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
static int64 nNextTime;
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;

// Only do it if there's been a new block since last time
static int64 nLastTime;
if (nTimeBestReceived < nLastTime)
return;
nLastTime = GetTime();
// Only do it if there's been a new block since last time
static int64 nLastTime;
if (nTimeBestReceived < nLastTime)
return;
nLastTime = GetTime();
}

// Rebroadcast any of our txes that aren't in a block yet
printf("ResendWalletTransactions()\n");
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CWallet : public CCryptoKeyStore
void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false);
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions();
void ResendWalletTransactions();
void ResendWalletTransactions(bool fForce=false);
int64 GetBalance() const;
int64 GetUnconfirmedBalance() const;
int64 GetImmatureBalance() const;
Expand Down

0 comments on commit 3a28452

Please sign in to comment.