-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploaddata.cpp
97 lines (74 loc) · 2.25 KB
/
uploaddata.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
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/transaction.hpp>
using namespace eosio;
using std::string;
class uploaddata : public eosio::contract {
private:
/// @abi table profiles
struct profile {
uint64_t key;
string value;
uint64_t primary_key() const { return key; }
EOSLIB_SERIALIZE(profile, (key)(value))
};
public:
using contract::contract;
explicit uploaddata(account_name self) : contract(self) {}
/// @abi action
void upload(const account_name account,
const uint64_t key,
const string& value)
{
require_auth(_self);
profile_table_t profile(_self,_self);
auto iter = profile.find(key);
eosio_assert(iter == profile.end(),"Account already has profile.");
profile.emplace(account, [&](struct profile& p){
p.key = key;
p.value = value;
});
require_recipient(_self);
print("profile upload");
}
/// @abi action
void update(const account_name account,
const uint64_t key,
const string& value)
{
require_auth(_self);
//require_auth(N(ecdowsurecom));
profile_table_t profile(_self,_self);
auto iter = profile.find(key);
profile.modify(iter, account, [&](struct profile& p){
p.key = key;
p.value = value;
});
require_recipient(_self);
print("profile modify");
}
/// @abi action
void show(uint64_t key)
{
profile_table_t profile(_self,_self);
auto iter = profile.find(key);
eosio_assert(iter != profile.end(),"Account dose not have a profile.");
print(iter->value.c_str());
}
/// @abi action
void remove(const account_name account,
const uint64_t key)
{
require_auth(_self);
//require_auth(N(ecdowsurecom));
profile_table_t profile(_self,_self);
auto iter = profile.find(key);
eosio_assert(iter != profile.end(),"Account dose not have a profile.");
profile.erase(iter);
require_recipient(_self);
print("profile removed");
}
private:
using profile_table_t = eosio::multi_index<N(profiles),profile>;
};
EOSIO_ABI(uploaddata, (upload)(update)(show)(remove))