Skip to content

Commit

Permalink
retreive deal
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc committed Nov 26, 2024
1 parent d40b1b8 commit 004985f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
17 changes: 15 additions & 2 deletions cli/polka-storage/storagext-cli/src/cmd/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pub(crate) enum MarketCommand {
/// The target account's ID.
account_id: <PolkaStorageConfig as subxt::Config>::AccountId,
},

/// Retrieve the deal for a given deal ID.
RetrieveDeal {
/// The target deal's ID.
deal_id: DealId,
},
}

impl MarketCommand {
Expand All @@ -97,8 +103,6 @@ impl MarketCommand {
let client = storagext::Client::new(node_rpc, n_retries, retry_interval).await?;

match self {
// Only command that doesn't need a key.
//
// NOTE: subcommand_negates_reqs does not work for this since it only negates the parents'
// requirements, and the global arguments (keys) are at the grandparent level
// https://users.rust-lang.org/t/clap-ignore-global-argument-in-sub-command/101701/8
Expand All @@ -116,6 +120,15 @@ impl MarketCommand {
tracing::error!("Could not find account {}", account_id);
}
}
MarketCommand::RetrieveDeal { deal_id } => {
if let Some(deal) = client.retrieve_deal(deal_id.clone()).await? {
tracing::debug!("Deal {:?}", deal);

println!("{}", output_format.format(&deal)?);
} else {
tracing::error!("Could not find deal {}", deal_id);
}
}
else_ => {
let Some(account_keypair) = account_keypair else {
return Err(missing_keypair_error::<Self>().into());
Expand Down
27 changes: 27 additions & 0 deletions cli/polka-storage/storagext/src/clients/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ pub trait MarketClientExt {
&self,
account_id: <PolkaStorageConfig as subxt::Config>::AccountId,
) -> impl Future<Output = Result<Option<BalanceEntry<u128>>, subxt::Error>>;

/// Retrieve the deal for a given deal ID.
fn retrieve_deal(
&self,
deal_id: DealId,
) -> impl Future<Output = Result<Option<DealProposal>, subxt::Error>>;
}

impl MarketClientExt for crate::runtime::client::Client {
Expand Down Expand Up @@ -279,4 +285,25 @@ impl MarketClientExt for crate::runtime::client::Client {
.fetch(&balance_table_query)
.await
}

#[tracing::instrument(level = "debug", skip_all, fields(deal_id))]
async fn retrieve_deal(&self, deal_id: DealId) -> Result<Option<DealProposal>, subxt::Error> {
let deal_table_query = runtime::storage().market().proposals(deal_id);
let Some(deal) = self
.client
.storage()
.at_latest()
.await?
.fetch(&deal_table_query)
.await?
else {
return Ok(None);
};

let deal = DealProposal::try_from(deal).map_err(|e| {
subxt::Error::Other(format!("failed to convert deal proposal: {:?}", e))
})?;

Ok(Some(deal))
}
}
22 changes: 17 additions & 5 deletions cli/polka-storage/storagext/src/runtime/display/market.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use crate::runtime::{
market::Event,
runtime_types::{
pallet_market::{pallet, pallet::BalanceEntry},
polka_storage_runtime::Runtime,
use crate::{
runtime::{
market::Event,
runtime_types::{
pallet_market::pallet::{self, BalanceEntry},
polka_storage_runtime::Runtime,
},
},
types::market::DealProposal,
};

impl std::fmt::Display for DealProposal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
"Deal Proposal {{ piece_cid: {}, piece_size: {}, provider: {}, client: {}, label: {}, start_block: {}, end_block: {}, storage_price_per_block: {}, provider_collateral: {} }}",
self.piece_cid, self.piece_size, self.provider, self.client, self.label, self.start_block, self.end_block, self.storage_price_per_block, self.provider_collateral
))
}
}

impl std::fmt::Display for pallet::SettledDealData<Runtime> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
Expand Down
5 changes: 4 additions & 1 deletion examples/rpc_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ target/release/storagext-cli --sr25519-key "$PROVIDER" market add-balance 250000
wait

# Register the SP
target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id"
target/release/storagext-cli --sr25519-key "$PROVIDER" storage-provider register "peer_id"

# Set PoRep verifying key
target/release/storagext-cli --sr25519-key "$PROVIDER" proofs set-porep-verifying-key @2KiB.porep.vk.scale

DEAL_JSON=$(
jq -n \
Expand Down

0 comments on commit 004985f

Please sign in to comment.