From 9067b41bab10224cc3978ee3150c5ed576698864 Mon Sep 17 00:00:00 2001
From: Michael Eberhardt <64731211+neutrinoks@users.noreply.github.com>
Date: Mon, 28 Oct 2024 10:08:56 +0400
Subject: [PATCH] feat: enable output-format by return root-event as well
---
Cargo.lock | 6 +-
Cargo.toml | 5 +-
cli/polka-storage-provider/server/src/rpc.rs | 11 +-
cli/polka-storage/storagext-cli/Cargo.toml | 1 +
.../storagext-cli/src/cmd/market.rs | 109 +++----
.../storagext-cli/src/cmd/mod.rs | 28 +-
.../storagext-cli/src/cmd/storage_provider.rs | 165 ++++++-----
cli/polka-storage/storagext/Cargo.toml | 1 +
.../storagext/src/clients/market.rs | 29 +-
.../storagext/src/clients/storage_provider.rs | 44 ++-
.../storagext/src/runtime/client.rs | 266 +++++-------------
11 files changed, 289 insertions(+), 376 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 0c28eba6..0055e68f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5881,9 +5881,9 @@ dependencies = [
[[package]]
name = "libm"
-version = "0.2.8"
+version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
+checksum = "3bda4c6077b0b08da2c48b172195795498381a7c8988c9e6212a6c55c5b9bd70"
[[package]]
name = "libp2p"
@@ -15762,6 +15762,7 @@ dependencies = [
"itertools 0.13.0",
"parity-scale-codec",
"primitives-proofs",
+ "scale-decode",
"serde",
"serde_json",
"sha2 0.10.8",
@@ -15786,6 +15787,7 @@ dependencies = [
"hex",
"parity-scale-codec",
"primitives-proofs",
+ "scale-decode",
"serde",
"serde_json",
"storagext",
diff --git a/Cargo.toml b/Cargo.toml
index f99d46bc..b73e97fc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -88,6 +88,8 @@ rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rand_xorshift = "0.3"
rocksdb = { version = "0.21" }
+scale-decode = { version = "0.13.1", default-features = false }
+scale-encode = { version = "0.7.1", default-features = false }
scale-info = { version = "2.11.1", default-features = false }
serde = { version = "1.0.197", default-features = false }
serde-big-array = { version = "0.3.2" }
@@ -111,9 +113,6 @@ tracing-subscriber = "0.3.18"
url = "2.5.0"
uuid = "1.8.0"
-scale-decode = { version = "0.13.1", default-features = false }
-scale-encode = { version = "0.7.1", default-features = false }
-
# Testing
rstest = { version = "0.22.0" }
diff --git a/cli/polka-storage-provider/server/src/rpc.rs b/cli/polka-storage-provider/server/src/rpc.rs
index 7218566e..0f0baae3 100644
--- a/cli/polka-storage-provider/server/src/rpc.rs
+++ b/cli/polka-storage-provider/server/src/rpc.rs
@@ -89,15 +89,20 @@ impl StorageProviderRpcServer for RpcServerState {
));
}
- let result = self
+ let submission_result = self
.xt_client
.publish_signed_storage_deals(&self.xt_keypair, vec![deal], true)
.await?
.expect("requested to return submission-result");
+ let events = if let Ok(events) = submission_result {
+ events
+ } else {
+ return Err(RpcError::internal_error("pallet returned an error", None));
+ };
// We currently just support a single deal and if there's no published deals,
// an error MUST've happened
- debug_assert_eq!(result.len(), 1);
+ debug_assert_eq!(events.len(), 1);
// We always publish only 1 deal
let deal_id = published_deals[0].deal_id;
@@ -145,7 +150,7 @@ impl StorageProviderRpcServer for RpcServerState {
tracing::info!("{:?}", precommit_result);
});
- Ok(result.event[0].deal_id)
+ Ok(events[0].variant.deal_id)
}
}
diff --git a/cli/polka-storage/storagext-cli/Cargo.toml b/cli/polka-storage/storagext-cli/Cargo.toml
index 15929b2c..f445f52e 100644
--- a/cli/polka-storage/storagext-cli/Cargo.toml
+++ b/cli/polka-storage/storagext-cli/Cargo.toml
@@ -20,6 +20,7 @@ codec.workspace = true
frame-support = { workspace = true, features = ["std"] }
hex = { workspace = true, features = ["serde", "std"] }
primitives-proofs = { workspace = true }
+scale-decode.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
subxt = { workspace = true, features = ["jsonrpsee", "substrate-compat"] }
diff --git a/cli/polka-storage/storagext-cli/src/cmd/market.rs b/cli/polka-storage/storagext-cli/src/cmd/market.rs
index bc06b7b1..cbe95950 100644
--- a/cli/polka-storage/storagext-cli/src/cmd/market.rs
+++ b/cli/polka-storage/storagext-cli/src/cmd/market.rs
@@ -6,7 +6,10 @@ use primitives_proofs::DealId;
use storagext::{
deser::DeserializablePath,
multipair::{DebugPair, MultiPairSigner},
- runtime::{market::events as MarketEvents, HashOfPsc, SubmissionResult},
+ runtime::{
+ market::{events as MktEvents, Event as MktEvent},
+ HashOfPsc, SubmissionResult,
+ },
types::market::DealProposal as SxtDealProposal,
MarketClientExt, PolkaStorageConfig,
};
@@ -18,6 +21,25 @@ use url::Url;
use super::display_submission_result;
use crate::{missing_keypair_error, operation_takes_a_while, OutputFormat};
+macro_rules! trace_submission_result {
+ ($submission_result:expr, $format:expr $(,$par1:expr)*) => (
+ if let Some(result) = $submission_result {
+ if let Ok(events) = result {
+ tracing::debug!(
+ $format,
+ events[0].hash,
+ $($par1),*
+ );
+ Ok(Some(Ok(events)))
+ } else {
+ Ok(Some(result))
+ }
+ } else {
+ Ok(None)
+ }
+ )
+}
+
#[derive(Debug, Subcommand)]
#[command(name = "market", about = "CLI Client to the Market Pallet", version)]
pub(crate) enum MarketCommand {
@@ -135,14 +157,16 @@ impl MarketCommand {
where
Client: MarketClientExt,
{
- operation_takes_a_while();
+ if wait_for_finalization {
+ operation_takes_a_while();
+ }
match self {
MarketCommand::AddBalance { amount } => {
let opt_result =
Self::add_balance(client, account_keypair, amount, wait_for_finalization)
.await?;
- display_submission_result::<_>(opt_result, output_format)?;
+ display_submission_result::<_, _>(opt_result, output_format)?;
}
MarketCommand::SettleDealPayments { deal_ids } => {
if deal_ids.is_empty() {
@@ -156,13 +180,13 @@ impl MarketCommand {
wait_for_finalization,
)
.await?;
- display_submission_result::<_>(opt_result, output_format)?;
+ display_submission_result::<_, _>(opt_result, output_format)?;
}
MarketCommand::WithdrawBalance { amount } => {
let opt_result =
Self::withdraw_balance(client, account_keypair, amount, wait_for_finalization)
.await?;
- display_submission_result::<_>(opt_result, output_format)?;
+ display_submission_result::<_, _>(opt_result, output_format)?;
}
MarketCommand::PublishStorageDeals {
deals,
@@ -185,7 +209,7 @@ impl MarketCommand {
wait_for_finalization,
)
.await?;
- display_submission_result::<_>(opt_result, output_format)?;
+ display_submission_result::<_, _>(opt_result, output_format)?;
}
_unsigned => unreachable!("unsigned commands should have been previously handled"),
};
@@ -198,23 +222,18 @@ impl MarketCommand {
account_keypair: MultiPairSigner,
amount: u128,
wait_for_finalization: bool,
- ) -> Result