Skip to content

Commit ef0893d

Browse files
authored
Merge pull request #118 from ipfs-force-community/feat/add_frc46_cmds
feat: 增加命令行用于计算方法数 / add cmd to calc method number
2 parents 7f6a959 + e0dc2b7 commit ef0893d

File tree

8 files changed

+83
-31
lines changed

8 files changed

+83
-31
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
- name: setup rust
2525
uses: actions-rs/toolchain@v1
2626
with:
27-
toolchain: nightly
2827
target: wasm32-unknown-unknown
2928
override: true
3029
components: rustfmt, clippy

.github/workflows/rust_check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
- name: setup rust
1919
uses: actions-rs/toolchain@v1
2020
with:
21-
toolchain: nightly
2221
target: wasm32-unknown-unknown
2322
override: true
2423
components: rustfmt, clippy

Cargo.lock

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

rust-toolchain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.64.0

tools/sdk_tool/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ xshell = "0.2"
2828
walkdir = "2"
2929
regex = "1"
3030
reqwest = { version = "0.11", features = ["blocking", "json"] }
31+
frc42_dispatch = "2.0.0"
32+
frc42_hasher = "1.2.0"
33+
blake2b_simd = "1.0.0"
3134

3235
actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", branch = "next", features = ["m2-native"] }
3336
fvm = { git = "https://github.com/ipfs-force-community/ref-fvm",rev="fa791e9726443c526800f0e90334137bdd80edcf", features = ["m2-native"]}

tools/sdk_tool/src/frc42.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use anyhow::Result;
2+
use blake2b_simd::blake2b;
3+
use clap::Parser;
4+
use frc42_dispatch::hash::MethodResolver;
5+
use frc42_hasher::hash::Hasher;
6+
7+
#[derive(Parser, Debug)]
8+
pub struct Frc42Config {
9+
#[clap(last = true)]
10+
pub name: String,
11+
}
12+
13+
pub struct Blake2bHasher {}
14+
impl Hasher for Blake2bHasher {
15+
fn hash(&self, bytes: &[u8]) -> Vec<u8> {
16+
blake2b(bytes).as_bytes().to_vec()
17+
}
18+
}
19+
20+
pub fn compute_frc46(cfg: &Frc42Config) -> Result<()> {
21+
let resolver = MethodResolver::new(Blake2bHasher {});
22+
let method_number = resolver.method_number(&cfg.name)?;
23+
println!("{}: {:#x} {}", cfg.name, method_number, method_number);
24+
Ok(())
25+
}

tools/sdk_tool/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod frc42;
12
mod patch;
23
mod template;
34
mod testing;
@@ -23,6 +24,8 @@ enum Commands {
2324
Test(testing::TestConfig),
2425
/// create new template project by module name
2526
New(template::NewTemplateConfig),
27+
/// calculate method number by name
28+
Frc42(frc42::Frc42Config),
2629
/// apply path for go/tinygo
2730
/// if your go and tinygo install in user home directory, just run./fvm_go_sdk patch
2831
/// if you go and tinygo is installed in /usr/local/go, use sudo ./fvm_go_sdk patch
@@ -55,6 +58,12 @@ fn main() {
5558
std::process::exit(1);
5659
}
5760
}
61+
Commands::Frc42(cfg) => {
62+
if let Err(e) = frc42::compute_frc46(cfg) {
63+
println!("run frc42 command fail {e}");
64+
std::process::exit(1);
65+
}
66+
}
5867
Commands::Patch(cfg) => {
5968
if let Err(e) = patch::apply_patch(cfg) {
6069
println!("apply patch command fail {e}");

tools/sdk_tool/src/utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn get_tinygo_env() -> Result<HashMap<String, String>> {
2727
Ok(output) => Ok(HashMap::from_iter(
2828
String::from_utf8(output.stdout)?
2929
.split('\n')
30-
.into_iter()
3130
.map(|v| v.trim())
3231
.filter(|v| !v.is_empty())
3332
.map(|v| {

0 commit comments

Comments
 (0)