Skip to content

Commit

Permalink
Remove print() from core functions
Browse files Browse the repository at this point in the history
Break dependency on util.
  • Loading branch information
laanwj committed Aug 20, 2014
1 parent dd28197 commit 8121258
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
38 changes: 9 additions & 29 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ std::string COutPoint::ToString() const
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
}

void COutPoint::print() const
{
LogPrintf("%s\n", ToString());
}

CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, unsigned int nSequenceIn)
{
prevout = prevoutIn;
Expand Down Expand Up @@ -46,11 +41,6 @@ std::string CTxIn::ToString() const
return str;
}

void CTxIn::print() const
{
LogPrintf("%s\n", ToString());
}

CTxOut::CTxOut(int64_t nValueIn, CScript scriptPubKeyIn)
{
nValue = nValueIn;
Expand All @@ -67,11 +57,6 @@ std::string CTxOut::ToString() const
return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30));
}

void CTxOut::print() const
{
LogPrintf("%s\n", ToString());
}

CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
{
if (nSize > 0)
Expand All @@ -92,8 +77,7 @@ int64_t CFeeRate::GetFee(size_t nSize) const

std::string CFeeRate::ToString() const
{
std::string result = FormatMoney(nSatoshisPerK) + " BTC/kB";
return result;
return strprintf("%d.%08d BTC/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
}

CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
Expand Down Expand Up @@ -171,11 +155,6 @@ std::string CTransaction::ToString() const
return str;
}

void CTransaction::print() const
{
LogPrintf("%s", ToString());
}

// Amount compression:
// * If the amount is 0, output 0
// * first, divide the amount (in base units) by the largest power of 10 possible; call the exponent e (e is max 9)
Expand Down Expand Up @@ -285,9 +264,10 @@ uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMer
return hash;
}

void CBlock::print() const
std::string CBlock::ToString() const
{
LogPrintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
Expand All @@ -296,11 +276,11 @@ void CBlock::print() const
vtx.size());
for (unsigned int i = 0; i < vtx.size(); i++)
{
LogPrintf(" ");
vtx[i].print();
s << " " << vtx[i].ToString() << "\n";
}
LogPrintf(" vMerkleTree: ");
s << " vMerkleTree: ";
for (unsigned int i = 0; i < vMerkleTree.size(); i++)
LogPrintf("%s ", vMerkleTree[i].ToString());
LogPrintf("\n");
s << " " << vMerkleTree[i].ToString();
s << "\n";
return s.str();
}
6 changes: 1 addition & 5 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class COutPoint
}

std::string ToString() const;
void print() const;
};

/** An inpoint - a combination of a transaction and an index n into its vin */
Expand Down Expand Up @@ -107,7 +106,6 @@ class CTxIn
}

std::string ToString() const;
void print() const;
};


Expand Down Expand Up @@ -200,7 +198,6 @@ class CTxOut
}

std::string ToString() const;
void print() const;
};


Expand Down Expand Up @@ -279,7 +276,6 @@ class CTransaction
}

std::string ToString() const;
void print() const;
};

/** A mutable version of CTransaction. */
Expand Down Expand Up @@ -497,7 +493,7 @@ class CBlock : public CBlockHeader

std::vector<uint256> GetMerkleBranch(int nIndex) const;
static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex);
void print() const;
std::string ToString() const;
};


Expand Down
3 changes: 1 addition & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ bool AppInit2(boost::thread_group& threadGroup)
CBlock block;
ReadBlockFromDisk(block, pindex);
block.BuildMerkleTree();
block.print();
LogPrintf("\n");
LogPrintf("%s\n", block.ToString());
nFound++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)

bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
{
pblock->print();
LogPrintf("%s\n", pblock->ToString());
LogPrintf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue));

// Found a solution
Expand Down

0 comments on commit 8121258

Please sign in to comment.