Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zcash #1525

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions rust/apps/aptos/src/aptos_type/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use alloc::vec;
use alloc::vec::Vec;
use core::iter::Peekable;


#[derive(Eq, PartialEq, Debug)]
enum Token {
U8Type,
Expand Down Expand Up @@ -145,7 +144,9 @@ fn next_token(s: &str) -> crate::errors::Result<Option<(Token, usize)>> {
match it.next() {
Some('"') => break,
Some(c) if c.is_ascii() => r.push(c),
_ => return Err(AptosError::ParseTxError("unrecognized token".to_string())),
_ => {
return Err(AptosError::ParseTxError("unrecognized token".to_string()))
}
}
}
let len = r.len() + 3;
Expand All @@ -158,7 +159,9 @@ fn next_token(s: &str) -> crate::errors::Result<Option<(Token, usize)>> {
match it.next() {
Some('"') => break,
Some(c) if c.is_ascii_hexdigit() => r.push(c),
_ => return Err(AptosError::ParseTxError("unrecognized token".to_string())),
_ => {
return Err(AptosError::ParseTxError("unrecognized token".to_string()))
}
}
}
let len = r.len() + 3;
Expand Down Expand Up @@ -218,7 +221,9 @@ impl<I: Iterator<Item = Token>> Parser<I> {
fn next(&mut self) -> crate::errors::Result<Token> {
match self.it.next() {
Some(tok) => Ok(tok),
None => Err(AptosError::ParseTxError("out of tokens, this should not happen".to_string())),
None => Err(AptosError::ParseTxError(
"out of tokens, this should not happen".to_string(),
)),
}
}

Expand Down
1 change: 0 additions & 1 deletion rust/apps/aptos/src/aptos_type/safe_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ where
S: Serializer,
T: Serialize,
{

t.serialize(s)
}

Expand Down
10 changes: 3 additions & 7 deletions rust/apps/aptos/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ impl Parser {
if is_tx(data) {
data_parse = data[32..].to_vec();
}
let tx: RawTransaction = bcs::from_bytes(&data_parse).map_err(|err| {
AptosError::ParseTxError(format!("bcs deserialize failed {}", err))
})?;
let tx: RawTransaction = bcs::from_bytes(&data_parse)
.map_err(|err| AptosError::ParseTxError(format!("bcs deserialize failed {}", err)))?;
Ok(AptosTx::new(tx))
}
pub fn parse_msg(data: &Vec<u8>) -> Result<String> {
Expand Down Expand Up @@ -71,10 +70,7 @@ impl AptosTx {
pub fn get_formatted_json(&self) -> Result<Value> {
match serde_json::to_string_pretty(&self.tx) {
Ok(v) => Ok(Value::String(v)),
Err(e) => Err(AptosError::ParseTxError(format!(
"to json failed {}",
e
))),
Err(e) => Err(AptosError::ParseTxError(format!("to json failed {}", e))),
}
}

Expand Down
3 changes: 1 addition & 2 deletions rust/apps/arweave/src/data_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ fn avro_decode_long(reader: &mut Vec<u8>) -> Result<i64> {
fn avro_decode_string(reader: &mut Vec<u8>) -> Result<String> {
let len = avro_decode_long(reader)?;
let buf = reader.drain(..len as usize).collect();
String::from_utf8(buf)
.map_err(|e| ArweaveError::AvroError(format!("{}", e)))
String::from_utf8(buf).map_err(|e| ArweaveError::AvroError(format!("{}", e)))
}

impl_public_struct!(DataItem {
Expand Down
3 changes: 2 additions & 1 deletion rust/apps/arweave/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ lazy_static! {
pub(crate) fn find_token(token_id: &str) -> Option<TokenInfo> {
TOKENS
.iter()
.find(|v| v.get_token_id().eq(token_id)).cloned()
.find(|v| v.get_token_id().eq(token_id))
.cloned()
}
5 changes: 1 addition & 4 deletions rust/apps/arweave/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ impl<'a> ToItems<'a, Tag<Base64>> for Tag<Base64> {
}

/// A struct of [`Vec<u8>`] used for all data and address fields.
#[derive(Debug, Clone, PartialEq)]
#[derive(Default)]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Base64(pub Vec<u8>);



impl fmt::Display for Base64 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let string = &base64::display::Base64Display::with_config(&self.0, base64::URL_SAFE_NO_PAD);
Expand Down
2 changes: 1 addition & 1 deletion rust/apps/cardano/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
use alloc::string::ToString;
use alloc::vec;
use bech32;

use cryptoxide::hashing::blake2b_224;
use keystore;

Expand Down
1 change: 0 additions & 1 deletion rust/apps/cardano/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub fn parse_payment_address(payment_address: Vec<u8>) -> R<String> {
#[cfg(test)]
mod tests {
use super::*;


#[test]
fn test_sign_voting_registration() {
Expand Down
11 changes: 9 additions & 2 deletions rust/apps/cardano/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ impl ParsedCardanoTx {
if tx.body().outputs().len() == 0 {
return 1;
}
tx.body().outputs().get(0).address().network_id().unwrap_or(1)
tx.body()
.outputs()
.get(0)
.address()
.network_id()
.unwrap_or(1)
}
Some(id) => match id.kind() {
NetworkIdKind::Mainnet => 1,
Expand Down Expand Up @@ -637,7 +642,9 @@ impl ParsedCardanoTx {
));
}
if let Some(_cert) = cert.as_drep_update() {
let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string());
let anchor_data_hash = _cert
.anchor()
.map(|anchor| anchor.anchor_data_hash().to_string());
let (variant1, variant1_label) = match _cert.voting_credential().kind() {
CredKind::Key => (
_cert
Expand Down
4 changes: 1 addition & 3 deletions rust/apps/cardano/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ pub fn sign_tx(tx: Vec<u8>, context: ParseContext, icarus_master_key: XPrv) -> R
#[cfg(test)]
mod test {
use super::*;


extern crate std;


use std::println;

use {cryptoxide::hashing::blake2b_256, hex};

#[test]
Expand Down
1 change: 0 additions & 1 deletion rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod type_urls;
pub use prost;
pub use prost_types::Any;


/// The version (commit hash) of the Cosmos SDK used when generating this library.
pub const COSMOS_SDK_VERSION: &str = include_str!("prost/cosmos-sdk/COSMOS_SDK_COMMIT");

Expand Down
1 change: 0 additions & 1 deletion rust/apps/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub fn derive_address(

#[cfg(test)]
mod tests {


use super::*;

Expand Down
30 changes: 6 additions & 24 deletions rust/apps/cosmos/src/proto_wrapper/msg/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
MsgSendWrapper::TYPE_URL => {
let unpacked: proto::cosmos::bank::v1beta1::MsgSend = MessageExt::from_any(message)
.map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgSend deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgSend deserialize failed {}", e))
})?;
let msg_send = MsgSendWrapper::try_from(&unpacked).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgSend deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgSend deserialize failed {}", e))
})?;
message_vec.push(Box::new(msg_send));
}
Expand All @@ -44,10 +38,7 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
))
})?;
let msg_delegate = MsgDelegateWrapper::try_from(&unpacked).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgDelegate deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgDelegate deserialize failed {}", e))
})?;
message_vec.push(Box::new(msg_delegate));
}
Expand Down Expand Up @@ -76,26 +67,17 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
))
})?;
let msg_transfer = MsgTransferWrapper::try_from(&unpacked).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgTransfer deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgTransfer deserialize failed {}", e))
})?;
message_vec.push(Box::new(msg_transfer));
}
MsgVoteWrapper::TYPE_URL => {
let unpacked: proto::cosmos::gov::v1beta1::MsgVote =
proto::cosmos::gov::v1beta1::MsgVote::decode(&*message.value).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgVote deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgVote deserialize failed {}", e))
})?;
let msg_vote = MsgVoteWrapper::try_from(&unpacked).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto MsgVote deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto MsgVote deserialize failed {}", e))
})?;
message_vec.push(Box::new(msg_vote));
}
Expand Down
26 changes: 7 additions & 19 deletions rust/apps/cosmos/src/proto_wrapper/msg/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ pub struct NotSupportMessage {
impl SerializeJson for NotSupportMessage {
fn to_json(&self) -> Result<Value, CosmosError> {
let value = serde_json::to_value(self).map_err(|err| {
CosmosError::ParseTxError(format!(
"NotSupportMessage serialize failed {}",
err
))
CosmosError::ParseTxError(format!("NotSupportMessage serialize failed {}", err))
})?;
let msg = json!({
"type": Value::String(Self::TYPE_URL.to_string()),
Expand Down Expand Up @@ -159,10 +156,7 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgUndelegate> for MsgUndelegate
impl SerializeJson for MsgUndelegate {
fn to_json(&self) -> Result<Value, CosmosError> {
let value = serde_json::to_value(self).map_err(|err| {
CosmosError::ParseTxError(format!(
"MsgUndelegate serialize failed {}",
err
))
CosmosError::ParseTxError(format!("MsgUndelegate serialize failed {}", err))
})?;
let msg = json!({
"type": Value::String(Self::TYPE_URL.to_string()),
Expand Down Expand Up @@ -305,9 +299,9 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf
};

let timeout_height: Option<Height> = proto.timeout_height.as_ref().map(|height| Height {
revision_number: Some(height.revision_number),
revision_height: Some(height.revision_height),
});
revision_number: Some(height.revision_number),
revision_height: Some(height.revision_height),
});

Ok(MsgTransfer {
source_port: proto.source_port.clone(),
Expand Down Expand Up @@ -405,10 +399,7 @@ impl TryFrom<&proto::ibc::core::client::v1::MsgUpdateClient> for MsgUpdateClient
impl SerializeJson for MsgUpdateClient {
fn to_json(&self) -> Result<Value, CosmosError> {
let value = serde_json::to_value(self).map_err(|err| {
CosmosError::ParseTxError(format!(
"MsgUpdateClient serialize failed {}",
err
))
CosmosError::ParseTxError(format!("MsgUpdateClient serialize failed {}", err))
})?;
let msg = json!({
"type": Value::String(Self::TYPE_URL.to_string()),
Expand Down Expand Up @@ -454,10 +445,7 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgBeginRedelegate> for MsgBeginR
impl SerializeJson for MsgBeginRedelegate {
fn to_json(&self) -> Result<Value, CosmosError> {
let value = serde_json::to_value(self).map_err(|err| {
CosmosError::ParseTxError(format!(
"MsgBeginRedelegate serialize failed {}",
err
))
CosmosError::ParseTxError(format!("MsgBeginRedelegate serialize failed {}", err))
})?;
let msg = json!({
"type": Value::String(Self::TYPE_URL.to_string()),
Expand Down
17 changes: 4 additions & 13 deletions rust/apps/cosmos/src/proto_wrapper/sign_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::proto_wrapper::fee::Fee;
use crate::proto_wrapper::msg::msg_serialize::Msg;
use crate::{CosmosError, Result};
use alloc::boxed::Box;
use alloc::string::{String};
use alloc::string::String;
use alloc::vec::Vec;
use serde::Serialize;

Expand All @@ -24,19 +24,13 @@ impl SignDoc {
fn from(proto: proto::cosmos::tx::v1beta1::SignDoc) -> Result<SignDoc> {
let tx_body: proto::cosmos::tx::v1beta1::TxBody =
Message::decode(Bytes::from(proto.body_bytes)).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto TxBody deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto TxBody deserialize failed {}", e))
})?;
let body = Body::try_from(tx_body)?;

let auth_info: proto::cosmos::tx::v1beta1::AuthInfo =
Message::decode(Bytes::from(proto.auth_info_bytes)).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto AuthInfo deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto AuthInfo deserialize failed {}", e))
})?;
let auth_info = AuthInfo::try_from(auth_info)?;

Expand All @@ -52,10 +46,7 @@ impl SignDoc {
pub fn parse(data: &Vec<u8>) -> Result<SignDoc> {
let proto_sign_doc: proto::cosmos::tx::v1beta1::SignDoc =
Message::decode(Bytes::from(data.clone())).map_err(|e| {
CosmosError::ParseTxError(format!(
"proto SignDoc deserialize failed {}",
e
))
CosmosError::ParseTxError(format!("proto SignDoc deserialize failed {}", e))
})?;
SignDoc::from(proto_sign_doc)
}
Expand Down
8 changes: 3 additions & 5 deletions rust/apps/cosmos/src/transaction/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl TryFrom<MsgBeginRedelegate> for DetailRedelegate {

fn try_from(data: MsgBeginRedelegate) -> Result<Self> {
let value = data
.amount.map(|coin| format_amount(vec![coin]))
.amount
.map(|coin| format_amount(vec![coin]))
.unwrap_or("".to_string());
Ok(Self {
method: "Re-delegate".to_string(),
Expand Down Expand Up @@ -67,10 +68,7 @@ impl TryFrom<MsgTransfer> for DetailTransfer {
type Error = CosmosError;

fn try_from(msg: MsgTransfer) -> Result<Self> {
let value = msg
.token
.and_then(format_coin)
.unwrap_or("".to_string());
let value = msg.token.and_then(format_coin).unwrap_or("".to_string());
Ok(Self {
method: "IBC Transfer".to_string(),
value,
Expand Down
2 changes: 0 additions & 2 deletions rust/apps/cosmos/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::transaction::overview::{CommonOverview, CosmosTxOverview, MsgOverview
use crate::transaction::structs::{CosmosTxDisplayType, DataType, ParsedCosmosTx};
use crate::transaction::utils::get_network_by_chain_id;



use self::detail::MsgDetail;

pub mod detail;
Expand Down
Loading
Loading