Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed Jul 24, 2024
0 parents commit 230cfc1
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
Cargo.lock

22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "omni-transaction-rs"
version = "0.1.0"
authors = ["Pagoda <[email protected]>"]
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]
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

mod transaction;
mod types;
74 changes: 74 additions & 0 deletions src/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

use crate::types::ChainKind;

// Multichain transaction builder.
pub struct TransactionBuilder {
receiver_id: Option<String>,
amount: Option<u128>,
bytecode: Option<Vec<u8>>,
gas_price: Option<u128>,
gas_limit: Option<u128>,
}

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<u8> {
// 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![]
}
}
}
}
12 changes: 12 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 230cfc1

Please sign in to comment.