Skip to content

Commit 61b685a

Browse files
authored
Merge pull request #1525 from KeystoneHQ/fix-zcash
Fix zcash
2 parents af6832e + 3b53a3e commit 61b685a

File tree

77 files changed

+409
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+409
-461
lines changed

rust/apps/aptos/src/aptos_type/parser.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use alloc::vec;
1616
use alloc::vec::Vec;
1717
use core::iter::Peekable;
1818

19-
2019
#[derive(Eq, PartialEq, Debug)]
2120
enum Token {
2221
U8Type,
@@ -145,7 +144,9 @@ fn next_token(s: &str) -> crate::errors::Result<Option<(Token, usize)>> {
145144
match it.next() {
146145
Some('"') => break,
147146
Some(c) if c.is_ascii() => r.push(c),
148-
_ => return Err(AptosError::ParseTxError("unrecognized token".to_string())),
147+
_ => {
148+
return Err(AptosError::ParseTxError("unrecognized token".to_string()))
149+
}
149150
}
150151
}
151152
let len = r.len() + 3;
@@ -158,7 +159,9 @@ fn next_token(s: &str) -> crate::errors::Result<Option<(Token, usize)>> {
158159
match it.next() {
159160
Some('"') => break,
160161
Some(c) if c.is_ascii_hexdigit() => r.push(c),
161-
_ => return Err(AptosError::ParseTxError("unrecognized token".to_string())),
162+
_ => {
163+
return Err(AptosError::ParseTxError("unrecognized token".to_string()))
164+
}
162165
}
163166
}
164167
let len = r.len() + 3;
@@ -218,7 +221,9 @@ impl<I: Iterator<Item = Token>> Parser<I> {
218221
fn next(&mut self) -> crate::errors::Result<Token> {
219222
match self.it.next() {
220223
Some(tok) => Ok(tok),
221-
None => Err(AptosError::ParseTxError("out of tokens, this should not happen".to_string())),
224+
None => Err(AptosError::ParseTxError(
225+
"out of tokens, this should not happen".to_string(),
226+
)),
222227
}
223228
}
224229

rust/apps/aptos/src/aptos_type/safe_serialize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ where
1313
S: Serializer,
1414
T: Serialize,
1515
{
16-
1716
t.serialize(s)
1817
}
1918

rust/apps/aptos/src/parser.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ impl Parser {
4141
if is_tx(data) {
4242
data_parse = data[32..].to_vec();
4343
}
44-
let tx: RawTransaction = bcs::from_bytes(&data_parse).map_err(|err| {
45-
AptosError::ParseTxError(format!("bcs deserialize failed {}", err))
46-
})?;
44+
let tx: RawTransaction = bcs::from_bytes(&data_parse)
45+
.map_err(|err| AptosError::ParseTxError(format!("bcs deserialize failed {}", err)))?;
4746
Ok(AptosTx::new(tx))
4847
}
4948
pub fn parse_msg(data: &Vec<u8>) -> Result<String> {
@@ -71,10 +70,7 @@ impl AptosTx {
7170
pub fn get_formatted_json(&self) -> Result<Value> {
7271
match serde_json::to_string_pretty(&self.tx) {
7372
Ok(v) => Ok(Value::String(v)),
74-
Err(e) => Err(AptosError::ParseTxError(format!(
75-
"to json failed {}",
76-
e
77-
))),
73+
Err(e) => Err(AptosError::ParseTxError(format!("to json failed {}", e))),
7874
}
7975
}
8076

rust/apps/arweave/src/data_item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ fn avro_decode_long(reader: &mut Vec<u8>) -> Result<i64> {
6464
fn avro_decode_string(reader: &mut Vec<u8>) -> Result<String> {
6565
let len = avro_decode_long(reader)?;
6666
let buf = reader.drain(..len as usize).collect();
67-
String::from_utf8(buf)
68-
.map_err(|e| ArweaveError::AvroError(format!("{}", e)))
67+
String::from_utf8(buf).map_err(|e| ArweaveError::AvroError(format!("{}", e)))
6968
}
7069

7170
impl_public_struct!(DataItem {

rust/apps/arweave/src/tokens.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ lazy_static! {
6363
pub(crate) fn find_token(token_id: &str) -> Option<TokenInfo> {
6464
TOKENS
6565
.iter()
66-
.find(|v| v.get_token_id().eq(token_id)).cloned()
66+
.find(|v| v.get_token_id().eq(token_id))
67+
.cloned()
6768
}

rust/apps/arweave/src/transaction.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ impl<'a> ToItems<'a, Tag<Base64>> for Tag<Base64> {
154154
}
155155

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

161-
162-
163160
impl fmt::Display for Base64 {
164161
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
165162
let string = &base64::display::Base64Display::with_config(&self.0, base64::URL_SAFE_NO_PAD);

rust/apps/cardano/src/address.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod tests {
122122
use alloc::string::ToString;
123123
use alloc::vec;
124124
use bech32;
125-
125+
126126
use cryptoxide::hashing::blake2b_224;
127127
use keystore;
128128

rust/apps/cardano/src/governance.rs

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub fn parse_payment_address(payment_address: Vec<u8>) -> R<String> {
9696
#[cfg(test)]
9797
mod tests {
9898
use super::*;
99-
10099

101100
#[test]
102101
fn test_sign_voting_registration() {

rust/apps/cardano/src/structs.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ impl ParsedCardanoTx {
298298
if tx.body().outputs().len() == 0 {
299299
return 1;
300300
}
301-
tx.body().outputs().get(0).address().network_id().unwrap_or(1)
301+
tx.body()
302+
.outputs()
303+
.get(0)
304+
.address()
305+
.network_id()
306+
.unwrap_or(1)
302307
}
303308
Some(id) => match id.kind() {
304309
NetworkIdKind::Mainnet => 1,
@@ -637,7 +642,9 @@ impl ParsedCardanoTx {
637642
));
638643
}
639644
if let Some(_cert) = cert.as_drep_update() {
640-
let anchor_data_hash = _cert.anchor().map(|anchor| anchor.anchor_data_hash().to_string());
645+
let anchor_data_hash = _cert
646+
.anchor()
647+
.map(|anchor| anchor.anchor_data_hash().to_string());
641648
let (variant1, variant1_label) = match _cert.voting_credential().kind() {
642649
CredKind::Key => (
643650
_cert

rust/apps/cardano/src/transaction.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,11 @@ pub fn sign_tx(tx: Vec<u8>, context: ParseContext, icarus_master_key: XPrv) -> R
184184
#[cfg(test)]
185185
mod test {
186186
use super::*;
187-
188187

189188
extern crate std;
190189

191-
192190
use std::println;
193-
191+
194192
use {cryptoxide::hashing::blake2b_256, hex};
195193

196194
#[test]

rust/apps/cosmos/src/cosmos_sdk_proto/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod type_urls;
1414
pub use prost;
1515
pub use prost_types::Any;
1616

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

rust/apps/cosmos/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub fn derive_address(
105105

106106
#[cfg(test)]
107107
mod tests {
108-
109108

110109
use super::*;
111110

rust/apps/cosmos/src/proto_wrapper/msg/common.rs

+6-24
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,10 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
2222
MsgSendWrapper::TYPE_URL => {
2323
let unpacked: proto::cosmos::bank::v1beta1::MsgSend = MessageExt::from_any(message)
2424
.map_err(|e| {
25-
CosmosError::ParseTxError(format!(
26-
"proto MsgSend deserialize failed {}",
27-
e
28-
))
25+
CosmosError::ParseTxError(format!("proto MsgSend deserialize failed {}", e))
2926
})?;
3027
let msg_send = MsgSendWrapper::try_from(&unpacked).map_err(|e| {
31-
CosmosError::ParseTxError(format!(
32-
"proto MsgSend deserialize failed {}",
33-
e
34-
))
28+
CosmosError::ParseTxError(format!("proto MsgSend deserialize failed {}", e))
3529
})?;
3630
message_vec.push(Box::new(msg_send));
3731
}
@@ -44,10 +38,7 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
4438
))
4539
})?;
4640
let msg_delegate = MsgDelegateWrapper::try_from(&unpacked).map_err(|e| {
47-
CosmosError::ParseTxError(format!(
48-
"proto MsgDelegate deserialize failed {}",
49-
e
50-
))
41+
CosmosError::ParseTxError(format!("proto MsgDelegate deserialize failed {}", e))
5142
})?;
5243
message_vec.push(Box::new(msg_delegate));
5344
}
@@ -76,26 +67,17 @@ pub fn map_messages(messages: &Vec<Any>) -> Result<Vec<Box<dyn Msg>>, CosmosErro
7667
))
7768
})?;
7869
let msg_transfer = MsgTransferWrapper::try_from(&unpacked).map_err(|e| {
79-
CosmosError::ParseTxError(format!(
80-
"proto MsgTransfer deserialize failed {}",
81-
e
82-
))
70+
CosmosError::ParseTxError(format!("proto MsgTransfer deserialize failed {}", e))
8371
})?;
8472
message_vec.push(Box::new(msg_transfer));
8573
}
8674
MsgVoteWrapper::TYPE_URL => {
8775
let unpacked: proto::cosmos::gov::v1beta1::MsgVote =
8876
proto::cosmos::gov::v1beta1::MsgVote::decode(&*message.value).map_err(|e| {
89-
CosmosError::ParseTxError(format!(
90-
"proto MsgVote deserialize failed {}",
91-
e
92-
))
77+
CosmosError::ParseTxError(format!("proto MsgVote deserialize failed {}", e))
9378
})?;
9479
let msg_vote = MsgVoteWrapper::try_from(&unpacked).map_err(|e| {
95-
CosmosError::ParseTxError(format!(
96-
"proto MsgVote deserialize failed {}",
97-
e
98-
))
80+
CosmosError::ParseTxError(format!("proto MsgVote deserialize failed {}", e))
9981
})?;
10082
message_vec.push(Box::new(msg_vote));
10183
}

rust/apps/cosmos/src/proto_wrapper/msg/msg.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ pub struct NotSupportMessage {
1818
impl SerializeJson for NotSupportMessage {
1919
fn to_json(&self) -> Result<Value, CosmosError> {
2020
let value = serde_json::to_value(self).map_err(|err| {
21-
CosmosError::ParseTxError(format!(
22-
"NotSupportMessage serialize failed {}",
23-
err
24-
))
21+
CosmosError::ParseTxError(format!("NotSupportMessage serialize failed {}", err))
2522
})?;
2623
let msg = json!({
2724
"type": Value::String(Self::TYPE_URL.to_string()),
@@ -159,10 +156,7 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgUndelegate> for MsgUndelegate
159156
impl SerializeJson for MsgUndelegate {
160157
fn to_json(&self) -> Result<Value, CosmosError> {
161158
let value = serde_json::to_value(self).map_err(|err| {
162-
CosmosError::ParseTxError(format!(
163-
"MsgUndelegate serialize failed {}",
164-
err
165-
))
159+
CosmosError::ParseTxError(format!("MsgUndelegate serialize failed {}", err))
166160
})?;
167161
let msg = json!({
168162
"type": Value::String(Self::TYPE_URL.to_string()),
@@ -305,9 +299,9 @@ impl TryFrom<&proto::ibc::applications::transfer::v1::MsgTransfer> for MsgTransf
305299
};
306300

307301
let timeout_height: Option<Height> = proto.timeout_height.as_ref().map(|height| Height {
308-
revision_number: Some(height.revision_number),
309-
revision_height: Some(height.revision_height),
310-
});
302+
revision_number: Some(height.revision_number),
303+
revision_height: Some(height.revision_height),
304+
});
311305

312306
Ok(MsgTransfer {
313307
source_port: proto.source_port.clone(),
@@ -405,10 +399,7 @@ impl TryFrom<&proto::ibc::core::client::v1::MsgUpdateClient> for MsgUpdateClient
405399
impl SerializeJson for MsgUpdateClient {
406400
fn to_json(&self) -> Result<Value, CosmosError> {
407401
let value = serde_json::to_value(self).map_err(|err| {
408-
CosmosError::ParseTxError(format!(
409-
"MsgUpdateClient serialize failed {}",
410-
err
411-
))
402+
CosmosError::ParseTxError(format!("MsgUpdateClient serialize failed {}", err))
412403
})?;
413404
let msg = json!({
414405
"type": Value::String(Self::TYPE_URL.to_string()),
@@ -454,10 +445,7 @@ impl TryFrom<&proto::cosmos::staking::v1beta1::MsgBeginRedelegate> for MsgBeginR
454445
impl SerializeJson for MsgBeginRedelegate {
455446
fn to_json(&self) -> Result<Value, CosmosError> {
456447
let value = serde_json::to_value(self).map_err(|err| {
457-
CosmosError::ParseTxError(format!(
458-
"MsgBeginRedelegate serialize failed {}",
459-
err
460-
))
448+
CosmosError::ParseTxError(format!("MsgBeginRedelegate serialize failed {}", err))
461449
})?;
462450
let msg = json!({
463451
"type": Value::String(Self::TYPE_URL.to_string()),

rust/apps/cosmos/src/proto_wrapper/sign_doc.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::proto_wrapper::fee::Fee;
77
use crate::proto_wrapper::msg::msg_serialize::Msg;
88
use crate::{CosmosError, Result};
99
use alloc::boxed::Box;
10-
use alloc::string::{String};
10+
use alloc::string::String;
1111
use alloc::vec::Vec;
1212
use serde::Serialize;
1313

@@ -24,19 +24,13 @@ impl SignDoc {
2424
fn from(proto: proto::cosmos::tx::v1beta1::SignDoc) -> Result<SignDoc> {
2525
let tx_body: proto::cosmos::tx::v1beta1::TxBody =
2626
Message::decode(Bytes::from(proto.body_bytes)).map_err(|e| {
27-
CosmosError::ParseTxError(format!(
28-
"proto TxBody deserialize failed {}",
29-
e
30-
))
27+
CosmosError::ParseTxError(format!("proto TxBody deserialize failed {}", e))
3128
})?;
3229
let body = Body::try_from(tx_body)?;
3330

3431
let auth_info: proto::cosmos::tx::v1beta1::AuthInfo =
3532
Message::decode(Bytes::from(proto.auth_info_bytes)).map_err(|e| {
36-
CosmosError::ParseTxError(format!(
37-
"proto AuthInfo deserialize failed {}",
38-
e
39-
))
33+
CosmosError::ParseTxError(format!("proto AuthInfo deserialize failed {}", e))
4034
})?;
4135
let auth_info = AuthInfo::try_from(auth_info)?;
4236

@@ -52,10 +46,7 @@ impl SignDoc {
5246
pub fn parse(data: &Vec<u8>) -> Result<SignDoc> {
5347
let proto_sign_doc: proto::cosmos::tx::v1beta1::SignDoc =
5448
Message::decode(Bytes::from(data.clone())).map_err(|e| {
55-
CosmosError::ParseTxError(format!(
56-
"proto SignDoc deserialize failed {}",
57-
e
58-
))
49+
CosmosError::ParseTxError(format!("proto SignDoc deserialize failed {}", e))
5950
})?;
6051
SignDoc::from(proto_sign_doc)
6152
}

rust/apps/cosmos/src/transaction/detail.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl TryFrom<MsgBeginRedelegate> for DetailRedelegate {
3737

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

6970
fn try_from(msg: MsgTransfer) -> Result<Self> {
70-
let value = msg
71-
.token
72-
.and_then(format_coin)
73-
.unwrap_or("".to_string());
71+
let value = msg.token.and_then(format_coin).unwrap_or("".to_string());
7472
Ok(Self {
7573
method: "IBC Transfer".to_string(),
7674
value,

rust/apps/cosmos/src/transaction/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::transaction::overview::{CommonOverview, CosmosTxOverview, MsgOverview
1111
use crate::transaction::structs::{CosmosTxDisplayType, DataType, ParsedCosmosTx};
1212
use crate::transaction::utils::get_network_by_chain_id;
1313

14-
15-
1614
use self::detail::MsgDetail;
1715

1816
pub mod detail;

0 commit comments

Comments
 (0)