OpenCBDC Transaction Processor
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
transaction.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_TRANSACTION_TRANSACTION_H_
7#define OPENCBDC_TX_SRC_TRANSACTION_TRANSACTION_H_
8
9#include "crypto/sha256.h"
10#include "util/common/hash.hpp"
11#include "util/common/keys.hpp"
14
15#include <cstdint>
16#include <optional>
17
18namespace cbdc::transaction {
27 struct out_point {
30
33 uint64_t m_index{0};
34
35 auto operator==(const out_point& rhs) const -> bool;
36 auto operator<(const out_point& rhs) const -> bool;
37
38 out_point(const hash_t& hash, uint64_t index);
39
40 out_point() = default;
41 };
42
49 struct output {
52
54 uint64_t m_value{0};
55
56 auto operator==(const output& rhs) const -> bool;
57 auto operator!=(const output& rhs) const -> bool;
58
59 output(hash_t witness_program_commitment, uint64_t value);
60
61 output() = default;
62 };
63
70 struct input {
73
76
77 auto operator==(const input& rhs) const -> bool;
78 auto operator!=(const input& rhs) const -> bool;
79
80 [[nodiscard]] auto hash() const -> hash_t;
81
82 input() = default;
83 };
84
94 struct full_tx {
96 std::vector<input> m_inputs{};
97
99 std::vector<output> m_outputs{};
100
102 std::vector<witness_t> m_witness{};
103
104 auto operator==(const full_tx& rhs) const -> bool;
105
106 full_tx() = default;
107 };
108
111 using sentinel_attestation = std::pair<pubkey_t, signature_t>;
112
119 struct compact_tx {
121 hash_t m_id{};
122
124 std::vector<hash_t> m_inputs;
125
127 std::vector<hash_t> m_uhs_outputs;
128
130 std::unordered_map<pubkey_t, signature_t, hashing::null>
132
135 auto operator==(const compact_tx& tx) const noexcept -> bool;
136
137 compact_tx() = default;
138
139 explicit compact_tx(const full_tx& tx);
140
146 [[nodiscard]] auto sign(secp256k1_context* ctx,
147 const privkey_t& key) const
149
157 [[nodiscard]] auto verify(secp256k1_context* ctx,
158 const sentinel_attestation& att) const
159 -> bool;
160
165 [[nodiscard]] auto hash() const -> hash_t;
166 };
167
169 auto operator()(compact_tx const& tx) const noexcept -> size_t;
170 };
171
181 [[nodiscard]] auto tx_id(const full_tx& tx) noexcept -> hash_t;
182
188 auto input_from_output(const full_tx& tx, size_t i, const hash_t& txid)
189 -> std::optional<input>;
190
195 auto input_from_output(const full_tx& tx, size_t i)
196 -> std::optional<input>;
197
198 auto uhs_id_from_output(const hash_t& entropy,
199 uint64_t i,
200 const output& output) -> hash_t;
201}
202
203#endif // OPENCBDC_TX_SRC_TRANSACTION_TRANSACTION_H_
struct secp256k1_context_struct secp256k1_context
Definition keys.hpp:14
auto uhs_id_from_output(const hash_t &entropy, uint64_t i, const output &output) -> hash_t
std::pair< pubkey_t, signature_t > sentinel_attestation
Sentinel attestation type.
auto input_from_output(const full_tx &tx, size_t i, const hash_t &txid) -> std::optional< input >
Converts the output at the specified index to an input.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
std::array< unsigned char, pubkey_len > privkey_t
A private key of a public/private keypair.
Definition keys.hpp:23
A condensed, hash-only transaction representation.
std::vector< hash_t > m_inputs
The set of hashes of the transaction's inputs.
std::unordered_map< pubkey_t, signature_t, hashing::null > m_attestations
Signatures from sentinels attesting the compact TX is valid.
std::vector< hash_t > m_uhs_outputs
The set of hashes of the new outputs created in the transaction.
A complete transaction.
An input for a new transaction.
out_point m_prevout
The unique identifier of the output.
auto hash() const -> hash_t
output m_prevout_data
The output's data.
auto operator==(const input &rhs) const -> bool
auto operator!=(const input &rhs) const -> bool
The unique identifier of a specific output from a transaction.
hash_t m_tx_id
The hash of the transaction which created the out_point.
auto operator==(const out_point &rhs) const -> bool
uint64_t m_index
The index of the output in the transaction's output list.
auto operator<(const out_point &rhs) const -> bool
An output of a transaction.
uint64_t m_value
The integral value of the output, in atomic units of currency.
auto operator!=(const output &rhs) const -> bool
auto operator==(const output &rhs) const -> bool
hash_t m_witness_program_commitment
Hash of the witness program.