Skip to content

Commit

Permalink
Use the serai_abi::Call in the actual Transaction type
Browse files Browse the repository at this point in the history
We prior required they had the same encoding, yet this ensures they do by
making them one and the same. This does require an large, ugly, From/TryInto
block which is deemed preferable for moving this more and more into syntax
(from semantics).

Further improvements (notably re: Extra) is possible, and this already lets us
strip some members from the Call enum.
  • Loading branch information
kayabaNerve committed Jun 4, 2024
1 parent 2a05cf3 commit 41ce5b1
Show file tree
Hide file tree
Showing 23 changed files with 677 additions and 211 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion coordinator/src/tributary/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ mod impl_pst_for_serai {
key_pair: KeyPair,
signature: Signature,
) {
let tx = SeraiValidatorSets::set_keys(set.network, removed, key_pair, signature);
// TODO: BoundedVec as an arg to avoid this expect
let tx = SeraiValidatorSets::set_keys(
set.network,
removed.try_into().expect("removing more than allowed"),
key_pair,
signature,
);
async fn check(serai: SeraiValidatorSets<'_>, set: ValidatorSet, (): ()) -> bool {
if matches!(serai.keys(set).await, Ok(Some(_))) {
log::info!("another coordinator set key pair for {:?}", set);
Expand Down
50 changes: 36 additions & 14 deletions substrate/abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,48 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true

[dependencies]
scale = { package = "parity-scale-codec", version = "3", features = ["derive"] }
scale-info = { version = "2", features = ["derive"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }

borsh = { version = "1", features = ["derive", "de_strict_order"], optional = true }
serde = { version = "1", features = ["derive", "alloc"], optional = true }
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }

sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-runtime = { git = "https://github.com/serai-dex/substrate" }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }

sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/substrate" }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }

serai-primitives = { path = "../primitives", version = "0.1" }
serai-coins-primitives = { path = "../coins/primitives", version = "0.1" }
serai-validator-sets-primitives = { path = "../validator-sets/primitives", version = "0.1" }
serai-in-instructions-primitives = { path = "../in-instructions/primitives", version = "0.1" }
serai-signals-primitives = { path = "../signals/primitives", version = "0.1" }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }

frame-support = { git = "https://github.com/serai-dex/substrate" }
serai-primitives = { path = "../primitives", version = "0.1", default-features = false }
serai-coins-primitives = { path = "../coins/primitives", version = "0.1", default-features = false }
serai-validator-sets-primitives = { path = "../validator-sets/primitives", version = "0.1", default-features = false }
serai-in-instructions-primitives = { path = "../in-instructions/primitives", version = "0.1", default-features = false }
serai-signals-primitives = { path = "../signals/primitives", version = "0.1", default-features = false }

[features]
std = [
"scale/std",
"scale-info/std",

"borsh?/std",
"serde?/std",

"sp-core/std",
"sp-runtime/std",

"sp-consensus-babe/std",
"sp-consensus-grandpa/std",

"frame-support/std",

"serai-primitives/std",
"serai-coins-primitives/std",
"serai-validator-sets-primitives/std",
"serai-in-instructions-primitives/std",
"serai-signals-primitives/std",
]
borsh = [
"dep:borsh",
"serai-primitives/borsh",
Expand All @@ -53,3 +74,4 @@ serde = [
"serai-in-instructions-primitives/serde",
"serai-signals-primitives/serde",
]
default = ["std"]
2 changes: 1 addition & 1 deletion substrate/abi/src/babe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serai_primitives::{Header, SeraiAddress};

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
pub struct ReportEquivocation {
pub equivocation_proof: Box<EquivocationProof<Header>>,
pub equivocation_proof: alloc::boxed::Box<EquivocationProof<Header>>,
pub key_owner_proof: SeraiAddress,
}

Expand Down
15 changes: 13 additions & 2 deletions substrate/abi/src/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use primitives::OutInstructionWithBalance;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
transfer { to: SeraiAddress, balance: Balance },
burn { balance: Balance },
Expand All @@ -14,7 +15,17 @@ pub enum Call {

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum LiquidityTokensCall {
transfer { to: SeraiAddress, balance: Balance },
burn { balance: Balance },
}

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
Mint { to: SeraiAddress, balance: Balance },
Burn { from: SeraiAddress, balance: Balance },
Expand Down
6 changes: 4 additions & 2 deletions substrate/abi/src/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type PoolId = Coin;
type MaxSwapPathLength = sp_core::ConstU32<3>;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
add_liquidity {
coin: Coin,
Expand Down Expand Up @@ -38,7 +39,8 @@ pub enum Call {
}

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
PoolCreated {
pool_id: PoolId,
Expand Down
9 changes: 5 additions & 4 deletions substrate/abi/src/grandpa.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sp_core::{ConstU32, bounded::BoundedVec};
use sp_consensus_grandpa::EquivocationProof;

use serai_primitives::{BlockNumber, SeraiAddress};

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
pub struct ReportEquivocation {
pub equivocation_proof: Box<EquivocationProof<[u8; 32], BlockNumber>>,
pub equivocation_proof: alloc::boxed::Box<EquivocationProof<[u8; 32], BlockNumber>>,
pub key_owner_proof: SeraiAddress,
}

Expand All @@ -15,10 +16,10 @@ pub enum Call {
}

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
NewAuthorities { authority_set: Vec<(SeraiAddress, u64)> },
NewAuthorities { authority_set: BoundedVec<(SeraiAddress, u64), ConstU32<0>> },
// TODO: Remove these
Paused,
Resumed,
Expand Down
6 changes: 4 additions & 2 deletions substrate/abi/src/in_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use primitives::SignedBatch;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
execute_batch { batch: SignedBatch },
}

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
Batch { network: NetworkId, id: u32, block: BlockHash, instructions_hash: [u8; 32] },
InstructionFailure { network: NetworkId, id: u32, index: u32 },
Expand Down
27 changes: 18 additions & 9 deletions substrate/abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(non_camel_case_types)]

extern crate alloc;

pub use serai_primitives as primitives;

pub mod system;

pub mod timestamp;
Expand All @@ -14,15 +21,13 @@ pub mod signals;
pub mod babe;
pub mod grandpa;

pub use serai_primitives as primitives;
pub mod tx;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
pub enum Call {
System,
Timestamp(timestamp::Call),
TransactionPayment,
Coins(coins::Call),
LiquidityTokens(coins::Call),
LiquidityTokens(coins::LiquidityTokensCall),
Dex(dex::Call),
ValidatorSets(validator_sets::Call),
InInstructions(in_instructions::Call),
Expand Down Expand Up @@ -53,21 +58,25 @@ pub enum Event {
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub struct Extra {
pub era: sp_runtime::generic::Era,
pub nonce: scale::Compact<u32>,
pub tip: scale::Compact<u64>,
#[codec(compact)]
pub nonce: u32,
#[codec(compact)]
pub tip: u64,
}

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub struct SignedPayloadExtra {
pub spec_version: u32,
pub tx_version: u32,
pub genesis: [u8; 32],
pub mortality_checkpoint: [u8; 32],
}

pub type Transaction = primitives::Transaction<Call, Extra>;
pub type Transaction = tx::Transaction<Call, Extra>;
6 changes: 4 additions & 2 deletions substrate/abi/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use primitives::SignalId;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
register_retirement_signal { in_favor_of: [u8; 32] },
revoke_retirement_signal { retirement_signal_id: [u8; 32] },
Expand All @@ -18,7 +19,8 @@ pub enum Call {

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
RetirementSignalRegistered {
signal_id: [u8; 32],
Expand Down
1 change: 0 additions & 1 deletion substrate/abi/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use frame_support::dispatch::{DispatchInfo, DispatchError};
use serai_primitives::SeraiAddress;

#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {
ExtrinsicSuccess { dispatch_info: DispatchInfo },
ExtrinsicFailed { dispatch_error: DispatchError, dispatch_info: DispatchInfo },
Expand Down
8 changes: 6 additions & 2 deletions substrate/abi/src/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
set { now: scale::Compact<u64> },
set {
#[codec(compact)]
now: u64,
},
}
Loading

0 comments on commit 41ce5b1

Please sign in to comment.