diff --git a/.github/workflows/cosmos-sdk-proto.yml b/.github/workflows/cosmos-sdk-proto.yml index 2daf4fc7..ddadf482 100644 --- a/.github/workflows/cosmos-sdk-proto.yml +++ b/.github/workflows/cosmos-sdk-proto.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.59.0 # MSRV - stable target: - x86_64-unknown-linux-gnu @@ -43,7 +43,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.59.0 # MSRV - stable steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/cosmrs.yml b/.github/workflows/cosmrs.yml index 651f2313..d6d85f48 100644 --- a/.github/workflows/cosmrs.yml +++ b/.github/workflows/cosmrs.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.59.0 # MSRV - stable target: - x86_64-unknown-linux-gnu @@ -44,7 +44,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.59.0 # MSRV - stable steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/rebuild-protos.yml b/.github/workflows/rebuild-protos.yml index da8c31f3..bedc94bf 100644 --- a/.github/workflows/rebuild-protos.yml +++ b/.github/workflows/rebuild-protos.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.57.0 # MSRV + toolchain: 1.59.0 # MSRV components: rustfmt override: true profile: minimal diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index f0e6f0ec..475b3eb0 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.57.0 # MSRV + toolchain: stable components: rustfmt override: true profile: minimal @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.57.0 # MSRV + toolchain: 1.59.0 components: clippy override: true profile: minimal diff --git a/README.md b/README.md index 803fc532..1ce34b47 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ all other crates, simply make the required edits in [main.rs](proto-build/main.r ## Minimum Supported Rust Version -Rust **1.57** +Rust **1.59** [//]: # "crates" diff --git a/cosmos-sdk-proto/Cargo.toml b/cosmos-sdk-proto/Cargo.toml index f5bd70fd..ee7282eb 100644 --- a/cosmos-sdk-proto/Cargo.toml +++ b/cosmos-sdk-proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmos-sdk-proto" -version = "0.14.0" +version = "0.15.0-pre" authors = [ "Justin Kilpatrick ", "Greg Szabo ", @@ -13,12 +13,12 @@ readme = "README.md" categories = ["cryptography", "cryptography::cryptocurrencies", "database"] keywords = ["blockchain", "cosmos", "tendermint", "proto"] edition = "2021" -rust-version = "1.56" +rust-version = "1.59" [dependencies] prost = "0.11" prost-types = "0.11" -tendermint-proto = "=0.23.9" +tendermint-proto = "0.26" # Optional dependencies tonic = { version = "0.8", optional = true, default-features = false, features = ["codegen", "prost"] } diff --git a/cosmos-sdk-proto/README.md b/cosmos-sdk-proto/README.md index cb6011b1..0af8bc21 100644 --- a/cosmos-sdk-proto/README.md +++ b/cosmos-sdk-proto/README.md @@ -20,7 +20,7 @@ Pull requests to expand coverage are welcome. ## Minimum Supported Rust Version -This crate is supported on Rust **1.57** or newer. +This crate is supported on Rust **1.59** or newer. [//]: # "badges" [crate-image]: https://buildstats.info/crate/cosmos-sdk-proto @@ -31,7 +31,7 @@ This crate is supported on Rust **1.57** or newer. [build-link]: https://github.com/cosmos/cosmos-rust/actions/workflows/cosmos-sdk-proto.yml [license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg [license-link]: https://github.com/cosmos/cosmos-rust/blob/master/LICENSE -[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.59+-blue.svg [//]: # "links" [Protobufs]: (https://github.com/cosmos/cosmos-sdk/tree/master/proto/) diff --git a/cosmrs/Cargo.toml b/cosmrs/Cargo.toml index f6f071d2..0133fa0d 100644 --- a/cosmrs/Cargo.toml +++ b/cosmrs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmrs" -version = "0.9.0" +version = "0.10.0-pre" authors = ["Tony Arcieri "] license = "Apache-2.0" repository = "https://github.com/cosmos/cosmos-rust/tree/main/cosmrs" @@ -9,10 +9,10 @@ readme = "README.md" categories = ["cryptography", "cryptography::cryptocurrencies", "encoding"] keywords = ["blockchain", "cosmos", "tendermint", "transaction"] edition = "2021" -rust-version = "1.57" +rust-version = "1.59" [dependencies] -cosmos-sdk-proto = { version = "0.14", default-features = false, path = "../cosmos-sdk-proto" } +cosmos-sdk-proto = { version = "=0.15.0-pre", default-features = false, path = "../cosmos-sdk-proto" } ecdsa = { version = "0.14", features = ["std"] } eyre = "0.6" k256 = { version = "0.11", features = ["ecdsa", "sha256"] } @@ -20,12 +20,12 @@ rand_core = { version = "0.6", features = ["std"] } serde = { version = "1", features = ["serde_derive"] } serde_json = "1" subtle-encoding = { version = "0.5", features = ["bech32-preview"] } -tendermint = { version = "=0.23.9", features = ["secp256k1"] } +tendermint = { version = "0.26", features = ["secp256k1"] } thiserror = "1" # optional dependencies bip32 = { version = "0.4", optional = true } -tendermint-rpc = { version = "=0.23.9", optional = true, features = ["http-client"] } +tendermint-rpc = { version = "0.26", optional = true, features = ["http-client"] } tokio = { version = "1", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/cosmrs/README.md b/cosmrs/README.md index 6de3a287..bb47451a 100644 --- a/cosmrs/README.md +++ b/cosmrs/README.md @@ -30,7 +30,7 @@ and message passing. ## Minimum Supported Rust Version -This crate is supported on Rust **1.57** or newer. +This crate is supported on Rust **1.59** or newer. [//]: # "badges" [crate-image]: https://buildstats.info/crate/cosmrs @@ -41,7 +41,7 @@ This crate is supported on Rust **1.57** or newer. [build-link]: https://github.com/cosmos/cosmos-rust/actions/workflows/cosmrs.yml [license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg [license-link]: https://github.com/cosmos/cosmos-rust/blob/master/LICENSE -[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.59+-blue.svg [//]: # "general links" [Cosmos]: https://cosmos.network/ diff --git a/cosmrs/src/abci.rs b/cosmrs/src/abci.rs index 79b5af85..4b6e7411 100644 --- a/cosmrs/src/abci.rs +++ b/cosmrs/src/abci.rs @@ -1,12 +1,14 @@ //! Abci-related functionality -use crate::tx::Msg; use crate::{ proto::{self, traits::Message}, - ErrorReport, Result, + tx::Msg, + ErrorReport, Gas, Result, }; use serde::{Deserialize, Serialize}; -use tendermint::abci::Gas; + +/// Transaction data. +pub type Data = Vec; /// MsgData defines the data returned in a Result object during message execution. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] @@ -61,12 +63,11 @@ pub struct TxMsgData { pub data: Vec, } -impl TryFrom for TxMsgData { +impl TryFrom for TxMsgData { type Error = ErrorReport; - fn try_from(data: tendermint::abci::Data) -> Result { - let proto = proto::cosmos::base::abci::v1beta1::TxMsgData::decode(data.value().as_ref())?; - proto.try_into() + fn try_from(data: Data) -> Result { + proto::cosmos::base::abci::v1beta1::TxMsgData::decode(data.as_ref())?.try_into() } } @@ -111,8 +112,8 @@ impl TryFrom for GasInfo { fn try_from(proto: proto::cosmos::base::abci::v1beta1::GasInfo) -> Result { Ok(GasInfo { - gas_wanted: Gas::from(proto.gas_wanted), - gas_used: Gas::from(proto.gas_used), + gas_wanted: proto.gas_wanted, + gas_used: proto.gas_used, }) } } @@ -120,8 +121,8 @@ impl TryFrom for GasInfo { impl From for proto::cosmos::base::abci::v1beta1::GasInfo { fn from(info: GasInfo) -> Self { proto::cosmos::base::abci::v1beta1::GasInfo { - gas_wanted: info.gas_wanted.value(), - gas_used: info.gas_wanted.value(), + gas_wanted: info.gas_wanted, + gas_used: info.gas_wanted, } } } diff --git a/cosmrs/src/base.rs b/cosmrs/src/base.rs index 91258a5a..362fdfa2 100644 --- a/cosmrs/src/base.rs +++ b/cosmrs/src/base.rs @@ -126,6 +126,9 @@ impl Serialize for AccountId { } } +/// Amounts. +pub type Amount = u128; + /// Coin defines a token with a denomination and an amount. #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] pub struct Coin { @@ -133,12 +136,12 @@ pub struct Coin { pub denom: Denom, /// Amount - pub amount: u128, + pub amount: Amount, } impl Coin { /// Constructor - pub fn new(amount: u128, denom: &str) -> Result { + pub fn new(amount: Amount, denom: &str) -> Result { Ok(Coin { amount, denom: denom.parse()?, @@ -232,6 +235,9 @@ impl Serialize for Denom { } } +/// Gas cost. +pub type Gas = u64; + #[cfg(test)] mod tests { use super::{AccountId, Coin, Denom}; diff --git a/cosmrs/src/dev.rs b/cosmrs/src/dev.rs index c67ed231..e36c993a 100644 --- a/cosmrs/src/dev.rs +++ b/cosmrs/src/dev.rs @@ -10,6 +10,7 @@ use crate::{ tx::{self, Tx}, }; use std::{ffi::OsStr, panic, process, str, time::Duration}; +use tendermint_rpc::abci::transaction::Hash; use tokio::time; /// Docker image (on Docker Hub) containing a single-node test environment for @@ -101,9 +102,13 @@ pub async fn poll_for_first_block(rpc_client: &rpc::HttpClient) { } /// Wait for a transaction with the given hash to appear in the blockchain -pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: tx::Hash) -> Tx { +pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: Hash) -> Tx { let attempts = 5; + // TODO(tarcieri): better conversion or unified `Hash` type, see tendermint-rs#1221 + #[allow(clippy::unwrap_used)] + let tx_hash = tx::Hash::Sha256(tx_hash.as_ref().try_into().unwrap()); + for _ in 0..attempts { // TODO(tarcieri): handle not found errors if let Ok(tx) = Tx::find_by_hash(rpc_client, tx_hash).await { diff --git a/cosmrs/src/lib.rs b/cosmrs/src/lib.rs index 6f7e077d..b2571c73 100644 --- a/cosmrs/src/lib.rs +++ b/cosmrs/src/lib.rs @@ -47,7 +47,7 @@ mod base; mod error; pub use crate::{ - base::{AccountId, Coin, Denom}, + base::{AccountId, Amount, Coin, Denom, Gas}, error::{Error, Result}, tx::Tx, }; diff --git a/cosmrs/src/tx.rs b/cosmrs/src/tx.rs index ae30e0d9..de60fb95 100644 --- a/cosmrs/src/tx.rs +++ b/cosmrs/src/tx.rs @@ -63,7 +63,7 @@ //! let chain_id = "cosmoshub-4".parse()?; //! let account_number = 1; //! let sequence_number = 0; -//! let gas = 100_000; +//! let gas = 100_000u64; //! let timeout_height = 9001u16; //! let memo = "example memo"; //! @@ -128,11 +128,11 @@ pub use crate::{ proto::{cosmos::tx::signing::v1beta1::SignMode, traits::MessageExt}, ErrorReport, }; -pub use tendermint::abci::{transaction::Hash, Gas}; +pub use tendermint::Hash; use crate::{ proto::{self, traits::Message}, - Error, Result, + Error, Gas, Result, }; #[cfg(feature = "rpc")] @@ -178,6 +178,12 @@ impl Tx { where C: rpc::Client + Send + Sync, { + // TODO(tarcieri): better conversion or unified `Hash` type, see tendermint-rs#1221 + let tx_hash = match tx_hash { + Hash::Sha256(bytes) => tendermint_rpc::abci::transaction::Hash::new(bytes), + _ => return Err(Error::Crypto.into()), + }; + let response = rpc_client.tx(tx_hash, false).await?; Tx::from_bytes(response.tx.as_bytes()) } diff --git a/cosmrs/src/tx/fee.rs b/cosmrs/src/tx/fee.rs index d13fb411..78a3d27c 100644 --- a/cosmrs/src/tx/fee.rs +++ b/cosmrs/src/tx/fee.rs @@ -72,7 +72,7 @@ impl TryFrom<&proto::cosmos::tx::v1beta1::Fee> for Fee { Ok(Fee { amount, - gas_limit: proto.gas_limit.into(), + gas_limit: proto.gas_limit, payer: proto.payer.parse_optional()?, granter: proto.granter.parse_optional()?, }) @@ -89,7 +89,7 @@ impl From<&Fee> for proto::cosmos::tx::v1beta1::Fee { fn from(fee: &Fee) -> proto::cosmos::tx::v1beta1::Fee { proto::cosmos::tx::v1beta1::Fee { amount: fee.amount.iter().map(Into::into).collect(), - gas_limit: fee.gas_limit.value(), + gas_limit: fee.gas_limit, payer: fee .payer .as_ref() diff --git a/cosmrs/tests/integration.rs b/cosmrs/tests/integration.rs index 71247762..b3723c70 100644 --- a/cosmrs/tests/integration.rs +++ b/cosmrs/tests/integration.rs @@ -58,7 +58,7 @@ fn msg_send() { let chain_id = CHAIN_ID.parse().unwrap(); let sequence_number = 0; - let gas = 100_000; + let gas = 100_000u64; let fee = Fee::from_amount_and_gas(amount, gas); let tx_body = tx::BodyBuilder::new().msg(msg_send).memo(MEMO).finish(); diff --git a/rust-toolchain b/rust-toolchain index 373aea97..bb120e87 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.57.0 +1.59.0