concordium_base/common/cbor/
contracts_common_types.rs1use crate::common::cbor::{
2 CborDecoder, CborDeserialize, CborEncoder, CborSerializationResult, CborSerialize,
3};
4use concordium_contracts_common::{constants::SHA256, hashes::Hash, AccountAddress};
5
6impl CborSerialize for AccountAddress {
7 fn serialize<C: CborEncoder>(&self, encoder: C) -> CborSerializationResult<()> {
8 self.0.serialize(encoder)
9 }
10}
11
12impl CborDeserialize for AccountAddress {
13 fn deserialize<C: CborDecoder>(decoder: C) -> CborSerializationResult<Self>
14 where
15 Self: Sized,
16 {
17 Ok(Self(CborDeserialize::deserialize(decoder)?))
18 }
19}
20
21impl CborSerialize for Hash {
22 fn serialize<C: CborEncoder>(&self, encoder: C) -> CborSerializationResult<()> {
23 self.as_ref().serialize(encoder)
24 }
25}
26
27impl CborDeserialize for Hash {
28 fn deserialize<C: CborDecoder>(decoder: C) -> CborSerializationResult<Self>
29 where
30 Self: Sized,
31 {
32 let bytes = <[u8; SHA256]>::deserialize(decoder)?;
33 Ok(Hash::from(bytes))
34 }
35}