mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add a non-canonical SCALE derivations feature
Enables representing IUMT within `StorageValues`. Applied to a variety of values. Fixes a bug where `Some([0; 32])` would be considered a valid block anchor.
This commit is contained in:
@@ -32,5 +32,6 @@ bech32 = { version = "0.11", default-features = false }
|
||||
rand_core = { version = "0.6", default-features = false, features = ["std"] }
|
||||
|
||||
[features]
|
||||
non_canonical_scale_derivations = []
|
||||
std = ["zeroize/std", "borsh/std", "ciphersuite/std", "dkg/std", "sp-core/std", "bech32/std"]
|
||||
default = ["std"]
|
||||
|
||||
@@ -10,18 +10,10 @@ use crate::coin::{ExternalCoin, Coin};
|
||||
pub type AmountRepr = u64;
|
||||
|
||||
/// A wrapper used to represent amounts.
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Hash,
|
||||
Debug,
|
||||
Zeroize,
|
||||
BorshSerialize,
|
||||
BorshDeserialize,
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
|
||||
#[cfg_attr(
|
||||
feature = "non_canonical_scale_derivations",
|
||||
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
|
||||
)]
|
||||
pub struct Amount(pub AmountRepr);
|
||||
|
||||
@@ -48,6 +40,10 @@ impl Mul for Amount {
|
||||
|
||||
/// An ExternalCoin and an Amount, forming a balance for an external coin.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
|
||||
#[cfg_attr(
|
||||
feature = "non_canonical_scale_derivations",
|
||||
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
|
||||
)]
|
||||
pub struct ExternalBalance {
|
||||
/// The coin this is a balance for.
|
||||
pub coin: ExternalCoin,
|
||||
@@ -78,6 +74,10 @@ impl Mul<Amount> for ExternalBalance {
|
||||
|
||||
/// A Coin and an Amount, forming a balance for a coin.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
|
||||
#[cfg_attr(
|
||||
feature = "non_canonical_scale_derivations",
|
||||
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
|
||||
)]
|
||||
pub struct Balance {
|
||||
/// The coin this is a balance for.
|
||||
pub coin: Coin,
|
||||
|
||||
@@ -9,6 +9,10 @@ use crate::network_id::{ExternalNetworkId, NetworkId};
|
||||
/// This type serializes to a subset of `Coin`.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
|
||||
#[borsh(use_discriminant = true)]
|
||||
#[cfg_attr(
|
||||
feature = "non_canonical_scale_derivations",
|
||||
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
|
||||
)]
|
||||
#[non_exhaustive]
|
||||
pub enum ExternalCoin {
|
||||
/// Bitcoin, from the Bitcoin network.
|
||||
@@ -31,6 +35,10 @@ impl ExternalCoin {
|
||||
|
||||
/// The type used to identify coins.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Zeroize)]
|
||||
#[cfg_attr(
|
||||
feature = "non_canonical_scale_derivations",
|
||||
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
|
||||
)]
|
||||
pub enum Coin {
|
||||
/// The Serai coin.
|
||||
Serai,
|
||||
|
||||
@@ -67,7 +67,8 @@ impl UnbalancedMerkleTree {
|
||||
}
|
||||
|
||||
/// An unbalanced Merkle tree which is incrementally created.
|
||||
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "non_canonical_scale_derivations", derive(scale::Encode, scale::Decode))]
|
||||
pub struct IncrementalUnbalancedMerkleTree {
|
||||
/// (number of children under branch, branch hash)
|
||||
branches: Vec<(u64, [u8; 32])>,
|
||||
|
||||
Reference in New Issue
Block a user