Skip to content

Commit

Permalink
Allow multiple accounts to use the same contrtact
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljyeates committed Oct 16, 2018
1 parent 16b94de commit 34f1129
Show file tree
Hide file tree
Showing 4 changed files with 755 additions and 583 deletions.
12 changes: 10 additions & 2 deletions tokenlock.abi
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
"base": "",
"fields": [
{
"name": "tok",
"type": "asset"
"name": "user",
"type": "name"
},
{
"name": "tok",
"type": "asset"
},
{
"name": "unlock_wait",
"type": "uint64"
Expand All @@ -42,6 +46,10 @@
"name": "unlockact",
"base": "",
"fields": [
{
"name": "user",
"type": "name"
},
{
"name": "tok",
"type": "asset"
Expand Down
21 changes: 8 additions & 13 deletions tokenlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ class tokenlock : public eosio::contract {
asset quantity,
string memo ) {

require_auth( _self );
require_auth( from );

if ( from != _self){
// only transfers from this account
return;
}

lockup_table locks(_self, _self);
lockup_table locks(_self, from);

auto lock = locks.find(quantity.symbol.name());
if ( lock != locks.end() ){
Expand All @@ -37,10 +32,10 @@ class tokenlock : public eosio::contract {
}

/// @abi action
void lock(asset tok, uint64_t time ) {
require_auth( _self );
void lock(name user, asset tok, uint64_t time ) {
require_auth( user );

lockup_table locks(_self, _self);
lockup_table locks(_self, user);

auto lock = locks.find(tok.symbol.name());

Expand All @@ -67,10 +62,10 @@ class tokenlock : public eosio::contract {
}
}
/// @abi action
void unlock(asset tok) {
require_auth( _self );
void unlock(name user, asset tok) {
require_auth( user );

lockup_table locks(_self, _self);
lockup_table locks(_self, user);

auto lock = locks.find(tok.symbol.name());
eosio_assert(lock != locks.end(), "Token is not managed");
Expand Down
Binary file modified tokenlock.wasm
Binary file not shown.
Loading

0 comments on commit 34f1129

Please sign in to comment.