Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add macros to generate clap commands and args for modules in runtime #423

Merged
merged 49 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
99f2f5d
module clap cli draft pr
Jun 19, 2023
139ca31
temp commit working state
Jun 19, 2023
923b69e
add impls for other fields of Runtime
Jun 20, 2023
ec5724e
working code
Jun 21, 2023
16c35b4
fix broken test
Jun 21, 2023
ae45100
fix cargo hack
Jun 21, 2023
606aee8
missing file
Jun 21, 2023
6ec977e
fix linting
Jun 21, 2023
ec1449d
Merge branch 'main' into dub/module_call_clap
Jun 21, 2023
b039549
lint fix
Jun 22, 2023
06f151c
Merge branch 'main' into dub/module_call_clap
preston-evans98 Jun 30, 2023
2d78879
Merge branch 'main' into dub/module_call_clap
preston-evans98 Jul 13, 2023
a2a8399
WIP: continue cleanup
preston-evans98 Jul 14, 2023
81b865e
Use anyhow::Error as FromStr error
preston-evans98 Jul 14, 2023
0d95cd5
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 19, 2023
5935c67
Rustc panics here
preston-evans98 Jul 19, 2023
1a6b7c3
Fix bug in cli_parser bounds extraction
preston-evans98 Jul 19, 2023
61fbefc
It works
preston-evans98 Jul 19, 2023
986fb62
Fix warnings/lints
preston-evans98 Jul 19, 2023
f0d2f56
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 20, 2023
e06edee
Defer serde bounds enforcement
preston-evans98 Jul 20, 2023
0ea1a26
Remove even more deserialize bounds
preston-evans98 Jul 20, 2023
9fb7ad0
Update CLI with inline tx generation
preston-evans98 Jul 20, 2023
c137a34
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 20, 2023
c50e4c7
Fix doc test; improve hygiene
preston-evans98 Jul 20, 2023
6b07bd2
cleanup; make hex optional
preston-evans98 Jul 20, 2023
6d721bb
remove duplicate Signature defn
preston-evans98 Jul 20, 2023
f7dd709
Fix unused import
preston-evans98 Jul 20, 2023
9e129dd
remove evm cli for now
preston-evans98 Jul 20, 2023
57620aa
fix warnings without default features
preston-evans98 Jul 20, 2023
090124f
Fix unused import
preston-evans98 Jul 20, 2023
e18f2ee
Fix evm skipping
preston-evans98 Jul 20, 2023
8f4535d
Fix formatting
preston-evans98 Jul 21, 2023
d9f2ad6
Fix bug in cli make batch
preston-evans98 Jul 21, 2023
3cb9b4a
Get cli_skip working
preston-evans98 Jul 21, 2023
f8717ec
Convert to derive macro
preston-evans98 Jul 21, 2023
0b42813
derive CliWalletArg for structs
preston-evans98 Jul 24, 2023
99ab9e0
Fix doc tests
preston-evans98 Jul 24, 2023
9399b6d
test cli_wallet_arg derive
preston-evans98 Jul 24, 2023
3bfc39b
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 24, 2023
2050a34
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 25, 2023
0354fdf
Merge branch 'nightly' into dub/module_call_clap
preston-evans98 Jul 25, 2023
b63b692
revert lockfile
preston-evans98 Jul 25, 2023
8a75190
Remove lockfile from git
preston-evans98 Jul 25, 2023
36fa638
lint
preston-evans98 Jul 25, 2023
3cd7048
Add missing cfg_attr
preston-evans98 Jul 25, 2023
1da491d
Remove commented code
preston-evans98 Jul 25, 2023
1b4132e
fix doc test
preston-evans98 Jul 25, 2023
738b122
Address code review feedback
preston-evans98 Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions adapters/celestia/src/celestia.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use std::{cell::RefCell, ops::Range};

use borsh::{BorshDeserialize, BorshSerialize};
Expand Down Expand Up @@ -335,6 +336,22 @@ impl From<[u8; 32]> for H160 {
}
}

impl FromStr for H160 {
type Err = anyhow::Error;
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Remove the "0x" prefix, if it exists.
let s = s.strip_prefix("0x").unwrap_or(s);
let bytes = hex::decode(s)?;
if bytes.len() != 20 {
return Err(anyhow::anyhow!("Invalid address length"));
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
}
let mut array = [0; 20];
array.copy_from_slice(&bytes);
Ok(H160(array))
}
}

impl Display for H160 {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{}", hex::encode(self.0))
Expand Down
12 changes: 12 additions & 0 deletions adapters/celestia/src/verifier/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use sov_rollup_interface::traits::AddressTrait;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

#[derive(Debug, PartialEq, Clone, Eq, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
pub struct CelestiaAddress(pub Vec<u8>);
Expand Down Expand Up @@ -32,4 +33,15 @@ impl Display for CelestiaAddress {
}
}

impl FromStr for CelestiaAddress {
type Err = anyhow::Error;
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Remove the "0x" prefix, if it exists.
let s = s.strip_prefix("0x").unwrap_or(s);
let bytes = hex::decode(s)?;
Ok(CelestiaAddress(bytes))
}
}

impl AddressTrait for CelestiaAddress {}
8 changes: 8 additions & 0 deletions examples/demo-simple-stf/tests/stf_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use sov_rollup_interface::{

use sov_rollup_interface::traits::AddressTrait;
use std::fmt::Display;
use std::str::FromStr;

#[derive(PartialEq, Debug, Clone, Eq, serde::Serialize, serde::Deserialize)]
pub struct DaAddress {
Expand All @@ -26,6 +27,13 @@ impl From<[u8; 32]> for DaAddress {
}
}

impl FromStr for DaAddress {
type Err = anyhow::Error;
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
fn from_str(_s: &str) -> Result<Self, Self::Err> {
unimplemented!()
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl<'a> TryFrom<&'a [u8]> for DaAddress {
type Error = anyhow::Error;

Expand Down
7 changes: 2 additions & 5 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ publish = false
[[bin]]
name = "sov-cli"
path = "src/sov-cli/main.rs"
required-features = ["native"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true}
borsh = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, optional = true }
serde_json = { workspace = true}
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
sha2 = { workspace = true }
clap = { workspace = true, optional = true }
clap = { workspace = true}
toml = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = ["http-client", "server"], optional = true }
hex = { workspace = true }
Expand Down Expand Up @@ -58,8 +57,6 @@ native = [
"sov-value-setter/native",
"sov-modules-api/native",
"sov-rollup-interface/mocks",
"clap",
"serde_json",
"jsonrpsee",
"toml"]
verifier = []
2 changes: 1 addition & 1 deletion examples/demo-stf/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sov_state::ProverStorage;
use sov_state::Storage;
use sov_state::ZkStorage;

pub struct DemoAppRunner<C: Context, Vm: Zkvm> {
pub struct DemoAppRunner<C: Context + 'static, Vm: Zkvm> {
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
pub stf: DemoApp<C, Vm>,
pub batch_builder: Option<FiFoStrictBatchBuilder<Runtime<C>, C>>,
}
Expand Down
5 changes: 4 additions & 1 deletion examples/demo-stf/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use sov_modules_api::Context;
use sov_modules_macros::{cli_parser, expose_rpc};
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};

#[cfg(feature = "native")]
use clap::Parser;
#[cfg(feature = "native")]
use sov_accounts::query::{AccountsRpcImpl, AccountsRpcServer};
#[cfg(feature = "native")]
Expand Down Expand Up @@ -53,12 +55,13 @@ use sov_value_setter::query::{ValueSetterRpcImpl, ValueSetterRpcServer};

#[cfg_attr(
feature = "native",
cli_parser(DefaultContext),
cli_parser(DefaultContext, "sequencer"),
preston-evans98 marked this conversation as resolved.
Show resolved Hide resolved
expose_rpc(DefaultContext)
)]
#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)]
#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)]
pub struct Runtime<C: Context> {
// #[cli_skip]
pub sequencer: sov_sequencer_registry::Sequencer<C>,
pub bank: sov_bank::Bank<C>,
pub election: sov_election::Election<C>,
Expand Down
Loading