Skip to content

Commit

Permalink
Merge pull request #287 from 0xcregis/286-fix-anychain-tron-from_bytes
Browse files Browse the repository at this point in the history
fix: anychain-tron from_bytes()
  • Loading branch information
loki-cmu authored Nov 12, 2024
2 parents cb820a4 + 4ecc0b1 commit 197b3d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/anychain-tron/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "anychain-tron"
description = "A Rust library for Tron-focused cryptocurrency wallets, enabling seamless transactions on the Tron blockchain"
version = "0.2.8"
version = "0.2.9"
keywords = ["tron", "blockchain", "wallet", "transactions"]
categories = ["cryptography::cryptocurrencies"]

Expand Down
24 changes: 16 additions & 8 deletions crates/anychain-tron/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,23 @@ impl Transaction for TronTransaction {
self.to_bytes()
}

fn from_bytes(tx: &[u8]) -> Result<Self, TransactionError> {
let (raw, sig) = if let Ok(tx) = TransactionProto::parse_from_bytes(tx) {
let raw = tx.raw_data.unwrap();
let sig = tx.signature[0].clone();
match sig.len() == 65 {
true => (raw, Some(TronTransactionSignature(sig))),
false => (raw, None),
fn from_bytes(stream: &[u8]) -> Result<Self, TransactionError> {
let (raw, sig) = if let Ok(tx) = TransactionProto::parse_from_bytes(stream) {
if !tx.signature.is_empty() {
let raw = tx.raw_data.unwrap();
let sig = tx.signature[0].clone();
match sig.len() == 65 {
true => (raw, Some(TronTransactionSignature(sig))),
false => (raw, None),
}
} else if let Ok(raw) = TransactionRaw::parse_from_bytes(stream) {
(raw, None)
} else {
return Err(TransactionError::Message(
"illegal tron transaction stream".to_string(),
));
}
} else if let Ok(raw) = TransactionRaw::parse_from_bytes(tx) {
} else if let Ok(raw) = TransactionRaw::parse_from_bytes(stream) {
(raw, None)
} else {
return Err(TransactionError::Message(
Expand Down

0 comments on commit 197b3d7

Please sign in to comment.