forked from near/omni-transaction-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 230cfc1
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target/ | ||
Cargo.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
mod transaction; | ||
mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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![] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |