Skip to content

Commit

Permalink
Merge pull request #54 from olisystems/cl/oli-pycli
Browse files Browse the repository at this point in the history
Cl/oli pycli
  • Loading branch information
m-yahya authored Aug 29, 2023
2 parents a952517 + 5c5ce46 commit 7989d6b
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

extern crate chrono;
use crate::{base_cli::BaseCommand, trusted_cli::TrustedCli, Cli, CliResult, CliResultOk};
pub use crate::{base_cli::BaseCommand, trusted_cli::TrustedCli, Cli, CliResult, CliResultOk};
use clap::Subcommand;

#[cfg(feature = "teeracle")]
Expand Down
12 changes: 6 additions & 6 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ mod evm;
#[cfg(feature = "teeracle")]
mod oracle;
mod trusted_base_cli;
mod trusted_cli;
mod trusted_command_utils;
mod trusted_operation;

pub mod commands;
pub mod trusted_cli;

use crate::commands::Commands;
use clap::Parser;
Expand All @@ -64,22 +64,22 @@ pub(crate) const ED25519_KEY_TYPE: KeyTypeId = KeyTypeId(*b"ed25");
pub struct Cli {
/// node url
#[clap(short = 'u', long, default_value_t = String::from("ws://127.0.0.1"))]
node_url: String,
pub node_url: String,

/// node port
#[clap(short = 'p', long, default_value_t = String::from("9944"))]
node_port: String,
pub node_port: String,

/// worker url
#[clap(short = 'U', long, default_value_t = String::from("wss://127.0.0.1"))]
worker_url: String,
pub worker_url: String,

/// worker direct invocation port
#[clap(short = 'P', long, default_value_t = String::from("2000"))]
trusted_worker_port: String,
pub trusted_worker_port: String,

#[clap(subcommand)]
command: Commands,
pub command: Commands,
}

pub enum CliResultOk {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/trusted_base_cli/commands/get_market_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use sp_core::Pair;
#[derive(Parser)]
pub struct GetMarketResultsCommand {
/// AccountId in ss58check format
account: String,
timestamp: String,
pub account: String,
pub timestamp: String,
}

impl GetMarketResultsCommand {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/trusted_base_cli/commands/pay_as_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use sp_core::Pair;
#[derive(Parser)]
pub struct PayAsBidCommand {
/// AccountId in ss58check format
account: String,
orders_string: String,
pub account: String,
pub orders_string: String,
}

impl PayAsBidCommand {
Expand Down
6 changes: 3 additions & 3 deletions cli/src/trusted_base_cli/commands/pay_as_bid_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use codec;
#[derive(Parser)]
pub struct PayAsBidProofCommand {
/// AccountId in ss58check format
account: String,
timestamp: String,
actor_id: String,
pub account: String,
pub timestamp: String,
pub actor_id: String,
}

impl PayAsBidProofCommand {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/trusted_base_cli/commands/verify_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_runtime::traits::Keccak256;

#[derive(Parser)]
pub struct VerifyMerkleProofCommand {
merkle_proof_json: String,
pub merkle_proof_json: String,
}

impl VerifyMerkleProofCommand {
Expand Down
33 changes: 24 additions & 9 deletions cli/src/trusted_base_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,38 @@
*/

use crate::{
trusted_base_cli::commands::{
balance::BalanceCommand, get_market_results::GetMarketResultsCommand, nonce::NonceCommand,
pay_as_bid::PayAsBidCommand, pay_as_bid_proof::PayAsBidProofCommand,
set_balance::SetBalanceCommand, transfer::TransferCommand,
unshield_funds::UnshieldFundsCommand, verify_proof::VerifyMerkleProofCommand,
},
trusted_cli::TrustedCli,
trusted_command_utils::get_keystore_path,
Cli, CliResult, CliResultOk, ED25519_KEY_TYPE, SR25519_KEY_TYPE,
trusted_cli::TrustedCli, trusted_command_utils::get_keystore_path, Cli, CliResult, CliResultOk,
ED25519_KEY_TYPE, SR25519_KEY_TYPE,
};
use log::*;
use sp_core::crypto::Ss58Codec;
use sp_keystore::Keystore;
use substrate_client_keystore::LocalKeystore;

// private modules defining commands.
mod commands;

// Public module re-exporting the commands.
pub mod cmds {
pub use super::commands::{
balance::BalanceCommand, nonce::NonceCommand, set_balance::SetBalanceCommand,
transfer::TransferCommand, unshield_funds::UnshieldFundsCommand,
};
}

// Commands for the BEST-energy worker.
// For upstream merges it is always better to have a clear separate between local code and upstream
// code.
pub mod oli_cmds {
pub use super::commands::{
get_market_results::GetMarketResultsCommand, pay_as_bid::PayAsBidCommand,
pay_as_bid_proof::PayAsBidProofCommand, verify_proof::VerifyMerkleProofCommand,
};
}

use cmds::*;
use oli_cmds::*;

#[derive(Subcommand)]
pub enum TrustedBaseCommand {
/// generates a new incognito account for the given shard
Expand Down
21 changes: 15 additions & 6 deletions cli/src/trusted_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,37 @@ use crate::{benchmark::BenchmarkCommand, Cli, CliResult};

#[cfg(feature = "evm")]
use crate::evm::EvmCommand;
use crate::trusted_base_cli::TrustedBaseCommand;

pub use crate::trusted_base_cli::cmds::{
BalanceCommand, NonceCommand, SetBalanceCommand, TransferCommand, UnshieldFundsCommand,
};

pub use crate::trusted_base_cli::oli_cmds::{
GetMarketResultsCommand, PayAsBidCommand, PayAsBidProofCommand, VerifyMerkleProofCommand,
};

pub use crate::trusted_base_cli::TrustedBaseCommand;

#[derive(Args)]
pub struct TrustedCli {
/// targeted worker MRENCLAVE
#[clap(short, long)]
pub(crate) mrenclave: String,
pub mrenclave: String,

/// shard identifier
#[clap(short, long)]
pub(crate) shard: Option<String>,
pub shard: Option<String>,

/// signer for publicly observable extrinsic
#[clap(short='a', long, default_value_t = String::from("//Alice"))]
pub(crate) xt_signer: String,
pub xt_signer: String,

/// insert if direct invocation call is desired
#[clap(short, long)]
pub(crate) direct: bool,
pub direct: bool,

#[clap(subcommand)]
pub(crate) command: TrustedCommand,
pub command: TrustedCommand,
}

#[derive(Subcommand)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub(crate) fn wait_until(
}

fn connection_can_be_closed(top_status: TrustedOperationStatus) -> bool {
!matches!(
matches!(
top_status,
TrustedOperationStatus::Submitted
| TrustedOperationStatus::Future
Expand Down

0 comments on commit 7989d6b

Please sign in to comment.