-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathouterNetDataService.cpp
95 lines (84 loc) · 2.45 KB
/
outerNetDataService.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
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include "outerNetDataService.hpp"
void OutNetDataSer::storeWebRequest(const webrequest & parrequestweb){
ReqWebTable tfs(contractCode, admin);
require_auth(parrequestweb.from);
auto ite = tfs.rbegin();
uint64_t idnew;
if(ite == tfs.rend())
{
idnew = 0;
}
else
{
idnew = ite->primary_key()+1;
}
web newweb;
newweb.id = idnew;
newweb.copyFrom(parrequestweb);
tfs.emplace(parrequestweb.from, [&](auto &s){
s = newweb;
});
}
void OutNetDataSer::storeWebResult(const webresult & parwebresult){
require_auth(admin);
ReqWebTable tfs(contractCode, admin);
MultiIndexWebRes miwr(contractCode, admin);
auto webIte = tfs.find(parwebresult.id);
eosio_assert(webIte != tfs.end(), ID_NOT_EXIST);
auto webresIte = miwr.find(parwebresult.id);
if(webresIte == miwr.end()){
miwr.emplace(admin, [&](auto &s){
s.id = parwebresult.id;
s.webdata = parwebresult.webdata;
s.errmsg = parwebresult.errmsg;
//s.status = parwebresult.status;
});
}else{
miwr.modify(webresIte, admin, [&](auto &s){
s.webdata = parwebresult.webdata;
s.errmsg = parwebresult.errmsg;
//s.status = parwebresult.status;
});
}
}
void OutNetDataSer::clearall(const clear & c){
require_auth(admin);
ReqWebTable tfs(contractCode, admin);
auto ite = tfs.begin();
while(ite!=tfs.end()){
ite = tfs.erase(ite);
}
}
/**
* The init() and apply() methods must have C calling convention so that the blockchain can lookup and
* call these methods.
*/
extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
switch(action)
{
case N(addwebreq):
{
OutNetDataSer().storeWebRequest(eosio::unpack_action_data<webrequest>());
break;
}
case N(addwebres):
{
OutNetDataSer().storeWebResult(eosio::unpack_action_data<webresult>());
break;
}
case N(clear):
{
OutNetDataSer().clearall(eosio::unpack_action_data<clear>());
break;
}
default:
break;
}
} // extern "C"
}