Skip to content

Commit

Permalink
Working on the zero-conf updates
Browse files Browse the repository at this point in the history
  • Loading branch information
etotheipi committed Jan 15, 2012
1 parent c485cf0 commit 1765f2e
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cppForSwig/BinaryData.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ class BinaryReader
uint32_t getSizeRemaining(void) const { return totalSize_ - pos_; }
bool isEndOfStream(void) const { return pos_ >= totalSize_; }
uint8_t* exposeDataPtr(void) { return bdStr_.getPtr(); }
uint8_t const * getCurrPtr(void) { return bdStr_.getPtr() + pos_; }
uint8_t const * getCurrPtr(void) { return bdStr_.getPtr() + pos_; }

private:
BinaryData bdStr_;
Expand Down Expand Up @@ -1018,7 +1018,7 @@ class BinaryRefReader
uint32_t getSizeRemaining(void) const { return totalSize_ - pos_; }
bool isEndOfStream(void) const { return pos_ >= totalSize_; }
uint8_t const * exposeDataPtr(void) { return bdRef_.getPtr(); }
uint8_t const * getCurrPtr(void) { return bdRef_.getPtr() + pos_; }
uint8_t const * getCurrPtr(void) { return bdRef_.getPtr() + pos_; }

private:
BinaryDataRef bdRef_;
Expand Down
2 changes: 2 additions & 0 deletions cppForSwig/BlockObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class Tx
};




////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// This class is mainly for sorting by priority
Expand Down
142 changes: 142 additions & 0 deletions cppForSwig/BlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
////////////////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <time.h>
#include "BlockUtils.h"


Expand Down Expand Up @@ -823,6 +824,12 @@ BlockDataManager_FullRAM::BlockDataManager_FullRAM(void) :
blockchainData_NEW_.clear();
headerHashMap_.clear();
txHashMap_.clear();

zeroConfTxList_.clear();
zeroConfMap_.clear();
zcEnabled_ = false;
zcFilename_ = string("");

headersByHeight_.clear();
txFileRefs_.clear();
headerFileRefs_.clear();
Expand Down Expand Up @@ -852,6 +859,7 @@ void BlockDataManager_FullRAM::SetBtcNetworkParams(
}



void BlockDataManager_FullRAM::SelectNetwork(string netName)
{
if(netName.compare("Main") == 0)
Expand Down Expand Up @@ -2098,5 +2106,139 @@ BlockDataManager_FullRAM::getNonStdUnspentTxOutsForWallet( BtcWallet & wlt)
cout << "Not implemented yet to retrieve non-std TxOuts..."<< endl;
return vector<UnspentTxOut>(0);
}



////////////////////////////////////////////////////////////////////////////////
// Methods for handling zero-confirmation transactions
////////////////////////////////////////////////////////////////////////////////
void BlockDataManager_FullRAM::enableZeroConf(string zcFilename)
{
zcEnabled_ = true;
zcFilename_ = zcFilename;

readZeroConfFile(zcFilename_); // does nothing if DNE
}

////////////////////////////////////////////////////////////////////////////////
void BlockDataManager_FullRAM::readZeroConfFile(string zcFilename)
{
ifstream zcFile(zcFilename_, ios::in | ios::binary);
if(zcFile)
{
zcFile.seekg(0, ios::end);
uint64_t filesize = (size_t)zcFile.tellg();
zcFile.seekg(0, ios::beg);
BinaryData zcData(filesize);
zcFile.read((char*)zcData.getPtr(), filesize);

// We succeeded opening the file...
BinaryRefReader brr(zcData);
while(brr.getSizeRemaining() > 8)
{
uint64_t txTime = brr.get_uint64_t();
uint32_t txLen = BtcUtils::TxCalcLength(brr.getCurrPtr());
BinaryData rawtx(txLen);
brr.get_BinaryData(rawtx.getPtr(), txLen);
}
zcFile.close();
}
//brr.isEndOfStream() ||
}

////////////////////////////////////////////////////////////////////////////////
void BlockDataManager_FullRAM::disableZeroConf(string zcFilename)
{
zcEnabled_ = false;
}


////////////////////////////////////////////////////////////////////////////////
void BlockDataManager_FullRAM::addNewZeroConfTx(BinaryData const & rawTx,
uint64_t txtime,
bool writeToFile)
{

if(txtime==0)
txtime = time(NULL);

BinaryData txHash = BtcUtils::getHash256(rawTx)
if(zeroConfMap_.find(txHash) != zeroConfMap_.end())
return;


zeroConfMap_[txHash] = ZeroConfData();
ZeroConfData & zc = zeroConfMap_[txHash];
zc.iter_ = zeroConfTxList_.insert(rawTx);
zc.txref_.unserialize(*newTxData);
zc.txtime_ = txtime;


// Record time. Write to file
if(writeToFile)
{
ofstream zcFile(zcFilename_, ios::app | ios::binary);
zcFile.write( (char*)(&zc.txtime_), sizeof(uint64_t) );
zcFile.write( (char*)(&zc.txref_.getPtr()), zc.txref_.getSize())
zcFile.close();
}
}



////////////////////////////////////////////////////////////////////////////////
void BlockDataManager_FullRAM::purgeZeroConfPool(void)
{
list< map<HashString, ZeroConfData>::iterator > mapRmList;

map<HashString, ZeroConfData>::iterator iter;
for(iter = zeroConfMap_.begin();
iter != zeroConfMap_.end();
iter++)
{
TxRef* txInBlockchain = getTxByHash(iter->first);
if(txInBlockchain != NULL)
mapRmList.push_back(ter);
}


list< map<HashString, ZeroConfData>::iterator >::iterator iter;
for(iter = mapRmList.begin();
iter != mapRmList.end();
iter++)
{
zeroConfTxList_.erase( (*iter)->second.iter_ );
zeroConfMap_.erase( *iter )
}
}

void BlockDataManager_FullRAM::updateWalletWithZeroConf(BtcWallet & wlt)
{

}


























12 changes: 9 additions & 3 deletions cppForSwig/BlockUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ class BtcWallet



class ZeroConfData
{
public:
TxRef txref_;
uint64_t txtime_;
list<BinaryData>::iterator iter_;
};


// Some might argue that inheritance would be useful here. I'm not a software
// guy, and I have to write all the methods for each class anyway. So I'm
Expand Down Expand Up @@ -494,9 +502,7 @@ class BlockDataManager_FullRAM
// We need the second map to make sure we can find the data to remove
// it, when necessary
list<BinaryData> zeroConfTxList_;
map<HashString, TxRef> zeroConfTxRefMap_;
map<HashString,
list<BinaryData>::iterator> zeroConfIterMap_;
map<HashString, ZeroConfData> zeroConfMap_;
bool zcEnabled_;
string zcFilename_;

Expand Down
11 changes: 5 additions & 6 deletions qtdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ def processUserString(self):

if not TheBDM.isInitialized():
reply = QMessageBox.critical(self, 'Cannot Sweep Address', \
'You need access to the internet and the blockchain in order '
'You need access to the Bitcoin network and the blockchain in order '
'to find the balance of this address and sweep its funds. ', \
QMessageBox.Ok)
return
Expand Down Expand Up @@ -3796,9 +3796,9 @@ def makeRecipFrame(self, nRecip):
self.widgetTable[-1].append( QLabel('Address %d:' % (i+1,)) )

self.widgetTable[-1].append( QLineEdit() )
self.widgetTable[-1][-1].setMinimumWidth(relaxedSizeNChar(GETFONT('var'), 33)[0])
self.widgetTable[-1][-1].setMinimumWidth(relaxedSizeNChar(GETFONT('var'), 40)[0])
self.widgetTable[-1][-1].setMaximumHeight(self.maxHeight)
self.widgetTable[-1][-1].setFont(GETFONT('var'))
self.widgetTable[-1][-1].setFont(GETFONT('var',9))

self.widgetTable[-1].append( QLabel('BTC:') )

Expand All @@ -3809,9 +3809,8 @@ def makeRecipFrame(self, nRecip):
self.widgetTable[-1][-1].setAlignment(Qt.AlignRight)

self.widgetTable[-1].append( QLabel('Comment:') )

self.widgetTable[-1].append( QLineEdit() )
self.widgetTable[-1][-1].setFont(GETFONT('var'))
self.widgetTable[-1][-1].setFont(GETFONT('var', 9))
self.widgetTable[-1][-1].setMaximumHeight(self.maxHeight)

if i<nRecip and i<prevNRecip:
Expand Down Expand Up @@ -5393,7 +5392,7 @@ def __init__(self, pytx, wlt=None, parent=None, main=None, mode=None, \
lbls[-1].append(createToolTipObject('Comment stored for this transaction in this wallet'))
lbls[-1].append(QLabel('User Comment:'))
if wlt.getComment(txHash):
lbls[-1].append(QLabel(wlt.getComment(txHash)))
lbls[-1].append(QRichLabel(wlt.getComment(txHash)))
else:
lbls[-1].append(QRichLabel('<font color="gray">[None]</font>'))

Expand Down

0 comments on commit 1765f2e

Please sign in to comment.