Skip to content

Commit

Permalink
Adding serialization for types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed Jul 27, 2024
1 parent 656b21b commit 2d50e82
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "omni-transaction-rs"
name = "omni-transaction"
version = "0.1.0"
authors = ["Pagoda <[email protected]>"]
edition = "2021"
Expand All @@ -20,8 +20,9 @@ overflow-checks = true
[dependencies]
rlp = "0.5.2"
hex = "0.4.3"
borsh = "1.0.0"
near-crypto = "0.23.0"
near-primitives = "0.23.0"
borsh = { version = "1.0.0", features = ["derive"] }
near-primitives = { version = "0.23" }
near-crypto = { version = "0.23" }
near-sdk = "5.2.0"

[dev-dependencies]
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
mod ethereum;
mod near;

mod transaction;
mod types;
pub mod transaction;
pub mod types;
11 changes: 5 additions & 6 deletions src/near.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

use borsh;

use near_primitives::account::id::AccountId;
use near_primitives::transaction::Transaction;
use near_primitives::transaction::{Transaction, Action};
use near_crypto::PublicKey;
use near_primitives::hash::CryptoHash;
use near_sdk::borsh;


pub fn near_transaction(signer_id: String, public_key: [u8; 64], nonce: u64, receiver_id: String) -> Vec<u8> {
let actions = vec![];
pub fn near_transaction(signer_id: String, public_key: [u8; 64], nonce: u64, receiver_id: String, actions: Vec<Action>) -> Vec<u8> {
let tx = Transaction {
signer_id: AccountId::new_unvalidated(signer_id),
public_key: PublicKey::SECP256K1(public_key.into()),
Expand All @@ -17,4 +16,4 @@ pub fn near_transaction(signer_id: String, public_key: [u8; 64], nonce: u64, rec
actions
};
borsh::to_vec(&tx).expect("failed to serialize NEAR transaction")
}
}
3 changes: 2 additions & 1 deletion src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl TransactionBuilder {
self.signer_public_key.expect("Missing signer public key"),
self.nonce.unwrap_or(0),
self.receiver_id.unwrap_or("".to_string()),
vec![]
)
}
ChainKind::EVM { chain_id } => {
Expand All @@ -92,8 +93,8 @@ impl TransactionBuilder {
ethereum_transaction(
chain_id,
self.nonce.unwrap_or(0).into(),
self.gas_price.unwrap_or(1),
1,
self.gas_price.unwrap_or(1),
self.gas_limit.unwrap_or(1),
Some(to),
// self.receiver_id.unwrap_or("".to_string()).parse().unwrap(),
Expand Down
10 changes: 8 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use near_sdk::serde::{Serialize, Deserialize};
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};

#[derive(Serialize, Deserialize, BorshDeserialize, BorshSerialize, Clone, PartialEq, Eq, PartialOrd, Hash)]
#[serde(crate = "near_sdk::serde")]
pub enum ChainKind {
NEAR,
EVM { chain_id: u64 },
Solana,
Cosmos { chain_id: String },
}

#[derive(Serialize, Deserialize, BorshDeserialize, BorshSerialize, PartialEq, Eq)]
#[serde(crate = "near_sdk::serde")]
pub struct OmniAddress {
chain_kind: ChainKind,
address: String,
pub chain_kind: ChainKind,
pub address: String,
}

0 comments on commit 2d50e82

Please sign in to comment.