Skip to content

Commit

Permalink
Wallet cached txdef
Browse files Browse the repository at this point in the history
  • Loading branch information
mike31 committed Oct 25, 2018
1 parent 1e4aa23 commit a789c94
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/wallet/wallettxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,29 @@ int mc_TxDB::IncrementSubKey(
return err;
}

int mc_TxDB::SetTxCache( // Returns tx definition if found, error if not found
const unsigned char *hash)
{
m_TxCachedDef.Zero();
m_TxCachedFlags=MC_TCF_ERROR;

int err=GetTx(&m_TxCachedDef,hash,IsCSkipped(MC_TET_GETDB_ADD_TX));
if(err == MC_ERR_NOERROR)
{
m_TxCachedFlags=MC_TCF_FOUND;
}
else
{
if (err == MC_ERR_NOT_FOUND)
{
m_TxCachedFlags=MC_TCF_NOT_FOUND;
}
}

return MC_ERR_NOERROR;
}


/*
* Adds tx to specific import
*/
Expand Down Expand Up @@ -1161,7 +1184,20 @@ int mc_TxDB::AddTx(mc_TxImport *import,

newtx=0;
ondisk=0;
err=GetTx(&txdef,hash,IsCSkipped(MC_TET_GETDB_ADD_TX));
// err=GetTx(&txdef,hash,IsCSkipped(MC_TET_GETDB_ADD_TX));
if(m_TxCachedFlags & MC_TCF_FOUND)
{
memcpy(&txdef,&(m_TxCachedDef),sizeof(mc_TxDefRow));
}
if(m_TxCachedFlags & MC_TCF_NOT_FOUND)
{
err=MC_ERR_NOT_FOUND;
}
if(m_TxCachedFlags & MC_TCF_ERROR)
{
err=MC_ERR_INTERNAL_ERROR;
}

if(err == MC_ERR_NOT_FOUND) // Tx is not found, neither on disk, nor in the mempool
{
err=MC_ERR_NOERROR;
Expand Down
13 changes: 12 additions & 1 deletion src/wallet/wallettxdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@

#define MC_TFL_IS_EXTENSION 0x01000000

#define MC_TCF_NOT_CACHED 0x00000000
#define MC_TCF_ERROR 0x00000001
#define MC_TCF_FOUND 0x00000002
#define MC_TCF_NOT_FOUND 0x00000004


/** Entity - wallet, address, stream, etc. **/

typedef struct mc_TxEntity
Expand Down Expand Up @@ -246,7 +252,9 @@ typedef struct mc_TxDB
uint32_t m_Mode;
void *m_Semaphore; // mc_TxDB object semaphore
uint64_t m_LockedBy; // ID of the thread locking it

mc_TxDefRow m_TxCachedDef;
uint32_t m_TxCachedFlags;

mc_TxDB()
{
Zero();
Expand Down Expand Up @@ -312,6 +320,9 @@ typedef struct mc_TxDB
uint32_t timestamp, // timestamp to be stored as timereceived
mc_Buffer *entities); // List of relevant entities for this tx

int SetTxCache( // Returns tx definition if found, error if not found
const unsigned char *hash); // Input. Tx hash

int GetTx( // Returns tx definition if found, error if not found
mc_TxDefRow *txdef, // Output. Tx def
const unsigned char *hash); // Input. Tx hash
Expand Down

0 comments on commit a789c94

Please sign in to comment.