Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updating to new subxt api
  • Loading branch information
ascjones committed Mar 3, 2022
commit 26aaff0be5dc76772f8f7cd5b7c1ab82350ad88e
6 changes: 3 additions & 3 deletions src/cmd/extrinsics/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

use super::{
RuntimeEvent,
runtime_api::api::contracts::events::ContractEmitted,
transcode::{env_types, ContractMessageTranscoder, TranscoderBuilder},
};
use crate::{maybe_println, Verbosity, DEFAULT_KEY_COL_WIDTH};
use colored::Colorize as _;

use anyhow::Result;
use scale::Input;
use subxt::{self, DefaultConfig, Event, TransactionEvents};

pub fn display_events(
result: &TransactionEvents<DefaultConfig>,
result: &TransactionEvents<DefaultConfig, RuntimeEvent>,
transcoder: &ContractMessageTranscoder,
subxt_metadata: &subxt::Metadata,
verbosity: &Verbosity,
Expand All @@ -46,7 +46,7 @@ pub fn display_events(

const EVENT_FIELD_INDENT: usize = DEFAULT_KEY_COL_WIDTH - 3;

for event in result.as_slice() {
for event in result.iter() {
log::debug!("displaying event {}::{}", event.pallet, event.variant);

let event_metadata = subxt_metadata.event(event.pallet_index, event.variant_index)?;
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ impl<'a> Exec<'a> {
display_events(&result, &self.transcoder, metadata, &self.verbosity)?;

let code_stored = result
.find_first_event::<api::contracts::events::CodeStored>()?
.find_first::<api::contracts::events::CodeStored>()?
.ok_or(anyhow!("Failed to find CodeStored event"))?;
let instantiated = result
.find_first_event::<api::contracts::events::Instantiated>()?
.find_first::<api::contracts::events::Instantiated>()?
.ok_or(anyhow!("Failed to find Instantiated event"))?;

Ok((code_stored.code_hash, instantiated.contract))
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a> Exec<'a> {
display_events(&result, &self.transcoder, metadata, &self.verbosity)?;

let instantiated = result
.find_first_event::<api::contracts::events::Instantiated>()?
.find_first::<api::contracts::events::Instantiated>()?
.ok_or(anyhow!("Failed to find Instantiated event"))?;

Ok(instantiated.contract)
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use subxt::{Config, DefaultConfig};
pub use call::CallCommand;
pub use instantiate::InstantiateCommand;
pub use upload::UploadCommand;
pub use runtime_api::api::{Event as RuntimeEvent, DispatchError as RuntimeDispatchError};

type Balance = u128;
type CodeHash = <DefaultConfig as Config>::Hash;
Expand Down Expand Up @@ -193,8 +194,8 @@ pub fn display_contract_exec_result<R>(result: &ContractResult<R, Balance>) -> R
/// Currently this will report success once the transaction is included in a block. In the future
/// there could be a flag to wait for finality before reporting success.
async fn wait_for_success_and_handle_error<T>(
tx_progress: subxt::TransactionProgress<'_, T, runtime_api::api::DispatchError>,
) -> Result<subxt::TransactionEvents<T>>
tx_progress: subxt::TransactionProgress<'_, T, RuntimeDispatchError, RuntimeEvent>,
) -> Result<subxt::TransactionEvents<'_, T, RuntimeEvent>>
where
T: Config,
{
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde::Serialize;
use sp_core::Bytes;
use std::{fmt::Debug, path::PathBuf};
use structopt::StructOpt;
use subxt::{rpc::NumberOrHex, ClientBuilder, Config, DefaultConfig, Signer, TransactionEvents};
use subxt::{rpc::NumberOrHex, ClientBuilder, Config, DefaultConfig, Signer};

type CodeUploadResult = pallet_contracts_primitives::CodeUploadResult<CodeHash, Balance>;
type CodeUploadReturnValue = pallet_contracts_primitives::CodeUploadReturnValue<CodeHash, Balance>;
Expand Down Expand Up @@ -65,11 +65,7 @@ impl UploadCommand {

Ok(())
} else {
let result = self.upload_code(code, &signer, &transcoder).await?;

let code_stored = result
.find_first_event::<api::contracts::events::CodeStored>()?
.ok_or(anyhow::anyhow!("Failed to find CodeStored event"))?;
let code_stored = self.upload_code(code, &signer, &transcoder).await?;

name_value_println!("Code hash", format!("{:?}", code_stored.code_hash));

Expand Down Expand Up @@ -107,7 +103,7 @@ impl UploadCommand {
code: Vec<u8>,
signer: &PairSigner,
transcoder: &ContractMessageTranscoder<'_>,
) -> Result<TransactionEvents<DefaultConfig>> {
) -> Result<api::contracts::events::CodeStored> {
let url = self.extrinsic_opts.url.to_string();
let api = ClientBuilder::new()
.set_url(&url)
Expand All @@ -131,7 +127,11 @@ impl UploadCommand {
&self.extrinsic_opts.verbosity()?,
)?;

Ok(result)
let code_stored = result
.find_first::<api::contracts::events::CodeStored>()?
.ok_or(anyhow::anyhow!("Failed to find CodeStored event"))?;

Ok(code_stored)
}
}

Expand Down