Skip to content

Commit f29d08a

Browse files
committed
feat: first it demo
- Replaced `setup_client` with `setup_testnet_client` in various CLI modules - Simplified client initialization and removed some unused imports - Updated command implementations to use new client setup method - Commented out some verbose logging in sync command - Added `pm-demo` crate to workspace configuration
1 parent 6c344e3 commit f29d08a

File tree

24 files changed

+947
-52
lines changed

24 files changed

+947
-52
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"crates/cli/oracle",
66
"crates/cli/publisher",
77
"crates/cli/utils",
8+
"crates/demo",
89
]
910
resolver = "1"
1011
default-members = [
@@ -13,6 +14,7 @@ default-members = [
1314
"crates/cli/oracle",
1415
"crates/cli/publisher",
1516
"crates/cli/utils",
17+
"crates/demo"
1618
]
1719

1820
[workspace.lints.rust]
@@ -32,6 +34,7 @@ pm-accounts = { path = "crates/accounts", default-features = false }
3234
pm-oracle-cli = { path = "crates/cli/oracle", default-features = false }
3335
pm-publisher-cli = { path = "crates/cli/publisher", default-features = false }
3436
pm-utils-cli = { path = "crates/cli/utils", default-features = false }
37+
pm-demo = { path = "crates/demo", default-features = false }
3538

3639
anyhow = "1.0.93"
3740
async-trait = "0.1.83"

crates/cli/oracle/src/commands/get_entry.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use pm_utils_cli::{
1919
#[clap(about = "Gets entry")]
2020
pub struct GetEntryCmd {
2121
// Input pair (format example: "BTC/USD")
22+
publisher_id: String, // TO REMOVE
2223
pair: String,
2324
}
2425

@@ -28,14 +29,14 @@ impl GetEntryCmd {
2829
let oracle_id = pragma_storage.get_key(ORACLE_ACCOUNT_COLUMN).unwrap();
2930
let oracle_id = AccountId::from_hex(oracle_id).unwrap();
3031

31-
let publisher_id = pragma_storage.get_key(PUBLISHER_ACCOUNT_COLUMN).unwrap();
32-
let publisher_id = AccountId::from_hex(publisher_id).unwrap();
32+
// let publisher_id: &String = pragma_storage.get_key(PUBLISHER_ACCOUNT_COLUMN).unwrap();
33+
let publisher_id = AccountId::from_hex(&self.publisher_id).unwrap();
3334
let publisher = client
3435
.get_account(publisher_id)
3536
.await
3637
.unwrap()
3738
.expect("Publisher account not found");
38-
let oracle = client
39+
let _ = client
3940
.get_account(oracle_id)
4041
.await
4142
.unwrap()
@@ -83,7 +84,7 @@ impl GetEntryCmd {
8384
.with_custom_script(get_entry_script)
8485
.unwrap()
8586
.build();
86-
let tx_result = client
87+
let _ = client
8788
.new_transaction(oracle_id, transaction_request)
8889
.await
8990
.map_err(|e| anyhow::anyhow!("Error while creating a transaction: {e:?}"))?;

crates/cli/oracle/src/commands/init.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ impl InitCmd {
104104
println!(
105105
"{}",
106106
r#"
107-
╭────────────────────────────────────────────────────────────╮
108-
│ pm-oracle-cli register-publisher 0x12345678
109-
│ pm-oracle-cli entry 0x12345678 BTC/USD │
110-
│ pm-oracle-cli median BTC/USD │
111-
╰────────────────────────────────────────────────────────────╯
107+
╭────────────────────────────────────────────────────────────────────
108+
│ pm-oracle-cli register-publisher 0x64cbfe4bc88cfe00000556901757eb
109+
│ pm-oracle-cli entry 96310150000 BTC/USD
110+
│ pm-oracle-cli median BTC/USD
111+
╰────────────────────────────────────────────────────────────────────
112112
"#
113113
.bright_blue()
114114
);

crates/cli/oracle/src/commands/median.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use pm_accounts::oracle::get_oracle_component_library;
1010
use pm_accounts::utils::word_to_masm;
1111
use pm_types::Pair;
1212
use pm_utils_cli::{JsonStorage, ORACLE_ACCOUNT_COLUMN, PRAGMA_ACCOUNTS_STORAGE_FILE};
13-
use std::fmt::Write; // Changed from io::Write to fmt::Write
1413
use std::str::FromStr;
15-
use std::sync::{Arc, Mutex};
1614

1715
#[derive(clap::Parser, Debug, Clone)]
1816
#[clap(about = "Compute the median for a given pair")]
@@ -27,7 +25,7 @@ impl MedianCmd {
2725

2826
let oracle_id = pragma_storage.get_key(ORACLE_ACCOUNT_COLUMN).unwrap();
2927
let oracle_id = AccountId::from_hex(oracle_id).unwrap();
30-
28+
client.sync_state().await.unwrap();
3129
let oracle = client
3230
.get_account(oracle_id)
3331
.await
@@ -54,7 +52,6 @@ impl MedianCmd {
5452
})
5553
.collect::<Result<_, _>>()
5654
.context("Failed to collect publisher array")?;
57-
5855
let mut foreign_accounts: Vec<ForeignAccount> = vec![];
5956
for publisher_id in publisher_array {
6057
let publisher = client
@@ -108,7 +105,7 @@ impl MedianCmd {
108105

109106
let transaction_request = transaction_request.build();
110107

111-
let result = client
108+
let _ = client
112109
.new_transaction(oracle_id, transaction_request)
113110
.await
114111
.map_err(|e| anyhow::anyhow!("Error while creating a transaction: {e:?}"))?;

crates/cli/oracle/src/commands/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use publishers::PublishersCmd;
1818
use register_publisher::RegisterPublisherCmd;
1919
use sync::SyncCmd;
2020

21-
use pm_utils_cli::{setup_client, STORE_FILENAME};
21+
use pm_utils_cli::{setup_client, setup_testnet_client, STORE_FILENAME};
2222

2323
#[derive(Debug, Parser, Clone)]
2424
pub enum SubCommand {
@@ -48,8 +48,8 @@ pub enum SubCommand {
4848

4949
impl SubCommand {
5050
pub async fn call(&self) -> anyhow::Result<()> {
51-
let exec_dir = PathBuf::new();
52-
let store_config = exec_dir.join(STORE_FILENAME);
51+
let crate_path = PathBuf::new();
52+
let store_config = crate_path.join(STORE_FILENAME);
5353
let mut client = setup_client(store_config).await.unwrap();
5454

5555
match self {

crates/cli/oracle/src/commands/sync.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ impl SyncCmd {
1414

1515
println!("🔁 Sync successful!\n");
1616

17-
println!("State synced to block {}", new_details.block_num);
18-
println!("New public notes: {}", new_details.received_notes.len());
19-
println!(
20-
"Tracked notes updated: {}",
21-
new_details.committed_notes.len()
22-
);
23-
println!(
24-
"Tracked notes consumed: {}",
25-
new_details.consumed_notes.len()
26-
);
27-
println!(
28-
"Tracked accounts updated: {}",
29-
new_details.updated_accounts.len()
30-
);
31-
println!(
32-
"Commited transactions: {}",
33-
new_details.committed_transactions.len()
34-
);
17+
// println!("State synced to block {}", new_details.block_num);
18+
// println!("New public notes: {}", new_details.received_notes.len());
19+
// println!(
20+
// "Tracked notes updated: {}",
21+
// new_details.committed_notes.len()
22+
// );
23+
// println!(
24+
// "Tracked notes consumed: {}",
25+
// new_details.consumed_notes.len()
26+
// );
27+
// println!(
28+
// "Tracked accounts updated: {}",
29+
// new_details.updated_accounts.len()
30+
// );
31+
// println!(
32+
// "Commited transactions: {}",
33+
// new_details.committed_transactions.len()
34+
// );
3535
Ok(())
3636
}
3737
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": {
3+
"publisher_account_id": "0x2fc8bcad8a205780000507e88e8332"
4+
}
5+
}

crates/cli/publisher/src/commands/entry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use chrono::{DateTime, Utc};
22
use miden_client::{account::AccountId, crypto::FeltRng, Client};
33
use pm_types::{Entry, Pair};
4-
use pm_utils_cli::{JsonStorage, PRAGMA_ACCOUNTS_STORAGE_FILE, PUBLISHER_ACCOUNT_COLUMN};
54
use prettytable::{Cell, Row, Table};
65
use std::str::FromStr;
76

crates/cli/publisher/src/commands/get_entry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use miden_client::{account::AccountId, crypto::FeltRng};
44
use pm_accounts::publisher::get_publisher_component_library;
55
use pm_accounts::utils::word_to_masm;
66
use pm_types::Pair;
7-
use pm_utils_cli::{JsonStorage, PRAGMA_ACCOUNTS_STORAGE_FILE, PUBLISHER_ACCOUNT_COLUMN};
87
use std::str::FromStr;
98

109
#[derive(clap::Parser, Debug, Clone)]

0 commit comments

Comments
 (0)