diff --git a/rust/chains/tw_bitcoin/src/modules/planner/psbt_planner.rs b/rust/chains/tw_bitcoin/src/modules/planner/psbt_planner.rs index 5818b199df9..545862d1691 100644 --- a/rust/chains/tw_bitcoin/src/modules/planner/psbt_planner.rs +++ b/rust/chains/tw_bitcoin/src/modules/planner/psbt_planner.rs @@ -68,7 +68,6 @@ impl PsbtPlanner { let out_point = Proto::OutPoint { hash: txin.previous_output.hash.to_vec().into(), vout: txin.previous_output.index, - ..Proto::OutPoint::default() }; let sequence = Proto::mod_Input::Sequence { sequence: txin.sequence, diff --git a/rust/chains/tw_bitcoin/src/modules/protobuf_builder/mod.rs b/rust/chains/tw_bitcoin/src/modules/protobuf_builder/mod.rs index 79f0a668df3..dc25bc975e5 100644 --- a/rust/chains/tw_bitcoin/src/modules/protobuf_builder/mod.rs +++ b/rust/chains/tw_bitcoin/src/modules/protobuf_builder/mod.rs @@ -32,7 +32,6 @@ impl ProtobufBuilder { out_point: Some(Proto::OutPoint { hash: Cow::from(input.previous_output.hash.to_vec()), vout: input.previous_output.index, - ..Proto::OutPoint::default() }), sequence: input.sequence, script_sig: Self::script_data(&input.script_sig), diff --git a/rust/chains/tw_greenfield/src/public_key.rs b/rust/chains/tw_greenfield/src/public_key.rs index d2f7a1a78fd..41f4a3cced6 100644 --- a/rust/chains/tw_greenfield/src/public_key.rs +++ b/rust/chains/tw_greenfield/src/public_key.rs @@ -20,9 +20,9 @@ impl JsonPublicKey for GreenfieldPublicKey { } impl ProtobufPublicKey for GreenfieldPublicKey { - fn to_proto(&self) -> google::protobuf::Any<'static> { + fn to_proto(&self) -> google::protobuf::Any { let proto = tw_cosmos_sdk::proto::cosmos::crypto::eth::ethsecp256k1::PubKey { - key: self.0.compressed().to_vec().into(), + key: self.0.compressed().to_vec(), }; to_any(&proto) } diff --git a/rust/chains/tw_greenfield/src/transaction/message/transfer_out.rs b/rust/chains/tw_greenfield/src/transaction/message/transfer_out.rs index e22b58598a9..00a01116db5 100644 --- a/rust/chains/tw_greenfield/src/transaction/message/transfer_out.rs +++ b/rust/chains/tw_greenfield/src/transaction/message/transfer_out.rs @@ -65,8 +65,8 @@ pub struct GreenfieldTransferOut { impl CosmosMessage for GreenfieldTransferOut { fn to_proto(&self) -> SigningResult { let msg = GreenfieldProto::bridge::MsgTransferOut { - from: self.from.to_string().into(), - to: self.to.to_string().into(), + from: self.from.to_string(), + to: self.to.to_string(), amount: Some(build_coin(&self.amount)), }; Ok(to_any(&msg)) diff --git a/rust/chains/tw_native_evmos/src/ethermint_public_key.rs b/rust/chains/tw_native_evmos/src/ethermint_public_key.rs index 2a480be2701..c2bf2d8f0ad 100644 --- a/rust/chains/tw_native_evmos/src/ethermint_public_key.rs +++ b/rust/chains/tw_native_evmos/src/ethermint_public_key.rs @@ -53,7 +53,7 @@ impl JsonPublicKey for EthermintEthSecp256PublicKey { } impl ProtobufPublicKey for EthermintEthSecp256PublicKey { - fn to_proto(&self) -> google::protobuf::Any<'static> { + fn to_proto(&self) -> google::protobuf::Any { self.0.to_proto() } } diff --git a/rust/chains/tw_native_injective/src/injective_public_key.rs b/rust/chains/tw_native_injective/src/injective_public_key.rs index e65a1ddc20c..c405867f6e8 100644 --- a/rust/chains/tw_native_injective/src/injective_public_key.rs +++ b/rust/chains/tw_native_injective/src/injective_public_key.rs @@ -53,7 +53,7 @@ impl JsonPublicKey for InjectiveEthSecp256PublicKey { } impl ProtobufPublicKey for InjectiveEthSecp256PublicKey { - fn to_proto(&self) -> google::protobuf::Any<'static> { + fn to_proto(&self) -> google::protobuf::Any { self.0.to_proto() } } diff --git a/rust/tw_cosmos_sdk/build.rs b/rust/tw_cosmos_sdk/build.rs index 4a5670aefbf..830293ac58a 100644 --- a/rust/tw_cosmos_sdk/build.rs +++ b/rust/tw_cosmos_sdk/build.rs @@ -58,6 +58,7 @@ fn main() { ) .expect("Error configuring pb-rs builder") .gen_info(true) + .dont_use_cow(true) .build(); FileDescriptor::run(&out_protos).expect("Error generating proto files"); } diff --git a/rust/tw_cosmos_sdk/src/modules/serializer/protobuf_serializer.rs b/rust/tw_cosmos_sdk/src/modules/serializer/protobuf_serializer.rs index 623132eb085..91141c2e1f1 100644 --- a/rust/tw_cosmos_sdk/src/modules/serializer/protobuf_serializer.rs +++ b/rust/tw_cosmos_sdk/src/modules/serializer/protobuf_serializer.rs @@ -10,16 +10,15 @@ use crate::public_key::ProtobufPublicKey; use crate::transaction::{ Coin, Fee, SignMode, SignedTransaction, SignerInfo, TxBody, UnsignedTransaction, }; -use std::borrow::Cow; use std::marker::PhantomData; use tw_coin_entry::error::prelude::*; use tw_memory::Data; use tw_proto::serialize; -pub fn build_coin(coin: &Coin) -> base_proto::Coin<'static> { +pub fn build_coin(coin: &Coin) -> base_proto::Coin { base_proto::Coin { - amount: coin.amount.to_string().into(), - denom: coin.denom.clone().into(), + amount: coin.amount.to_string(), + denom: coin.denom.clone(), } } @@ -38,34 +37,26 @@ pub struct SignDirectArgs { impl ProtobufSerializer { /// Serializes a signed transaction into the Cosmos [`tx_proto::TxRaw`] message. /// [`tx_proto::TxRaw`] can be broadcasted to the network. - pub fn build_signed_tx( - signed: &SignedTransaction, - ) -> SigningResult> { + pub fn build_signed_tx(signed: &SignedTransaction) -> SigningResult { let tx_body = Self::build_tx_body(&signed.tx_body)?; - let body_bytes = serialize(&tx_body) - .expect("Unexpected error on tx_body serialization") - .into(); + let body_bytes = serialize(&tx_body).expect("Unexpected error on tx_body serialization"); let auth_info = Self::build_auth_info(&signed.signer, &signed.fee); - let auth_info_bytes = serialize(&auth_info) - .expect("Unexpected error on auth_info serialization") - .into(); + let auth_info_bytes = + serialize(&auth_info).expect("Unexpected error on auth_info serialization"); Ok(tx_proto::TxRaw { body_bytes, auth_info_bytes, - signatures: vec![signed.signature.clone().into()], + signatures: vec![signed.signature.clone()], }) } - pub fn build_direct_signed_tx( - args: &SignDirectArgs, - signature: Data, - ) -> tx_proto::TxRaw<'static> { + pub fn build_direct_signed_tx(args: &SignDirectArgs, signature: Data) -> tx_proto::TxRaw { tx_proto::TxRaw { - body_bytes: args.tx_body.clone().into(), - auth_info_bytes: args.auth_info.clone().into(), - signatures: vec![signature.into()], + body_bytes: args.tx_body.clone(), + auth_info_bytes: args.auth_info.clone(), + signatures: vec![signature], } } @@ -73,30 +64,27 @@ impl ProtobufSerializer { /// [`tx_proto::SignDoc`] is used to generate a transaction prehash and sign it. pub fn build_sign_doc( unsigned: &UnsignedTransaction, - ) -> SigningResult> { + ) -> SigningResult { let tx_body = Self::build_tx_body(&unsigned.tx_body)?; - let body_bytes = serialize(&tx_body) - .expect("Unexpected error on tx_body serialization") - .into(); + let body_bytes = serialize(&tx_body).expect("Unexpected error on tx_body serialization"); let auth_info = Self::build_auth_info(&unsigned.signer, &unsigned.fee); - let auth_info_bytes = serialize(&auth_info) - .expect("Unexpected error on auth_info serialization") - .into(); + let auth_info_bytes = + serialize(&auth_info).expect("Unexpected error on auth_info serialization"); Ok(tx_proto::SignDoc { body_bytes, auth_info_bytes, - chain_id: unsigned.chain_id.clone().into(), + chain_id: unsigned.chain_id.clone(), account_number: unsigned.account_number, }) } - pub fn build_direct_sign_doc(args: &SignDirectArgs) -> tx_proto::SignDoc<'static> { + pub fn build_direct_sign_doc(args: &SignDirectArgs) -> tx_proto::SignDoc { tx_proto::SignDoc { - body_bytes: args.tx_body.clone().into(), - auth_info_bytes: args.auth_info.clone().into(), - chain_id: args.chain_id.clone().into(), + body_bytes: args.tx_body.clone(), + auth_info_bytes: args.auth_info.clone(), + chain_id: args.chain_id.clone(), account_number: args.account_number, } } @@ -104,7 +92,7 @@ impl ProtobufSerializer { pub fn build_auth_info( signer: &SignerInfo, fee: &Fee, - ) -> tx_proto::AuthInfo<'static> { + ) -> tx_proto::AuthInfo { tx_proto::AuthInfo { signer_infos: vec![Self::build_signer_info(signer)], fee: Some(Self::build_fee(fee)), @@ -113,7 +101,7 @@ impl ProtobufSerializer { } } - pub fn build_tx_body(tx_body: &TxBody) -> SigningResult> { + pub fn build_tx_body(tx_body: &TxBody) -> SigningResult { let messages: Vec<_> = tx_body .messages .iter() @@ -122,14 +110,14 @@ impl ProtobufSerializer { Ok(tx_proto::TxBody { messages, - memo: tx_body.memo.clone().into(), + memo: tx_body.memo.clone(), timeout_height: tx_body.timeout_height, extension_options: Vec::default(), non_critical_extension_options: Vec::default(), }) } - pub fn build_signer_info(signer: &SignerInfo) -> tx_proto::SignerInfo<'static> { + pub fn build_signer_info(signer: &SignerInfo) -> tx_proto::SignerInfo { use tx_proto::mod_ModeInfo::{self as mode_info, OneOfsum as SumEnum}; // Single is the mode info for a single signer. It is structured as a message @@ -147,13 +135,13 @@ impl ProtobufSerializer { } } - fn build_fee(fee: &Fee) -> tx_proto::Fee<'static> { + fn build_fee(fee: &Fee) -> tx_proto::Fee { tx_proto::Fee { amount: fee.amounts.iter().map(build_coin).collect(), gas_limit: fee.gas_limit, // Ignore `payer` and `granter` even if they set. - payer: Cow::default(), - granter: Cow::default(), + payer: String::default(), + granter: String::default(), } } diff --git a/rust/tw_cosmos_sdk/src/modules/tx_builder.rs b/rust/tw_cosmos_sdk/src/modules/tx_builder.rs index 5cd9f6740d4..4f190f32272 100644 --- a/rust/tw_cosmos_sdk/src/modules/tx_builder.rs +++ b/rust/tw_cosmos_sdk/src/modules/tx_builder.rs @@ -632,11 +632,10 @@ where let grant_msg = match auth.grant_type { ProtoGrantType::grant_stake(ref stake) => google::protobuf::Any { - type_url: STAKE_AUTHORIZATION_MSG_TYPE.to_string().into(), + type_url: STAKE_AUTHORIZATION_MSG_TYPE.to_string(), value: serialize(stake) .tw_err(|_| SigningErrorType::Error_invalid_params) - .context("Error serializing Grant Stake Protobuf message")? - .into(), + .context("Error serializing Grant Stake Protobuf message")?, }, ProtoGrantType::None => { return SigningError::err(SigningErrorType::Error_invalid_params) diff --git a/rust/tw_cosmos_sdk/src/public_key/mod.rs b/rust/tw_cosmos_sdk/src/public_key/mod.rs index 578f202e94e..746de80b584 100644 --- a/rust/tw_cosmos_sdk/src/public_key/mod.rs +++ b/rust/tw_cosmos_sdk/src/public_key/mod.rs @@ -39,7 +39,7 @@ pub trait CosmosPublicKey: JsonPublicKey + ProtobufPublicKey + Sized { } pub trait ProtobufPublicKey { - fn to_proto(&self) -> google::protobuf::Any<'static>; + fn to_proto(&self) -> google::protobuf::Any; } pub trait JsonPublicKey { diff --git a/rust/tw_cosmos_sdk/src/public_key/secp256k1.rs b/rust/tw_cosmos_sdk/src/public_key/secp256k1.rs index 1bff6136c4e..6b147ed4238 100644 --- a/rust/tw_cosmos_sdk/src/public_key/secp256k1.rs +++ b/rust/tw_cosmos_sdk/src/public_key/secp256k1.rs @@ -62,9 +62,9 @@ impl CosmosPublicKey for Secp256PublicKey { } impl ProtobufPublicKey for Secp256PublicKey { - fn to_proto(&self) -> google::protobuf::Any<'static> { + fn to_proto(&self) -> google::protobuf::Any { let proto = cosmos::crypto::secp256k1::PubKey { - key: self.public_key.clone().into(), + key: self.public_key.clone(), }; to_any_with_type_url(&proto, self.protobuf_type_url.clone()) } diff --git a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_auth_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_auth_message.rs index 073f3499af9..32918948a7f 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_auth_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_auth_message.rs @@ -12,7 +12,7 @@ use tw_proto::{google, to_any}; pub struct AuthGrantMessage { pub granter: Address, pub grantee: Address, - pub grant_msg: ProtobufMessage, + pub grant_msg: google::protobuf::Any, pub expiration_secs: i64, } @@ -28,8 +28,8 @@ impl CosmosMessage for AuthGrantMessage
{ }; let proto_msg = cosmos::authz::v1beta1::MsgGrant { - granter: self.granter.to_string().into(), - grantee: self.grantee.to_string().into(), + granter: self.granter.to_string(), + grantee: self.grantee.to_string(), grant: Some(grant), }; Ok(to_any(&proto_msg)) @@ -46,9 +46,9 @@ pub struct AuthRevokeMessage { impl CosmosMessage for AuthRevokeMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::authz::v1beta1::MsgRevoke { - granter: self.granter.to_string().into(), - grantee: self.grantee.to_string().into(), - msg_type_url: self.msg_type_url.clone().into(), + granter: self.granter.to_string(), + grantee: self.grantee.to_string(), + msg_type_url: self.msg_type_url.clone(), }; Ok(to_any(&proto_msg)) } diff --git a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_bank_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_bank_message.rs index e6bac168271..7b09ec52056 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_bank_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_bank_message.rs @@ -26,8 +26,8 @@ pub struct SendMessage { impl CosmosMessage for SendMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::bank::v1beta1::MsgSend { - from_address: self.from_address.to_string().into(), - to_address: self.to_address.to_string().into(), + from_address: self.from_address.to_string(), + to_address: self.to_address.to_string(), amount: self.amount.iter().map(build_coin).collect(), }; Ok(to_any(&proto_msg)) diff --git a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_gov_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_gov_message.rs index 7e074f3c19f..6c990c14fff 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_gov_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_gov_message.rs @@ -36,7 +36,7 @@ impl CosmosMessage for VoteMessage
{ let proto_msg = cosmos::gov::v1beta1::MsgVote { proposal_id: self.proposal_id, - voter: self.voter.to_string().into(), + voter: self.voter.to_string(), option, }; Ok(to_any(&proto_msg)) diff --git a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_staking_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_staking_message.rs index aab7e5b3c4f..dc3c6238b9c 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/cosmos_staking_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/cosmos_staking_message.rs @@ -31,8 +31,8 @@ impl CosmosMessage for DelegateMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::staking::v1beta1::MsgDelegate { amount: Some(build_coin(&self.amount)), - delegator_address: self.delegator_address.to_string().into(), - validator_address: self.validator_address.to_string().into(), + delegator_address: self.delegator_address.to_string(), + validator_address: self.validator_address.to_string(), }; Ok(to_any(&proto_msg)) } @@ -60,8 +60,8 @@ impl CosmosMessage for UndelegateMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::staking::v1beta1::MsgUndelegate { amount: Some(build_coin(&self.amount)), - delegator_address: self.delegator_address.to_string().into(), - validator_address: self.validator_address.to_string().into(), + delegator_address: self.delegator_address.to_string(), + validator_address: self.validator_address.to_string(), }; Ok(to_any(&proto_msg)) } @@ -90,9 +90,9 @@ impl CosmosMessage for BeginRedelegateMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::staking::v1beta1::MsgBeginRedelegate { amount: Some(build_coin(&self.amount)), - delegator_address: self.delegator_address.to_string().into(), - validator_src_address: self.validator_src_address.to_string().into(), - validator_dst_address: self.validator_dst_address.to_string().into(), + delegator_address: self.delegator_address.to_string(), + validator_src_address: self.validator_src_address.to_string(), + validator_dst_address: self.validator_dst_address.to_string(), }; Ok(to_any(&proto_msg)) } @@ -118,8 +118,8 @@ pub struct WithdrawDelegationRewardMessage { impl CosmosMessage for WithdrawDelegationRewardMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::distribution::v1beta1::MsgWithdrawDelegatorReward { - delegator_address: self.delegator_address.to_string().into(), - validator_address: self.validator_address.to_string().into(), + delegator_address: self.delegator_address.to_string(), + validator_address: self.validator_address.to_string(), }; Ok(to_any(&proto_msg)) } @@ -145,8 +145,8 @@ pub struct SetWithdrawAddressMessage { impl CosmosMessage for SetWithdrawAddressMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmos::distribution::v1beta1::MsgSetWithdrawAddress { - delegator_address: self.delegator_address.to_string().into(), - withdraw_address: self.withdraw_address.to_string().into(), + delegator_address: self.delegator_address.to_string(), + withdraw_address: self.withdraw_address.to_string(), }; Ok(to_any(&proto_msg)) } diff --git a/rust/tw_cosmos_sdk/src/transaction/message/ibc_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/ibc_message.rs index 54756cbe698..e3cb7ae29eb 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/ibc_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/ibc_message.rs @@ -38,11 +38,11 @@ impl CosmosMessage for TransferTokensMessage
{ }; let proto_msg = ibc::applications::transfer::v1::MsgTransfer { - source_port: self.source_port.clone().into(), - source_channel: self.source_channel.clone().into(), + source_port: self.source_port.clone(), + source_channel: self.source_channel.clone(), token: Some(build_coin(&self.token)), - sender: self.sender.to_string().into(), - receiver: self.receiver.to_string().into(), + sender: self.sender.to_string(), + receiver: self.receiver.to_string(), timeout_height: Some(height), timeout_timestamp: self.timeout_timestamp, }; diff --git a/rust/tw_cosmos_sdk/src/transaction/message/mod.rs b/rust/tw_cosmos_sdk/src/transaction/message/mod.rs index e5785909372..0ecc466e1fc 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/mod.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/mod.rs @@ -19,7 +19,7 @@ pub mod terra_wasm_message; pub mod thorchain_message; pub mod wasm_message; -pub type ProtobufMessage = google::protobuf::Any<'static>; +pub type ProtobufMessage = google::protobuf::Any; pub type CosmosMessageBox = Box; pub type JsonMessage = AnyMsg; diff --git a/rust/tw_cosmos_sdk/src/transaction/message/stride_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/stride_message.rs index b2556a43798..1ef8e86eaec 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/stride_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/stride_message.rs @@ -18,9 +18,9 @@ pub struct StrideLiquidStakeMessage { impl CosmosMessage for StrideLiquidStakeMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = stride::stakeibc::MsgLiquidStake { - creator: self.creator.to_string().into(), - amount: self.amount.to_string().into(), - host_denom: self.host_denom.clone().into(), + creator: self.creator.to_string(), + amount: self.amount.to_string(), + host_denom: self.host_denom.clone(), }; Ok(to_any(&proto_msg)) } @@ -36,10 +36,10 @@ pub struct StrideLiquidRedeemMessage { impl CosmosMessage for StrideLiquidRedeemMessage { fn to_proto(&self) -> SigningResult { let proto_msg = stride::stakeibc::MsgRedeemStake { - creator: self.creator.clone().into(), - amount: self.amount.to_string().into(), - receiver: self.receiver.clone().into(), - host_zone: self.host_zone.clone().into(), + creator: self.creator.clone(), + amount: self.amount.to_string(), + receiver: self.receiver.clone(), + host_zone: self.host_zone.clone(), }; Ok(to_any(&proto_msg)) } diff --git a/rust/tw_cosmos_sdk/src/transaction/message/terra_wasm_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/terra_wasm_message.rs index acce6442063..b74e6a01bd5 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/terra_wasm_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/terra_wasm_message.rs @@ -28,9 +28,9 @@ pub struct TerraExecuteContractMessage { impl CosmosMessage for TerraExecuteContractMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = terra::wasm::v1beta1::MsgExecuteContract { - sender: self.sender.to_string().into(), - contract: self.contract.to_string().into(), - execute_msg: self.execute_msg.to_bytes().into(), + sender: self.sender.to_string(), + contract: self.contract.to_string(), + execute_msg: self.execute_msg.to_bytes(), coins: self.coins.iter().map(build_coin).collect(), }; Ok(to_any(&proto_msg)) diff --git a/rust/tw_cosmos_sdk/src/transaction/message/thorchain_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/thorchain_message.rs index 18765c17587..6158c4f5815 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/thorchain_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/thorchain_message.rs @@ -21,9 +21,9 @@ pub struct ThorchainAsset { impl ThorchainAsset { pub fn to_proto(&self) -> types::Asset { types::Asset { - chain: self.chain.clone().into(), - symbol: self.symbol.clone().into(), - ticker: self.ticker.clone().into(), + chain: self.chain.clone(), + symbol: self.symbol.clone(), + ticker: self.ticker.clone(), synth: self.synth, } } @@ -39,7 +39,7 @@ impl ThorchainCoin { pub fn to_proto(&self) -> types::Coin { types::Coin { asset: Some(self.asset.to_proto()), - amount: self.amount.to_string().into(), + amount: self.amount.to_string(), decimals: self.decimals, } } @@ -54,8 +54,8 @@ pub struct ThorchainSendMessage { impl CosmosMessage for ThorchainSendMessage { fn to_proto(&self) -> SigningResult { let proto_msg = types::MsgSend { - from_address: self.from_address.clone().into(), - to_address: self.to_address.clone().into(), + from_address: self.from_address.clone(), + to_address: self.to_address.clone(), amount: self.amount.iter().map(build_coin).collect(), }; Ok(to_any(&proto_msg)) @@ -72,8 +72,8 @@ impl CosmosMessage for ThorchainDepositMessage { fn to_proto(&self) -> SigningResult { let proto_msg = types::MsgDeposit { coins: self.coins.iter().map(ThorchainCoin::to_proto).collect(), - memo: self.memo.clone().into(), - signer: self.signer.clone().into(), + memo: self.memo.clone(), + signer: self.signer.clone(), }; Ok(to_any(&proto_msg)) } diff --git a/rust/tw_cosmos_sdk/src/transaction/message/wasm_message.rs b/rust/tw_cosmos_sdk/src/transaction/message/wasm_message.rs index 11c80a2c8e2..21163f691a3 100644 --- a/rust/tw_cosmos_sdk/src/transaction/message/wasm_message.rs +++ b/rust/tw_cosmos_sdk/src/transaction/message/wasm_message.rs @@ -63,9 +63,9 @@ pub struct WasmExecuteContractMessage { impl CosmosMessage for WasmExecuteContractMessage
{ fn to_proto(&self) -> SigningResult { let proto_msg = cosmwasm::wasm::v1::MsgExecuteContract { - sender: self.sender.to_string().into(), - contract: self.contract.to_string().into(), - msg: self.msg.to_bytes().into(), + sender: self.sender.to_string(), + contract: self.contract.to_string(), + msg: self.msg.to_bytes(), funds: self.coins.iter().map(build_coin).collect(), }; Ok(to_any(&proto_msg)) diff --git a/rust/tw_cosmos_sdk/tests/sign.rs b/rust/tw_cosmos_sdk/tests/sign.rs index 4a23db87668..ae3c5595f14 100644 --- a/rust/tw_cosmos_sdk/tests/sign.rs +++ b/rust/tw_cosmos_sdk/tests/sign.rs @@ -289,6 +289,8 @@ fn test_sign_direct() { /// and `AuthInfo` will be generated from `SigningInput` parameters. #[test] fn test_sign_direct_with_body_bytes() { + use tw_cosmos_sdk::proto::cosmos::tx::v1beta1 as tx_proto; + let coin = TestCoinContext::default() .with_public_key_type(PublicKeyType::Secp256k1) .with_hrp("cosmos"); @@ -300,7 +302,7 @@ fn test_sign_direct_with_body_bytes() { // Do not specify the `AuthInfo` bytes. auth_info_bytes: Cow::default(), }; - let input = Proto::SigningInput { + let mut input = Proto::SigningInput { account_number: 1037, chain_id: "gaia-13003".into(), fee: Some(make_fee(200000, make_amount("muon", "200"))), @@ -315,7 +317,7 @@ fn test_sign_direct_with_body_bytes() { // also similar TX: BCDAC36B605576C8182C2829C808B30A69CAD4959D5ED1E6FF9984ABF280D603 test_sign_protobuf::(TestInput { coin: &coin, - input, + input: input.clone(), tx: r#"{"mode":"BROADCAST_MODE_BLOCK","tx_bytes":"CowBCokBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEmkKLWNvc21vczFoc2s2anJ5eXFqZmhwNWRoYzU1dGM5anRja3lneDBlcGg2ZGQwMhItY29zbW9zMXp0NTBhenVwYW5xbGZhbTVhZmh2M2hleHd5dXRudWtlaDRjNTczGgkKBG11b24SATESZQpQCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAlcobsPzfTNVe7uqAAsndErJAjqplnyudaGB0f+R+p3FEgQKAggBGAgSEQoLCgRtdW9uEgMyMDAQwJoMGkD54fQAFlekIAnE62hZYl0uQelh/HLv0oQpCciY5Dn8H1SZFuTsrGdu41PH1Uxa4woptCELi/8Ov9yzdeEFAC9H"}"#, signature: "f9e1f4001657a42009c4eb6859625d2e41e961fc72efd2842909c898e439fc1f549916e4ecac676ee353c7d54c5ae30a29b4210b8bff0ebfdcb375e105002f47", signature_json: r#"[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AlcobsPzfTNVe7uqAAsndErJAjqplnyudaGB0f+R+p3F"},"signature":"+eH0ABZXpCAJxOtoWWJdLkHpYfxy79KEKQnImOQ5/B9UmRbk7KxnbuNTx9VMWuMKKbQhC4v/Dr/cs3XhBQAvRw=="}]"#, @@ -387,12 +389,12 @@ fn test_sign_vote() { // Successfully broadcasted https://www.mintscan.io/cosmos/txs/2EFA054B842B1641B131137B13360F95164C6C1D51BB4A4AC6DE8F75F504AA4C test_sign_protobuf::(TestInput { - coin: &coin, - input: input.clone(), - tx: r#"{"mode":"BROADCAST_MODE_BLOCK","tx_bytes":"ClQKUgobL2Nvc21vcy5nb3YudjFiZXRhMS5Nc2dWb3RlEjMITRItY29zbW9zMW1yeTQ3cGtnYTV0ZHN3dGx1eTBtOHRlc2xwYWxrZHEwN3Bzd3U0GAESZQpOCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAsv9teRyiTMiKU5gzwiD1D30MeEInSnstEep5tVQRarlEgQKAggBEhMKDQoFdWF0b20SBDI0MTgQkfsFGkA+Nb3NULc38quGC1x+8ZXry4w9mMX3IA7wUjFboTv7kVOwPlleIc8UqIsjVvKTUFnUuW8dlGQzNR1KkvbvZ1NA"}"#, - signature: "3e35bdcd50b737f2ab860b5c7ef195ebcb8c3d98c5f7200ef052315ba13bfb9153b03e595e21cf14a88b2356f2935059d4b96f1d946433351d4a92f6ef675340", - signature_json: r#"[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"Asv9teRyiTMiKU5gzwiD1D30MeEInSnstEep5tVQRarl"},"signature":"PjW9zVC3N/KrhgtcfvGV68uMPZjF9yAO8FIxW6E7+5FTsD5ZXiHPFKiLI1byk1BZ1LlvHZRkMzUdSpL272dTQA=="}]"#, - }); + coin: &coin, + input: input.clone(), + tx: r#"{"mode":"BROADCAST_MODE_BLOCK","tx_bytes":"ClQKUgobL2Nvc21vcy5nb3YudjFiZXRhMS5Nc2dWb3RlEjMITRItY29zbW9zMW1yeTQ3cGtnYTV0ZHN3dGx1eTBtOHRlc2xwYWxrZHEwN3Bzd3U0GAESZQpOCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAsv9teRyiTMiKU5gzwiD1D30MeEInSnstEep5tVQRarlEgQKAggBEhMKDQoFdWF0b20SBDI0MTgQkfsFGkA+Nb3NULc38quGC1x+8ZXry4w9mMX3IA7wUjFboTv7kVOwPlleIc8UqIsjVvKTUFnUuW8dlGQzNR1KkvbvZ1NA"}"#, + signature: "3e35bdcd50b737f2ab860b5c7ef195ebcb8c3d98c5f7200ef052315ba13bfb9153b03e595e21cf14a88b2356f2935059d4b96f1d946433351d4a92f6ef675340", + signature_json: r#"[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"Asv9teRyiTMiKU5gzwiD1D30MeEInSnstEep5tVQRarl"},"signature":"PjW9zVC3N/KrhgtcfvGV68uMPZjF9yAO8FIxW6E7+5FTsD5ZXiHPFKiLI1byk1BZ1LlvHZRkMzUdSpL272dTQA=="}]"#, + }); // `MsgVote` doesn't support JSON serialization and signing. test_sign_json_error::(TestErrorInput { diff --git a/rust/tw_proto/build.rs b/rust/tw_proto/build.rs index db64fb9f778..83b73253681 100644 --- a/rust/tw_proto/build.rs +++ b/rust/tw_proto/build.rs @@ -13,9 +13,8 @@ fn main() { let proto_ext = Some(Path::new("proto").as_os_str()); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto"); - let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - let proto_dir = cargo_manifest_dir + let proto_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) .join("..") .join("..") .join("src") @@ -47,21 +46,9 @@ fn main() { .create(&out_dir) .expect("Error creating out directory"); - // `tw_proto/common_proto` contains google.protobuf proto files that are used in Cosmos protocol. - let common_proto_dir = cargo_manifest_dir - .join("src") - .join("common") - .canonicalize() - .expect("Cannot find common proto directory"); - - let out_protos = ConfigBuilder::new( - &protos, - None, - Some(&out_dir), - &[common_proto_dir, proto_dir], - ) - .expect("Error configuring pb-rs builder") - .build(); + let out_protos = ConfigBuilder::new(&protos, None, Some(&out_dir), &[proto_dir]) + .expect("Error configuring pb-rs builder") + .build(); FileDescriptor::run(&out_protos).expect("Error generating proto files"); #[cfg(feature = "fuzz")] diff --git a/rust/tw_proto/src/common/google/protobuf/any.proto b/rust/tw_proto/src/common/google/protobuf/any.proto index 9771c5c2a26..c7aa5a0baa1 100644 --- a/rust/tw_proto/src/common/google/protobuf/any.proto +++ b/rust/tw_proto/src/common/google/protobuf/any.proto @@ -32,7 +32,7 @@ // To recompile the file use the following command inside `wallet-core` directory: // ``` // cargo install pb-rs -// pb-rs --single-mod --output_directory rust/tw_proto/src/common/google/protobuf/ rust/tw_proto/src/common/google/protobuf/any.proto +// pb-rs --dont_use_cow --single-mod --output_directory rust/tw_proto/common_proto/google/protobuf/ rust/tw_proto/common_proto/google/protobuf/any.proto // ``` syntax = "proto3"; diff --git a/rust/tw_proto/src/common/google/protobuf/any.rs b/rust/tw_proto/src/common/google/protobuf/any.rs index fbd3f90464b..743b9b93b94 100644 --- a/rust/tw_proto/src/common/google/protobuf/any.rs +++ b/rust/tw_proto/src/common/google/protobuf/any.rs @@ -9,25 +9,24 @@ #![cfg_attr(rustfmt, rustfmt_skip)] -use std::borrow::Cow; use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; use quick_protobuf::sizeofs::*; use super::*; #[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Debug, arbitrary::Arbitrary, Default, PartialEq, Clone)] -pub struct Any<'a> { - pub type_url: Cow<'a, str>, - pub value: Cow<'a, [u8]>, +#[derive(Debug, Default, PartialEq, Clone)] +pub struct Any { + pub type_url: String, + pub value: Vec, } -impl<'a> MessageRead<'a> for Any<'a> { +impl<'a> MessageRead<'a> for Any { fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { let mut msg = Self::default(); while !r.is_eof() { match r.next_tag(bytes) { - Ok(10) => msg.type_url = r.read_string(bytes).map(Cow::Borrowed)?, - Ok(18) => msg.value = r.read_bytes(bytes).map(Cow::Borrowed)?, + Ok(10) => msg.type_url = r.read_string(bytes)?.to_owned(), + Ok(18) => msg.value = r.read_bytes(bytes)?.to_owned(), Ok(t) => { r.read_unknown(bytes, t)?; } Err(e) => return Err(e), } @@ -36,16 +35,16 @@ impl<'a> MessageRead<'a> for Any<'a> { } } -impl<'a> MessageWrite for Any<'a> { +impl MessageWrite for Any { fn get_size(&self) -> usize { 0 - + if self.type_url == "" { 0 } else { 1 + sizeof_len((&self.type_url).len()) } - + if self.value == Cow::Borrowed(b"") { 0 } else { 1 + sizeof_len((&self.value).len()) } + + if self.type_url == String::default() { 0 } else { 1 + sizeof_len((&self.type_url).len()) } + + if self.value.is_empty() { 0 } else { 1 + sizeof_len((&self.value).len()) } } fn write_message(&self, w: &mut Writer) -> Result<()> { - if self.type_url != "" { w.write_with_tag(10, |w| w.write_string(&**&self.type_url))?; } - if self.value != Cow::Borrowed(b"") { w.write_with_tag(18, |w| w.write_bytes(&**&self.value))?; } + if self.type_url != String::default() { w.write_with_tag(10, |w| w.write_string(&**&self.type_url))?; } + if !self.value.is_empty() { w.write_with_tag(18, |w| w.write_bytes(&**&self.value))?; } Ok(()) } } diff --git a/rust/tw_proto/src/common/google/protobuf/timestamp.proto b/rust/tw_proto/src/common/google/protobuf/timestamp.proto index 8b33782ea8b..353b1632497 100644 --- a/rust/tw_proto/src/common/google/protobuf/timestamp.proto +++ b/rust/tw_proto/src/common/google/protobuf/timestamp.proto @@ -32,7 +32,7 @@ // To recompile the file use the following command inside `wallet-core` directory: // ``` // cargo install pb-rs -// pb-rs --single-mod --output_directory rust/tw_proto/src/common/google/protobuf/ rust/tw_proto/src/common/google/protobuf/timestamp.proto +// pb-rs --dont_use_cow --single-mod --output_directory rust/tw_proto/common_proto/google/protobuf/ rust/tw_proto/common_proto/google/protobuf/any.proto // ``` syntax = "proto3"; diff --git a/rust/tw_proto/src/common/google/protobuf/timestamp.rs b/rust/tw_proto/src/common/google/protobuf/timestamp.rs index a0e81e5aab3..2e073dbe982 100644 --- a/rust/tw_proto/src/common/google/protobuf/timestamp.rs +++ b/rust/tw_proto/src/common/google/protobuf/timestamp.rs @@ -14,7 +14,7 @@ use quick_protobuf::sizeofs::*; use super::*; #[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Debug, arbitrary::Arbitrary, Default, PartialEq, Clone)] +#[derive(Debug, Default, PartialEq, Clone)] pub struct Timestamp { pub seconds: i64, pub nanos: i32, diff --git a/rust/tw_proto/src/lib.rs b/rust/tw_proto/src/lib.rs index 86a9b6a31f5..aa0620c22bc 100644 --- a/rust/tw_proto/src/lib.rs +++ b/rust/tw_proto/src/lib.rs @@ -3,7 +3,6 @@ // Copyright © 2017 Trust Wallet. use quick_protobuf::{BytesReader, MessageInfo, Writer}; -use std::borrow::Cow; #[allow(non_snake_case)] #[rustfmt::skip] @@ -15,8 +14,6 @@ mod impls; #[allow(unused_variables)] #[rustfmt::skip] mod generated { - use crate::google; - include!(concat!(env!("OUT_DIR"), "/proto/mod.rs")); } @@ -45,21 +42,20 @@ pub fn deserialize<'a, T: MessageRead<'a>>(data: &'a [u8]) -> ProtoResult { T::from_reader(&mut reader, data) } -pub fn to_any(message: &T) -> google::protobuf::Any<'static> +pub fn to_any(message: &T) -> google::protobuf::Any where T: MessageInfo + MessageWrite, { - let value = Cow::from(serialize(message).expect("Protobuf serialization should never fail")); - let type_url = Cow::from(type_url::()); + let value = serialize(message).expect("Protobuf serialization should never fail"); + let type_url = type_url::(); google::protobuf::Any { type_url, value } } -pub fn to_any_with_type_url(message: &T, type_url: String) -> google::protobuf::Any<'static> +pub fn to_any_with_type_url(message: &T, type_url: String) -> google::protobuf::Any where T: MessageInfo + MessageWrite, { - let type_url = Cow::from(type_url); - let value = Cow::from(serialize(message).expect("Protobuf serialization should never fail")); + let value = serialize(message).expect("Protobuf serialization should never fail"); google::protobuf::Any { type_url, value } } diff --git a/rust/tw_tests/tests/chains/common/bitcoin/mod.rs b/rust/tw_tests/tests/chains/common/bitcoin/mod.rs index 7c33bef9628..8a3e5af260f 100644 --- a/rust/tw_tests/tests/chains/common/bitcoin/mod.rs +++ b/rust/tw_tests/tests/chains/common/bitcoin/mod.rs @@ -75,7 +75,6 @@ pub mod input { Some(Proto::OutPoint { hash: reverse_txid(txid).into(), vout, - ..Proto::OutPoint::default() }) } diff --git a/src/proto/BitcoinV2.proto b/src/proto/BitcoinV2.proto index 37b58c1c1fa..8f74dbb53c4 100644 --- a/src/proto/BitcoinV2.proto +++ b/src/proto/BitcoinV2.proto @@ -5,7 +5,6 @@ option java_package = "wallet.core.jni.proto"; import "BabylonStaking.proto"; import "Common.proto"; -import "google/protobuf/any.proto"; enum InputSelector { // Automatically select enough inputs in an ascending order to cover the outputs of the transaction. @@ -44,10 +43,6 @@ message OutPoint { // The position in the previous transactions output that this input references. uint32 vout = 2; - - // Chain specific arguments, like for Decred. - // Should be empty for Bitcoin chain. - google.protobuf.Any chain_specific = 3; } message Input { @@ -258,9 +253,6 @@ message TransactionBuilder { // If set, `SigningInput.outputs` and `SigningInput.change` will be ignored. // The `Output.value` will be overwritten, leave default. Output max_amount_output = 8; - // Chain specific arguments, like for ZCash. - // Should be empty for Bitcoin chain. - google.protobuf.Any chain_specific = 12; // One of the "Dust" amount policies. // Later, we plan to add support for `DynamicDust` policy with a `min_relay_fee` amount. oneof dust_policy { diff --git a/src/proto/Zcash.proto b/src/proto/Zcash.proto deleted file mode 100644 index c6fd076cf59..00000000000 --- a/src/proto/Zcash.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package TW.Zcash.Proto; -option java_package = "wallet.core.jni.proto"; - -import "BitcoinV2.proto"; -import "Common.proto"; - -message TransactionBuilderExtraData { - // Currently, `branch_id` is the only configurable Zcash specific parameter. - // There can also be `version_group_id` configured in the future. - bytes branch_id = 1; -}