-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelphyforecast.cpp
More file actions
118 lines (99 loc) · 3.67 KB
/
delphyforecast.cpp
File metadata and controls
118 lines (99 loc) · 3.67 KB
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
#include <eosiolib/eosio.hpp>
#include "delphyforecast.hpp"
using namespace eosio;
void Delphyforecast::clearquery(uint64_t id){
require_auth(admin);
OralceQureyContainer oralceQureyContainer(_self, admin);
auto ite = oralceQureyContainer.find(id);
if(ite != oralceQureyContainer.end()){
oralceQureyContainer.erase(ite);
}
}
void Delphyforecast::addqurey( OracleQuery oq ) {
require_auth(oq.from);
OralceQureyContainer oralceQureyContainer(_self, admin);
auto ite = oralceQureyContainer.find(oq.id);
auto iteQueryId = oralceQureyContainer.rbegin();
uint64_t id = 0;
if(iteQueryId == oralceQureyContainer.rend()){
id = 0;
}else{
id = iteQueryId->id + 1;
}
oralceQureyContainer.emplace(oq.from, [&](auto &s){
s.id = id;
s.from = oq.from;
s.roles = oq.roles;
s.mode = oq.mode;
s.mode_detail = oq.mode_detail;
s.type = oq.type;
s.aspect = oq.aspect;
s.provider = oq.provider;
s.startdate = oq.startdate;
s.enddate = oq.enddate;
s.conditions = oq.conditions;
s.appealenddate = oq.appealenddate;
s.unit = oq.unit;
s.status = QUERY_STATUS_NOT_DEAL;
s.created = now();
s.updated = now();
});
}
void Delphyforecast::addappeal(const Appeal & a){
require_auth(a.from);
OralceQureyContainer oralceQureyContainer(_self, admin);
auto iteQuery = oralceQureyContainer.find(a.idquery);
eosio_assert(iteQuery != oralceQureyContainer.end(), QUERY_EXPIRED);
AppealContainer appealContainer(_self, admin);
auto ite = appealContainer.rbegin();
uint64_t id = 0;
if(ite == appealContainer.rend()){
id = 0;
}else{
id = ite->id + 1;
}
appealContainer.emplace(admin, [&](auto &s){
s.id = id ;
s.idquery = a.idquery;
s.from = a.from ;
s.reason = a.reason ;
s.created = now();
s.updated = now();
});
}
void Delphyforecast::addanswer(const QueryResult & queryResult){
require_auth(admin);
OralceQureyContainer oralceQureyContainer(_self, admin);
auto iteQuery = oralceQureyContainer.find(queryResult.idquery);
eosio_assert(iteQuery!= oralceQureyContainer.end(), QUERY_NOT_EXISTS);
eosio_assert(iteQuery->enddate<=now(), TIME_NOT_REACHED);
QueryResultContainer queryResultContainer(_self, admin);
auto ite = queryResultContainer.find(queryResult.idquery);
if(ite == queryResultContainer.end()){
queryResultContainer.emplace(admin, [&](auto&s){
s.idquery = queryResult.idquery;
s.checked = queryResult.checked;
s.appealnum = queryResult.appealnum;
s.realvalue = queryResult.realvalue;
s.result = queryResult.result;
s.unitrate = queryResult.unitrate;
s.created = queryResult.created;
s.updated = queryResult.updated;
});
}else{
queryResultContainer.modify(queryResult, admin, [&](auto&s){
s.idquery = queryResult.idquery;
s.checked = queryResult.checked;
s.appealnum = queryResult.appealnum;
s.realvalue = queryResult.realvalue;
s.result = queryResult.result;
s.unitrate = queryResult.unitrate;
s.created = queryResult.created;
s.updated = queryResult.updated;
});
}
oralceQureyContainer.modify(iteQuery, admin, [&](auto &s){
s.status = QUERY_STATUS_DEALED;
});
eosio::print("version12");
}