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

Revert Zcash changes #4216

Merged
merged 1 commit into from
Jan 16, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl<Context: UtxoContext> PsbtPlanner<Context> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_greenfield/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub struct GreenfieldTransferOut {
impl CosmosMessage for GreenfieldTransferOut {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_native_evmos/src/ethermint_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
1 change: 1 addition & 0 deletions rust/tw_cosmos_sdk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
68 changes: 28 additions & 40 deletions rust/tw_cosmos_sdk/src/modules/serializer/protobuf_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand All @@ -38,73 +37,62 @@ pub struct SignDirectArgs {
impl<Context: CosmosContext> ProtobufSerializer<Context> {
/// 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<Context>,
) -> SigningResult<tx_proto::TxRaw<'static>> {
pub fn build_signed_tx(signed: &SignedTransaction<Context>) -> SigningResult<tx_proto::TxRaw> {
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],
}
}

/// Serializes an unsigned transaction into the Cosmos [`tx_proto::SignDoc`] message.
/// [`tx_proto::SignDoc`] is used to generate a transaction prehash and sign it.
pub fn build_sign_doc(
unsigned: &UnsignedTransaction<Context>,
) -> SigningResult<tx_proto::SignDoc<'static>> {
) -> SigningResult<tx_proto::SignDoc> {
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,
}
}

pub fn build_auth_info(
signer: &SignerInfo<Context::PublicKey>,
fee: &Fee<Context::Address>,
) -> tx_proto::AuthInfo<'static> {
) -> tx_proto::AuthInfo {
tx_proto::AuthInfo {
signer_infos: vec![Self::build_signer_info(signer)],
fee: Some(Self::build_fee(fee)),
Expand All @@ -113,7 +101,7 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {
}
}

pub fn build_tx_body(tx_body: &TxBody) -> SigningResult<tx_proto::TxBody<'static>> {
pub fn build_tx_body(tx_body: &TxBody) -> SigningResult<tx_proto::TxBody> {
let messages: Vec<_> = tx_body
.messages
.iter()
Expand All @@ -122,14 +110,14 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {

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<Context::PublicKey>) -> tx_proto::SignerInfo<'static> {
pub fn build_signer_info(signer: &SignerInfo<Context::PublicKey>) -> 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
Expand All @@ -147,13 +135,13 @@ impl<Context: CosmosContext> ProtobufSerializer<Context> {
}
}

fn build_fee(fee: &Fee<Context::Address>) -> tx_proto::Fee<'static> {
fn build_fee(fee: &Fee<Context::Address>) -> 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(),
}
}

Expand Down
5 changes: 2 additions & 3 deletions rust/tw_cosmos_sdk/src/modules/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rust/tw_cosmos_sdk/src/public_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rust/tw_cosmos_sdk/src/public_key/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tw_proto::{google, to_any};
pub struct AuthGrantMessage<Address: CosmosAddress> {
pub granter: Address,
pub grantee: Address,
pub grant_msg: ProtobufMessage,
pub grant_msg: google::protobuf::Any,
pub expiration_secs: i64,
}

Expand All @@ -28,8 +28,8 @@ impl<Address: CosmosAddress> CosmosMessage for AuthGrantMessage<Address> {
};

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))
Expand All @@ -46,9 +46,9 @@ pub struct AuthRevokeMessage<Address: CosmosAddress> {
impl<Address: CosmosAddress> CosmosMessage for AuthRevokeMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub struct SendMessage<Address: CosmosAddress> {
impl<Address: CosmosAddress> CosmosMessage for SendMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<Address: CosmosAddress> CosmosMessage for VoteMessage<Address> {

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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl<Address: CosmosAddress> CosmosMessage for DelegateMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand Down Expand Up @@ -60,8 +60,8 @@ impl<Address: CosmosAddress> CosmosMessage for UndelegateMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand Down Expand Up @@ -90,9 +90,9 @@ impl<Address: CosmosAddress> CosmosMessage for BeginRedelegateMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand All @@ -118,8 +118,8 @@ pub struct WithdrawDelegationRewardMessage<Address: CosmosAddress> {
impl<Address: CosmosAddress> CosmosMessage for WithdrawDelegationRewardMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand All @@ -145,8 +145,8 @@ pub struct SetWithdrawAddressMessage<Address: CosmosAddress> {
impl<Address: CosmosAddress> CosmosMessage for SetWithdrawAddressMessage<Address> {
fn to_proto(&self) -> SigningResult<ProtobufMessage> {
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))
}
Expand Down
8 changes: 4 additions & 4 deletions rust/tw_cosmos_sdk/src/transaction/message/ibc_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ impl<Address: CosmosAddress> CosmosMessage for TransferTokensMessage<Address> {
};

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,
};
Expand Down
2 changes: 1 addition & 1 deletion rust/tw_cosmos_sdk/src/transaction/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn CosmosMessage>;
pub type JsonMessage = AnyMsg<Json>;

Expand Down
Loading
Loading