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
#![no_std]
use gmeta::{InOut, Metadata};
use gstd::{prelude::*, ActorId};
use primitive_types::H256;

pub struct FTStorageMetadata;

impl Metadata for FTStorageMetadata {
    type Init = ();
    type Handle = InOut<FTStorageAction, FTStorageEvent>;
    type Others = ();
    type Reply = ();
    type Signal = ();
    type State = FTStorageState;
}

#[derive(Default, Encode, Decode, TypeInfo, Debug)]
pub struct FTStorageState {
    pub ft_logic_id: ActorId,
    pub transaction_status: Vec<(H256, bool)>,
    pub balances: Vec<(ActorId, u128)>,
    pub approvals: Vec<(ActorId, Vec<(ActorId, u128)>)>,
    pub permits: Vec<(ActorId, u128)>,
}

#[derive(Encode, Decode, Debug, Copy, Clone, TypeInfo)]
pub enum FTStorageAction {
    GetBalance(ActorId),
    GetPermitId(ActorId),
    IncrementPermitId {
        transaction_hash: H256,
        account: ActorId,
        expected_permit_id: u128,
    },
    IncreaseBalance {
        transaction_hash: H256,
        account: ActorId,
        amount: u128,
    },
    DecreaseBalance {
        transaction_hash: H256,
        msg_source: ActorId,
        account: ActorId,
        amount: u128,
    },
    Approve {
        transaction_hash: H256,
        msg_source: ActorId,
        account: ActorId,
        amount: u128,
    },
    Transfer {
        transaction_hash: H256,
        msg_source: ActorId,
        sender: ActorId,
        recipient: ActorId,
        amount: u128,
    },
}

#[derive(Encode, Decode, Clone, Debug, TypeInfo)]
pub enum FTStorageEvent {
    Ok,
    Err,
    Balance(u128),
    PermitId(u128),
}