-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathocaskans.hpp
More file actions
executable file
·194 lines (150 loc) · 4.2 KB
/
ocaskans.hpp
File metadata and controls
executable file
·194 lines (150 loc) · 4.2 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
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
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eosiolib/eosio.hpp>
#include <eosiolib/db.h>
#include <eosiolib/asset.hpp>
#include<eosiolib/serialize.hpp>
#include"tool.hpp"
const static uint32_t lable_not_release = 0;
const static uint32_t lable_released = 1;
struct transferfromact {
account_name from;
account_name to;
eosio::asset quantity;
EOSLIB_SERIALIZE(transferfromact, (from)(to)(quantity))
};
struct transfer
{
account_name from;
account_name to;
eosio::asset quantity;
std::string memo;
EOSLIB_SERIALIZE( transfer, (from)(to)(quantity)(memo) )
};
/**
* @abi table
*/
struct ask{
uint64_t id;
uint32_t endtime;
account_name from;
eosio::asset quantity;
uint32_t releasedLable;
uint32_t createtime;
uint64_t optionanswerscnt;
std::string asktitle;
std::string optionanswers;
uint64_t primary_key()const { return id; }
EOSLIB_SERIALIZE( ask, (id)(endtime)(from)(quantity)(releasedLable)(createtime)(optionanswerscnt)(asktitle)(optionanswers))
};
/**
* @abi action ask
*/
struct actask{
uint64_t id;
uint32_t endtime;
account_name from;
eosio::asset quantity;
uint32_t createtime;
uint64_t optionanswerscnt;
std::string asktitle;
std::string optionanswers;
uint64_t primary_key()const { return id; }
EOSLIB_SERIALIZE( actask, (id)(endtime)(from)(quantity)(createtime)(optionanswerscnt)(asktitle)(optionanswers))
};
/*
@abi action answer
*/
struct answer{
uint64_t askid;
account_name from;
uint32_t choosedanswer;
uint64_t primary_key()const { return askid; }
uint64_t get_secondary()const { return from; }
EOSLIB_SERIALIZE(answer, (askid)(from)(choosedanswer))
};
/**
* @abi table
*/
struct answers{
uint64_t askid;
std::vector<answer> answerlist;
uint64_t primary_key()const { return askid; }
EOSLIB_SERIALIZE(answers, (askid)(answerlist))
};
/**
* @abi action
*/
struct releasemog{
uint64_t askid;
EOSLIB_SERIALIZE(releasemog, (askid))
};
/*
@abi action
@abi table configa
*/
struct config{
account_name admin;
eosio::asset ansreqoct;
account_name primary_key()const { return admin; }
EOSLIB_SERIALIZE(config, (admin)(ansreqoct))
};
typedef eosio::multi_index<N(configa), config> Config;
/*
@abi action
@abi table configaskid
*/
struct configaskid{
uint64_t key;
uint64_t value;
uint64_t primary_key()const { return key; }
EOSLIB_SERIALIZE(configaskid, (key)(value))
};
typedef eosio::multi_index<N(configaskid), configaskid> ConfigAskId;
#define INDEX_ASKID 0
/*
@abi action
*/
struct rmask{
uint64_t askid;
EOSLIB_SERIALIZE(rmask, (askid))
};
typedef eosio::multi_index<N(ask), ask> askIndex;
typedef eosio::multi_index<N(answers), answers> AnswerIndex;
class ocaskans:public eosio::contract{
public:
ocaskans(account_name self):contract(self){
ansreqoct.amount = 0;
eosio::symbol_name sn = eosio::string_to_symbol(4, globalsymbolname.c_str());
ansreqoct.symbol = eosio::symbol_type(sn);
Config c(self, aksansadmin);
auto ite = c.find(aksansadmin);
if(ite != c.end()){
ansreqoct = ite->ansreqoct;
}
ConfigAskId cai(currentAdmin, aksansadmin);
latestaskid = 1000;
auto askIndexIdItem = cai.find(INDEX_ASKID);
if(askIndexIdItem!=cai.end()){
latestaskid = askIndexIdItem->value;
}
}
uint32_t getAnswerCount(uint64_t askid);
void removeAsk(const rmask & ra);
void releaseMortgage( const releasemog& rm );
void store_answer(const answer &a);
void store_ask(const actask &c);
void transferInline(const transfer &trs);
void transferFromInline(const transferfromact &tf);
void configinfo(const config &ansreqoct);
static const uint64_t aksansadmin = N(ocaskans);
static const uint64_t tokenContract = N(octoneos);
static const uint64_t currentAdmin = N(ocaskans);
eosio::asset ansreqoct;
uint64_t latestaskid;
private:
std::string globalsymbolname = "OCT";
void send_deferred_transferfrom_transaction(transferfromact tf);
};