-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangevariable.cpp
More file actions
63 lines (45 loc) · 1.53 KB
/
changevariable.cpp
File metadata and controls
63 lines (45 loc) · 1.53 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
#include <eosio/eosio.hpp>
using namespace eosio;
class [[eosio::contract("test1")]] test1 : public eosio::contract {
public:
test1(name receiver, name code, datastream<const char*> ds): contract(receiver, code, ds) {}
[[eosio::action]]
void change(name user, uint64_t variable) {
require_auth( user );
address_index addresses( get_self(), get_first_receiver().value );
auto iterator = addresses.find(user.value);
check(iterator != addresses.end(), "Record does not exist");
addresses.modify(iterator, user, [&]( auto& row ) {
row.key = user;
row.variable=variable;
});
}
[[eosio::action]]
void init(name user, uint64_t variable) {
require_auth( user );
address_index addresses( get_self(), get_first_receiver().value );
auto iterator = addresses.find(user.value);
addresses.emplace( user, [&]( auto& row ) {
row.key = user;
row.variable = variable;
});
}
[[eosio::action]]
void settozero(name user) {
require_auth(user);
address_index addresses( get_self(), get_first_receiver().value);
auto iterator = addresses.find(user.value);
check(iterator != addresses.end(), "Record does not exist");
addresses.modify(iterator, user, [&]( auto& row ) {
row.key = row.key;
row.variable = 0;
});
}
private:
struct [[eosio::table]] person {
name key;
uint64_t variable;
uint64_t primary_key() const { return key.value; }
};
using address_index = eosio::multi_index<"people"_n, person>;
};