1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::{NumBytes, Read, UnsignedInt, Write};
use alloc::string::String;
use core::fmt;
macro_rules! key_type {
($ident:ident, $bytes:literal) => {
#[derive(Read, Write, NumBytes, Clone)]
#[eosio(crate_path = "crate::bytes")]
pub struct $ident {
pub type_: UnsignedInt,
pub data: [u8; $bytes],
}
impl $ident {
#[must_use]
pub const fn as_bytes(&self) -> &[u8; $bytes] {
&self.data
}
#[must_use]
pub const fn to_bytes(&self) -> [u8; $bytes] {
self.data
}
#[must_use]
pub fn as_slice(&self) -> &[u8] {
&self.data
}
}
impl Default for $ident {
#[must_use]
fn default() -> Self {
Self {
type_: UnsignedInt::default(),
data: [0_u8; $bytes],
}
}
}
impl PartialEq for $ident {
#[must_use]
fn eq(&self, other: &Self) -> bool {
self.type_ == other.type_ && self.as_slice() == other.as_slice()
}
}
impl fmt::Debug for $ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.type_, f)?;
fmt::Debug::fmt(self.as_slice(), f)
}
}
};
}
key_type!(PublicKey, 34);
key_type!(Signature, 66);
#[derive(Read, Write, NumBytes, Clone)]
#[eosio(crate_path = "crate::bytes")]
pub struct PrivateKey(String);