Skip to content

Commit b391ee5

Browse files
committed
wip
1 parent c17b76d commit b391ee5

File tree

12 files changed

+379
-46
lines changed

12 files changed

+379
-46
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
members = [
44
"fvm_dispatch",
55
"fil_token",
6-
"testing/actors/fil_token_actor",
6+
"testing/integration",
7+
"testing/integration/actors/fil_token_actor",
78
]

fil_token/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ edition = "2021"
88
[dependencies]
99
anyhow = "1.0.56"
1010
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
11+
fvm_dispatch = { version = "0.1.0", path = "../fvm_dispatch" }
1112
fvm_ipld_blockstore = "0.1.1"
1213
fvm_ipld_hamt = "0.5.1"
1314
fvm_ipld_amt = { version = "0.4.2", features = ["go-interop"] }
1415
fvm_ipld_encoding = "0.2.2"
16+
fvm_sdk = { version = "1.0.0" }
1517
fvm_shared = { version = "0.8.0" }
1618
serde = { version = "1.0.136", features = ["derive"] }

fil_token/src/blockstore.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::convert::TryFrom;
2+
3+
use anyhow::{anyhow, Result};
4+
use cid::multihash::Code;
5+
use cid::Cid;
6+
use fvm_ipld_blockstore::Block;
7+
use fvm_sdk::ipld;
8+
9+
/// A blockstore that delegates to IPLD syscalls.
10+
#[derive(Default, Debug, Copy, Clone)]
11+
pub struct Blockstore;
12+
13+
impl fvm_ipld_blockstore::Blockstore for Blockstore {
14+
fn get(&self, cid: &Cid) -> Result<Option<Vec<u8>>> {
15+
// If this fails, the _CID_ is invalid. I.e., we have a bug.
16+
ipld::get(cid)
17+
.map(Some)
18+
.map_err(|e| anyhow!("get failed with {:?} on CID '{}'", e, cid))
19+
}
20+
21+
fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()> {
22+
let code = Code::try_from(k.hash().code()).map_err(|e| anyhow!(e.to_string()))?;
23+
let k2 = self.put(code, &Block::new(k.codec(), block))?;
24+
if k != &k2 {
25+
return Err(anyhow!("put block with cid {} but has cid {}", k, k2));
26+
}
27+
Ok(())
28+
}
29+
fn put<D>(&self, code: Code, block: &Block<D>) -> Result<Cid>
30+
where
31+
D: AsRef<[u8]>,
32+
{
33+
// TODO: Don't hard-code the size. Unfortunately, there's no good way to get it from the
34+
// codec at the moment.
35+
const SIZE: u32 = 32;
36+
let k = ipld::put(code.into(), SIZE, block.codec, block.data.as_ref())
37+
.map_err(|e| anyhow!("put failed with {:?}", e))?;
38+
Ok(k)
39+
}
40+
}

fil_token/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod blockstore;
12
pub mod token;
23

34
#[cfg(test)]

0 commit comments

Comments
 (0)