Files
thehub/libs/p2p/BroadcastTxData.h
T
TomZ 652fc1e161 Introduce structure to broadcast transactions.
To send out transactions in the p2p net is quite a lot of work,
you need to find multiple peers to send the transaction to. First
you send an INV, then you respond to a getData to actually send
the transaction and last you wait for 'reject' messages that may
indicate that there is something wrong with the transaction.

This introduces the BroadcastTxData class that wraps a transaction
and gets callbacks for sending and for rejects, abstracting away
all the complexity for the user.
2020-06-08 21:35:10 +02:00

49 lines
1.1 KiB
C++

#ifndef BROADCASTTXDATA_H
#define BROADCASTTXDATA_H
#include <primitives/FastTransaction.h>
#include <string>
class BroadcastTxData
{
public:
BroadcastTxData(const Tx &tx);
virtual ~BroadcastTxData();
enum RejectReason {
InvalidTx = 0x10,
DoubleSpend = 0x12,
NonStandard = 0x40,
Dust = 0x41,
LowFee = 0x42
};
/**
* @brief txRejected is called with the remote peers reject message.
* @param reason the reason for the reject, notice that this is foreign input from
* a random node on the Intenet. The value doesn't have to be included in
the enum.
* @param message
*/
virtual void txRejected(RejectReason reason, const std::string &message) = 0;
virtual void sentOne() = 0;
/// the wallet, or privacy segment this transaction is associated with.
virtual uint16_t privSegment() const = 0;
inline Tx transaction() const {
return m_tx;
}
inline const uint256 &hash() const {
return m_hash;
}
private:
const Tx m_tx;
const uint256 m_hash;
};
#endif