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

Update subxt to 0.30.1 with new subxt-signer crate #1236

Merged
merged 6 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
920 changes: 870 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ url = { version = "2.4.0", features = ["serde"] }

# dependencies for extrinsics (deploying and calling a contract)
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
subxt = "0.29.0"
subxt = "0.30.1"
hex = "0.4.3"

[build-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion crates/extrinsics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sp-runtime = "24.0.0"
sp-weights = "20.0.0"
pallet-contracts-primitives = "24.0.0"
scale-info = "2.8.0"
subxt = "0.29.0"
subxt = "0.30.1"
subxt-signer = { version = "0.30.1", features = ["subxt", "sr25519"] }
hex = "0.4.3"
jsonrpsee = { version = "0.19.0", features = ["ws-client"] }
12 changes: 6 additions & 6 deletions crates/extrinsics/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
PairSigner,
StorageDeposit,
TokenMetadata,
DEFAULT_KEY_COL_WIDTH,
Expand All @@ -56,6 +55,7 @@ use subxt::{
Config,
OnlineClient,
};
use subxt_signer::sr25519::Keypair;

#[derive(Debug, clap::Args)]
#[clap(name = "call", about = "Call a contract")]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl CallCommand {
let call_data = transcoder.encode(&self.message, &self.args)?;
tracing::debug!("Message data: {:?}", hex::encode(&call_data));

let signer = super::pair_signer(self.extrinsic_opts.signer()?);
let signer = self.extrinsic_opts.signer()?;

Runtime::new()?
.block_on(async {
Expand Down Expand Up @@ -168,7 +168,7 @@ impl CallCommand {
&self,
input_data: Vec<u8>,
client: &Client,
signer: &PairSigner,
signer: &Keypair,
) -> Result<ContractExecResult<Balance, ()>> {
let url = self.extrinsic_opts.url_to_string();
let token_metadata = TokenMetadata::query(client).await?;
Expand All @@ -179,7 +179,7 @@ impl CallCommand {
.map(|bv| bv.denominate_balance(&token_metadata))
.transpose()?;
let call_request = CallRequest {
origin: signer.account_id().clone(),
origin: subxt::tx::Signer::<DefaultConfig>::account_id(signer),
dest: self.contract.clone(),
value: self.value.denominate_balance(&token_metadata)?,
gas_limit: None,
Expand All @@ -193,7 +193,7 @@ impl CallCommand {
&self,
client: &Client,
data: Vec<u8>,
signer: &PairSigner,
signer: &Keypair,
transcoder: &ContractMessageTranscoder,
) -> Result<(), ErrorVariant> {
tracing::debug!("calling contract {:?}", self.contract);
Expand Down Expand Up @@ -245,7 +245,7 @@ impl CallCommand {
&self,
client: &Client,
data: Vec<u8>,
signer: &PairSigner,
signer: &Keypair,
) -> Result<Weight> {
if self.extrinsic_opts.skip_dry_run {
return match (self.gas_limit, self.proof_size) {
Expand Down
8 changes: 4 additions & 4 deletions crates/extrinsics/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
PairSigner,
StorageDeposit,
TokenMetadata,
DEFAULT_KEY_COL_WIDTH,
Expand Down Expand Up @@ -59,6 +58,7 @@ use subxt::{
Config,
OnlineClient,
};
use subxt_signer::sr25519::Keypair;
use tokio::runtime::Runtime;

#[derive(Debug, clap::Args)]
Expand Down Expand Up @@ -111,7 +111,7 @@ impl InstantiateCommand {
let artifacts = self.extrinsic_opts.contract_artifacts()?;
let transcoder = artifacts.contract_transcoder()?;
let data = transcoder.encode(&self.constructor, &self.args)?;
let signer = super::pair_signer(self.extrinsic_opts.signer()?);
let signer = self.extrinsic_opts.signer()?;
let url = self.extrinsic_opts.url_to_string();
let verbosity = self.extrinsic_opts.verbosity()?;
let code = if let Some(code) = artifacts.code {
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct Exec {
verbosity: Verbosity,
url: String,
client: Client,
signer: PairSigner,
signer: Keypair,
transcoder: ContractMessageTranscoder,
output_json: bool,
}
Expand Down Expand Up @@ -364,7 +364,7 @@ impl Exec {
> {
let storage_deposit_limit = self.args.storage_deposit_limit;
let call_request = InstantiateRequest {
origin: self.signer.account_id().clone(),
origin: subxt::tx::Signer::<DefaultConfig>::account_id(&self.signer),
value: self.args.value,
gas_limit: None,
storage_deposit_limit,
Expand Down
33 changes: 14 additions & 19 deletions crates/extrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ use scale::{
Decode,
Encode,
};
use sp_core::{
crypto::Pair,
sr25519,
Bytes,
};
use sp_core::Bytes;
use sp_weights::Weight;
use subxt::{
blocks,
Expand All @@ -75,6 +71,10 @@ use subxt::{
Config,
OnlineClient,
};
use subxt_signer::{
sr25519::Keypair,
SecretUri,
};

use std::{
option::Option,
Expand All @@ -97,7 +97,6 @@ pub use remove::RemoveCommand;
pub use subxt::PolkadotConfig as DefaultConfig;
pub use upload::UploadCommand;

type PairSigner = tx::PairSigner<DefaultConfig, sr25519::Pair>;
pub type Client = OnlineClient<DefaultConfig>;
pub type Balance = u128;
pub type CodeHash = <DefaultConfig as Config>::Hash;
Expand All @@ -121,11 +120,12 @@ pub struct ExtrinsicOpts {
)]
url: url::Url,
/// Secret key URI for the account deploying the contract.
///
/// e.g.
/// - for a dev account "//Alice"
/// - with a password "//Alice///SECRET_PASSWORD"
#[clap(name = "suri", long, short)]
suri: String,
/// Password for the secret key.
#[clap(name = "password", long, short)]
password: Option<String>,
#[clap(flatten)]
verbosity: VerbosityFlags,
/// Submit the extrinsic for on-chain execution.
Expand Down Expand Up @@ -153,9 +153,10 @@ impl ExtrinsicOpts {
}

/// Returns the signer for contract extrinsics.
pub fn signer(&self) -> Result<sr25519::Pair> {
Pair::from_string(&self.suri, self.password.as_ref().map(String::as_ref))
.map_err(|_| anyhow::anyhow!("Secret string error"))
pub fn signer(&self) -> Result<Keypair> {
let uri = <SecretUri as std::str::FromStr>::from_str(&self.suri)?;
let keypair = Keypair::from_uri(&uri)?;
Ok(keypair)
}

/// Returns the verbosity
Expand Down Expand Up @@ -320,11 +321,6 @@ impl WasmCode {
}
}

/// Create a new `PairSigner` from the given [`sr25519::Pair`].
pub fn pair_signer(pair: sr25519::Pair) -> PairSigner {
PairSigner::new(pair)
}

const STORAGE_DEPOSIT_KEY: &str = "Storage Deposit";
pub const MAX_KEY_COL_WIDTH: usize = STORAGE_DEPOSIT_KEY.len() + 1;

Expand Down Expand Up @@ -399,8 +395,7 @@ where
T: Config,
Call: tx::TxPayload,
Signer: tx::Signer<T>,
<T::ExtrinsicParams as config::ExtrinsicParams<T::Index, T::Hash>>::OtherParams:
Default,
<T::ExtrinsicParams as config::ExtrinsicParams<T::Hash>>::OtherParams: Default,
{
client
.tx()
Expand Down
6 changes: 3 additions & 3 deletions crates/extrinsics/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
PairSigner,
TokenMetadata,
};
use anyhow::Result;
Expand All @@ -38,6 +37,7 @@ use subxt::{
Config,
OnlineClient,
};
use subxt_signer::sr25519::Keypair;
use tokio::runtime::Runtime;

#[derive(Debug, clap::Args)]
Expand All @@ -61,7 +61,7 @@ impl RemoveCommand {
pub fn run(&self) -> Result<(), ErrorVariant> {
let artifacts = self.extrinsic_opts.contract_artifacts()?;
let transcoder = artifacts.contract_transcoder()?;
let signer = super::pair_signer(self.extrinsic_opts.signer()?);
let signer = self.extrinsic_opts.signer()?;

let artifacts_path = artifacts.artifact_path().to_path_buf();

Expand Down Expand Up @@ -117,7 +117,7 @@ impl RemoveCommand {
&self,
client: &Client,
code_hash: CodeHash,
signer: &PairSigner,
signer: &Keypair,
transcoder: &ContractMessageTranscoder,
) -> Result<Option<CodeRemoved>, ErrorVariant> {
let call = api::tx()
Expand Down
10 changes: 5 additions & 5 deletions crates/extrinsics/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
PairSigner,
TokenMetadata,
WasmCode,
};
Expand All @@ -42,6 +41,7 @@ use subxt::{
Config,
OnlineClient,
};
use subxt_signer::sr25519::Keypair;
use tokio::runtime::Runtime;

#[derive(Debug, clap::Args)]
Expand All @@ -61,7 +61,7 @@ impl UploadCommand {

pub fn run(&self) -> Result<(), ErrorVariant> {
let artifacts = self.extrinsic_opts.contract_artifacts()?;
let signer = super::pair_signer(self.extrinsic_opts.signer()?);
let signer = self.extrinsic_opts.signer()?;

let artifacts_path = artifacts.artifact_path().to_path_buf();
let code = artifacts.code.ok_or_else(|| {
Expand Down Expand Up @@ -128,7 +128,7 @@ impl UploadCommand {
&self,
code: WasmCode,
client: &Client,
signer: &PairSigner,
signer: &Keypair,
) -> Result<CodeUploadResult<CodeHash, Balance>> {
let url = self.extrinsic_opts.url_to_string();
let token_metadata = TokenMetadata::query(client).await?;
Expand All @@ -139,7 +139,7 @@ impl UploadCommand {
.map(|bv| bv.denominate_balance(&token_metadata))
.transpose()?;
let call_request = CodeUploadRequest {
origin: signer.account_id().clone(),
origin: subxt::tx::Signer::<DefaultConfig>::account_id(signer),
code: code.0,
storage_deposit_limit,
determinism: Determinism::Enforced,
Expand All @@ -151,7 +151,7 @@ impl UploadCommand {
&self,
client: &Client,
code: WasmCode,
signer: &PairSigner,
signer: &Keypair,
) -> Result<Option<api::contracts::events::CodeStored>, ErrorVariant> {
let token_metadata = TokenMetadata::query(client).await?;
let storage_deposit_limit =
Expand Down
Loading