Skip to content

Commit 4480da3

Browse files
convert shared
1 parent 6a0a750 commit 4480da3

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,10 +1,9 @@
11
use std::fmt::{Debug, Display, Formatter};
22

3-
use anyhow::anyhow;
43
use bimap::BiBTreeMap;
54
use cid::Cid;
65
use fvm_ipld_blockstore::Blockstore;
7-
use fvm_ipld_encoding::CborStore;
6+
use fvm_ipld_encoding::{CborStore, CborStoreError};
87
use num_derive::FromPrimitive;
98
use serde_repr::{Deserialize_repr, Serialize_repr};
109

@@ -115,26 +114,36 @@ impl Display for Type {
115114
/// A mapping of builtin actor CIDs to their respective types.
116115
pub type Manifest = BiBTreeMap<Cid, Type>;
117116

118-
pub fn load_manifest<B: Blockstore>(bs: &B, root_cid: &Cid, ver: u32) -> anyhow::Result<Manifest> {
117+
pub fn load_manifest<B: Blockstore>(
118+
bs: &B,
119+
root_cid: &Cid,
120+
ver: u32,
121+
) -> Result<Manifest, ManifestError<B>> {
119122
match ver {
120123
0 => load_manifest_v0(bs, root_cid),
121124
1 => load_manifest_v1(bs, root_cid),
122-
_ => Err(anyhow!("unknown manifest version {}", ver)),
125+
_ => Err(ManifestError::UnknownVersion(ver)),
123126
}
124127
}
125128

126-
pub fn load_manifest_v0<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result<Manifest> {
129+
pub fn load_manifest_v0<B: Blockstore>(
130+
bs: &B,
131+
root_cid: &Cid,
132+
) -> Result<Manifest, ManifestError<B>> {
127133
match bs.get_cbor::<Manifest>(root_cid)? {
128134
Some(mf) => Ok(mf),
129-
None => Err(anyhow!("cannot find manifest root cid {}", root_cid)),
135+
None => Err(ManifestError::MissingRootCid(*root_cid)),
130136
}
131137
}
132138

133-
pub fn load_manifest_v1<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result<Manifest> {
139+
pub fn load_manifest_v1<B: Blockstore>(
140+
bs: &B,
141+
root_cid: &Cid,
142+
) -> Result<Manifest, ManifestError<B>> {
134143
let vec: Vec<(String, Cid)> = match bs.get_cbor(root_cid)? {
135144
Some(vec) => vec,
136145
None => {
137-
return Err(anyhow!("cannot find manifest root cid {}", root_cid));
146+
return Err(ManifestError::MissingRootCid(*root_cid));
138147
}
139148
};
140149
let mut manifest = Manifest::new();
@@ -145,9 +154,21 @@ pub fn load_manifest_v1<B: Blockstore>(bs: &B, root_cid: &Cid) -> anyhow::Result
145154
manifest.insert(code_cid, t);
146155
}
147156
Err(what) => {
148-
return Err(anyhow!("bad builtin actor name: {}: {} ", name, what));
157+
return Err(ManifestError::BadBuiltinActor(name, what));
149158
}
150159
}
151160
}
152161
Ok(manifest)
153162
}
163+
164+
#[derive(thiserror::Error, Debug)]
165+
pub enum ManifestError<BS: Blockstore> {
166+
#[error("unknown manifest version {0}")]
167+
UnknownVersion(u32),
168+
#[error("cannot find manifest root cid {0}")]
169+
MissingRootCid(Cid),
170+
#[error("bad builtin actor name: {0}: {1}")]
171+
BadBuiltinActor(String, String),
172+
#[error("encoding {0}")]
173+
Encoding(#[from] CborStoreError<BS>),
174+
}

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};
@@ -38,17 +37,25 @@ impl Message {
3837
}
3938

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

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

0 commit comments

Comments
 (0)