kudu/chain.rs
1//!
2//! this contains some basic types for the chain FIXME FIXME write me properly!!
3//!
4//! Other useful types include [`Action`], [`PermissionLevel`].
5//!
6
7mod action;
8mod trace;
9mod transaction;
10
11use std::collections::{BTreeMap, BTreeSet};
12
13use serde::{Deserialize, Serialize};
14
15use crate::{
16 ABISerializable, AccountName, ActionName, Asset, Name, contract,
17};
18
19// this is needed to be able to call the `ABISerializable` derive macro, which needs
20// access to the `kudu` crate
21extern crate self as kudu;
22
23// =============================================================================
24//
25// Type definitions for Antelope structs found in the
26// https://github.com/AntelopeIO/spring/blob/main/libraries/chain/ folder
27//
28// Type correspondence:
29// - fc::unsigned_int -> VarUint32
30// - fc::microseconds -> i64
31// - boost::flat_map -> BTreeMap
32// - boost::flat_set -> BTreeSet
33// - std::vector<char> -> Bytes
34//
35// Notes:
36// - on x86, char is usually signed char, but can be converted losslessly
37// to unsigned char, so we keep u8 as a representation
38// see: https://en.cppreference.com/w/cpp/language/types
39//
40// =============================================================================
41
42
43pub type Map<K, V> = BTreeMap<K, V>;
44pub type Set<T> = BTreeSet<T>;
45
46
47pub trait Contract: ABISerializable {
48 fn account() -> AccountName;
49 fn name() -> ActionName;
50}
51
52pub use action::{Action, ActionError, PermissionLevel};
53pub use trace::{
54 AccountAuthSequence, AccountDelta,
55 ActionReceipt, ActionReceiptV0,
56 ActionTrace, ActionTraceV0, ActionTraceV1,
57 PackedTransactionV0,
58 Trace,
59 TransactionTrace, TransactionTraceV0, TransactionTraceException, TransactionTraceMsg,
60};
61pub use transaction::Transaction;
62
63
64/// not a native Antelope type but normally defined through an ABI
65/// It is provided here for convenience
66#[derive(Clone, Debug, PartialEq, Eq, ABISerializable, Serialize, Deserialize)]
67#[contract(account="eosio.token", name="transfer")]
68pub struct Transfer {
69 pub from: Name,
70 pub to: Name,
71 pub quantity: Asset,
72 pub memo: String,
73}
74
75
76// impl Contract for Transfer {
77// fn account() -> AccountName {
78// const { AccountName::constant("eosio.token") }
79// }
80// fn name() -> ActionName {
81// const { ActionName::constant("transfer") }
82// }
83// }