From 230cfc14252dd76f46d81452450571fb7d01ddf9 Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Wed, 24 Jul 2024 21:52:55 +0100 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ Cargo.toml | 22 ++++++++++++++ src/lib.rs | 3 ++ src/transaction.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++ src/types.rs | 12 ++++++++ 5 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs create mode 100644 src/transaction.rs create mode 100644 src/types.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66ba3f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +Cargo.lock + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0d41fd9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "omni-transaction-rs" +version = "0.1.0" +authors = ["Pagoda "] +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib", "rlib"] + +[profile.release] +codegen-units = 1 +# Tell `rustc` to optimize for small code size. +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = true + +[dependencies] + +[dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c244813 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ + +mod transaction; +mod types; diff --git a/src/transaction.rs b/src/transaction.rs new file mode 100644 index 0000000..4c0d982 --- /dev/null +++ b/src/transaction.rs @@ -0,0 +1,74 @@ + +use crate::types::ChainKind; + +// Multichain transaction builder. +pub struct TransactionBuilder { + receiver_id: Option, + amount: Option, + bytecode: Option>, + gas_price: Option, + gas_limit: Option, +} + +impl TransactionBuilder { + pub fn new() -> Self { + Self { + receiver_id: None, + amount: None, + bytecode: None, + gas_price: None, + gas_limit: None, + } + } + + /// Recevier of the transaction. + pub fn receiver(mut self, receiver_id: String) -> Self { + self.receiver_id = Some(receiver_id); + self + } + + /// Amount attached to the transaction. + pub fn amount(mut self, amount: u128) -> Self { + self.amount = Some(amount); + self + } + + /// Deploy contract with the given bytecode. + pub fn deploy_contract(mut self, bytecode: &[u8]) -> Self { + self.bytecode = Some(bytecode.to_vec()); + self + } + + pub fn gas_price(mut self, gas_price: u128) -> Self { + self.gas_price = Some(gas_price); + self + } + + pub fn gas_limit(mut self, gas_limit: u128) -> Self { + self.gas_limit = Some(gas_limit); + self + } + + /// Build a transaction for the given chain into serialized payload. + pub fn build(self, chain_kind: ChainKind) -> Vec { + // Build a transaction + match chain_kind { + ChainKind::NEAR => { + // Build a NEAR transaction + vec![] + } + ChainKind::EVM { chain_id } => { + // Build an EVM transaction + vec![] + } + ChainKind::Solana => { + // Build a Solana transaction + vec![] + } + ChainKind::Cosmos { chain_id } => { + // Build a Cosmos transaction + vec![] + } + } + } +} diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..eccff40 --- /dev/null +++ b/src/types.rs @@ -0,0 +1,12 @@ + +pub enum ChainKind { + NEAR, + EVM { chain_id: u64 }, + Solana, + Cosmos { chain_id: String }, +} + +pub struct OmniAddress { + chain_kind: ChainKind, + address: String, +}