forest/lotus_json/
signed_message.rs1use crate::message::SignedMessage;
5use crate::shim::{crypto::Signature, message::Message};
6use ::cid::Cid;
7
8use super::*;
9
10#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
11#[serde(rename_all = "PascalCase")]
12#[schemars(rename = "SignedMessage")]
13pub struct SignedMessageLotusJson {
14 #[schemars(with = "LotusJson<Message>")]
15 #[serde(with = "crate::lotus_json")]
16 message: Message,
17 #[schemars(with = "LotusJson<Signature>")]
18 #[serde(with = "crate::lotus_json")]
19 signature: Signature,
20 #[schemars(with = "LotusJson<Option<Cid>>")]
21 #[serde(
22 with = "crate::lotus_json",
23 rename = "CID",
24 skip_serializing_if = "Option::is_none",
25 default
26 )]
27 cid: Option<Cid>,
28}
29
30impl SignedMessageLotusJson {
31 pub fn with_cid(mut self, cid: Cid) -> Self {
32 self.cid = Some(cid);
33 self
34 }
35}
36
37impl HasLotusJson for SignedMessage {
38 type LotusJson = SignedMessageLotusJson;
39
40 #[cfg(test)]
41 fn snapshots() -> Vec<(serde_json::Value, Self)> {
42 vec![(
43 json!({
44 "Message": {
45 "From": "f00",
46 "GasFeeCap": "0",
47 "GasLimit": 0,
48 "GasPremium": "0",
49 "Method": 0,
50 "Nonce": 0,
51 "Params": null,
52 "To": "f00",
53 "Value": "0",
54 "Version": 0,
55 "CID": {
56 "/": "bafy2bzaced3xdk2uf6azekyxgcttujvy3fzyeqmibtpjf2fxcpfdx2zcx4s3g"
57 },
58 },
59 "Signature": {"Type": 2, "Data": "aGVsbG8gd29ybGQh"},
60 "CID": {
61 "/": "bafy2bzaced3xdk2uf6azekyxgcttujvy3fzyeqmibtpjf2fxcpfdx2zcx4s3g"
62 },
63 }),
64 SignedMessage::new_unchecked(Message::default(), Signature {
65 sig_type: crate::shim::crypto::SignatureType::Bls,
66 bytes: Vec::from_iter(*b"hello world!"),
67 }),
68 )]
69 }
70
71 fn into_lotus_json(self) -> Self::LotusJson {
72 let cid = Some(self.cid());
73 let (message, signature) = self.into_parts();
74 Self::LotusJson {
75 cid,
76 message,
77 signature,
78 }
79 }
80
81 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
82 let Self::LotusJson {
83 message,
84 signature,
85 cid: _ignored, } = lotus_json;
87 Self::new_unchecked(message, signature)
88 }
89}