Skip to content

Commit

Permalink
Feature/pre cosmrs updates (#935)
Browse files Browse the repository at this point in the history
* Updated nymd client

* Fixed contract upload and initialisation

* Increased default contract upload fee

* [ci skip] Generate TS types

Co-authored-by: jstuczyn <jstuczyn@users.noreply.github.com>
  • Loading branch information
jstuczyn and jstuczyn authored Dec 6, 2021
1 parent 18978c7 commit a04d450
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 90 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion common/client-libs/validator-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ network-defaults = { path = "../../network-defaults" }
async-trait = { version = "0.1.51", optional = true }
bip39 = { version = "1", features = ["rand"], optional = true }
config = { path = "../../config", optional = true }
cosmrs = { version = "0.3", features = ["rpc", "bip32", "cosmwasm"], optional = true }
#cosmrs = { version = "0.3", features = ["rpc", "bip32", "cosmwasm"], optional = true }
cosmrs = { git = "https://github.com/jstuczyn/cosmos-rust/", branch="jstuczyn/wasmd-021-update", features = ["rpc", "bip32", "cosmwasm"], optional = true }
prost = { version = "0.9", default-features = false, optional = true }
flate2 = { version = "1.0.20", optional = true }
sha2 = { version = "0.9.5", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cosmrs::proto::cosmos::auth::v1beta1::{
use cosmrs::proto::cosmos::bank::v1beta1::{
QueryAllBalancesRequest, QueryAllBalancesResponse, QueryBalanceRequest, QueryBalanceResponse,
};
use cosmrs::proto::cosmwasm::wasm::v1beta1::*;
use cosmrs::proto::cosmwasm::wasm::v1::*;
use cosmrs::rpc::endpoint::block::Response as BlockResponse;
use cosmrs::rpc::endpoint::broadcast;
use cosmrs::rpc::endpoint::tx::Response as TxResponse;
Expand Down Expand Up @@ -213,7 +213,7 @@ pub trait CosmWasmClient: rpc::Client {
}

async fn get_codes(&self) -> Result<Vec<Code>, NymdError> {
let path = Some("/cosmwasm.wasm.v1beta1.Query/Codes".parse().unwrap());
let path = Some("/cosmwasm.wasm.v1.Query/Codes".parse().unwrap());

let mut raw_codes = Vec::new();
let mut pagination = None;
Expand All @@ -240,7 +240,7 @@ pub trait CosmWasmClient: rpc::Client {
}

async fn get_code_details(&self, code_id: ContractCodeId) -> Result<CodeDetails, NymdError> {
let path = Some("/cosmwasm.wasm.v1beta1.Query/Code".parse().unwrap());
let path = Some("/cosmwasm.wasm.v1.Query/Code".parse().unwrap());

let req = QueryCodeRequest { code_id };

Expand All @@ -255,11 +255,7 @@ pub trait CosmWasmClient: rpc::Client {
}
}
async fn get_contracts(&self, code_id: ContractCodeId) -> Result<Vec<AccountId>, NymdError> {
let path = Some(
"/cosmwasm.wasm.v1beta1.Query/ContractsByCode"
.parse()
.unwrap(),
);
let path = Some("/cosmwasm.wasm.v1.Query/ContractsByCode".parse().unwrap());

let mut raw_contracts = Vec::new();
let mut pagination = None;
Expand Down Expand Up @@ -290,7 +286,7 @@ pub trait CosmWasmClient: rpc::Client {
}

async fn get_contract(&self, address: &AccountId) -> Result<Contract, NymdError> {
let path = Some("/cosmwasm.wasm.v1beta1.Query/ContractInfo".parse().unwrap());
let path = Some("/cosmwasm.wasm.v1.Query/ContractInfo".parse().unwrap());

let req = QueryContractInfoRequest {
address: address.to_string(),
Expand All @@ -315,11 +311,7 @@ pub trait CosmWasmClient: rpc::Client {
&self,
address: &AccountId,
) -> Result<Vec<ContractCodeHistoryEntry>, NymdError> {
let path = Some(
"/cosmwasm.wasm.v1beta1.Query/ContractHistory"
.parse()
.unwrap(),
);
let path = Some("/cosmwasm.wasm.v1.Query/ContractHistory".parse().unwrap());

let mut raw_entries = Vec::new();
let mut pagination = None;
Expand Down Expand Up @@ -353,11 +345,7 @@ pub trait CosmWasmClient: rpc::Client {
address: &AccountId,
query_data: Vec<u8>,
) -> Result<Vec<u8>, NymdError> {
let path = Some(
"/cosmwasm.wasm.v1beta1.Query/RawContractState"
.parse()
.unwrap(),
);
let path = Some("/cosmwasm.wasm.v1.Query/RawContractState".parse().unwrap());

let req = QueryRawContractStateRequest {
address: address.to_string(),
Expand All @@ -381,7 +369,7 @@ pub trait CosmWasmClient: rpc::Client {
for<'a> T: Deserialize<'a>,
{
let path = Some(
"/cosmwasm.wasm.v1beta1.Query/SmartContractState"
"/cosmwasm.wasm.v1.Query/SmartContractState"
.parse()
.unwrap(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
wasm_code: Vec<u8>,
fee: Fee,
memo: impl Into<String> + Send + 'static,
mut meta: Option<UploadMeta>,
) -> Result<UploadResult, NymdError> {
let compressed = compress_wasm_code(&wasm_code)?;
let compressed_size = compressed.len();
Expand All @@ -42,14 +41,6 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
let upload_msg = cosmwasm::MsgStoreCode {
sender: sender_address.clone(),
wasm_byte_code: compressed,
source: meta
.as_mut()
.map(|meta| meta.source.take())
.unwrap_or_default(),
builder: meta
.as_mut()
.map(|meta| meta.builder.take())
.unwrap_or_default(),
instantiate_permission: Default::default(),
}
.to_any()
Expand All @@ -66,7 +57,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
// the reason I think unwrap here is fine is that if the transaction succeeded and those
// fields do not exist or code_id is not a number, there's no way we can recover, we're probably connected
// to wrong validator or something
let code_id = logs::find_attribute(&logs, "message", "code_id")
let code_id = logs::find_attribute(&logs, "store_code", "code_id")
.unwrap()
.value
.parse()
Expand Down Expand Up @@ -111,7 +102,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
// now this is a weird one. the protobuf files say this field is optional,
// but if you omit it, the initialisation will fail CheckTx
label: Some(label),
init_msg: serde_json::to_vec(msg)?,
msg: serde_json::to_vec(msg)?,
funds: options.map(|options| options.funds).unwrap_or_default(),
}
.to_any()
Expand All @@ -128,7 +119,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
// the reason I think unwrap here is fine is that if the transaction succeeded and those
// fields do not exist or address is malformed, there's no way we can recover, we're probably connected
// to wrong validator or something
let contract_address = logs::find_attribute(&logs, "message", "contract_address")
let contract_address = logs::find_attribute(&logs, "instantiate", "_contract_address")
.unwrap()
.value
.parse()
Expand Down Expand Up @@ -209,7 +200,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
sender: sender_address.clone(),
contract: contract_address.clone(),
code_id,
migrate_msg: serde_json::to_vec(msg)?,
msg: serde_json::to_vec(msg)?,
}
.to_any()
.map_err(|_| NymdError::SerializationError("MsgMigrateContract".to_owned()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::nymd::cosmwasm_client::logs::Log;
use crate::nymd::error::NymdError;
use cosmrs::crypto::PublicKey;
use cosmrs::proto::cosmos::auth::v1beta1::BaseAccount;
use cosmrs::proto::cosmwasm::wasm::v1beta1::{
use cosmrs::proto::cosmwasm::wasm::v1::{
CodeInfoResponse, ContractCodeHistoryEntry as ProtoContractCodeHistoryEntry,
ContractCodeHistoryOperationType, ContractInfo as ProtoContractInfo,
};
Expand Down Expand Up @@ -70,18 +70,6 @@ pub struct Code {

/// sha256 hash of the code stored
pub data_hash: Vec<u8>,

/// An URL to a .tar.gz archive of the source code of the contract,
/// which can be used to reproducibly build the Wasm bytecode.
///
/// @see https://github.com/CosmWasm/cosmwasm-verify
pub source: Option<String>,

/// A docker image (including version) to reproducibly build the Wasm bytecode from the source code.
///
/// @example ```cosmwasm/rust-optimizer:0.8.0```
/// @see https://github.com/CosmWasm/cosmwasm-verify
pub builder: Option<String>,
}

impl TryFrom<CodeInfoResponse> for Code {
Expand All @@ -92,31 +80,16 @@ impl TryFrom<CodeInfoResponse> for Code {
code_id,
creator,
data_hash,
source,
builder,
} = value;

let creator = creator
.parse()
.map_err(|_| NymdError::MalformedAccountAddress(creator))?;

let source = if source.is_empty() {
None
} else {
Some(source)
};
let builder = if builder.is_empty() {
None
} else {
Some(builder)
};

Ok(Code {
code_id,
creator,
data_hash,
source,
builder,
})
}
}
Expand Down Expand Up @@ -254,21 +227,6 @@ pub struct SignerData {
pub chain_id: chain::Id,
}

#[derive(Debug)]
pub struct UploadMeta {
/// An URL to a .tar.gz archive of the source code of the contract,
/// which can be used to reproducibly build the Wasm bytecode.
///
/// @see https://github.com/CosmWasm/cosmwasm-verify
pub source: Option<String>,

/// A docker image (including version) to reproducibly build the Wasm bytecode from the source code.
///
/// @example ```cosmwasm/rust-optimizer:0.8.0```
/// @see https://github.com/CosmWasm/cosmwasm-verify
pub builder: Option<String>,
}

#[derive(Debug)]
pub struct UploadResult {
/// Size of the original wasm code in bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Operation {
// TODO: some value tweaking
pub fn default_gas_limit(&self) -> Gas {
match self {
Operation::Upload => 2_500_000u64.into(),
Operation::Upload => 3_000_000u64.into(),
Operation::Init => 500_000u64.into(),
Operation::Migrate => 200_000u64.into(),
Operation::ChangeAdmin => 80_000u64.into(),
Expand Down
5 changes: 2 additions & 3 deletions common/client-libs/validator-client/src/nymd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::nymd::cosmwasm_client::signing_client;
use crate::nymd::cosmwasm_client::types::{
ChangeAdminResult, ContractCodeId, ExecuteResult, InstantiateOptions, InstantiateResult,
MigrateResult, SequenceResponse, UploadMeta, UploadResult,
MigrateResult, SequenceResponse, UploadResult,
};
use crate::nymd::error::NymdError;
use crate::nymd::fee_helpers::Operation;
Expand Down Expand Up @@ -501,14 +501,13 @@ impl<C> NymdClient<C> {
&self,
wasm_code: Vec<u8>,
memo: impl Into<String> + Send + 'static,
meta: Option<UploadMeta>,
) -> Result<UploadResult, NymdError>
where
C: SigningCosmWasmClient + Sync,
{
let fee = self.get_fee(Operation::Upload);
self.client
.upload(self.address(), wasm_code, fee, memo, meta)
.upload(self.address(), wasm_code, fee, memo)
.await
}

Expand Down
6 changes: 2 additions & 4 deletions nym-wallet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nym-wallet/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ url = "2.0"
rand = "0.6.5"


cosmrs = { version = "0.3", features = ["rpc", "bip32", "cosmwasm"] }
cosmrs = { git = "https://github.com/jstuczyn/cosmos-rust/", branch="jstuczyn/wasmd-021-update", features = ["rpc", "bip32", "cosmwasm"] }
cosmwasm-std = "1.0.0-beta2"

validator-client = { path = "../../common/client-libs/validator-client", features = [
Expand Down

0 comments on commit a04d450

Please sign in to comment.