thruput_xdr/address_auth.rs
1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
5
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(non_upper_case_globals)]
9#![allow(unused_imports)]
10#![allow(dead_code)]
11#![allow(unused_variables)]
12#![allow(clippy::unnecessary_cast)]
13
14use crate::*;
15use core::option::Option;
16use core::ops::{Deref, DerefMut};
17
18#[cfg(feature = "std")]
19use std::io::{Read, Write};
20#[cfg(feature = "xdrs")]
21use xdrs::*;
22
23
24#[cfg(feature = "serde")]
25use ::serde::{{Serialize, Deserialize}};
26
27
28
29//==============================================================================
30// Address Authorization Data
31//
32// This module defines the authorization configuration stored at each address.
33// This configuration data tells Thruput whether or not a given transaction
34// can begin execution in a given block.
35//
36// In Thruput, every address can originate transactions and can be configured
37// with multiple signing keys and weighted multi-signature requirements.
38//
39// TODO: give an example of what that might look like here.
40//
41// Unlike the common blockchain model (as in, for example, Ethereum), in which
42// there is an explicit demarcation between so-called "externally owned addresses" (EOAs)
43// that can initiate transactions but have no associated code, and "contract addresses",
44// which hold invocable code but cannot initiate transactions,
45// Thruput treats every address uniformly: all addresses can both hold a contract
46// and initiate a transaction.
47//==============================================================================
48
49//------------------------------------------------------------------------------
50// Public Key Configuration
51//------------------------------------------------------------------------------
52
53/// Configuration for a single public key registered to an address.
54///
55/// Each address can have up to `kMaxSigners` public keys, each with an
56/// associated weight for multi-signature authorization.
57#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
58#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
59#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
60#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
61#[repr(C)]
62pub struct PublicKeyConfig {
63 /// The public key (supports multiple cryptographic schemes via union).
64 pub key: PublicKey,
65 /// The weight of this key in multi-signature calculations.
66 ///
67 /// When verifying weighted auth claims, weights from signing keys
68 /// are accumulated and compared against the required threshold.
69 pub max_weight: Weight,
70}
71
72/// Optional `PublicKeyConfig`, used in the `public_keys` array.
73///
74/// A null value indicates that key slot is unoccupied.
75//
76#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
77#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
78#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
79#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
80#[repr(transparent)]
81#[cfg_attr(feature = "serde", serde(transparent))]
82pub struct PublicKeyConfigOpt {
83 inner: Option<PublicKeyConfig>,
84}
85impl From<Option<PublicKeyConfig>> for PublicKeyConfigOpt {
86 fn from(_inner: Option<PublicKeyConfig>) -> Self {
87 Self { inner: _inner }
88 }
89}
90impl PublicKeyConfigOpt {
91 pub fn into_inner(self) -> Option<PublicKeyConfig> {
92 self.inner
93 }
94 pub const fn new(_inner: Option<PublicKeyConfig>) -> Self {
95 Self { inner: _inner }
96 }
97}
98
99impl Deref for PublicKeyConfigOpt {
100 type Target = Option<PublicKeyConfig>;
101
102 fn deref(&self) -> &Self::Target {
103 &self.inner
104 }
105}
106impl DerefMut for PublicKeyConfigOpt {
107 fn deref_mut(&mut self) -> &mut Self::Target {
108 &mut self.inner
109 }
110}
111
112//------------------------------------------------------------------------------
113// Default Initialization Values
114//------------------------------------------------------------------------------
115
116/// Default required weight for a newly initialized address.
117///
118/// An address has no [`AddressAuthData`] until a change registers a key or
119/// writes a threshold for it. The row that change creates requires this
120/// weight unless the change writes a threshold of its own.
121pub const kDefaultNewAddressRequiredWeight : u32 = 1;
122
123/// The key ID a `kPubkeySignature` claim's single signature must carry.
124///
125/// Nothing is installed under it: an address authorized by a pubkey claim has
126/// no [`AddressAuthData`] at all.
127pub const kDefaultNewAddressKeyID : u32 = 0;
128
129//------------------------------------------------------------------------------
130// Address Authorization Data
131//------------------------------------------------------------------------------
132
133/// The complete authorization configuration for an address.
134///
135/// This struct stores all the information needed to verify transactions
136/// originating from an address:
137/// - The set of public keys and their weights
138/// - The minimum weight threshold required to authorize a transaction
139///
140/// When a transaction is submitted with a `kSourceAddressAuthData`
141/// [`AuthClaim`], the claim is verified against this data to determine if the
142/// transaction is properly authorized.
143///
144/// This is the type stored at storage key type `AuthData`.
145///
146/// # TODO
147///
148/// The initialization workflow (when upgrading an address from just a pk to
149/// a full contract) should explicitly set the auth data with sensible
150/// defaults, so that the default is NOT to accidentally lock the address.
151#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
152#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
153#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
154#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
155#[repr(C)]
156pub struct AddressAuthData {
157 /// Array of up to `kMaxSigners` public keys.
158 ///
159 /// Null entries indicate unoccupied key slots.
160 pub public_keys: [PublicKeyConfigOpt; kMaxSigners as usize],
161 /// The minimum total weight required from signing keys to authorize
162 /// a transaction from this address.
163 pub required_weight: Weight,
164 /// The block height at which this auth data was last modified.
165 ///
166 /// # TODO
167 ///
168 /// This can be removed once the database has a way to track this directly
169 /// on each db item.
170 pub last_written_height: BlockHeight,
171}
172
173
174//
175// XDR internals below this point
176//
177
178