Skip to content

Commit fd4dabb

Browse files
committed
create a MethodDispatcher that makes calls to other actors by method name
1 parent eca7499 commit fd4dabb

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

fvm_dispatch/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
fvm_sdk = { version = "1.0.0" }
9+
fvm_ipld_encoding = { version = "0.2.2" }
10+
fvm_sdk = { version = "1.0.0" }
11+
fvm_shared = { version = "0.8.0" }

fvm_dispatch/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pub mod hash;
2+
pub mod message;
3+
24
#[cfg(test)]
35
mod tests {}

fvm_dispatch/src/message.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::hash::{Hasher, MethodHasher};
2+
3+
use fvm_ipld_encoding::RawBytes;
4+
use fvm_sdk::{send, SyscallResult};
5+
use fvm_shared::{address::Address, econ::TokenAmount, receipt::Receipt};
6+
7+
#[derive(Default)]
8+
pub struct MethodDispatcher<T: Hasher> {
9+
method_hasher: MethodHasher<T>,
10+
}
11+
12+
impl<T: Hasher> MethodDispatcher<T> {
13+
pub fn new(hasher: T) -> Self {
14+
Self {
15+
method_hasher: MethodHasher::new(hasher),
16+
}
17+
}
18+
19+
pub fn call_method(
20+
&self,
21+
to: &Address,
22+
method: &str,
23+
params: RawBytes,
24+
value: TokenAmount,
25+
) -> SyscallResult<Receipt> {
26+
let method = self.method_hasher.method_number(method);
27+
send::send(to, method, params, value)
28+
}
29+
}

0 commit comments

Comments
 (0)