Skip to content

Commit

Permalink
[misc]: Fix tw_bitcoin compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Apr 22, 2024
1 parent 5bc7603 commit 3ed3211
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tw_bech32_address::bech32_prefix::Bech32Prefix;
use tw_bech32_address::Bech32Address;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::{AddressError, AddressResult};
use tw_coin_entry::error::prelude::*;
use tw_cosmos_sdk::address::CosmosAddress;
use tw_keypair::tw::PublicKey;
use tw_memory::Data;
Expand Down
6 changes: 3 additions & 3 deletions rust/chains/tw_binance/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::transaction::SignerInfo;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::{PublicKeyBytes, SignatureBytes};
use tw_coin_entry::common::compile_input::SingleSignaturePubkey;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_coin_entry::signing_output_error;
use tw_cosmos_sdk::modules::serializer::json_serializer::JsonSerializer;
use tw_cosmos_sdk::public_key::secp256k1::Secp256PublicKey;
Expand Down Expand Up @@ -89,8 +89,8 @@ impl BinanceCompiler {

let encoded_tx = BinanceAminoSerializer::serialize_signed_tx(&signed_tx)?;

let signature_json = serde_json::to_string(&signature_json)
.map_err(|_| SigningError(SigningErrorType::Error_internal))?;
let signature_json =
serde_json::to_string(&signature_json).tw_err(|_| SigningErrorType::Error_internal)?;
Ok(Proto::SigningOutput {
encoded: encoded_tx.into(),
signature: signature_bytes.into(),
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tw_bech32_address::bech32_prefix::Bech32Prefix;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::{CoinEntry, PublicKeyBytes, SignatureBytes};
use tw_coin_entry::derivation::Derivation;
use tw_coin_entry::error::AddressResult;
use tw_coin_entry::error::prelude::*;
use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
Expand Down
6 changes: 3 additions & 3 deletions rust/chains/tw_binance/src/modules/preimager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright © 2017 Trust Wallet.

use crate::transaction::UnsignedTransaction;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_hash::{sha2, H256};

pub struct JsonTxPreimage {
Expand All @@ -15,8 +15,8 @@ pub struct JsonPreimager;

impl JsonPreimager {
pub fn preimage_hash(unsigned: &UnsignedTransaction) -> SigningResult<JsonTxPreimage> {
let encoded_tx = serde_json::to_string(unsigned)
.map_err(|_| SigningError(SigningErrorType::Error_internal))?;
let encoded_tx =
serde_json::to_string(unsigned).tw_err(|_| SigningErrorType::Error_internal)?;
let tx_hash = sha2::sha256(encoded_tx.as_bytes());
let tx_hash = H256::try_from(tx_hash.as_slice()).expect("sha256 must return 32 bytes");
Ok(JsonTxPreimage {
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_binance/src/modules/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::amino::AminoEncoder;
use crate::transaction::SignedTransaction;
use std::borrow::Cow;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_cosmos_sdk::public_key::CosmosPublicKey;
use tw_memory::Data;
use tw_misc::traits::ToBytesVec;
Expand Down Expand Up @@ -58,6 +58,6 @@ impl BinanceAminoSerializer {
sequence: signed.unsigned.sequence,
};
// There is no need to use Amino encoding here as the prefix is empty.
serialize(&sign_msg).map_err(|_| SigningError(SigningErrorType::Error_internal))
serialize(&sign_msg).tw_err(|_| SigningErrorType::Error_internal)
}
}
5 changes: 3 additions & 2 deletions rust/chains/tw_binance/src/modules/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::transaction::message::{BinanceMessageEnum, TWBinanceProto};
use crate::transaction::UnsignedTransaction;
use std::borrow::Cow;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_proto::Binance::Proto;

pub struct TxBuilder;
Expand All @@ -32,7 +32,8 @@ impl TxBuilder {
unsigned: &UnsignedTransaction,
) -> SigningResult<Proto::SigningInput<'static>> {
if unsigned.msgs.len() != 1 {
return Err(SigningError(SigningErrorType::Error_invalid_params));
return SigningError::err(SigningErrorType::Error_invalid_params)
.context("Expected exactly one Transaction Message");
}
let msg = unsigned
.msgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::modules::tx_builder::TxBuilder;
use crate::modules::wallet_connect::types::SignAminoRequest;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_coin_entry::modules::wallet_connector::WalletConnector;
use tw_coin_entry::signing_output_error;
use tw_proto::WalletConnect::Proto::{
Expand All @@ -32,7 +32,8 @@ impl BinanceWalletConnector {
) -> SigningResult<WCProto::ParseRequestOutput<'static>> {
match request.method {
WCProto::Method::CosmosSignAmino => Self::parse_sign_amino_request(coin, request),
_ => Err(SigningError(SigningErrorType::Error_not_supported)),
_ => SigningError::err(SigningErrorType::Error_not_supported)
.context("Unknown WalletConnect method"),
}
}

Expand All @@ -41,7 +42,8 @@ impl BinanceWalletConnector {
request: WCProto::ParseRequestInput<'_>,
) -> SigningResult<WCProto::ParseRequestOutput<'static>> {
let amino_req: SignAminoRequest = serde_json::from_str(&request.payload)
.map_err(|_| SigningError(SigningErrorType::Error_input_parse))?;
.tw_err(|_| SigningErrorType::Error_input_parse)
.context("Error deserializing WalletConnect signAmino request as JSON")?;

// Parse a `SigningInput` from the given `signDoc`.
let signing_input = TxBuilder::unsigned_tx_to_proto(&amino_req.sign_doc)?;
Expand Down
6 changes: 3 additions & 3 deletions rust/chains/tw_binance/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::modules::tx_builder::TxBuilder;
use crate::signature::BinanceSignature;
use crate::transaction::SignerInfo;
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_coin_entry::signing_output_error;
use tw_cosmos_sdk::modules::serializer::json_serializer::JsonSerializer;
use tw_cosmos_sdk::public_key::secp256k1::Secp256PublicKey;
Expand Down Expand Up @@ -54,8 +54,8 @@ impl BinanceSigner {
});
let encoded_tx = BinanceAminoSerializer::serialize_signed_tx(&signed_tx)?;

let signature_json = serde_json::to_string(&signature_json)
.map_err(|_| SigningError(SigningErrorType::Error_internal))?;
let signature_json =
serde_json::to_string(&signature_json).tw_err(|_| SigningErrorType::Error_internal)?;
Ok(Proto::SigningOutput {
encoded: encoded_tx.into(),
signature: signature_bytes.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto, Token};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::SigningResult;
use tw_coin_entry::error::prelude::*;
use tw_encoding::hex::as_hex;
use tw_memory::Data;
use tw_proto::Binance::Proto;
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_binance/src/transaction/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize, Serializer};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_memory::Data;
use tw_proto::Binance::Proto::{self, mod_SigningInput::OneOforder_oneof as BinanceMessageProto};

Expand Down Expand Up @@ -138,7 +138,7 @@ impl TWBinanceProto for BinanceMessageEnum {
side_chain_delegate::StakeMigrationOrder::from_tw_proto(coin, order)
.map(BinanceMessageEnum::StakeMigrationOrder)
},
BinanceMessageProto::None => Err(SigningError(SigningErrorType::Error_invalid_params)),
BinanceMessageProto::None => SigningError::err(SigningErrorType::Error_invalid_params),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto, Token};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::SigningResult;
use tw_coin_entry::error::prelude::*;
use tw_memory::Data;
use tw_proto::Binance::Proto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto, Token};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_evm::address::Address as EthereumAddress;
use tw_memory::Data;
use tw_misc::serde::Typed;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl TWBinanceProto for SideDelegateOrder {
let delegation = msg
.delegation
.as_ref()
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;

let value = SideDelegateOrderValue {
delegator_addr,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl TWBinanceProto for SideRedelegateOrder {
let amount = msg
.amount
.as_ref()
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;

let value = SideRedelegateOrderValue {
delegator_addr,
Expand Down Expand Up @@ -182,7 +182,7 @@ impl TWBinanceProto for SideUndelegateOrder {
let amount = msg
.amount
.as_ref()
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;

let value = SideUndelegateOrderValue {
delegator_addr,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl TWBinanceProto for StakeMigrationOrder {
let amount = msg
.amount
.as_ref()
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;

let value = StakeMigrationOrderValue {
amount: Token::from_tw_proto(amount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto, Token};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::SigningResult;
use tw_coin_entry::error::prelude::*;
use tw_memory::Data;
use tw_proto::Binance::Proto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::SigningResult;
use tw_coin_entry::error::prelude::*;
use tw_memory::Data;
use tw_proto::Binance::Proto;

Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_binance/src/transaction/message/trade_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_memory::Data;
use tw_proto::Binance::Proto;

Expand Down Expand Up @@ -61,7 +61,7 @@ impl TWBinanceProto for NewTradeOrder {

fn from_tw_proto(coin: &dyn CoinContext, msg: &Self::Proto<'_>) -> SigningResult<Self> {
let order_type = OrderType::from_repr(msg.ordertype)
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;
let sender = BinanceAddress::from_key_hash_with_coin(coin, msg.sender.to_vec())?;

Ok(NewTradeOrder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::transaction::message::{BinanceMessage, TWBinanceProto, Token};
use serde::{Deserialize, Serialize};
use tw_coin_entry::coin_context::CoinContext;
use tw_coin_entry::coin_entry::CoinAddress;
use tw_coin_entry::error::{SigningError, SigningErrorType, SigningResult};
use tw_coin_entry::error::prelude::*;
use tw_evm::address::Address as EthereumAddress;
use tw_hash::H160;
use tw_memory::Data;
Expand Down Expand Up @@ -41,14 +41,14 @@ impl TWBinanceProto for TransferOutOrder {
fn from_tw_proto(coin: &dyn CoinContext, msg: &Self::Proto<'_>) -> SigningResult<Self> {
let from = BinanceAddress::from_key_hash_with_coin(coin, msg.from.to_vec())?;

let to_bytes = H160::try_from(msg.to.as_ref())
.map_err(|_| SigningError(SigningErrorType::Error_invalid_address))?;
let to_bytes =
H160::try_from(msg.to.as_ref()).tw_err(|_| SigningErrorType::Error_invalid_address)?;
let to = EthereumAddress::from_bytes(to_bytes);

let amount_proto = msg
.amount
.as_ref()
.ok_or(SigningError(SigningErrorType::Error_invalid_params))?;
.or_tw_err(SigningErrorType::Error_invalid_params)?;

Ok(TransferOutOrder {
from,
Expand Down

0 comments on commit 3ed3211

Please sign in to comment.