Bitcoin ABC  0.24.7
P2P Digital Currency
proofbuilder.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_AVALANCHE_PROOFBUILDER_H
6 #define BITCOIN_AVALANCHE_PROOFBUILDER_H
7 
8 #include <avalanche/proof.h>
9 #include <key.h>
10 
11 #include <cstdio>
12 
13 namespace avalanche {
14 
15 struct TestProofBuilder;
16 
17 class ProofBuilder {
18  uint64_t sequence;
19  int64_t expirationTime;
22 
23  struct StakeSigner {
26 
27  StakeSigner(Stake stake_, CKey key_)
28  : stake(std::move(stake_)), key(std::move(key_)) {}
29 
30  SignedStake sign(const StakeCommitment &commitment);
31  };
32 
34  bool operator()(const StakeSigner &lhs, const StakeSigner &rhs) const {
35  return lhs.stake.getId() < rhs.stake.getId();
36  }
37  };
38  std::set<StakeSigner, StakeSignerComparator> stakes;
39 
40 public:
41  ProofBuilder(uint64_t sequence_, int64_t expirationTime_, CKey masterKey_,
42  const CScript &payoutScriptPubKey_ = CScript())
43  : sequence(sequence_), expirationTime(expirationTime_),
44  masterKey(std::move(masterKey_)),
45  payoutScriptPubKey(payoutScriptPubKey_) {}
46 
47  [[nodiscard]] bool addUTXO(COutPoint utxo, Amount amount, uint32_t height,
48  bool is_coinbase, CKey key);
49 
50  ProofRef build();
51 
52 private:
54  ProofId getProofId() const;
55 
56  friend struct TestProofBuilder;
57 };
58 
59 } // namespace avalanche
60 
61 #endif // BITCOIN_AVALANCHE_PROOFBUILDER_H
avalanche::ProofBuilder
Definition: proofbuilder.h:17
avalanche::ProofBuilder::StakeSigner::key
CKey key
Definition: proofbuilder.h:25
avalanche::ProofBuilder::StakeSigner::sign
SignedStake sign(const StakeCommitment &commitment)
Definition: proofbuilder.cpp:12
avalanche
Definition: avalanche.h:11
avalanche::ProofBuilder::expirationTime
int64_t expirationTime
Definition: proofbuilder.h:19
avalanche::ProofBuilder::StakeSigner
Definition: proofbuilder.h:23
avalanche::ProofBuilder::getLimitedProofId
LimitedProofId getLimitedProofId() const
Definition: proofbuilder.cpp:61
avalanche::ProofBuilder::StakeSignerComparator
Definition: proofbuilder.h:33
avalanche::SignedStake
Definition: proof.h:85
avalanche::ProofId
Definition: proofid.h:17
avalanche::TestProofBuilder
Definition: util.h:23
avalanche::ProofBuilder::addUTXO
bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key)
Definition: proofbuilder.cpp:23
avalanche::ProofBuilder::StakeSigner::stake
Stake stake
Definition: proofbuilder.h:24
avalanche::ProofBuilder::build
ProofRef build()
Definition: proofbuilder.cpp:36
avalanche::Stake
Definition: proof.h:50
avalanche::StakeCommitment
Definition: proof.h:43
avalanche::ProofBuilder::StakeSigner::StakeSigner
StakeSigner(Stake stake_, CKey key_)
Definition: proofbuilder.h:27
avalanche::ProofBuilder::ProofBuilder
ProofBuilder(uint64_t sequence_, int64_t expirationTime_, CKey masterKey_, const CScript &payoutScriptPubKey_=CScript())
Definition: proofbuilder.h:41
avalanche::ProofBuilder::getProofId
ProofId getProofId() const
Definition: proofbuilder.cpp:78
avalanche::ProofBuilder::payoutScriptPubKey
CScript payoutScriptPubKey
Definition: proofbuilder.h:21
avalanche::ProofBuilder::StakeSignerComparator::operator()
bool operator()(const StakeSigner &lhs, const StakeSigner &rhs) const
Definition: proofbuilder.h:34
avalanche::LimitedProofId
Definition: proofid.h:28
Amount
Definition: amount.h:19
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
key.h
CKey
An encapsulated secp256k1 private key.
Definition: key.h:28
proof.h
avalanche::Stake::getId
const StakeId & getId() const
Definition: proof.h:82
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
avalanche::ProofRef
std::shared_ptr< const Proof > ProofRef
Definition: proof.h:163
avalanche::ProofBuilder::stakes
std::set< StakeSigner, StakeSignerComparator > stakes
Definition: proofbuilder.h:38
avalanche::ProofBuilder::sequence
uint64_t sequence
Definition: proofbuilder.h:18
avalanche::ProofBuilder::masterKey
CKey masterKey
Definition: proofbuilder.h:20