Skip to content

Commit

Permalink
fix, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Jul 3, 2024
1 parent 9352098 commit afb31c8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 52 deletions.
3 changes: 2 additions & 1 deletion crates/common/src/node_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ impl<P> NodeAccount<P>
where
P: Provider + Sync + Send + 'static,
{
pub fn new(private_key: Vec<u8>, address: FieldElement, network: Network, provider: P) -> Self {
pub fn new(private_key: Vec<u8>, address: Vec<u8>, network: Network, provider: P) -> Self {
let secret_key = libp2p::identity::ecdsa::SecretKey::try_from_bytes(private_key.as_slice())
.expect("Failed to create secret key from private key.");
let p2p_keypair =
libp2p::identity::Keypair::from(libp2p::identity::ecdsa::Keypair::from(secret_key));
let signing_key = SigningKey::from_secret_scalar(
FieldElement::from_byte_slice_be(private_key.as_slice()).unwrap(),
);
let address = FieldElement::from_byte_slice_be(address.as_slice()).unwrap();
let signer = LocalWallet::from(signing_key.clone());
let network = network.to_field_element();
let account =
Expand Down
35 changes: 34 additions & 1 deletion crates/delegator/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
## zetina-delegator
## zetina-delegator

## `zetina-submit`

Install:

```sh
cargo install -f --path crates/delegator/
```

Command:

```console
zetina-submit --help
A shared peer-to-peer network of Zero-Knowledge Provers

Usage: zetina-submit <NETWORK> <PRIVATE_KEY> <ACCOUNT_ADDRESS> <RPC_URL>

Arguments:
<NETWORK> [possible values: mainnet, sepolia]
<PRIVATE_KEY>
<ACCOUNT_ADDRESS>
<RPC_URL>

Options:
-h, --help Print help
-V, --version Print version
```

Example Usage:

```console
zetina-submit sepolia 07c7a41c77c7a3b19e7c77485854fc88b09ed7041361595920009f81236d55d2 cdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b https://starknet-sepolia.public.blastapi.io
```
31 changes: 9 additions & 22 deletions crates/delegator/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use clap::{command, Parser};
use libp2p::gossipsub;
use starknet::{
core::types::FieldElement,
providers::{jsonrpc::HttpTransport, JsonRpcClient, Url},
};
use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Url};
use tokio::sync::{broadcast, mpsc};
use tonic::transport::Server;
use tracing_subscriber::EnvFilter;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
use zetina_common::{
graceful_shutdown::shutdown_signal,
job_witness::JobWitness,
network::Network,
node_account::NodeAccount,
topic::{gossipsub_ident_topic, Topic},
value_parser::{parse_bytes, parse_field_element},
};

use crate::{
Expand All @@ -27,29 +24,19 @@ use crate::{
#[command(version, about, long_about = None)]
pub struct DelegatorCommand {
pub network: Network,
#[arg(value_parser = parse_bytes)]
pub private_key: Vec<u8>,
#[arg(value_parser = parse_field_element)]
pub account_address: FieldElement,
pub private_key: String,
pub account_address: String,
pub rpc_url: Url,
}

pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
let _ = tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).try_init();
let subscriber = FmtSubscriber::builder().with_max_level(Level::INFO).finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let delegator_command = DelegatorCommand::parse();
let DelegatorCommand { network, private_key, account_address, rpc_url } = delegator_command;

// // TODO: common setup in node initiate binary
// let network = Network::Sepolia;
// let private_key =
// hex::decode("018ef9563461ec2d88236d59039babf44c97d8bf6200d01d81170f1f60a78f32")?;
// let account_address =
// hex::decode("cdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b")?;
// let url = "https://starknet-sepolia.public.blastapi.io";

let node_account = NodeAccount::new(
private_key,
account_address,
hex::decode(private_key)?,
hex::decode(account_address)?,
network,
JsonRpcClient::new(HttpTransport::new(rpc_url)),
);
Expand Down
36 changes: 35 additions & 1 deletion crates/executor/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
## zetina-executor
## zetina-executor

## `zetina-executor`

Install:

```sh
cargo install -f --path crates/executor/
```

Command:

```console
zetina-executor --help
A shared peer-to-peer network of Zero-Knowledge Provers

Usage: zetina-executor <NETWORK> <PRIVATE_KEY> <ACCOUNT_ADDRESS> <RPC_URL> <BOOTLOADER_PROGRAM_PATH>

Arguments:
<NETWORK> [possible values: mainnet, sepolia]
<PRIVATE_KEY>
<ACCOUNT_ADDRESS>
<RPC_URL>
<BOOTLOADER_PROGRAM_PATH>

Options:
-h, --help Print help
-V, --version Print version
```

Example Usage:

```console
zetina-executor sepolia 07c7a41c77c7a3b19e7c77485854fc88b09ed7041361595920009f81236d55d2 cdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b https://starknet-sepolia.public.blastapi.io ./target/bootloader.json
```
41 changes: 14 additions & 27 deletions crates/executor/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::path::PathBuf;

use clap::Parser;
use libp2p::gossipsub;
use starknet::{
core::types::FieldElement,
providers::{jsonrpc::HttpTransport, JsonRpcClient, Url},
};
use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Url};
use tokio::sync::mpsc;
use tonic::transport::Server;
use tracing_subscriber::EnvFilter;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
use zetina_common::{
graceful_shutdown::shutdown_signal,
network::Network,
node_account::NodeAccount,
topic::{gossipsub_ident_topic, Topic},
value_parser::{parse_bytes, parse_field_element},
};
use zetina_prover::stone_prover::StoneProver;
use zetina_runner::cairo_runner::CairoRunner;
Expand All @@ -28,34 +27,22 @@ use crate::{
#[command(version, about, long_about = None)]
pub struct ExecutorCommand {
pub network: Network,
#[arg(value_parser = parse_bytes)]
pub private_key: Vec<u8>,
#[arg(value_parser = parse_field_element)]
pub account_address: FieldElement,
pub private_key: String,
pub account_address: String,
pub rpc_url: Url,
pub bootloader_program_path: PathBuf,
}

pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
let _ = tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).try_init();
let subscriber = FmtSubscriber::builder().with_max_level(Level::INFO).finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let executor_command = ExecutorCommand::parse();
let ExecutorCommand { network, private_key, account_address, rpc_url } = executor_command;
let ws_root = std::path::PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env not present"),
)
.join("../../");
let bootloader_program_path = ws_root.join("target/bootloader.json");

// // TODO: common setup in node initiate binary
// let network = Network::Sepolia;
// let private_key =
// hex::decode("07c7a41c77c7a3b19e7c77485854fc88b09ed7041361595920009f81236d55d2")?;
// let account_address =
// hex::decode("cdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b")?;
// let url = "https://starknet-sepolia.public.blastapi.io";
let ExecutorCommand { network, private_key, account_address, rpc_url, bootloader_program_path } =
executor_command;

let node_account = NodeAccount::new(
private_key,
account_address,
hex::decode(private_key)?,
hex::decode(account_address)?,
network,
JsonRpcClient::new(HttpTransport::new(rpc_url)),
);
Expand Down

0 comments on commit afb31c8

Please sign in to comment.