Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
proofbuilder.cpp
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
6
7#include <random.h>
8
9namespace avalanche {
10
12 bool is_coinbase, CKey key) {
13 if (!key.IsValid()) {
14 return false;
15 }
16
18 auto stake =
19 Stake(std::move(utxo), amount, height, is_coinbase, key.GetPubKey());
20 const uint256 h = stake.getHash(commitment);
22 if (!key.SignSchnorr(h, sig)) {
23 sig.fill(0);
24 }
25
26 return stakes.emplace(std::move(stake), std::move(sig)).second;
27}
28
31 const LimitedProofId limitedProofId = getLimitedProofId();
32 if (!masterKey.SignSchnorr(limitedProofId, proofSignature)) {
33 proofSignature.fill(0);
34 }
35 std::vector<SignedStake> signedStakes;
36 signedStakes.reserve(stakes.size());
37
38 while (!stakes.empty()) {
39 auto handle = stakes.extract(stakes.begin());
40 signedStakes.push_back(handle.value());
41 }
42
45 std::move(proofSignature));
46}
47
49 HashWriter ss{};
50 ss << sequence;
53
54 WriteCompactSize(ss, stakes.size());
55 for (const auto &s : stakes) {
56 ss << s.getStake();
57 }
58
59 return LimitedProofId(ss.GetHash());
60}
61
63 HashWriter ss{};
66
67 return ProofId(ss.GetHash());
68}
69
70} // namespace avalanche
An encapsulated secp256k1 private key.
Definition key.h:28
bool IsValid() const
Check whether this private key is valid.
Definition key.h:97
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition key.cpp:210
bool SignSchnorr(const uint256 &hash, SchnorrSig &sig, uint32_t test_case=0) const
Create a Schnorr signature.
Definition key.cpp:288
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:20
A writer stream (for serialization) that computes a 256-bit hash.
Definition hash.h:100
static RCUPtr make(Args &&...args)
Construct a new object that is owned by the pointer.
Definition rcu.h:112
bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key)
std::set< SignedStake, SignedStakeComparator > stakes
ProofId getProofId() const
LimitedProofId getLimitedProofId() const
256-bit opaque blob.
Definition uint256.h:129
std::array< uint8_t, CPubKey::SCHNORR_SIZE > SchnorrSig
a Schnorr signature
Definition key.h:25
SchnorrSig sig
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
Definition serialize.h:1254