mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Consolidates all primitives into a single crate. We didn't benefit from its fragmentation. I'm hesitant to say the new internal-organization is better (it may be just as clunky), but it's at least in a single crate (not spread out over micro-crates). The ABI is the most distinct. We now entirely own it. Block header hashes don't directly commit to any BABE data (avoiding potentially ~4 KB headers upon session changes), and are hashed as borsh (a more widely used codec than SCALE). There are still Substrate variants, using SCALE and with the BABE data, but they're prunable from a protocol design perspective. Defines a transaction as a Vec of Calls, allowing atomic operations.
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use borsh::{BorshSerialize, BorshDeserialize};
|
|
|
|
use serai_primitives::{
|
|
BlockHash, network_id::ExternalNetworkId, validator_sets::Session, instructions::SignedBatch,
|
|
};
|
|
|
|
/// A call to `InInstruction`s.
|
|
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
|
|
pub enum Call {
|
|
/// Execute a batch of `InInstruction`s.
|
|
execute_batch {
|
|
/// The batch to execute.
|
|
batch: SignedBatch,
|
|
},
|
|
}
|
|
|
|
impl Call {
|
|
pub(crate) fn is_signed(&self) -> bool {
|
|
match self {
|
|
Call::execute_batch { .. } => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// An event from `InInstruction`s.
|
|
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
|
|
pub enum Event {
|
|
/// A batch of `InInstruction`s was executed.
|
|
Batch {
|
|
/// The network for which a batch was executed.
|
|
network: ExternalNetworkId,
|
|
/// The session which published the batch.
|
|
publishing_session: Session,
|
|
/// The ID of the batch.
|
|
id: u32,
|
|
/// The hash of the block on the external network which caused this batch's creation.
|
|
external_network_block_hash: BlockHash,
|
|
/// The hash of the `InInstruction`s within this batch.
|
|
in_instructions_hash: [u8; 32],
|
|
/// The results of each `InInstruction` within the batch.
|
|
#[borsh(
|
|
serialize_with = "serai_primitives::sp_borsh::borsh_serialize_bitvec",
|
|
deserialize_with = "serai_primitives::sp_borsh::borsh_deserialize_bitvec"
|
|
)]
|
|
in_instruction_results: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
|
|
},
|
|
}
|