forked from fioprotocol/fio.contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fio.fee.hpp
149 lines (114 loc) · 5.65 KB
/
fio.fee.hpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/** FioFee implementation file
* Description: FioFee is the smart contract that manages fees. see fio.fee.cpp
* @author Adam Androulidakis, Casey Gardiner, Ed Rotthoff
* @modifedby
* @file fio.fee.cpp
* @license FIO Foundation ( https://github.com/fioprotocol/fio/blob/master/LICENSE ) Dapix
*/
#pragma once
#include <eosiolib/eosio.hpp>
using std::string;
namespace fioio {
using namespace eosio;
enum class feetype {
mandatory = 0, // these fees are applied each time an operation takes place.
bundleeligible = 1 // these fees are free until a predetermined number of operations takes place,
// then a fee is applied. the number of free transactions is determined by votes of the block producers.
};
struct feevalue {
string end_point = ""; //this is the name of the endpoint, which is by convention the same as the
//url to which the signed transaction is sent.
int64_t value; //this it the value of the fee in FIO SUFs (Smallest unit of FIO).
EOSLIB_SERIALIZE( feevalue, (end_point)(value))
};
struct feevalue_ts {
string end_point = ""; //this is the name of the endpoint, which is by convention the same as the
//url to which the signed transaction is sent.
int64_t value = -1; //this it the value of the fee in FIO SUFs (Smallest unit of FIO).
uint64_t timestamp = 0; //this is the timestamp when the value was last set.
EOSLIB_SERIALIZE( feevalue_ts, (end_point)(value)(timestamp))
};
//this is the amount of time that must elapse for votes to be recorded into the FIO protocol for fees.
const uint32_t TIME_BETWEEN_VOTES_SECONDS = 120;
const uint32_t TIME_BETWEEN_FEE_VOTES_SECONDS = 3600;
// This table contains the data attributes associated with a fee.
// @abi table fiofee i64
struct [[eosio::action]] fiofee {
uint64_t fee_id; // one up index starting at 0
string end_point;
uint128_t end_point_hash;
uint64_t type; // this is the fee type from the feetype enumeration.
uint64_t suf_amount;
eosio::binary_extension<bool> votes_pending = false;
uint64_t primary_key() const { return fee_id; }
uint128_t by_endpoint() const { return end_point_hash; }
uint64_t by_type() const { return type; }
EOSLIB_SERIALIZE(fiofee, (fee_id)(end_point)(end_point_hash)(type)(suf_amount)(votes_pending)
)
};
typedef multi_index<"fiofees"_n, fiofee,
indexed_by<"byendpoint"_n, const_mem_fun < fiofee, uint128_t, &fiofee::by_endpoint>>,
indexed_by<"bytype"_n, const_mem_fun<fiofee, uint64_t, &fiofee::by_type>>
>
fiofee_table;
// this is the feevoter table, it holds the votes made for fees, a fee vote has producer name and
// a multiplier that will be applied to the vote to arrive at the final fee amount used.
// @abi table feevoter i64
struct [[eosio::action]] feevoter {
name block_producer_name;
double fee_multiplier;
uint64_t lastvotetimestamp;
uint64_t primary_key() const { return block_producer_name.value; }
EOSLIB_SERIALIZE(feevoter, (block_producer_name)(fee_multiplier)(lastvotetimestamp)
)
};
typedef multi_index<"feevoters"_n, feevoter> feevoters_table;
// the bundlevoter table holds the block producer votes for the number of transactions that will be
// free before the user is charged a fee.
// @abi table bundlevoter i64
struct [[eosio::action]] bundlevoter {
name block_producer_name;
int64_t bundledbvotenumber;
uint64_t lastvotetimestamp;
uint64_t primary_key() const { return block_producer_name.value; }
EOSLIB_SERIALIZE(bundlevoter, (block_producer_name)(bundledbvotenumber)(lastvotetimestamp)
)
};
typedef multi_index<"bundlevoters"_n, bundlevoter> bundlevoters_table;
//this structure is retired, left here so that replays can be achieved.
struct [[eosio::action]] feevote {
uint64_t id; //unique one up id
name block_producer_name;
string end_point;
uint128_t end_point_hash;
uint64_t suf_amount;
uint64_t lastvotetimestamp;
uint64_t primary_key() const { return id; }
uint64_t by_bpname() const { return block_producer_name.value; }
EOSLIB_SERIALIZE(feevote, (id)(block_producer_name)(end_point)(end_point_hash)(suf_amount)(lastvotetimestamp)
)
};
//this table is retired, left in state so that replays can be performed.
typedef multi_index<"feevotes"_n, feevote,
indexed_by<"bybpname"_n, const_mem_fun<feevote, uint64_t, &feevote::by_bpname>>
>
feevotes_table;
// This table holds block producer votes for fees. each table entry table holds the fee ratio votes
// for each fee for each block producer
// The votes here will be multiplied by the multiplier in the feevoters table.
// @abi table feevote i64
struct [[eosio::action]] feevote2 {
uint64_t id; //unique one up id
name block_producer_name;
std::vector<feevalue_ts> feevotes; //fee votes are order dependant, the idx in this vector must match the id of the vote
uint64_t lastvotetimestamp;
uint64_t primary_key() const { return id; }
uint64_t by_bpname() const { return block_producer_name.value; }
EOSLIB_SERIALIZE(feevote2, (id)(block_producer_name)(feevotes)(lastvotetimestamp)
)
};
typedef multi_index<"feevotes2"_n, feevote2,
indexed_by<"bybpname"_n, const_mem_fun<feevote2, uint64_t, &feevote2::by_bpname>>
>
feevotes2_table;
} // namespace fioio