use crate::{define_enum, define_simple_type, define_struct};
pub const MAX_TX_SIZE: usize = 8000;
pub type ExchangeCall = crate::message::CallMessage<crate::address::Address>;
pub type BankCall = bank::CallMessage<crate::address::Address>;
#[derive(
Clone,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Serialize,
serde::Deserialize,
borsh::BorshDeserialize,
borsh::BorshSerialize,
)]
#[cfg_attr(feature = "schema", derive(sov_universal_wallet::UniversalWallet))]
#[repr(u8)]
#[serde(rename_all = "snake_case")]
#[borsh(use_discriminant = true)]
pub enum Transaction {
V0(Version0) = 0,
}
#[derive(
Clone,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Serialize,
serde::Deserialize,
borsh::BorshDeserialize,
borsh::BorshSerialize,
)]
#[cfg_attr(feature = "schema", derive(sov_universal_wallet::UniversalWallet))]
pub struct Version0 {
#[serde(with = "hex::serde")]
#[cfg_attr(feature = "schema", sov_wallet(display = "hex"))]
pub signature: [u8; 64],
#[serde(with = "hex::serde")]
#[cfg_attr(feature = "schema", sov_wallet(display = "hex"))]
pub pub_key: [u8; 32],
pub runtime_call: RuntimeCall,
pub uniqueness: UniquenessData,
pub details: TxDetails,
}
define_struct! {
struct UnsignedTransaction {
runtime_call: RuntimeCall,
uniqueness: UniquenessData,
details: TxDetails,
}
}
define_enum! {
enum RuntimeCall {
Bank(BankCall) = 2,
Exchange(ExchangeCall) = 7,
}
}
define_enum! {
enum UniquenessData {
Nonce(u64) = 0,
Generation(u64) = 1,
}
}
define_struct! {
struct TxDetails {
max_priority_fee_bips: PriorityFeeBips,
max_fee: Amount,
gas_limit: Option<Gas>,
chain_id: u64,
}
}
define_simple_type!(
#[cfg_attr(feature = "schema", derive(sov_universal_wallet::UniversalWallet))]
Gas([u64; 2])
+ Debug
);
define_simple_type!(PriorityFeeBips(u64));
define_simple_type!(Amount(u128));
#[cfg(feature = "schema")]
impl sov_universal_wallet::ty::IntegerDisplayable for Amount {
fn integer_type() -> sov_universal_wallet::ty::IntegerType {
sov_universal_wallet::ty::IntegerType::u128
}
}
pub mod bank {
use crate::string::CustomString;
use crate::transaction::Amount;
use crate::{define_enum, define_simple_type, define_struct};
define_simple_type!(
#[cfg_attr(feature = "schema", derive(sov_universal_wallet::UniversalWallet))]
TokenId(
#[cfg_attr(
feature = "schema",
sov_wallet(display(bech32m(prefix = "token_id_prefix()")))
)]
[u8; 32]
) + Debug
);
#[cfg(feature = "schema")]
fn token_id_prefix() -> &'static str {
"token_"
}
define_enum! {
enum CallMessage<Address> {
#[cfg_attr(feature="schema", sov_wallet(show_as = "Transfer to address {} {} with memo `{}`."))]
TransferWithMemo {
to: Address,
coins: Coins,
memo: CustomString,
} = 6,
}
}
define_struct! {
#[cfg_attr(feature="schema", sov_wallet(show_as = "{} coins of token ID {}"))]
struct Coins {
#[cfg_attr(feature="schema", sov_wallet(fixed_point(from_field(1, offset = 31))))]
amount: Amount,
token_id: TokenId,
}
}
}