Bitcoin ABC  0.22.12
P2P Digital Currency
util.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 
5 #include <amount.h>
7 #include <avalanche/test/util.h>
8 #include <key.h>
10 #include <random.h>
11 #include <script/standard.h>
12 #include <validation.h>
13 
14 #include <limits>
15 
16 namespace avalanche {
17 
18 Proof buildRandomProof(uint32_t score, const CPubKey &master) {
19  CKey key;
20  key.MakeNewKey(true);
21 
22  const COutPoint o(TxId(GetRandHash()), 0);
23  const Amount v = (int64_t(score) * COIN) / 100;
24  const int height = 1234;
25  const bool is_coinbase = false;
26 
27  {
29 
30  LOCK(cs_main);
32  coins.AddCoin(o, Coin(CTxOut(v, script), height, is_coinbase), false);
33  }
34 
35  ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), master);
36  pb.addUTXO(o, v, height, is_coinbase, std::move(key));
37  return pb.build();
38 }
39 
40 } // namespace avalanche
A UTXO entry.
Definition: coins.h:27
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:210
uint256 GetRandHash() noexcept
Definition: random.cpp:654
Definition: amount.h:17
Proof buildRandomProof(uint32_t score, const CPubKey &master)
Definition: util.cpp:18
CChainState & ChainstateActive()
Definition: validation.cpp:67
static constexpr Amount COIN
Definition: amount.h:153
#define LOCK(cs)
Definition: sync.h:230
An encapsulated public key.
Definition: pubkey.h:31
bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:183
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:90
An output of a transaction.
Definition: transaction.h:141
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:246
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:429
A TxId is the identifier of a transaction.
Definition: txid.h:14
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:831
void AddCoin(const COutPoint &outpoint, Coin coin, bool potential_overwrite)
Add a coin.
Definition: coins.cpp:103
An encapsulated secp256k1 private key.
Definition: key.h:25
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:204