bee_block/
dto.rs

1// Copyright 2022 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use primitive_types::U256;
5use serde::{Deserialize, Serialize};
6
7/// Describes a U256.
8#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
9pub struct U256Dto(pub String);
10
11impl From<&U256> for U256Dto {
12    fn from(value: &U256) -> Self {
13        Self(prefix_hex::encode(*value))
14    }
15}
16
17impl TryFrom<&U256Dto> for U256 {
18    type Error = prefix_hex::Error;
19
20    fn try_from(value: &U256Dto) -> Result<Self, Self::Error> {
21        prefix_hex::decode(&value.0)
22    }
23}