forked from fioprotocol/fio.contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fio.fee.cpp
635 lines (525 loc) · 28 KB
/
fio.fee.cpp
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
/** FioFee implementation file
* Description: FioFee is the smart contract that manages fees.
* @author Adam Androulidakis, Casey Gardiner, Ed Rotthoff
* @modifedby
* @file fio.fee.cpp
* @license FIO Foundation ( https://github.com/fioprotocol/fio/blob/master/LICENSE ) Dapix
*/
#include "fio.fee.hpp"
#include <fio.address/fio.address.hpp>
#include <fio.common/fio.common.hpp>
#include <fio.common/fioerror.hpp>
#include <eosio/native/intrinsics.hpp>
#include <string>
#include <map>
using std::string;
namespace fioio {
/***
* This contract maintains fee related actions and data. It provides voting actions which allow the
* setting of fee amounts for mandatory fees, and the setting of bundle counts for bundled fees
* by the active block producers. It provides datga structures representing the fee construct within
* the FIO protocol. It provides the computation of fees from the voting
* results of block producers.
*/
class [[eosio::contract("FioFee")]] FioFee : public eosio::contract {
private:
const int MIN_FEE_VOTERS_FOR_MEDIAN = 15;
fiofee_table fiofees;
feevoters_table feevoters;
bundlevoters_table bundlevoters;
feevotes2_table feevotes;
eosiosystem::top_producers_table topprods;
eosiosystem::producers_table prods;
vector<name> getTopProds(){
int NUMBER_TO_SELECT = 150;
auto idx = prods.get_index<"prototalvote"_n>();
std::vector< name > topprods;
topprods.reserve(NUMBER_TO_SELECT);
for( auto it = idx.cbegin(); it != idx.cend() && topprods.size() < NUMBER_TO_SELECT && 0 < it->total_votes && it->active(); ++it ) {
topprods.push_back(it->owner);
}
return topprods;
}
uint32_t update_fees() {
vector<uint64_t> fee_ids; //hashes for endpoints to process.
int NUMBER_FEES_TO_PROCESS = 10;
//get the fees needing processing.
auto fee = fiofees.begin();
while (fee != fiofees.end()) {
if(fee->votes_pending.value()){
fee_ids.push_back(fee->fee_id);
//only get the specified number of fees to process.
if (fee_ids.size() == NUMBER_FEES_TO_PROCESS){
break;
}
}
fee++;
}
//throw a 400 error if fees to process is empty.
fio_400_assert(fee_ids.size() > 0, "compute fees", "compute fees",
"No Work.", ErrorNoWork);
vector<uint64_t> votesufs;
int processed_fees = 0;
for(int i=0;i<fee_ids.size();i++) { //for each fee to process
votesufs.clear();
auto topprod = topprods.begin();
while (topprod != topprods.end()) { //get the votes of the producers, compute the voted fee, and median.
//get the fee voters record of this BP.
auto voters_iter = feevoters.find(topprod->producer.value);
//if there is no fee voters record, then there is not a multiplier, skip this BP.
if (voters_iter != feevoters.end()) {
//get all the fee votes made by this BP.
auto votesbybpname = feevotes.get_index<"bybpname"_n>();
auto bpvote_iter = votesbybpname.find(topprod->producer.value);
int countem = 0;
if (bpvote_iter != votesbybpname.end()) {
//if its in the votes list, and if it has a vote, IE end_point is greater 0, then use if.
if ((bpvote_iter->feevotes.size() > fee_ids[i]) &&
(bpvote_iter->feevotes[fee_ids[i]].end_point.length() > 0)) {
const double dresult = voters_iter->fee_multiplier *
(double) bpvote_iter->feevotes[fee_ids[i]].value;
const uint64_t voted_fee = (uint64_t)(dresult);
votesufs.push_back(voted_fee);
}
}
}
topprod++;
}
//compute the median from the votesufs.
int64_t median_fee = -1;
if (votesufs.size() >= MIN_FEE_VOTERS_FOR_MEDIAN) {
sort(votesufs.begin(), votesufs.end());
int size = votesufs.size();
if (votesufs.size() % 2 == 0) {
median_fee = (votesufs[size / 2 - 1] + votesufs[size / 2]) / 2;
} else {
median_fee = votesufs[size / 2];
}
}
//set median as the new fee amount.
//update the fee.
auto fee_iter = fiofees.find(fee_ids[i]);
if((fee_iter != fiofees.end())) {
if ( median_fee > 0) {
fiofees.modify(fee_iter, _self, [&](struct fiofee &ff) {
ff.suf_amount = median_fee;
ff.votes_pending.emplace(false);
});
processed_fees++;
}else { //just clear the pending flag, not enough votes to update the fee yet/
fiofees.modify(fee_iter, _self, [&](struct fiofee &ff) {
ff.votes_pending.emplace(false);
});
}
}
}
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
return processed_fees;
}
public:
using contract::contract;
FioFee(name s, name code, datastream<const char *> ds)
: contract(s, code, ds),
fiofees(_self, _self.value),
bundlevoters(_self, _self.value),
feevoters(_self, _self.value),
feevotes(_self, _self.value),
topprods(SYSTEMACCOUNT, SYSTEMACCOUNT.value),
prods(SYSTEMACCOUNT,SYSTEMACCOUNT.value){
}
/*********
* This action provides the ability to set a fee vote by a block producer.
* the user submits a list of feevalue objects each of which contains a suf amount
* (to which a multiplier will later be applied, and an endpoint name which must
* match one of the endpoint names in the fees table.
* @param fee_values this is a vector of feevalue objects each has the
* endpoint name and desired fee in FIO SUF
* @param actor this is the string rep of the fio account for the user making the call, a block producer.
*/
// @abi action
[[eosio::action]]
void setfeevote(const vector <feevalue> &fee_values, const int64_t &max_fee, const name &actor) {
require_auth(actor);
bool dbgout = false;
//check that the actor is in the top42.
vector<name> top_prods = getTopProds();
fio_400_assert((std::find(top_prods.begin(), top_prods.end(), actor)) !=
top_prods.end(), "actor", actor.to_string()," Not a top 150 BP",ErrorFioNameNotReg);
fio_400_assert(max_fee >= 0, "max_fee", to_string(max_fee), "Invalid fee value",
ErrorMaxFeeInvalid);
const uint32_t nowtime = now();
//get all the votes made by this actor. go through the list
//and find the fee vote to update.
auto feevotesbybpname = feevotes.get_index<"bybpname"_n>();
// auto votebyname_iter = feevotesbybpname.lower_bound(actor.value);
auto votebyname_iter = feevotesbybpname.find(actor.value);
vector<feevalue_ts> feevotesv;
bool emplacerec = true;
//check for time violation.
if (votebyname_iter != feevotesbybpname.end()){
emplacerec = false;
feevotesv = votebyname_iter->feevotes;
}
// go through all the fee values passed in.
for (auto &feeval : fee_values) {
//check the endpoint exists for this fee
const uint128_t endPointHash = string_to_uint128_hash(feeval.end_point.c_str());
auto feesbyendpoint = fiofees.get_index<"byendpoint"_n>();
auto fees_iter = feesbyendpoint.find(endPointHash);
fio_400_assert(fees_iter != feesbyendpoint.end(), "end_point", feeval.end_point,
"invalid end_point", ErrorEndpointNotFound);
fio_400_assert(feeval.value >= 0, "fee_value", feeval.end_point,
"invalid fee value", ErrorFeeInvalid);
uint64_t feeid = fees_iter->fee_id;
// if the vector doesnt have an entry at this fees id index, add items out to this index.
// items with an empty string for end_point will NOT be used in median calcs.
if (feevotesv.size() < (feeid+1)){
for(int ix = feevotesv.size();ix<=(feeid+1);ix++)
{
feevalue_ts tfv;
feevotesv.push_back(tfv);
}
}
uint64_t idtoremove;
bool found = false;
fio_400_assert(!(feevotesv[feeid].timestamp > (nowtime - TIME_BETWEEN_FEE_VOTES_SECONDS)), "", "", "Too soon since last call", ErrorTimeViolation);
feevotesv[feeid].end_point = feeval.end_point;
feevotesv[feeid].value = feeval.value;
feevotesv[feeid].timestamp = (uint64_t)nowtime;
if(topprods.find(actor.value) != topprods.end()) {
feesbyendpoint.modify(fees_iter, _self, [&](struct fiofee &a) {
a.votes_pending.emplace(true);
});
}
}
//emplace or update.
if (emplacerec){
feevotes.emplace(actor, [&](struct feevote2 &fv) {
fv.id = feevotes.available_primary_key();
fv.block_producer_name = actor;
fv.feevotes = feevotesv;
fv.lastvotetimestamp = nowtime;
});
} else {
feevotesbybpname.modify(votebyname_iter, actor, [&](struct feevote2 &fv) {
fv.feevotes = feevotesv;
fv.lastvotetimestamp = nowtime;
});
}
//begin new fees, logic for Mandatory fees.
uint128_t endpoint_hash = string_to_uint128_hash(SUBMIT_FEE_RATIOS_ENDPOINT);
auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>();
auto fee_iter = fees_by_endpoint.find(endpoint_hash);
//if the fee isnt found for the endpoint, then 400 error.
fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", SUBMIT_FEE_RATIOS_ENDPOINT,
"FIO fee not found for endpoint", ErrorNoEndpoint);
uint64_t reg_amount = fee_iter->suf_amount;
uint64_t fee_type = fee_iter->type;
//if its not a mandatory fee then this is an error.
fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type),
"submit_fee_ratios unexpected fee type for endpoint submit_fee_ratios, expected 0",
ErrorNoEndpoint);
fio_400_assert(max_fee >= (int64_t)reg_amount, "max_fee", to_string(max_fee), "Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);
fio_fees(actor, asset(reg_amount, FIOSYMBOL), SUBMIT_FEE_RATIOS_ENDPOINT);
processrewardsnotpid(reg_amount, get_self());
//end new fees, logic for Mandatory fees.
const string response_string = string("{\"status\": \"OK\"") +
string(",\"fee_collected\":") +
to_string(reg_amount) + string("}");
if (SETFEEVOTERAM > 0) {
action(
permission_level{SYSTEMACCOUNT, "active"_n},
"eosio"_n,
"incram"_n,
std::make_tuple(actor, SETFEEVOTERAM)
).send();
}
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
send_response(response_string.c_str());
}
/**********
* This method will update the fees based upon the present votes made by producers.
*/
[[eosio::action]]
void computefees() {
uint32_t numberprocessed = update_fees();
const string response_string = string("{\"status\": \"OK\",\"fees_processed\":") +
to_string(numberprocessed) + string("}");
send_response(response_string.c_str());
}
/********
* This action allows block producers to vote for the number of transactions that will be permitted
* for free in the FIO bundled transaction model.
* @param bundled_transactions the number of bundled transactions per FIO user.
* @param actor the block producer actor that is presently voting, the signer of this tx.
*/
// @abi action
[[eosio::action]]
void bundlevote(
const int64_t &bundled_transactions,
const int64_t &max_fee,
const name &actor
) {
require_auth(actor);
//check that the actor is in the top150.
vector<name> top_prods = getTopProds();
fio_400_assert((std::find(top_prods.begin(), top_prods.end(), actor)) !=
top_prods.end(), "actor", actor.to_string()," Not a top 150 BP",ErrorFioNameNotReg);
fio_400_assert(bundled_transactions > 0, "bundled_transactions", to_string(bundled_transactions),
" Must be positive",
ErrorFioNameNotReg);
const uint32_t nowtime = now();
auto voter_iter = bundlevoters.find(actor.value);
if (voter_iter != bundlevoters.end()) //update if it exists
{
const uint32_t lastupdate = voter_iter->lastvotetimestamp;
if (lastupdate <= (nowtime - TIME_BETWEEN_VOTES_SECONDS)) {
bundlevoters.modify(voter_iter, _self, [&](struct bundlevoter &a) {
a.block_producer_name = actor;
a.bundledbvotenumber = bundled_transactions;
a.lastvotetimestamp = nowtime;
});
} else {
fio_400_assert(false, "", "", "Too soon since last call", ErrorTimeViolation);
}
} else {
bundlevoters.emplace(actor, [&](struct bundlevoter &f) {
f.block_producer_name = actor;
f.bundledbvotenumber = bundled_transactions;
f.lastvotetimestamp = nowtime;
});
}
//begin new fees, logic for Mandatory fees.
uint128_t endpoint_hash = string_to_uint128_hash(SUBMIT_BUNDLED_TRANSACTION_ENDPOINT);
auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>();
auto fee_iter = fees_by_endpoint.find(endpoint_hash);
//if the fee isnt found for the endpoint, then 400 error.
fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", SUBMIT_BUNDLED_TRANSACTION_ENDPOINT,
"FIO fee not found for endpoint", ErrorNoEndpoint);
uint64_t reg_amount = fee_iter->suf_amount;
uint64_t fee_type = fee_iter->type;
//if its not a mandatory fee then this is an error.
fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type),
"submit_bundled_transaction unexpected fee type for endpoint submit_bundled_transaction, expected 0",
ErrorNoEndpoint);
fio_400_assert(max_fee >= (int64_t)reg_amount, "max_fee", to_string(max_fee), "Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);
fio_fees(actor, asset(reg_amount, FIOSYMBOL), SUBMIT_BUNDLED_TRANSACTION_ENDPOINT);
processrewardsnotpid(reg_amount, get_self());
//end new fees, logic for Mandatory fees.
const string response_string = string("{\"status\": \"OK\"}");
if (BUNDLEVOTERAM > 0) {
action(
permission_level{SYSTEMACCOUNT, "active"_n},
"eosio"_n,
"incram"_n,
std::make_tuple(actor, BUNDLEVOTERAM)
).send();
}
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
send_response(response_string.c_str());
}
/**********
* This action will create a new feevoters record if the specified block producer does not yet exist in the
* feevoters table,
* it will verify that the producer making the request is a present active block producer, it will update the
* feevoters record if a pre-existing feevoters record exists.
* @param multiplier this is the multiplier that will be applied to all fee votes for this producer before
* computing the median fee.
* @param actor this is the block producer voter.
*/
// @abi action
[[eosio::action]]
void setfeemult(
const double &multiplier,
const int64_t &max_fee,
const name &actor
) {
require_auth(actor);
//check that the actor is in the top42.
vector<name> top_prods = getTopProds();
fio_400_assert((std::find(top_prods.begin(), top_prods.end(), actor)) !=
top_prods.end(), "actor", actor.to_string()," Not a top 150 BP",ErrorFioNameNotReg);
fio_400_assert(multiplier > 0, "multiplier", to_string(multiplier),
" Must be positive",
ErrorFioNameNotReg);
fio_400_assert(max_fee >= 0, "max_fee", to_string(max_fee), "Invalid fee value",
ErrorMaxFeeInvalid);
const uint32_t nowtime = now();
auto voter_iter = feevoters.find(actor.value);
if (voter_iter != feevoters.end())
{
const uint32_t lastupdate = voter_iter->lastvotetimestamp;
if (lastupdate <= (nowtime - 120)) {
feevoters.modify(voter_iter, _self, [&](struct feevoter &a) {
a.block_producer_name = actor;
a.fee_multiplier = multiplier;
a.lastvotetimestamp = nowtime;
});
} else {
fio_400_assert(false, "", "", "Too soon since last call", ErrorTimeViolation);
}
} else {
feevoters.emplace(actor, [&](struct feevoter &f) {
f.block_producer_name = actor;
f.fee_multiplier = multiplier;
f.lastvotetimestamp = nowtime;
});
}
//get all voted fees and set votes pending.
auto feevotesbybpname = feevotes.get_index<"bybpname"_n>();
auto votebyname_iter = feevotesbybpname.find(actor.value);
auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>();
if(topprods.find(actor.value) != topprods.end()) {
if (votebyname_iter != feevotesbybpname.end()) {
//loop over all fee votes, for all voted fees set the pending flag.
for(int i=0;i<votebyname_iter->feevotes.size();i++) {
if (votebyname_iter->block_producer_name.value != actor.value) {
break;
} else {
auto fee_iter = fiofees.find(i);
if(fee_iter != fiofees.end()) {
fiofees.modify(fee_iter, _self, [&](struct fiofee &a) {
a.votes_pending.emplace(true);
});
}
}
}
}
}
//begin new fees, logic for Mandatory fees.
uint128_t endpoint_hash = string_to_uint128_hash(SUBMIT_FEE_MULTIPLER_ENDPOINT);
auto fee_iter = fees_by_endpoint.find(endpoint_hash);
//if the fee isnt found for the endpoint, then 400 error.
fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", SUBMIT_FEE_MULTIPLER_ENDPOINT,
"FIO fee not found for endpoint", ErrorNoEndpoint);
uint64_t reg_amount = fee_iter->suf_amount;
uint64_t fee_type = fee_iter->type;
//if its not a mandatory fee then this is an error.
fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type),
"submit_fee_multiplier unexpected fee type for endpoint submit_fee_multiplier, expected 0",
ErrorNoEndpoint);
fio_400_assert(max_fee >= (int64_t)reg_amount, "max_fee", to_string(max_fee), "Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);
fio_fees(actor, asset(reg_amount, FIOSYMBOL), SUBMIT_FEE_MULTIPLER_ENDPOINT);
processrewardsnotpid(reg_amount, get_self());
//end new fees, logic for Mandatory fees.
const string response_string = string("{\"status\": \"OK\"") +
string(",\"fee_collected\":") +
to_string(reg_amount) + string("}");
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
send_response(response_string.c_str());
}
// @abi action
[[eosio::action]]
void mandatoryfee(
const string &end_point,
const name &account,
const int64_t &max_fee
) {
require_auth(account);
//begin new fees, logic for Mandatory fees.
const uint128_t endpoint_hash = fioio::string_to_uint128_hash(end_point.c_str());
auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>();
auto fee_iter = fees_by_endpoint.find(endpoint_hash);
//if the fee isnt found for the endpoint, then 400 error.
fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", end_point,
"FIO fee not found for endpoint", ErrorNoEndpoint);
const uint64_t reg_amount = fee_iter->suf_amount;
const uint64_t fee_type = fee_iter->type;
//if its not a mandatory fee then this is an error.
fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type),
"register_producer unexpected fee type for endpoint register_producer, expected 0",
ErrorNoEndpoint);
fio_400_assert(max_fee >= (int64_t)reg_amount, "max_fee", to_string(max_fee), "Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);
fio_fees(account, asset(reg_amount, FIOSYMBOL), end_point);
processrewardsnotpid(reg_amount, get_self());
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
}
// @abi action
[[eosio::action]]
void bytemandfee(
const string &end_point,
const name &account,
const int64_t &max_fee,
const int64_t &bytesize
) {
require_auth(account);
//begin new fees, logic for Mandatory fees.
const uint128_t endpoint_hash = fioio::string_to_uint128_hash(end_point.c_str());
auto fees_by_endpoint = fiofees.get_index<"byendpoint"_n>();
auto fee_iter = fees_by_endpoint.find(endpoint_hash);
//if the fee isnt found for the endpoint, then 400 error.
fio_400_assert(fee_iter != fees_by_endpoint.end(), "endpoint_name", end_point,
"FIO fee not found for endpoint", ErrorNoEndpoint);
uint64_t reg_amount = fee_iter->suf_amount;
uint64_t remv = bytesize % 1000;
uint64_t divv = bytesize / 1000;
if (remv > 0 ){
divv ++;
}
reg_amount = divv * reg_amount;
const uint64_t fee_type = fee_iter->type;
//if its not a mandatory fee then this is an error.
fio_400_assert(fee_type == 0, "fee_type", to_string(fee_type),
"register_producer unexpected fee type for endpoint register_producer, expected 0",
ErrorNoEndpoint);
fio_400_assert(max_fee >= (int64_t)reg_amount, "max_fee", to_string(max_fee), "Fee exceeds supplied maximum.",
ErrorMaxFeeExceeded);
fio_fees(account, asset(reg_amount, FIOSYMBOL), end_point);
processrewardsnotpid(reg_amount, get_self());
//end new fees, logic for Mandatory fees.
}
/*******
* This action will create a new fee on the FIO protocol.
* @param end_point this is the api endpoint name associated with the fee
* @param type consult feetype, mandatory is 0 bundle eligible is 1
* @param suf_amount this is the fee amount in FIO SUFs
*/
// @abi action
[[eosio::action]]
void createfee(
string end_point,
int64_t type,
int64_t suf_amount
) {
require_auth(_self);
fio_400_assert(suf_amount >= 0, "suf_amount", to_string(suf_amount),
" invalid suf amount",
ErrorFeeInvalid);
const uint128_t endPointHash = string_to_uint128_hash(end_point.c_str());
const uint64_t fee_id = fiofees.available_primary_key();
auto feesbyendpoint = fiofees.get_index<"byendpoint"_n>();
auto fees_iter = feesbyendpoint.find(endPointHash);
if (fees_iter != feesbyendpoint.end())
{
feesbyendpoint.modify(fees_iter, _self, [&](struct fiofee &a) {
a.type = type;
a.suf_amount = suf_amount;
//leave votes_pending as is, if votes are pending they need processed.
});
} else {
fiofees.emplace(get_self(), [&](struct fiofee &f) {
f.fee_id = fee_id;
f.end_point = end_point;
f.end_point_hash = endPointHash;
f.type = type;
f.suf_amount = suf_amount;
f.votes_pending.emplace(false);
});
}
fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()),
"Transaction is too large", ErrorTransactionTooLarge);
}
};
EOSIO_DISPATCH(FioFee, (setfeevote)(bundlevote)(setfeemult)(computefees)
(mandatoryfee)(bytemandfee)(createfee)
)
}