Browse Source

adds userName to transaction

miguelfreitas
Miguel Freitas 12 years ago
parent
commit
9cb71491a6
  1. 6
      src/chainparams.cpp
  2. 10
      src/core.cpp
  3. 11
      src/core.h
  4. 28
      src/main.cpp
  5. 4
      src/qt/transactionrecord.cpp
  6. 2
      src/rpcmining.cpp
  7. 10
      src/rpcwallet.cpp
  8. 14
      src/wallet.cpp
  9. 6
      src/wallet.h

6
src/chainparams.cpp

@ -51,10 +51,12 @@ public:
genesis.hashMerkleRoot = genesis.BuildMerkleTree(); genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.nVersion = 1; genesis.nVersion = 1;
genesis.nTime = 1231006505; genesis.nTime = 1231006505;
genesis.nBits = 0x1d00ffff; genesis.nBits = 0x207fffff;
genesis.nNonce = 2083236893; genesis.nNonce = 0;
hashGenesisBlock = genesis.GetHash(); hashGenesisBlock = genesis.GetHash();
printf("hashGenesisBlock %s\n", hashGenesisBlock.ToString().c_str());
printf("genesis.hashMerkleRoot %s\n", genesis.hashMerkleRoot.ToString().c_str());
//assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")); //assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
//assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")); //assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));

10
src/core.cpp

@ -87,9 +87,13 @@ std::string CTransaction::ToString() const
message.size(), message.size(),
userID.size(), userID.size(),
pubKey.size()); pubKey.size());
str += " " + message.ToString() + "\n"; if( message.size() ) {
str += " " + userID.ToString() + "\n"; str += " message: " + message.ToString() + "\n";
str += " " + pubKey.ToString() + "\n"; } else {
str += " userName: " + userName.ToString() + "\n";
str += " userID: " + userID.ToString() + "\n";
str += " pubKey: " + pubKey.ToString() + "\n";
}
return str; return str;
} }

11
src/core.h

@ -183,6 +183,7 @@ public:
static const int CURRENT_VERSION=1; static const int CURRENT_VERSION=1;
int nVersion; int nVersion;
CScript message; CScript message;
CScript userName;
CScript userID; CScript userID;
CScript pubKey; CScript pubKey;
//std::vector<CTxIn> vin; //std::vector<CTxIn> vin;
@ -199,6 +200,7 @@ public:
READWRITE(this->nVersion); READWRITE(this->nVersion);
nVersion = this->nVersion; nVersion = this->nVersion;
READWRITE(message); READWRITE(message);
READWRITE(userName);
READWRITE(userID); READWRITE(userID);
READWRITE(pubKey); READWRITE(pubKey);
) )
@ -207,21 +209,21 @@ public:
{ {
nVersion = CTransaction::CURRENT_VERSION; nVersion = CTransaction::CURRENT_VERSION;
message.clear(); message.clear();
userName.clear();
userID.clear(); userID.clear();
pubKey.clear(); pubKey.clear();
} }
bool IsNull() const bool IsNull() const
{ {
return (message.empty() && userID.empty() && pubKey.empty()); return (message.empty() && userName.empty() && userID.empty() && pubKey.empty());
} }
uint256 GetHash() const; uint256 GetHash() const;
bool IsNewerThan(const CTransaction& old) const; bool IsNewerThan(const CTransaction& old) const;
bool IsCoinBase() const bool IsSpamMessage() const
{ {
//[MF] reusing coinbase as spam string
return (!message.empty() && userID.empty() && pubKey.empty()); return (!message.empty() && userID.empty() && pubKey.empty());
} }
@ -229,6 +231,7 @@ public:
{ {
return (a.nVersion == b.nVersion && return (a.nVersion == b.nVersion &&
a.message == b.message && a.message == b.message &&
a.userName == b.userName &&
a.userID == b.userID && a.userID == b.userID &&
a.pubKey == b.pubKey); a.pubKey == b.pubKey);
} }
@ -393,7 +396,7 @@ public:
int nVersion; int nVersion;
// construct a CCoins from a CTransaction, at a given height // construct a CCoins from a CTransaction, at a given height
CCoins(const CTransaction &tx, int nHeightIn) : fCoinBase(tx.IsCoinBase()), vout(), nHeight(nHeightIn), nVersion(tx.nVersion) { } CCoins(const CTransaction &tx, int nHeightIn) : fCoinBase(tx.IsSpamMessage()), vout(), nHeight(nHeightIn), nVersion(tx.nVersion) { }
// empty constructor // empty constructor
CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { } CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }

28
src/main.cpp

@ -575,7 +575,7 @@ int64 GetValueOut(const CTransaction& tx)
// //
bool AreInputsStandard(const CTransaction& tx, CCoinsViewCache& mapInputs) bool AreInputsStandard(const CTransaction& tx, CCoinsViewCache& mapInputs)
{ {
if (tx.IsCoinBase()) if (tx.IsSpamMessage())
return true; // Coinbases don't use vin normally return true; // Coinbases don't use vin normally
/* [MF] /* [MF]
for (unsigned int i = 0; i < tx.vin.size(); i++) for (unsigned int i = 0; i < tx.vin.size(); i++)
@ -645,7 +645,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx)
unsigned int GetP2SHSigOpCount(const CTransaction& tx, CCoinsViewCache& inputs) unsigned int GetP2SHSigOpCount(const CTransaction& tx, CCoinsViewCache& inputs)
{ {
if (tx.IsCoinBase()) if (tx.IsSpamMessage())
return 0; return 0;
unsigned int nSigOps = 0; unsigned int nSigOps = 0;
@ -820,7 +820,7 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fLimitFr
return error("CTxMemPool::accept() : CheckTransaction failed"); return error("CTxMemPool::accept() : CheckTransaction failed");
// Coinbase is only valid in a block, not as a loose transaction // Coinbase is only valid in a block, not as a loose transaction
if (tx.IsCoinBase()) if (tx.IsSpamMessage())
return state.DoS(100, error("CTxMemPool::accept() : coinbase as individual tx")); return state.DoS(100, error("CTxMemPool::accept() : coinbase as individual tx"));
/* /*
@ -1092,7 +1092,7 @@ int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
int CMerkleTx::GetBlocksToMaturity() const int CMerkleTx::GetBlocksToMaturity() const
{ {
if (!IsCoinBase()) if (!IsSpamMessage())
return 0; return 0;
return max(0, (COINBASE_MATURITY+20) - GetDepthInMainChain()); return max(0, (COINBASE_MATURITY+20) - GetDepthInMainChain());
} }
@ -1113,7 +1113,7 @@ bool CWalletTx::AcceptWalletTransaction()
// Add previous supporting transactions first // Add previous supporting transactions first
BOOST_FOREACH(CMerkleTx& tx, vtxPrev) BOOST_FOREACH(CMerkleTx& tx, vtxPrev)
{ {
if (!tx.IsCoinBase()) if (!tx.IsSpamMessage())
{ {
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();
if (!mempool.exists(hash) && pcoinsTip->HaveCoins(hash)) if (!mempool.exists(hash) && pcoinsTip->HaveCoins(hash))
@ -1523,7 +1523,7 @@ const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input)
int64 CCoinsViewCache::GetValueIn(const CTransaction& tx) int64 CCoinsViewCache::GetValueIn(const CTransaction& tx)
{ {
if (tx.IsCoinBase()) if (tx.IsSpamMessage())
return 0; return 0;
int64 nResult = 0; int64 nResult = 0;
@ -1537,7 +1537,7 @@ int64 CCoinsViewCache::GetValueIn(const CTransaction& tx)
void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash) void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash)
{ {
// mark inputs spent // mark inputs spent
if (!tx.IsCoinBase()) { if (!tx.IsSpamMessage()) {
/* [MF] /* [MF]
BOOST_FOREACH(const CTxIn &txin, tx.vin) { BOOST_FOREACH(const CTxIn &txin, tx.vin) {
CCoins &coins = inputs.GetCoins(txin.prevout.hash); CCoins &coins = inputs.GetCoins(txin.prevout.hash);
@ -1554,7 +1554,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
bool CCoinsViewCache::HaveInputs(const CTransaction& tx) bool CCoinsViewCache::HaveInputs(const CTransaction& tx)
{ {
if (!tx.IsCoinBase()) { if (!tx.IsSpamMessage()) {
/* [MF] /* [MF]
// first check whether information about the prevout hash is available // first check whether information about the prevout hash is available
for (unsigned int i = 0; i < tx.vin.size(); i++) { for (unsigned int i = 0; i < tx.vin.size(); i++) {
@ -1594,7 +1594,7 @@ bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned in
bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, std::vector<CScriptCheck> *pvChecks) bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, std::vector<CScriptCheck> *pvChecks)
{ {
if (!tx.IsCoinBase()) if (!tx.IsSpamMessage())
{ {
/* [MF] /* [MF]
if (pvChecks) if (pvChecks)
@ -1886,7 +1886,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
*/ */
CTxUndo txundo; CTxUndo txundo;
UpdateCoins(tx, state, view, txundo, pindex->nHeight, block.GetTxHash(i)); UpdateCoins(tx, state, view, txundo, pindex->nHeight, block.GetTxHash(i));
if (!tx.IsCoinBase()) if (!tx.IsSpamMessage())
blockundo.vtxundo.push_back(txundo); blockundo.vtxundo.push_back(txundo);
vPos.push_back(std::make_pair(block.GetTxHash(i), pos)); vPos.push_back(std::make_pair(block.GetTxHash(i), pos));
@ -1997,7 +1997,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
// We only do this for blocks after the last checkpoint (reorganisation before that // We only do this for blocks after the last checkpoint (reorganisation before that
// point should only happen with -reindex/-loadblock, or a misbehaving peer. // point should only happen with -reindex/-loadblock, or a misbehaving peer.
BOOST_FOREACH(const CTransaction& tx, block.vtx) BOOST_FOREACH(const CTransaction& tx, block.vtx)
if (!tx.IsCoinBase() && pindex->nHeight > Checkpoints::GetTotalBlocksEstimate()) if (!tx.IsSpamMessage() && pindex->nHeight > Checkpoints::GetTotalBlocksEstimate())
vResurrect.push_back(tx); vResurrect.push_back(tx);
} }
@ -2281,10 +2281,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
return state.Invalid(error("CheckBlock() : block timestamp too far in the future")); return state.Invalid(error("CheckBlock() : block timestamp too far in the future"));
// First transaction must be coinbase, the rest must not be // First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase()) if (block.vtx.empty() || !block.vtx[0].IsSpamMessage())
return state.DoS(100, error("CheckBlock() : first tx is not coinbase")); return state.DoS(100, error("CheckBlock() : first tx is not coinbase"));
for (unsigned int i = 1; i < block.vtx.size(); i++) for (unsigned int i = 1; i < block.vtx.size(); i++)
if (block.vtx[i].IsCoinBase()) if (block.vtx[i].IsSpamMessage())
return state.DoS(100, error("CheckBlock() : more than one coinbase")); return state.DoS(100, error("CheckBlock() : more than one coinbase"));
// Check transactions // Check transactions
@ -4367,7 +4367,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi) for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
{ {
CTransaction& tx = (*mi).second; CTransaction& tx = (*mi).second;
if (tx.IsCoinBase() || !IsFinalTx(tx)) if (tx.IsSpamMessage() || !IsFinalTx(tx))
continue; continue;
COrphan* porphan = NULL; COrphan* porphan = NULL;

4
src/qt/transactionrecord.cpp

@ -7,7 +7,7 @@
*/ */
bool TransactionRecord::showTransaction(const CWalletTx &wtx) bool TransactionRecord::showTransaction(const CWalletTx &wtx)
{ {
if (wtx.IsCoinBase()) if (wtx.IsSpamMessage())
{ {
// Ensures we show generated coins / mined transactions at depth 1 // Ensures we show generated coins / mined transactions at depth 1
if (!wtx.IsInMainChain()) if (!wtx.IsInMainChain())
@ -155,7 +155,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
// Sort order, unrecorded transactions sort to the top // Sort order, unrecorded transactions sort to the top
status.sortKey = strprintf("%010d-%01d-%010u-%03d", status.sortKey = strprintf("%010d-%01d-%010u-%03d",
(pindex ? pindex->nHeight : std::numeric_limits<int>::max()), (pindex ? pindex->nHeight : std::numeric_limits<int>::max()),
(wtx.IsCoinBase() ? 1 : 0), (wtx.IsSpamMessage() ? 1 : 0),
wtx.nTimeReceived, wtx.nTimeReceived,
idx); idx);
status.confirmed = wtx.IsConfirmed(); status.confirmed = wtx.IsConfirmed();

2
src/rpcmining.cpp

@ -304,7 +304,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
uint256 txHash = tx.GetHash(); uint256 txHash = tx.GetHash();
setTxIndex[txHash] = i++; setTxIndex[txHash] = i++;
if (tx.IsCoinBase()) if (tx.IsSpamMessage())
continue; continue;
Object entry; Object entry;

10
src/rpcwallet.cpp

@ -36,7 +36,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
{ {
int confirms = wtx.GetDepthInMainChain(); int confirms = wtx.GetDepthInMainChain();
entry.push_back(Pair("confirmations", confirms)); entry.push_back(Pair("confirmations", confirms));
if (wtx.IsCoinBase()) if (wtx.IsSpamMessage())
entry.push_back(Pair("generated", true)); entry.push_back(Pair("generated", true));
if (confirms) if (confirms)
{ {
@ -408,7 +408,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !IsFinalTx(wtx)) if (wtx.IsSpamMessage() || !IsFinalTx(wtx))
continue; continue;
/* /*
BOOST_FOREACH(const CTxOut& txout, wtx.vout) BOOST_FOREACH(const CTxOut& txout, wtx.vout)
@ -455,7 +455,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !IsFinalTx(wtx)) if (wtx.IsSpamMessage() || !IsFinalTx(wtx))
continue; continue;
/* /*
BOOST_FOREACH(const CTxOut& txout, wtx.vout) BOOST_FOREACH(const CTxOut& txout, wtx.vout)
@ -841,7 +841,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !IsFinalTx(wtx)) if (wtx.IsSpamMessage() || !IsFinalTx(wtx))
continue; continue;
int nDepth = wtx.GetDepthInMainChain(); int nDepth = wtx.GetDepthInMainChain();
@ -997,7 +997,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
Object entry; Object entry;
entry.push_back(Pair("account", account)); entry.push_back(Pair("account", account));
entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString())); entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString()));
if (wtx.IsCoinBase()) if (wtx.IsSpamMessage())
{ {
if (wtx.GetDepthInMainChain() < 1) if (wtx.GetDepthInMainChain() < 1)
entry.push_back(Pair("category", "orphan")); entry.push_back(Pair("category", "orphan"));

14
src/wallet.cpp

@ -629,7 +629,7 @@ int CWalletTx::GetRequestCount() const
int nRequests = -1; int nRequests = -1;
{ {
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
if (IsCoinBase()) if (IsSpamMessage())
{ {
// Generated block // Generated block
if (hashBlock != 0) if (hashBlock != 0)
@ -838,7 +838,7 @@ void CWallet::ReacceptWalletTransactions()
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{ {
CWalletTx& wtx = item.second; CWalletTx& wtx = item.second;
if (wtx.IsCoinBase() && wtx.IsSpent(0)) if (wtx.IsSpamMessage() && wtx.IsSpent(0))
continue; continue;
CCoins coins; CCoins coins;
@ -870,7 +870,7 @@ void CWallet::ReacceptWalletTransactions()
else else
{ {
// Re-accept any txes of ours that aren't already in a block // Re-accept any txes of ours that aren't already in a block
if (!wtx.IsCoinBase()) if (!wtx.IsSpamMessage())
wtx.AcceptWalletTransaction(); wtx.AcceptWalletTransaction();
} }
} }
@ -887,11 +887,11 @@ void CWalletTx::RelayWalletTransaction()
{ {
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
{ {
if (!tx.IsCoinBase()) if (!tx.IsSpamMessage())
if (tx.GetDepthInMainChain() == 0) if (tx.GetDepthInMainChain() == 0)
RelayTransaction((CTransaction)tx, tx.GetHash()); RelayTransaction((CTransaction)tx, tx.GetHash());
} }
if (!IsCoinBase()) if (!IsSpamMessage())
{ {
if (GetDepthInMainChain() == 0) { if (GetDepthInMainChain() == 0) {
uint256 hash = GetHash(); uint256 hash = GetHash();
@ -1014,7 +1014,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed) const
if (fOnlyConfirmed && !pcoin->IsConfirmed()) if (fOnlyConfirmed && !pcoin->IsConfirmed())
continue; continue;
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) if (pcoin->IsSpamMessage() && pcoin->GetBlocksToMaturity() > 0)
continue; continue;
/* /*
for (unsigned int i = 0; i < pcoin->vout.size(); i++) { for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
@ -1708,7 +1708,7 @@ std::map<CTxDestination, int64> CWallet::GetAddressBalances()
if (!IsFinalTx(*pcoin) || !pcoin->IsConfirmed()) if (!IsFinalTx(*pcoin) || !pcoin->IsConfirmed())
continue; continue;
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) if (pcoin->IsSpamMessage() && pcoin->GetBlocksToMaturity() > 0)
continue; continue;
int nDepth = pcoin->GetDepthInMainChain(); int nDepth = pcoin->GetDepthInMainChain();

6
src/wallet.h

@ -585,7 +585,7 @@ public:
int64 GetCredit(bool fUseCache=true) const int64 GetCredit(bool fUseCache=true) const
{ {
// Must wait until coinbase is safely deep enough in the chain before valuing it // Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0) if (IsSpamMessage() && GetBlocksToMaturity() > 0)
return 0; return 0;
// GetBalance can assume transactions in mapWallet won't change // GetBalance can assume transactions in mapWallet won't change
@ -598,7 +598,7 @@ public:
int64 GetImmatureCredit(bool fUseCache=true) const int64 GetImmatureCredit(bool fUseCache=true) const
{ {
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) if (IsSpamMessage() && GetBlocksToMaturity() > 0 && IsInMainChain())
{ {
if (fUseCache && fImmatureCreditCached) if (fUseCache && fImmatureCreditCached)
return nImmatureCreditCached; return nImmatureCreditCached;
@ -613,7 +613,7 @@ public:
int64 GetAvailableCredit(bool fUseCache=true) const int64 GetAvailableCredit(bool fUseCache=true) const
{ {
// Must wait until coinbase is safely deep enough in the chain before valuing it // Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0) if (IsSpamMessage() && GetBlocksToMaturity() > 0)
return 0; return 0;
if (fUseCache && fAvailableCreditCached) if (fUseCache && fAvailableCreditCached)

Loading…
Cancel
Save