Skip to content

Commit b1038f9

Browse files
authored
Makes expiration support user_types (#19)
* Add user_type to the community contract * Adjust make file * Adjust contract name so abigen works * Change behavior of the expiration feature
1 parent 4252d85 commit b1038f9

File tree

10 files changed

+147
-112
lines changed

10 files changed

+147
-112
lines changed

community/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ obj = $(src:.cpp=.wasm)
55
OPTS = -D'__TOKEN_ACCOUNT__=cambiatus.tk' -D'__BACKEND_ACCOUNT__=bespiral'
66

77
community.wasm: $(src)
8-
eosio-cpp $(OPTS) -o $@ $^
9-
# eosio-cpp $(OPTS) -o $@ -abigen -R ./ricardian $^
8+
eosio-cpp $(OPTS) -o $@ -abigen -R ./ricardian $^
109

1110
clean:
1211
rm $(obj)

community/community.abi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@
356356
{
357357
"name": "new_user",
358358
"type": "name"
359+
},
360+
{
361+
"name": "user_type",
362+
"type": "string"
359363
}
360364
]
361365
},
@@ -378,6 +382,10 @@
378382
{
379383
"name": "invited_by",
380384
"type": "name"
385+
},
386+
{
387+
"name": "user_type",
388+
"type": "string"
381389
}
382390
]
383391
},

community/community.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void cambiatus::create(eosio::asset cmm_asset, eosio::name creator, std::string
4545
eosio::action netlink = eosio::action(eosio::permission_level{get_self(), eosio::name{"active"}}, // Permission
4646
get_self(), // Account
4747
eosio::name{"netlink"}, // Action
48-
std::make_tuple(cmm_asset, creator, creator));
48+
std::make_tuple(cmm_asset, creator, creator, "natural"));
4949
netlink.send();
5050

5151
// Notify creator
@@ -77,7 +77,7 @@ void cambiatus::update(eosio::asset cmm_asset, std::string logo, std::string nam
7777
});
7878
}
7979

80-
void cambiatus::netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name new_user)
80+
void cambiatus::netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name new_user, std::string user_type)
8181
{
8282
eosio::check(is_account(new_user), "new user account doesn't exists");
8383

@@ -98,6 +98,9 @@ void cambiatus::netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name
9898
require_auth(backend_account);
9999
}
100100

101+
// Validate user type
102+
eosio::check(user_type == "natural" || user_type == "juridical", "User type must be 'natural' or 'juridical'");
103+
101104
// Validates community
102105
eosio::symbol cmm_symbol = cmm_asset.symbol;
103106
communities community(_self, _self.value);
@@ -123,6 +126,7 @@ void cambiatus::netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name
123126
r.community = cmm_symbol;
124127
r.invited_user = new_user;
125128
r.invited_by = inviter;
129+
r.user_type = user_type;
126130
});
127131

128132
// Notify user
@@ -991,6 +995,15 @@ void cambiatus::clean(std::string t)
991995
itr = communities_table.erase(itr);
992996
}
993997
}
998+
999+
if (t == "network")
1000+
{
1001+
networks network_table(_self, _self.value);
1002+
for (auto itr = network_table.begin(); itr != network_table.end();)
1003+
{
1004+
itr = network_table.erase(itr);
1005+
}
1006+
}
9941007
}
9951008

9961009
void cambiatus::migrateafter(std::uint64_t claim_id, std::uint64_t increment)

community/community.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define TOSTR_(T) #T
66
#define TOSTR(T) TOSTR_(T)
77

8-
class [[eosio::contract("cambiatus.community")]] cambiatus : public eosio::contract
8+
class [[eosio::contract("community")]] cambiatus : public eosio::contract
99
{
1010
public:
1111
using contract::contract;
@@ -38,13 +38,14 @@ class [[eosio::contract("cambiatus.community")]] cambiatus : public eosio::contr
3838
eosio::symbol community;
3939
eosio::name invited_user;
4040
eosio::name invited_by;
41+
std::string user_type;
4142

4243
// keys and indexes
4344
std::uint64_t primary_key() const { return id; }
4445
std::uint64_t users_by_cmm() const { return community.raw(); }
4546

4647
EOSLIB_SERIALIZE(network,
47-
(id)(community)(invited_user)(invited_by));
48+
(id)(community)(invited_user)(invited_by)(user_type));
4849
};
4950

5051
TABLE objective
@@ -167,7 +168,7 @@ class [[eosio::contract("cambiatus.community")]] cambiatus : public eosio::contr
167168

168169
/// @abi action
169170
/// Adds a user to a community
170-
ACTION netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name new_user);
171+
ACTION netlink(eosio::asset cmm_asset, eosio::name inviter, eosio::name new_user, std::string user_type);
171172

172173
/// @abi action
173174
/// Create a new community objective

community/community.wasm

1.72 KB
Binary file not shown.

token/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ obj = $(src:.cpp=.wasm)
55
OPTS = -D'__COMMUNITY_ACCOUNT__=cambiatus.cm'
66

77
token.wasm: $(src)
8-
eosio-cpp $(OPTS) -o $@ $^
9-
# eosio-cpp $(OPTS) -o $@ $^ -abigen -R ./ricardian
8+
eosio-cpp $(OPTS) -o $@ $^ -abigen -R ./ricardian
109

1110
clean:
1211
rm $(obj)

token/token.abi

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
"type": "symbol"
7575
},
7676
{
77-
"name": "expiration_period",
77+
"name": "natural_expiration_period",
78+
"type": "uint32"
79+
},
80+
{
81+
"name": "juridical_expiration_period",
7882
"type": "uint32"
7983
},
8084
{
@@ -94,6 +98,10 @@
9498
{
9599
"name": "account",
96100
"type": "name"
101+
},
102+
{
103+
"name": "inviter",
104+
"type": "name"
97105
}
98106
]
99107
},
@@ -120,12 +128,12 @@
120128
"base": "",
121129
"fields": [
122130
{
123-
"name": "from",
124-
"type": "name"
131+
"name": "currency",
132+
"type": "symbol"
125133
},
126134
{
127-
"name": "quantity",
128-
"type": "asset"
135+
"name": "user_type",
136+
"type": "string"
129137
},
130138
{
131139
"name": "memo",
@@ -142,7 +150,11 @@
142150
"type": "symbol"
143151
},
144152
{
145-
"name": "expiration_period",
153+
"name": "natural_expiration_period",
154+
"type": "uint32"
155+
},
156+
{
157+
"name": "juridical_expiration_period",
146158
"type": "uint32"
147159
},
148160
{
@@ -192,37 +204,37 @@
192204
{
193205
"name": "create",
194206
"type": "create",
195-
"ricardian_contract": ""
207+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: create placeholder\nsummary: placeholder\nicon:"
196208
},
197209
{
198210
"name": "initacc",
199211
"type": "initacc",
200-
"ricardian_contract": ""
212+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: initacc placeholder\nsummary: placeholder\nicon:"
201213
},
202214
{
203215
"name": "issue",
204216
"type": "issue",
205-
"ricardian_contract": ""
217+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: issue placeholder\nsummary: placeholder\nicon:"
206218
},
207219
{
208220
"name": "retire",
209221
"type": "retire",
210-
"ricardian_contract": ""
222+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: retire placeholder\nsummary: placeholder\nicon:"
211223
},
212224
{
213225
"name": "setexpiry",
214226
"type": "setexpiry",
215-
"ricardian_contract": ""
227+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: setexpiry placeholder\nsummary: placeholder\nicon:"
216228
},
217229
{
218230
"name": "transfer",
219231
"type": "transfer",
220-
"ricardian_contract": ""
232+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: transfer placeholder\nsummary: placeholder\nicon:"
221233
},
222234
{
223235
"name": "update",
224236
"type": "update",
225-
"ricardian_contract": ""
237+
"ricardian_contract": "---\nspec-version: 0.0.1\ntitle: update placeholder\nsummary: placeholder\nicon:"
226238
}
227239
],
228240
"tables": [
@@ -248,6 +260,11 @@
248260
"key_types": []
249261
}
250262
],
251-
"ricardian_clauses": [],
263+
"ricardian_clauses": [
264+
{
265+
"id": "Data Storage",
266+
"body": "---\nspec-version: 0.0.1\ntitle: General Data Storage\nsummary: This smart contract will store data added by the user. The user consents to the storage of this data by signing the transaction.\nicon:"
267+
}
268+
],
252269
"variants": []
253270
}

0 commit comments

Comments
 (0)