Skip to content

Commit ac70fab

Browse files
convert shared
1 parent e022544 commit ac70fab

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

ipld/blockstore/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use block::*;
1313
/// An IPLD blockstore suitable for injection into the FVM.
1414
///
1515
/// The cgo blockstore adapter implements this trait.
16-
pub trait Blockstore {
16+
pub trait Blockstore: std::fmt::Debug {
1717
type Error: std::error::Error + std::fmt::Debug;
1818

1919
/// Gets the block from the blockstore.

shared/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ log = "0.4.8"
2323
cid = { version = "0.8.2", default-features = false, features = ["serde-codec", "std"] }
2424
multihash = { version = "0.16.1", default-features = false, features = ["blake2b", "multihash-impl"] }
2525
unsigned-varint = "0.7.1"
26-
anyhow = "1.0.51"
2726
bimap = { version = "0.6.2", features = ["serde"] }
2827
fvm_ipld_blockstore = { version = "0.1", path = "../ipld/blockstore" }
2928
fvm_ipld_encoding = { version = "0.1", path = "../ipld/encoding" }

shared/src/actor/builtin.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use anyhow::anyhow;
21
use bimap::BiBTreeMap;
32
use cid::Cid;
43
use fvm_ipld_blockstore::Blockstore;
5-
use fvm_ipld_encoding::CborStore;
4+
use fvm_ipld_encoding::{CborStore, CborStoreError};
65
use num_derive::FromPrimitive;
76
use serde_repr::{Deserialize_repr, Serialize_repr};
87

@@ -107,26 +106,36 @@ impl From<&Type> for String {
107106
/// A mapping of builtin actor CIDs to their respective types.
108107
pub type Manifest = BiBTreeMap<Cid, Type>;
109108

110-
pub fn load_manifest<B: Blockstore>(bs: &B, root_cid: &Cid, ver: u32) -> anyhow::Result<Manifest> {
109+
pub fn load_manifest<B: Blockstore>(
110+
bs: &B,
111+
root_cid: &Cid,
112+
ver: u32,
113+
) -> Result<Manifest, ManifestError<B>> {
111114
match ver {
112115
0 => load_manifest_v0(bs, root_cid),
113116
1 => load_manifest_v1(bs, root_cid),
114-
_ => Err(anyhow!("unknown manifest version {}", ver)),
117+
_ => Err(ManifestError::UnknownVersion(ver)),
115118
}
116119
}
117120

118-
pub fn load_manifest_v0<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result<Manifest> {
121+
pub fn load_manifest_v0<B: Blockstore>(
122+
bs: &B,
123+
root_cid: &Cid,
124+
) -> Result<Manifest, ManifestError<B>> {
119125
match bs.get_cbor::<Manifest>(root_cid)? {
120126
Some(mf) => Ok(mf),
121-
None => Err(anyhow!("cannot find manifest root cid {}", root_cid)),
127+
None => Err(ManifestError::MissingRootCid(*root_cid)),
122128
}
123129
}
124130

125-
pub fn load_manifest_v1<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result<Manifest> {
131+
pub fn load_manifest_v1<B: Blockstore>(
132+
bs: &B,
133+
root_cid: &Cid,
134+
) -> Result<Manifest, ManifestError<B>> {
126135
let vec: Vec<(String, Cid)> = match bs.get_cbor(root_cid)? {
127136
Some(vec) => vec,
128137
None => {
129-
return Err(anyhow!("cannot find manifest root cid {}", root_cid));
138+
return Err(ManifestError::MissingRootCid(*root_cid));
130139
}
131140
};
132141
let mut manifest = Manifest::new();
@@ -137,9 +146,21 @@ pub fn load_manifest_v1<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result
137146
manifest.insert(code_cid, t);
138147
}
139148
Err(what) => {
140-
return Err(anyhow!("bad builtin actor name: {}: {} ", name, what));
149+
return Err(ManifestError::BadBuiltinActor(name, what));
141150
}
142151
}
143152
}
144153
Ok(manifest)
145154
}
155+
156+
#[derive(thiserror::Error, Debug)]
157+
pub enum ManifestError<BS: Blockstore> {
158+
#[error("unknown manifest version {0}")]
159+
UnknownVersion(u32),
160+
#[error("cannot find manifest root cid {0}")]
161+
MissingRootCid(Cid),
162+
#[error("bad builtin actor name: {0}: {1}")]
163+
BadBuiltinActor(String, String),
164+
#[error("encoding {0}")]
165+
Encoding(#[from] CborStoreError<BS>),
166+
}

shared/src/message.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2019-2022 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use anyhow::anyhow;
54
use fvm_ipld_encoding::de::{Deserialize, Deserializer};
65
use fvm_ipld_encoding::ser::{Serialize, Serializer};
76
use fvm_ipld_encoding::{Cbor, RawBytes};
@@ -37,17 +36,25 @@ impl Message {
3736
}
3837

3938
/// Does some basic checks on the Message to see if the fields are valid.
40-
pub fn check(self: &Message) -> anyhow::Result<()> {
39+
pub fn check(self: &Message) -> Result<(), MessageError> {
4140
if self.gas_limit == 0 {
42-
return Err(anyhow!("Message has no gas limit set"));
41+
return Err(MessageError::MissingGasLimit);
4342
}
4443
if self.gas_limit < 0 {
45-
return Err(anyhow!("Message has negative gas limit"));
44+
return Err(MessageError::NegativeGasLimit);
4645
}
4746
Ok(())
4847
}
4948
}
5049

50+
#[derive(thiserror::Error, Debug)]
51+
pub enum MessageError {
52+
#[error("Message has no gas limit set")]
53+
MissingGasLimit,
54+
#[error("Message has negative gas limit")]
55+
NegativeGasLimit,
56+
}
57+
5158
impl Serialize for Message {
5259
fn serialize<S>(&self, s: S) -> std::result::Result<S::Ok, S::Error>
5360
where

0 commit comments

Comments
 (0)