Skip to content

Commit

Permalink
move transaction to primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Feb 2, 2021
1 parent f678144 commit 6a121ef
Show file tree
Hide file tree
Showing 26 changed files with 1,519 additions and 1,391 deletions.
9 changes: 9 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ GRIDCOIN_CORE_H = \
gridcoin/voting/result.h \
gridcoin/voting/vote.h \
hash.h \
index/disktxpos.h \
index/txindex.h \
init.h \
key.h \
keystore.h \
Expand All @@ -137,7 +139,9 @@ GRIDCOIN_CORE_H = \
netbase.h \
net.h \
pbkdf2.h \
policy/fees.h \
prevector.h \
primitives/transaction.h \
protocol.h \
reverselock.h \
rpc/client.h \
Expand Down Expand Up @@ -166,6 +170,7 @@ GRIDCOIN_CORE_H = \
util/threadnames.h \
util/time.h \
util.h \
validation.h \
version.h \
wallet/coincontrol.h \
wallet/db.h \
Expand Down Expand Up @@ -206,6 +211,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
gridcoin/superblock.cpp \
gridcoin/support/block_finder.cpp \
gridcoin/tally.cpp \
gridcoin/tx_message.cpp \
gridcoin/upgrade.cpp \
gridcoin/voting/builders.cpp \
gridcoin/voting/claims.cpp \
Expand All @@ -223,6 +229,8 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
net.cpp \
noui.cpp \
pbkdf2.cpp \
policy/fees.cpp \
primitives/transaction.cpp \
protocol.cpp \
rpc/blockchain.cpp \
rpc/client.cpp \
Expand All @@ -248,6 +256,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
util/threadnames.cpp \
util/time.cpp \
util.cpp \
validation.cpp \
version.cpp \
wallet/db.cpp \
wallet/rpcdump.cpp \
Expand Down
6 changes: 4 additions & 2 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "amount.h"

static const int LAST_POW_BLOCK = 2050;
static const int CONSENSUS_LOOKBACK = 5; //Amount of blocks to go back from best block, to avoid counting forked blocks
static const int BLOCK_GRANULARITY = 10; //Consensus block divisor
Expand All @@ -20,6 +22,6 @@ static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
/** The maximum number of entries in an 'inv' protocol message */
static const unsigned int MAX_INV_SZ = 50000;
/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
static const int64_t MIN_TX_FEE = 10000;
static const CAmount MIN_TX_FEE = 10000;
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */
static const int64_t MIN_RELAY_TX_FEE = MIN_TX_FEE;
static const CAmount MIN_RELAY_TX_FEE = MIN_TX_FEE;
27 changes: 27 additions & 0 deletions src/gridcoin/tx_message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2014-2020 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <string>

#include "gridcoin/support/xml.h"
#include "gridcoin/tx_message.h"

std::string GetMessage(const CTransaction& tx)
{
if (tx.nVersion <= 1) {
return ExtractXML(tx.hashBoinc, "<MESSAGE>", "</MESSAGE>");
}

if (tx.vContracts.empty()) {
return std::string();
}

if (tx.vContracts.front().m_type != GRC::ContractType::MESSAGE) {
return std::string();
}

const auto payload = tx.vContracts.front().SharePayloadAs<GRC::TxMessage>();

return payload->m_message;
}
6 changes: 6 additions & 0 deletions src/gridcoin/tx_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "gridcoin/contract/payload.h"
#include "primitives/transaction.h"

#include <string>

Expand Down Expand Up @@ -103,3 +104,8 @@ class TxMessage : public IContractPayload
}
}; // TxMessage
}

//!
//! \brief Get the custom, user-supplied transaction message, if any.
//!
std::string GetMessage(const CTransaction& tx);
3 changes: 2 additions & 1 deletion src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "gridcoin/voting/vote.h"
#include "txdb.h"
#include "ui_interface.h"
#include "validation.h"

using namespace GRC;
using LogFlags = BCLog::LogFlags;
Expand Down Expand Up @@ -149,7 +150,7 @@ class PollClaimValidator

CTransaction tx;

if (!tx.ReadFromDisk(tx_index.pos)) {
if (!ReadTxFromDisk(tx, tx_index.pos)) {
throw InvalidPollError();
}

Expand Down
65 changes: 65 additions & 0 deletions src/index/disktxpos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2019-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_INDEX_DISKTXPOS_H
#define BITCOIN_INDEX_DISKTXPOS_H

#include <serialize.h>
#include "tinyformat.h"

/** Position on disk for a particular transaction. */
class CDiskTxPos
{
public:
unsigned int nFile;
unsigned int nBlockPos;
unsigned int nTxPos;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(nFile);
READWRITE(nBlockPos);
READWRITE(nTxPos);
}

CDiskTxPos()
{
SetNull();
}

CDiskTxPos(unsigned int nFileIn, unsigned int nBlockPosIn, unsigned int nTxPosIn)
{
nFile = nFileIn;
nBlockPos = nBlockPosIn;
nTxPos = nTxPosIn;
}

void SetNull() { nFile = (unsigned int) -1; nBlockPos = 0; nTxPos = 0; }
bool IsNull() const { return (nFile == (unsigned int) -1); }

friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b)
{
return (a.nFile == b.nFile &&
a.nBlockPos == b.nBlockPos &&
a.nTxPos == b.nTxPos);
}

friend bool operator!=(const CDiskTxPos& a, const CDiskTxPos& b)
{
return !(a == b);
}

std::string ToString() const
{
if (IsNull())
return "null";
else
return strprintf("(nFile=%u, nBlockPos=%u, nTxPos=%u)", nFile, nBlockPos, nTxPos);
}
};

#endif // BITCOIN_INDEX_DISKTXPOS_H
66 changes: 66 additions & 0 deletions src/index/txindex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2017-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_INDEX_TXINDEX_H
#define BITCOIN_INDEX_TXINDEX_H

/** A txdb record that contains the disk location of a transaction and the
* locations of transactions that spend its outputs. vSpent is really only
* used as a flag, but having the location is very helpful for debugging.
*/
class CTxIndex
{
public:
CDiskTxPos pos;
std::vector<CDiskTxPos> vSpent;

CTxIndex()
{
SetNull();
}

CTxIndex(const CDiskTxPos& posIn, unsigned int nOutputs)
{
pos = posIn;
vSpent.resize(nOutputs);
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
if (!(s.GetType() & SER_GETHASH)) {
int nVersion = s.GetVersion();
READWRITE(nVersion);
}

READWRITE(pos);
READWRITE(vSpent);
}

void SetNull()
{
pos.SetNull();
vSpent.clear();
}

bool IsNull()
{
return pos.IsNull();
}

friend bool operator==(const CTxIndex& a, const CTxIndex& b)
{
return (a.pos == b.pos &&
a.vSpent == b.vSpent);
}

friend bool operator!=(const CTxIndex& a, const CTxIndex& b)
{
return !(a == b);
}
};

#endif // BITCOIN_INDEX_TXINDEX_H
Loading

0 comments on commit 6a121ef

Please sign in to comment.