From 7f668a7e64627881d6339c86ae965598990dfce8 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 09:46:11 -0800 Subject: [PATCH 01/15] update instrument and rights contract --- contracts/ore.instrument/ore.instrument.hpp | 62 +++++++++--------- .../ore.rights_registry.hpp | 19 +++--- .../ore.rights_registry.wasm | Bin 0 -> 20962 bytes contracts/ore_types/ore_types.hpp | 4 +- 4 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 contracts/ore.rights_registry/ore.rights_registry.wasm diff --git a/contracts/ore.instrument/ore.instrument.hpp b/contracts/ore.instrument/ore.instrument.hpp index 7108746..a00c1ee 100644 --- a/contracts/ore.instrument/ore.instrument.hpp +++ b/contracts/ore.instrument/ore.instrument.hpp @@ -4,9 +4,9 @@ #include #include -#include -#include -#include +#include "eosiolib/eosio.hpp" +#include "eosiolib/asset.hpp" +#include "eosiolib/transaction.hpp" #include "../ore.rights_registry/ore.rights_registry.hpp" using namespace eosio; @@ -15,12 +15,12 @@ using namespace std; class instrument : public eosio::contract { public: - instrument(account_name self) + instrument(name self) : contract(self), _account(_self, _self), _tokens(_self, _self) {} struct instrument_data { - account_name issuer; + name issuer; string instrument_class; string description; string instrument_template; @@ -40,8 +40,8 @@ class instrument : public eosio::contract { //721 standard properties uint64_t id; - account_name owner; - account_name minted_by; + name owner; + name minted_by; uint64_t minted_at; //instrument properties @@ -70,7 +70,7 @@ class instrument : public eosio::contract //@abi table account i64 struct accountdata { - account_name owner; + name owner; uint64_t balance; vector instruments; uint64_t primary_key() const { return owner; } @@ -85,7 +85,7 @@ class instrument : public eosio::contract // struct allowancedata // { // uint64_t token_id; - // account_name to; + // name to; // uint64_t primary_key() const { return token_id; } @@ -108,7 +108,7 @@ class instrument : public eosio::contract { asset supply; asset max_supply; - account_name issuer; + name issuer; uint64_t primary_key() const { return supply.symbol.name(); } }; @@ -116,20 +116,20 @@ class instrument : public eosio::contract typedef eosio::multi_index accounts; typedef eosio::multi_index stats; - void sub_balance(account_name owner, asset value); - void sub_balance_from(account_name sender, account_name owner, asset value); - void add_balance(account_name owner, asset value, account_name ram_payer); - void transfer_balances(account_name from, account_name to, uint64_t instrument_id, int64_t amount = 1); + void sub_balance(name owner, asset value); + void sub_balance_from(name sender, name owner, asset value); + void add_balance(name owner, asset value, name ram_payer); + void transfer_balances(name from, name to, uint64_t instrument_id, int64_t amount = 1); public: //public utility functions token find_token_by_id(uint64_t id); bool isToken(uint64_t id); token find_token_by_template(string instrument_template); - bool _owns(account_name claimant, uint64_t token_id); + bool _owns(name claimant, uint64_t token_id); uint64_t total_supply(); - uint64_t balance_of(account_name owner); - account_name owner_of(uint64_t token_id); + uint64_t balance_of(name owner); + name owner_of(uint64_t token_id); inline static uint64_t hashStringToInt(const string &strkey) { @@ -137,16 +137,16 @@ class instrument : public eosio::contract } //actions - void approve(account_name from, account_name to, uint64_t token_id); - void mint(account_name minter, account_name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId); - void checkright(account_name minter, account_name issuer, string rightname, uint64_t deferred_transaction_id); - void update(account_name updater, string instrument_template, instrument_data instrument, uint64_t instrument_id, uint64_t start_time, uint64_t end_time); - void transfer(account_name sender, account_name to, uint64_t token_id); - void revoke(account_name revoker, uint64_t token_id); - void burn(account_name burner, uint64_t token_id); - void create(account_name issuer, asset maximum_supply); - void createinst(account_name minter, account_name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time); - void issue(account_name to, asset quantity, string memo); + void approve(name from, name to, uint64_t token_id); + void mint(name minter, name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId); + void checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id); + void update(name updater, string instrument_template, instrument_data instrument, uint64_t instrument_id, uint64_t start_time, uint64_t end_time); + void transfer(name sender, name to, uint64_t token_id); + void revoke(name revoker, uint64_t token_id); + void burn(name burner, uint64_t token_id); + void create(name issuer, asset maximum_supply); + void createinst(name minter, name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time); + void issue(name to, asset quantity, string memo); }; instrument::token instrument::find_token_by_id(uint64_t id) @@ -198,14 +198,14 @@ instrument::token instrument::find_token_by_template(string instrument_template) } // Return an account's total balance -uint64_t instrument::balance_of(account_name owner) +uint64_t instrument::balance_of(name owner) { auto account = _account.find(owner); return account->balance; } // Returns who owns a token -account_name instrument::owner_of(uint64_t token_id) +name instrument::owner_of(uint64_t token_id) { auto token = _tokens.find(token_id); return token->owner; @@ -225,12 +225,12 @@ uint64_t instrument::total_supply() } // Check if account owns the token -bool instrument::_owns(account_name claimant, uint64_t token_id) +bool instrument::_owns(name claimant, uint64_t token_id) { return owner_of(token_id) == claimant; } -void instrument::transfer_balances(account_name from, account_name to, uint64_t instrument_id, int64_t amount) +void instrument::transfer_balances(name from, name to, uint64_t instrument_id, int64_t amount) { auto fromitr = _account.find(from); diff --git a/contracts/ore.rights_registry/ore.rights_registry.hpp b/contracts/ore.rights_registry/ore.rights_registry.hpp index 04e021f..8696f28 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.hpp +++ b/contracts/ore.rights_registry/ore.rights_registry.hpp @@ -4,12 +4,12 @@ */ #pragma once -#include +#include "eosiolib/eosio.hpp" #include "../ore_types/ore_types.hpp" using namespace eosio; using namespace std; -class rights_registry : public contract +class [[eosio::contract("ore.rights_registry")]] rights_registry : public contract { public: //@abi table rights i64 @@ -17,23 +17,24 @@ class rights_registry : public contract { uint64_t id; string right_name; - account_name owner; + name owner; vector urls; - vector issuer_whitelist; + vector issuer_whitelist; uint64_t primary_key() const { return id; } EOSLIB_SERIALIZE(right_reg, (id)(right_name)(owner)(urls)(issuer_whitelist)) }; - typedef multi_index right_registration_index; + typedef multi_index<"rights"_n, right_reg> right_registration_index; public: - rights_registry(account_name self) - : contract(self) {} + // rights_registry(name self) + // : contract(self) {} + using contract::contract; - void upsertright(account_name owner, string &right_name, vector urls, vector issuer_whitelist); - void deleteright(account_name owner, string &right_name); + void upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist); + void deleteright(name owner, string &right_name); inline static uint64_t hashStr(const string &strkey) { diff --git a/contracts/ore.rights_registry/ore.rights_registry.wasm b/contracts/ore.rights_registry/ore.rights_registry.wasm new file mode 100644 index 0000000000000000000000000000000000000000..f88dec92465fa1397593e66c4429d5dc9446a2ec GIT binary patch literal 20962 zcmd6vYm8mjb>GkPo^$WH<2g!LXF|Hsz9(!miYb?rr4c1FH4ke_V&zDcsl7WRdC{REjnr{UvBxsG=Q0or`+{YKSNMR>%0~M`N1ZWGkC;}HK3ZX5K zrU=6R{%h}Z=MEoo>K2amm~+lP`?2J#&SrvA~zp4zPkZ+IW6FGH-Czt`-Vg}?NTE|z+& zf1>1@$wTRQ`&z#8>dxLIN_1bZtWMT;wwEuhOjefn*M4an%~|v6)xEv(_GEc)ygFXH zHr|U;H4nSy$=cS~H&vHjU4CtC`_l5-(&JH~P6JwAA5W~Irv`P|9>3{ZhH9CkWpBK- zb8T$B`ZhOh`;(nL-&A$ouI>VwZyQ**@y`C*&hpCs{+KMVKK;~iIGpRp!}4SE z_54E*@iZ*?_o3l@Pq(EW%BcJ??&JC4e1E>*AO3jRANGAZ?m!Cg%YW4DXbz}eP)?-gBy>e;=g+J0sg=#moz)eHsTSY1bZxw(+8z&(X&(-5=0PnqyZe9J{`D*rlZra{P&sKw|PS3sn_Rrn= zYV|Q*Jd)aIO{L{`$ZE)_=%1o1$H~=8FCB=<;y0Kg!j6o$+P+)_PO6 z>GN|@<@&Ct$EbblN>i?@LmxDi8!Q?>I~Na=O6$=ner7JNlC#_;&j^?{eReK!{YRsu zttT#LekOY~iraGLDdI%{K=1Q*jtzA!EINP9Mf>lKV&)yRkFPH#QB!hv((Za%r))0+ zbIXDoqk?UNeIrWz(p>B!FcQ(B$=O!!iuLyLvup}50~$*=okVjp_%zcmtUuG%HDvMo z8$2Syv~C?Lox7!f{?<3Y^G|O=(+m)!=U7N%TvY$WT{BdoEMp%@&%V^Y8#ASDNA!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*GRA<8*=YPQOXZDR-ceXdLyK5_(YnR+> zdpldktBs9n-2U}_z@Y!?&ed(>`rnSKFZv<UKxWj1e}$b7{Q4_WHJ$Je%{?F|4r( fSG$$hkVLn9dAzb~T~~Jy9Da0;g~RXM!NLCr-W;Fv literal 0 HcmV?d00001 diff --git a/contracts/ore_types/ore_types.hpp b/contracts/ore_types/ore_types.hpp index c61726a..11a29dd 100644 --- a/contracts/ore_types/ore_types.hpp +++ b/contracts/ore_types/ore_types.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "eosiolib/transaction.hpp" #include using namespace std; @@ -57,7 +57,7 @@ class ore_types : public contract { string right_name; vector urls; - vector whitelist; + vector whitelist; }; struct api_voucher_params From 5c754bfdc68bdafd457b21226a36ca6310435558 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 15:41:09 -0800 Subject: [PATCH 02/15] upgrade rights_registry contrcat to be compatible with EOS v1.5.0 --- .../ore.rights_registry.cpp | 24 +++++++++---------- .../ore.rights_registry.hpp | 24 ++++++++++++------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.cpp b/contracts/ore.rights_registry/ore.rights_registry.cpp index 51e6bec..5e570fe 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.cpp +++ b/contracts/ore.rights_registry/ore.rights_registry.cpp @@ -3,17 +3,17 @@ using namespace eosio; // transfer action -void rights_registry::upsertright(account_name owner, string &right_name, vector urls, vector issuer_whitelist) +void rights_registry::upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist) { require_auth(owner); - right_registration_index right_registration(_self, _self); + //right_registration_index right_registration(_self, _self); - auto itr = right_registration.find(hashStr(right_name)); + auto itr = rightsindex.find(hashStr(right_name)); - if (itr == right_registration.end()) + if (itr == rightsindex.end()) { - right_registration.emplace(owner, [&](auto &end) { + rightsindex.emplace(owner, [&](auto &end) { end.id = hashStr(right_name); end.right_name = right_name; end.owner = owner; @@ -26,7 +26,7 @@ void rights_registry::upsertright(account_name owner, string &right_name, vector else { eosio_assert(itr->owner == owner, "You are not the issuer of the existing right name. Update canceled!"); - right_registration.modify(itr, owner, [&](auto &end) { + rightsindex.modify(itr, owner, [&](auto &end) { end.urls = urls; end.issuer_whitelist = issuer_whitelist; }); @@ -34,17 +34,17 @@ void rights_registry::upsertright(account_name owner, string &right_name, vector } } -void rights_registry::deleteright(account_name owner, string &right_name) +void rights_registry::deleteright(name owner, string &right_name) { require_auth(owner); - right_registration_index right_registration(_self, _self); + //right_registration_index right_registration(_self, _self); - auto itr = right_registration.find(hashStr(right_name)); + auto itr = rightsindex.find(hashStr(right_name)); - eosio_assert(itr != right_registration.end(), "There is no right with that name"); + eosio_assert(itr != rightsindex.end(), "There is no right with that name"); - right_registration.erase(itr); + rightsindex.erase(itr); } -EOSIO_ABI(rights_registry, (upsertright)(deleteright)) +EOSIO_DISPATCH(rights_registry, (upsertright)(deleteright)) diff --git a/contracts/ore.rights_registry/ore.rights_registry.hpp b/contracts/ore.rights_registry/ore.rights_registry.hpp index 8696f28..bd4749f 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.hpp +++ b/contracts/ore.rights_registry/ore.rights_registry.hpp @@ -12,8 +12,10 @@ using namespace std; class [[eosio::contract("ore.rights_registry")]] rights_registry : public contract { public: - //@abi table rights i64 - struct right_reg + using contract::contract; + rights_registry( name receiver, name code, datastream ds): contract(receiver, code, ds), rightsindex(receiver, receiver.value){} + + struct [[eosio::table]] right_reg { uint64_t id; string right_name; @@ -26,14 +28,18 @@ class [[eosio::contract("ore.rights_registry")]] rights_registry : public contra EOSLIB_SERIALIZE(right_reg, (id)(right_name)(owner)(urls)(issuer_whitelist)) }; - typedef multi_index<"rights"_n, right_reg> right_registration_index; + using right_registration_index = eosio::multi_index<"rights"_n, right_reg> ; + +// private: +// right_registration_index rightsindex; public: - // rights_registry(name self) - // : contract(self) {} - using contract::contract; + right_registration_index rightsindex; + [[eosio::action]] void upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist); + + [[eosio::action]] void deleteright(name owner, string &right_name); inline static uint64_t hashStr(const string &strkey) @@ -43,11 +49,11 @@ class [[eosio::contract("ore.rights_registry")]] rights_registry : public contra right_reg find_right_by_name(string right_name) { - right_registration_index _endpoints(_self, _self); + // right_registration_index endpoints(_self, _self); - auto rightitr = _endpoints.find(hashStr(right_name)); + auto rightitr = rightsindex.find(hashStr(right_name)); - if (rightitr == _endpoints.end()) + if (rightitr == rightsindex.end()) { return right_reg{0}; } From 983dc6ee9eafc7416293b1053a36a6f6e768a496 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 15:45:42 -0800 Subject: [PATCH 03/15] use typedef to define multi-index --- contracts/ore.rights_registry/ore.rights_registry.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.hpp b/contracts/ore.rights_registry/ore.rights_registry.hpp index bd4749f..26af688 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.hpp +++ b/contracts/ore.rights_registry/ore.rights_registry.hpp @@ -28,11 +28,8 @@ class [[eosio::contract("ore.rights_registry")]] rights_registry : public contra EOSLIB_SERIALIZE(right_reg, (id)(right_name)(owner)(urls)(issuer_whitelist)) }; - using right_registration_index = eosio::multi_index<"rights"_n, right_reg> ; - -// private: -// right_registration_index rightsindex; - + typedef eosio::multi_index<"rights"_n, right_reg>right_registration_index; + public: right_registration_index rightsindex; From 62b2898887289cb6d8e199afa81b625aa723bf41 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 15:48:27 -0800 Subject: [PATCH 04/15] remove wasm file --- .../ore.rights_registry.wasm | Bin 20962 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 contracts/ore.rights_registry/ore.rights_registry.wasm diff --git a/contracts/ore.rights_registry/ore.rights_registry.wasm b/contracts/ore.rights_registry/ore.rights_registry.wasm deleted file mode 100644 index f88dec92465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g~RXM!NLCr-W;Fv From 173e07cdefccceaadf77b5ee09a2515e03b47b00 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 15:50:17 -0800 Subject: [PATCH 05/15] remove commented out code --- contracts/ore.rights_registry/ore.rights_registry.cpp | 4 ---- contracts/ore.rights_registry/ore.rights_registry.hpp | 2 -- 2 files changed, 6 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.cpp b/contracts/ore.rights_registry/ore.rights_registry.cpp index 5e570fe..79fb484 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.cpp +++ b/contracts/ore.rights_registry/ore.rights_registry.cpp @@ -7,8 +7,6 @@ void rights_registry::upsertright(name owner, string &right_name, vector Date: Thu, 6 Dec 2018 17:09:53 -0800 Subject: [PATCH 06/15] update ore.usagelog.cpp to be compatible with eos v1.5 --- contracts/ore.usage_log/ore.usage_log.cpp | 39 ++++++++++------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/contracts/ore.usage_log/ore.usage_log.cpp b/contracts/ore.usage_log/ore.usage_log.cpp index a08ca87..be3639e 100644 --- a/contracts/ore.usage_log/ore.usage_log.cpp +++ b/contracts/ore.usage_log/ore.usage_log.cpp @@ -1,21 +1,20 @@ #include #include +#include #include using namespace eosio; using namespace std; -class usage_log : public eosio::contract +class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract { public: - usage_log(account_name self) : eosio::contract(self) {} + using contract::contract; + usage_log(name receiver, name code, datastream ds): contract(receiver, code, ds), _logs(receiver, receiver.value){} - //@abi action + [[eosio::action]] void createlog(uint64_t instrument_id, string right_name, string token_hash, uint64_t timestamp) { - - logs_table _logs(_self, _self); - uint64_t right_hash = hashStr(right_name); _logs.emplace(_self, [&](auto &a) { @@ -29,11 +28,9 @@ class usage_log : public eosio::contract // TODO: require authority of the reconciler // delets the entry from the log table with matching token_hash - // @abi action + [[eosio::action]] void deletelog(uint64_t instrument_id, string token_hash) { - logs_table _logs(_self, _self); - auto itr = _logs.find(hashStr(token_hash)); eosio_assert(itr != _logs.end(), "No log exist for the given pair or right and instrument"); @@ -43,13 +40,11 @@ class usage_log : public eosio::contract _logs.erase(itr); } - //@abi action + [[eosio::action]] void updatecount(uint64_t instrument_id, string right_name, asset cpu) { uint64_t right_hash = hashStr(right_name); - //Test the scoping - counts_table _counts(_self, instrument_id); auto itr = _counts.find(right_hash); @@ -59,7 +54,7 @@ class usage_log : public eosio::contract _counts.emplace(_self, [&](auto &a) { a.right_hash = right_hash; a.right_name = right_name; - a.last_usage_time = now(); + a.last_usage_time = time_point_sec(now()); a.total_count = 1; a.total_cpu = cpu; }); @@ -67,7 +62,7 @@ class usage_log : public eosio::contract else { _counts.modify(itr, _self, [&](auto &a) { - a.last_usage_time = now(); + a.last_usage_time = time_point_sec(now()); a.total_count += 1; a.total_cpu += cpu; }); @@ -75,8 +70,7 @@ class usage_log : public eosio::contract } private: - //@abi table logs i64 - struct log + struct [[eosio::table]] log { uint64_t instrument_id; uint64_t right_hash; @@ -89,25 +83,26 @@ class usage_log : public eosio::contract }; //following structure enables fast query of api call count for the verifier - //@abi table counts i64 - struct callcount + struct [[eosio::table]] callcount { uint64_t right_hash; string right_name; - time last_usage_time; + time_point_sec last_usage_time; uint64_t total_count; asset total_cpu; auto primary_key() const { return right_hash; } EOSLIB_SERIALIZE(callcount, (right_hash)(right_name)(last_usage_time)(total_count)(total_cpu)) }; + + typedef eosio::multi_index<"counts"_n, callcount> counts_table; + typedef eosio::multi_index<"logs"_n, log> logs_table; - typedef eosio::multi_index counts_table; - typedef eosio::multi_index logs_table; + logs_table _logs; uint64_t hashStr(const string &strkey) { return hash{}(strkey); } }; -EOSIO_ABI(usage_log, (createlog)(deletelog)(updatecount)) +EOSIO_DISPATCH(usage_log, (createlog)(deletelog)(updatecount)) From edb77e1754bcbf1de3586d28a6ecd941a0e50de9 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 17:23:31 -0800 Subject: [PATCH 07/15] use ACTION and TABLE macros --- .../ore.rights_registry.cpp | 18 +++++++++--------- .../ore.rights_registry.hpp | 17 ++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.cpp b/contracts/ore.rights_registry/ore.rights_registry.cpp index 79fb484..4df390e 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.cpp +++ b/contracts/ore.rights_registry/ore.rights_registry.cpp @@ -3,15 +3,15 @@ using namespace eosio; // transfer action -void rights_registry::upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist) +ACTION rights_registry::upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist) { require_auth(owner); - auto itr = rightsindex.find(hashStr(right_name)); + auto itr = _rights.find(hashStr(right_name)); - if (itr == rightsindex.end()) + if (itr == _rights.end()) { - rightsindex.emplace(owner, [&](auto &end) { + _rights.emplace(owner, [&](auto &end) { end.id = hashStr(right_name); end.right_name = right_name; end.owner = owner; @@ -24,7 +24,7 @@ void rights_registry::upsertright(name owner, string &right_name, vectorowner == owner, "You are not the issuer of the existing right name. Update canceled!"); - rightsindex.modify(itr, owner, [&](auto &end) { + _rights.modify(itr, owner, [&](auto &end) { end.urls = urls; end.issuer_whitelist = issuer_whitelist; }); @@ -32,15 +32,15 @@ void rights_registry::upsertright(name owner, string &right_name, vector ds): contract(receiver, code, ds), rightsindex(receiver, receiver.value){} + rights_registry( name receiver, name code, datastream ds): contract(receiver, code, ds), _rights(receiver, receiver.value){} - struct [[eosio::table]] right_reg + TABLE right_reg { uint64_t id; string right_name; @@ -31,13 +32,11 @@ class [[eosio::contract("ore.rights_registry")]] rights_registry : public contra typedef eosio::multi_index<"rights"_n, right_reg>right_registration_index; public: - right_registration_index rightsindex; + right_registration_index _rights; - [[eosio::action]] - void upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist); + ACTION upsertright(name owner, string &right_name, vector urls, vector issuer_whitelist); - [[eosio::action]] - void deleteright(name owner, string &right_name); + ACTION deleteright(name owner, string &right_name); inline static uint64_t hashStr(const string &strkey) { @@ -46,9 +45,9 @@ class [[eosio::contract("ore.rights_registry")]] rights_registry : public contra right_reg find_right_by_name(string right_name) { - auto rightitr = rightsindex.find(hashStr(right_name)); + auto rightitr = _rights.find(hashStr(right_name)); - if (rightitr == rightsindex.end()) + if (rightitr == _rights.end()) { return right_reg{0}; } From 08b00755b18472455f19478f300ab4c8708ffa88 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 17:26:17 -0800 Subject: [PATCH 08/15] use macros for tables and actions --- .../ore.rights_registry/ore.rights_registry.hpp | 2 +- contracts/ore.usage_log/ore.usage_log.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.hpp b/contracts/ore.rights_registry/ore.rights_registry.hpp index 4d0fd43..2ff8eca 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.hpp +++ b/contracts/ore.rights_registry/ore.rights_registry.hpp @@ -10,7 +10,7 @@ using namespace eosio; using namespace std; -class [[eosio::contract("ore.rights_registry")]] rights_registry : public contract +class [[eosio::contract("ore.rights_registry")]] rights_registry : public eosio::contract { public: using contract::contract; diff --git a/contracts/ore.usage_log/ore.usage_log.cpp b/contracts/ore.usage_log/ore.usage_log.cpp index be3639e..43c6b32 100644 --- a/contracts/ore.usage_log/ore.usage_log.cpp +++ b/contracts/ore.usage_log/ore.usage_log.cpp @@ -12,8 +12,7 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract using contract::contract; usage_log(name receiver, name code, datastream ds): contract(receiver, code, ds), _logs(receiver, receiver.value){} - [[eosio::action]] - void createlog(uint64_t instrument_id, string right_name, string token_hash, uint64_t timestamp) + ACTION createlog(uint64_t instrument_id, string right_name, string token_hash, uint64_t timestamp) { uint64_t right_hash = hashStr(right_name); @@ -28,8 +27,7 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract // TODO: require authority of the reconciler // delets the entry from the log table with matching token_hash - [[eosio::action]] - void deletelog(uint64_t instrument_id, string token_hash) + ACTION deletelog(uint64_t instrument_id, string token_hash) { auto itr = _logs.find(hashStr(token_hash)); @@ -40,8 +38,7 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract _logs.erase(itr); } - [[eosio::action]] - void updatecount(uint64_t instrument_id, string right_name, asset cpu) + ACTION updatecount(uint64_t instrument_id, string right_name, asset cpu) { uint64_t right_hash = hashStr(right_name); @@ -70,7 +67,7 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract } private: - struct [[eosio::table]] log + TABLE log { uint64_t instrument_id; uint64_t right_hash; @@ -83,7 +80,7 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract }; //following structure enables fast query of api call count for the verifier - struct [[eosio::table]] callcount + TABLE callcount { uint64_t right_hash; string right_name; From fff731e3c6f34807915649aef29c766b3dedce64 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Thu, 6 Dec 2018 18:48:26 -0800 Subject: [PATCH 09/15] upgrade instrument contract to be compatible with eosv1.5 --- contracts/ore.instrument/ore.instrument.cpp | 102 ++++++++++---------- contracts/ore.instrument/ore.instrument.hpp | 77 ++++++++------- 2 files changed, 88 insertions(+), 91 deletions(-) diff --git a/contracts/ore.instrument/ore.instrument.cpp b/contracts/ore.instrument/ore.instrument.cpp index 3c6b72a..aaeecec 100644 --- a/contracts/ore.instrument/ore.instrument.cpp +++ b/contracts/ore.instrument/ore.instrument.cpp @@ -1,9 +1,6 @@ #include "ore.instrument.hpp" using namespace eosio; -// transaction id for deferred transaction -account_name RIGHTS_CONTRACT_NAME = N(rights.ore); - // Creates new instrument // NOTE: this should result in changes in the following tables : // tokens - add new token @@ -14,12 +11,12 @@ account_name RIGHTS_CONTRACT_NAME = N(rights.ore); // checkright - for each right in the instrument object, mint instrument calls check right within a deferred transaction // createinst - once all the rights are checked, the last action in the deferred transaction is createinst which adds the instrument to the tokens table // NOTE: if any of the checkright action fails, it will cancel the deferred transaction and the creatinst action will not be called. Hence no instrument will be created. -void instrument::mint(account_name minter, account_name owner, instrument_data instrument, +ACTION instrument::mint(name minter, name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId = 0) { // Checking if the minter has the required authorization require_auth(minter); - auto hashtable = _tokens.get_index(); + auto hashtable = _tokens.get_index<"templatehash"_n>(); auto item = hashtable.find(hashStringToInt(instrument.instrument_template)); if (instrument.rights.size() == 0) @@ -69,7 +66,7 @@ void instrument::mint(account_name minter, account_name owner, instrument_data i // Adding createinst action to the deferred transaction to add the new instrument to the tokens table create_instrument.actions.emplace_back( - permission_level{N(instr.ore), N(active)}, _self, N(createinst), + permission_level{"instr.ore"_n, "active"_n}, _self, "createinst"_n, std::make_tuple(minter, owner, instrumentId, @@ -93,7 +90,7 @@ void instrument::mint(account_name minter, account_name owner, instrument_data i for (int i = 0; i < instrument.rights.size(); i++) { deferred_instrument.actions.emplace_back( - permission_level{N(instr.ore), N(active)}, _self, N(checkright), + permission_level{"instr.ore"_n, "active"_n}, _self, "checkright"_n, std::make_tuple( minter, instrument.issuer, @@ -103,7 +100,7 @@ void instrument::mint(account_name minter, account_name owner, instrument_data i // Adding createinst action to the deferred transaction to add the new instrument to the tokens table deferred_instrument.actions.emplace_back( - permission_level{N(instr.ore), N(active)}, _self, N(createinst), + permission_level{"instr.ore"_n, "active"_n}, _self, "createinst"_n, std::make_tuple(minter, owner, instrumentId, @@ -116,10 +113,10 @@ void instrument::mint(account_name minter, account_name owner, instrument_data i } } -void instrument::createinst(account_name minter, account_name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time) +ACTION instrument::createinst(name minter, name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time) { require_auth(_self); - auto accountitr = _account.find(owner); + auto accountitr = _account.find(owner.value); // check if account is already registered to accounts table if (accountitr == _account.end()) @@ -129,7 +126,7 @@ void instrument::createinst(account_name minter, account_name owner, uint64_t in a.balance = 0; print("new instrument account: ", a.primary_key(), "\n"); }); - accountitr = _account.find(owner); + accountitr = _account.find(owner.value); } // writing to tokens table @@ -137,7 +134,7 @@ void instrument::createinst(account_name minter, account_name owner, uint64_t in a.id = instrumentId; a.owner = owner; a.minted_by = minter; - a.minted_at = time(0); + a.minted_at = now();; a.instrument = instrument; a.revoked = false; a.start_time = start_time; @@ -147,7 +144,7 @@ void instrument::createinst(account_name minter, account_name owner, uint64_t in }); // increasing the account balance (total token count) - _account.modify(accountitr, 0, [&](auto &a) { + _account.modify(accountitr, same_payer, [&](auto &a) { a.balance++; a.instruments.push_back(instrumentId); }); @@ -159,22 +156,22 @@ void instrument::createinst(account_name minter, account_name owner, uint64_t in eosio_assert(is_account(owner), "to account does not exist"); // transfer 1 OREINST from the issuer account for OREINST to the owner account of instrument - sub_balance(_self, asset(10000, symbol_type(S(4, OREINST)))); - add_balance(owner, asset(10000, symbol_type(S(4, OREINST))), _self); + sub_balance(_self, asset(10000, symbol(symbol_code("OREINST"),4))); + add_balance(owner, asset(10000, symbol(symbol_code("OREINST"),4)), _self); } -void instrument::checkright(account_name minter, account_name issuer, string rightname, uint64_t deferred_transaction_id = 0) +ACTION instrument::checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id = 0) { require_auth(_self); //instantiating rights.ore contract - rights_registry rights_contract = rights_registry(RIGHTS_CONTRACT_NAME); + rights_registry rights_contract = rights_registry(_self,_code,_ds); - print("action:checkright:", rightname, "\n"); + print("action:checkright:", name{rightname}, "\n"); auto rightitr = rights_contract.find_right_by_name(rightname); - if (rightitr.owner == 0) + if (rightitr.owner.value == 0) { if (deferred_transaction_id != 0) { @@ -212,7 +209,7 @@ void instrument::checkright(account_name minter, account_name issuer, string rig // tokens - the instrument token gets updated depending on the mutabiility // if mutability is 1, start_time and/or end_time can be updated // if mutability is 2, everything except the owner can be updated -void instrument::update(account_name updater, string instrument_template, instrument_data instrument = {}, +ACTION instrument::update(name updater, string instrument_template, instrument_data instrument = {}, uint64_t instrument_id = 0, uint64_t start_time = 0, uint64_t end_time = 0) { require_auth(updater); @@ -235,7 +232,7 @@ void instrument::update(account_name updater, string instrument_template, instru eosio_assert(item.instrument.mutability == 1 || item.instrument.mutability == 2, "the instrument to be updated is immutable"); - rights_registry rights_contract = rights_registry(RIGHTS_CONTRACT_NAME); + rights_registry rights_contract = rights_registry(_self,_code,_ds); auto tokenitr = _tokens.find(item.id); @@ -262,7 +259,7 @@ void instrument::update(account_name updater, string instrument_template, instru if (item.instrument.mutability == 1) { // update the instrument token in the tokens table - _tokens.modify(tokenitr, 0, [&](auto &a) { + _tokens.modify(tokenitr, same_payer, [&](auto &a) { a.start_time = new_start; a.end_time = new_end; }); @@ -284,7 +281,7 @@ void instrument::update(account_name updater, string instrument_template, instru for (int i = 0; i < instrument.rights.size(); i++) { auto rightitr = rights_contract.find_right_by_name(instrument.rights[i].right_name); - if (rightitr.owner == 0) + if (rightitr.owner.value == 0) eosio_assert(false, "right doesn't exist"); if (rightitr.owner != instrument.issuer) @@ -304,11 +301,11 @@ void instrument::update(account_name updater, string instrument_template, instru auto tokenitr = _tokens.find(item.id); // update the instrument token in the tokens table - _tokens.modify(tokenitr, 0, [&](auto &a) { + _tokens.modify(tokenitr, same_payer, [&](auto &a) { a.id = item.id; a.owner = item.owner; a.minted_by = updater; - a.minted_at = time(0); + a.minted_at = now(); a.instrument = item.instrument; a.revoked = false; a.start_time = new_start; @@ -328,7 +325,7 @@ void instrument::update(account_name updater, string instrument_template, instru // tokens - owner field of the token gets updated // account - instrument owner's list of owned instruments get updated // accounts - OREINST symbol balance gets updated -void instrument::transfer(account_name sender, account_name to, uint64_t token_id) +ACTION instrument::transfer(name sender, name to, uint64_t token_id) { require_auth(sender); @@ -367,14 +364,16 @@ void instrument::transfer(account_name sender, account_name to, uint64_t token_i // } transfer_balances(sender, to, token_id); - sub_balance(sender, asset(10000, symbol_type(S(4, OREINST)))); - add_balance(to, asset(10000, symbol_type(S(4, OREINST))), sender); - _tokens.modify(tokenitr, 0, [&](auto &a) { + + sub_balance(sender, asset(10000, symbol(symbol_code("OREINST"),4))); + add_balance(to, asset(10000, symbol(symbol_code("OREINST"),4)), sender); + + _tokens.modify(tokenitr, same_payer, [&](auto &a) { a.owner = to; }); } -void instrument::revoke(account_name revoker, uint64_t token_id) +ACTION instrument::revoke(name revoker, uint64_t token_id) { require_auth(revoker); @@ -386,7 +385,7 @@ void instrument::revoke(account_name revoker, uint64_t token_id) eosio_assert(tokenitr->revoked == false, "Token is already revoked"); - _tokens.modify(tokenitr, 0, [&](auto &t) { + _tokens.modify(tokenitr, same_payer, [&](auto &t) { t.revoked = true; }); } @@ -396,7 +395,7 @@ void instrument::revoke(account_name revoker, uint64_t token_id) // tokens - burnt token gets removed from the table // account - instrument owner's list of owned instruments get updated // accounts - OREINST symbol balance gets updated -void instrument::burn(account_name burner, uint64_t token_id) +ACTION instrument::burn(name burner, uint64_t token_id) { require_auth(burner); bool from = false; @@ -409,30 +408,30 @@ void instrument::burn(account_name burner, uint64_t token_id) eosio_assert(tokenitr->instrument.mutability == 2, "Instrument is not mutable"); - transfer_balances(burner, 0, token_id); - sub_balance(burner, asset(10000, symbol_type(S(4, OREINST)))); + transfer_balances(burner, same_payer, token_id); + sub_balance(burner, asset(10000, symbol(symbol_code("OREINST"),4))); _tokens.erase(tokenitr); } // -CUSTOM_CODE-it replicates the create function of ore.standard_token // Creates a new currency OREINST -void instrument::create(account_name issuer, +ACTION instrument::create(name issuer, asset maximum_supply) { require_auth(_self); // Symbol is hardcoded here to prevent creating any other symbol than OREINST // auto sym = "maximum_supply.symbol"; - eosio::symbol_type sym = eosio::string_to_symbol(4, "OREINST"); + eosio::symbol sym = symbol(symbol_code("OREINST"),4); eosio_assert(maximum_supply.symbol == sym, "symbol name must be ORINST"); eosio_assert(sym.is_valid(), "invalid symbol name"); eosio_assert(maximum_supply.is_valid(), "invalid supply"); eosio_assert(maximum_supply.amount > 0, "max-supply must be positive"); - stats statstable(_self, sym.name()); - auto existing = statstable.find(sym.name()); + stats statstable(_self, sym.code().raw()); + auto existing = statstable.find(sym.code().raw()); eosio_assert(existing == statstable.end(), "token with symbol already exists"); statstable.emplace(_self, [&](auto &s) { @@ -444,15 +443,14 @@ void instrument::create(account_name issuer, // -CUSTOM_CODE-it replicates the issue function of ore.standard_token except the inline transfer action present in ore.standard_token // issue OREINST to an account -void instrument::issue(account_name to, asset quantity, string memo) +ACTION instrument::issue(name to, asset quantity, string memo) { auto sym = quantity.symbol; eosio_assert(sym.is_valid(), "invalid symbol name"); eosio_assert(memo.size() <= 256, "memo has more than 256 bytes"); - auto sym_name = sym.name(); - stats statstable(_self, sym_name); - auto existing = statstable.find(sym_name); + stats statstable(_self, sym.code().raw()); + auto existing = statstable.find(sym.code().raw()); eosio_assert(existing != statstable.end(), "token with symbol does not exist, create token before issue"); const auto &st = *existing; @@ -463,7 +461,7 @@ void instrument::issue(account_name to, asset quantity, string memo) eosio_assert(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); eosio_assert(quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply"); - statstable.modify(st, 0, [&](auto &s) { + statstable.modify(st, same_payer, [&](auto &s) { s.supply += quantity; }); @@ -477,11 +475,11 @@ void instrument::issue(account_name to, asset quantity, string memo) } // -CUSTOM_CODE-it replicates the sub_balance function of ore.standard_token -void instrument::sub_balance(account_name owner, asset value) +void instrument::sub_balance(name owner, asset value) { - accounts from_acnts(_self, owner); + accounts from_acnts(_self, owner.value); - const auto &from = from_acnts.get(value.symbol.name(), "no balance object found"); + const auto &from = from_acnts.get(value.symbol.code().raw(), "no balance object found"); eosio_assert(from.balance.amount >= value.amount, "overdrawn balance"); if (from.balance.amount == value.amount) @@ -500,7 +498,7 @@ void instrument::sub_balance(account_name owner, asset value) // NOTE: Uncomment and use in future if required // It is used by transfer_from account to specify the RAM payer as the "sender" account and not the "owner" account as in the sub_balance function // NOTE: used by instrument::approve action -// void instrument::sub_balance_from(account_name sender, account_name owner, asset value) +// void instrument::sub_balance_from(name sender, name owner, asset value) // { // accounts from_acnts(_self, owner); @@ -520,10 +518,10 @@ void instrument::sub_balance(account_name owner, asset value) // } // -CUSTOM_CODE-it replicates the add_balance function of ore.standard_token -void instrument::add_balance(account_name owner, asset value, account_name ram_payer) +void instrument::add_balance(name owner, asset value, name ram_payer) { - accounts to_acnts(_self, owner); - auto to = to_acnts.find(value.symbol.name()); + accounts to_acnts(_self, owner.value); + auto to = to_acnts.find(value.symbol.code().raw()); if (to == to_acnts.end()) { to_acnts.emplace(ram_payer, [&](auto &a) { @@ -532,10 +530,10 @@ void instrument::add_balance(account_name owner, asset value, account_name ram_p } else { - to_acnts.modify(to, 0, [&](auto &a) { + to_acnts.modify(to, same_payer, [&](auto &a) { a.balance += value; }); } } -EOSIO_ABI(instrument, (transfer)(mint)(checkright)(createinst)(update)(revoke)(burn)(create)(issue)) +EOSIO_DISPATCH(instrument, (transfer)(mint)(checkright)(createinst)(update)(revoke)(burn)(create)(issue)) diff --git a/contracts/ore.instrument/ore.instrument.hpp b/contracts/ore.instrument/ore.instrument.hpp index a00c1ee..e72024f 100644 --- a/contracts/ore.instrument/ore.instrument.hpp +++ b/contracts/ore.instrument/ore.instrument.hpp @@ -7,16 +7,16 @@ #include "eosiolib/eosio.hpp" #include "eosiolib/asset.hpp" #include "eosiolib/transaction.hpp" +#include "eosiolib/time.hpp" #include "../ore.rights_registry/ore.rights_registry.hpp" using namespace eosio; using namespace std; -class instrument : public eosio::contract +class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract { public: - instrument(name self) - : contract(self), _account(_self, _self), _tokens(_self, _self) {} + instrument( name receiver, name code, datastream ds): contract(receiver, code, ds), _account(receiver, receiver.value), _tokens(receiver, receiver.value) {} struct instrument_data { @@ -35,8 +35,7 @@ class instrument : public eosio::contract uint8_t mutability; // 0- immutable, 1- only datesi 2- all }; - //@abi table tokens i64 - struct token + TABLE token { //721 standard properties uint64_t id; @@ -54,31 +53,33 @@ class instrument : public eosio::contract uint64_t class_hash; uint64_t primary_key() const { return id; } - uint64_t by_owner() const { return owner; } + uint64_t by_owner() const { return owner.value; } uint64_t by_template() const { return template_hash; } uint64_t by_class() const { return class_hash; } EOSLIB_SERIALIZE(token, (id)(owner)(minted_by)(minted_at)(instrument)(revoked)(start_time)(end_time)(template_hash)(class_hash)) }; - eosio::multi_index>, - indexed_by>, - indexed_by>> - _tokens; + typedef eosio::multi_index<"tokens"_n, token, + indexed_by<"owner"_n, const_mem_fun>, + indexed_by<"templatehash"_n, const_mem_fun>, + indexed_by<"classhash"_n, const_mem_fun> + >tokenindex; - //@abi table account i64 - struct accountdata + tokenindex _tokens; + + TABLE accountdata { name owner; uint64_t balance; vector instruments; - uint64_t primary_key() const { return owner; } + uint64_t primary_key() const { return owner.value; } EOSLIB_SERIALIZE(accountdata, (owner)(balance)(instruments)) }; - eosio::multi_index _account; + typedef eosio::multi_index<"account"_n, accountdata> accountindex; + accountindex _account; // NOTE: Uncomment and use in future if required // Schema for allowance feature like in ERC-721 //@abi table allowances i64 @@ -95,26 +96,24 @@ class instrument : public eosio::contract // typedef eosio::multi_index allowances; private: - //@abi table accounts i64 - struct account + TABLE accountbalance { asset balance; - uint64_t primary_key() const { return balance.symbol.name(); } + uint64_t primary_key() const { return balance.symbol.code().raw(); } }; - //@abi table stat i64 - struct currencystat + TABLE currencystat { asset supply; asset max_supply; name issuer; - uint64_t primary_key() const { return supply.symbol.name(); } + uint64_t primary_key() const { return supply.symbol.code().raw(); } }; - typedef eosio::multi_index accounts; - typedef eosio::multi_index stats; + typedef eosio::multi_index<"accounts"_n, accountbalance> accounts; + typedef eosio::multi_index<"stat"_n, currencystat> stats; void sub_balance(name owner, asset value); void sub_balance_from(name sender, name owner, asset value); @@ -137,16 +136,16 @@ class instrument : public eosio::contract } //actions - void approve(name from, name to, uint64_t token_id); - void mint(name minter, name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId); - void checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id); - void update(name updater, string instrument_template, instrument_data instrument, uint64_t instrument_id, uint64_t start_time, uint64_t end_time); - void transfer(name sender, name to, uint64_t token_id); - void revoke(name revoker, uint64_t token_id); - void burn(name burner, uint64_t token_id); - void create(name issuer, asset maximum_supply); - void createinst(name minter, name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time); - void issue(name to, asset quantity, string memo); + ACTION approve(name from, name to, uint64_t token_id); + ACTION mint(name minter, name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId); + ACTION checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id); + ACTION update(name updater, string instrument_template, instrument_data instrument, uint64_t instrument_id, uint64_t start_time, uint64_t end_time); + ACTION transfer(name sender, name to, uint64_t token_id); + ACTION revoke(name revoker, uint64_t token_id); + ACTION burn(name burner, uint64_t token_id); + ACTION create(name issuer, asset maximum_supply); + ACTION createinst(name minter, name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time); + ACTION issue(name to, asset quantity, string memo); }; instrument::token instrument::find_token_by_id(uint64_t id) @@ -181,7 +180,7 @@ bool instrument::isToken(uint64_t id) instrument::token instrument::find_token_by_template(string instrument_template) { - auto hashtable = _tokens.get_index(); + auto hashtable = _tokens.get_index<"templatehash"_n>(); auto item = hashtable.find(hashStringToInt(instrument_template)); if (item == hashtable.end()) eosio_assert(false, "instrument with given template not found"); @@ -200,7 +199,7 @@ instrument::token instrument::find_token_by_template(string instrument_template) // Return an account's total balance uint64_t instrument::balance_of(name owner) { - auto account = _account.find(owner); + auto account = _account.find(owner.value); return account->balance; } @@ -232,21 +231,21 @@ bool instrument::_owns(name claimant, uint64_t token_id) void instrument::transfer_balances(name from, name to, uint64_t instrument_id, int64_t amount) { - auto fromitr = _account.find(from); + auto fromitr = _account.find(from.value); eosio_assert(fromitr != _account.end(), "Sender account doesn't exists"); eosio_assert(fromitr->balance > 0, "Sender account's balance is 0"); - _account.modify(fromitr, 0, [&](auto &a) { + _account.modify(fromitr, same_payer, [&](auto &a) { a.balance -= amount; a.instruments.erase(std::remove(a.instruments.begin(), a.instruments.end(), instrument_id), a.instruments.end()); }); - auto toitr = _account.find(to); + auto toitr = _account.find(to.value); if (toitr != _account.end()) { - _account.modify(toitr, 0, [&](auto &a) { + _account.modify(toitr, same_payer, [&](auto &a) { a.balance += amount; a.instruments.push_back(instrument_id); }); From 1f14ce186451d28873c6118ab5ff2346897a188a Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 15:35:08 -0800 Subject: [PATCH 10/15] add comments for instrument contract and delete dead code --- contracts/ore.instrument/ore.instrument.cpp | 299 +++++++++++--------- contracts/ore.instrument/ore.instrument.hpp | 22 +- 2 files changed, 171 insertions(+), 150 deletions(-) diff --git a/contracts/ore.instrument/ore.instrument.cpp b/contracts/ore.instrument/ore.instrument.cpp index aaeecec..f75b716 100644 --- a/contracts/ore.instrument/ore.instrument.cpp +++ b/contracts/ore.instrument/ore.instrument.cpp @@ -1,21 +1,34 @@ #include "ore.instrument.hpp" using namespace eosio; -// Creates new instrument -// NOTE: this should result in changes in the following tables : -// tokens - add new token -// account - instrument owner's list of owned instruments get updated -// accounts - OREINST symbol balance gets updated - -// mint action internally calls a deferred transaction with 2 types of actions: -// checkright - for each right in the instrument object, mint instrument calls check right within a deferred transaction -// createinst - once all the rights are checked, the last action in the deferred transaction is createinst which adds the instrument to the tokens table -// NOTE: if any of the checkright action fails, it will cancel the deferred transaction and the creatinst action will not be called. Hence no instrument will be created. +/* + Creates new instrument + NOTE: this should result in changes in the following tables : + tokens - add new token + account - instrument owner's list of owned instruments get updated + accounts - OREINST symbol balance gets updated + + mint action internally calls a deferred transaction with 2 types of actions: + checkright - for each right in the instrument object, mint instrument calls check right within a deferred transaction + createinst - once all the rights are checked, the last action in the deferred transaction is createinst which adds the instrument to the tokens table + NOTE: if any of the checkright action fails, it will cancel the deferred transaction and the creatinst action will not be called. Hence no instrument will be created. + + owner - owner of the new instrument + minter - account authorized to mint the instrument's rights + either the minter or the owner should own the right (or be whitelisted by the owner of the right) + */ ACTION instrument::mint(name minter, name owner, instrument_data instrument, uint64_t start_time, uint64_t end_time, uint64_t instrumentId = 0) { // Checking if the minter has the required authorization require_auth(minter); + + string msg = "owner account does not exist " + owner.to_string(); + eosio_assert(is_account(owner), string_to_char(msg)); + + // if an instrument_template name is passed-in, look from an instrument with the same name on the chain + // ...if one exists, the new instrument will be a copy of that one + // All instruments with the same template name will have the same data - only the dates may be different auto hashtable = _tokens.get_index<"templatehash"_n>(); auto item = hashtable.find(hashStringToInt(instrument.instrument_template)); @@ -25,12 +38,12 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, } // If instrumentId value passed as 0, next available primate key will be automatically assigned as instrumentId - // This mean, you can not set instrumentId specifically to 0, because it means pick the next available key. + // So, instrumentId can't be set to 0 if (instrumentId == 0) { - if (_tokens.available_primary_key() == 0) + if (_tokens.available_primary_key() == 0) //first instrument created { - instrumentId = 1; // assigning the available key + instrumentId = 1; } else { @@ -44,7 +57,10 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, eosio_assert(institr == _tokens.end(), "instrumentId exists!"); } - // If an instrument already exists with the given template name, get the instrument data from the existing instrument + // ------- Copy an existing intstrument from a template + // If an instrument already exists with the given template name + // ... copy the instrument data from the existing instrument + // ... the owner of the new instrument is the same as existing instrument (you can't make a copy of someone else's template) if (instrument.instrument_template != "" && item != hashtable.end()) { instrument.issuer = item->instrument.issuer; @@ -62,31 +78,35 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, transaction create_instrument{}; // create an unique id for the deferred transaction - uint64_t create_transaction_id = now(); + uint64_t transaction_id = instrumentId; // Adding createinst action to the deferred transaction to add the new instrument to the tokens table create_instrument.actions.emplace_back( - permission_level{"instr.ore"_n, "active"_n}, _self, "createinst"_n, + permission_level{"instr.ore"_n, "active"_n}, "instr.ore"_n, "createinst"_n, std::make_tuple(minter, owner, instrumentId, instrument, start_time, end_time, - create_transaction_id)); + transaction_id)); // send deferred transaction - create_instrument.send(create_transaction_id, minter); + create_instrument.send(transaction_id, minter); } else { + // ------- Create a new intstrument // create a deferred transaction object to check rights and add instrument to the tokens table transaction deferred_instrument{}; // create an unique id for the deferred transaction - uint64_t deferred_trx_id = now(); + // this deferred_transaction_id is different than the actual completed transaction Id + uint64_t deferred_transaction_id = instrumentId; - // checking if the issuer is the owner of the rights + // The creation of this instrument is a series of steps grouped into one deferred transaction + + // Step 1 - add one action for each right to check if the issuer is approved to issue an instrument with that right for (int i = 0; i < instrument.rights.size(); i++) { deferred_instrument.actions.emplace_back( @@ -95,10 +115,11 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, minter, instrument.issuer, instrument.rights[i].right_name, - deferred_trx_id)); + deferred_transaction_id)); } - // Adding createinst action to the deferred transaction to add the new instrument to the tokens table + // Step 2 - if all the prior actions are sucessful (did not cancel because a right was invalid) + // ... create the instrument as the last step in the transaction chain (using the createinst action) deferred_instrument.actions.emplace_back( permission_level{"instr.ore"_n, "active"_n}, _self, "createinst"_n, std::make_tuple(minter, @@ -108,17 +129,23 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, start_time, end_time)); - // send deferred transaction - deferred_instrument.send(deferred_trx_id, minter); + // Step 3 - send deferred transaction + deferred_instrument.send(deferred_transaction_id, minter); } } +/* + createinst creates a row in the instruments table + This is called by the mint action - as the last step in the list of deferred transactions + This can only be called within the instrument contract (requires _self for instr.ore) +*/ ACTION instrument::createinst(name minter, name owner, uint64_t instrumentId, instrument_data instrument, uint64_t start_time, uint64_t end_time) { require_auth(_self); auto accountitr = _account.find(owner.value); - // check if account is already registered to accounts table + // We track every instrumentId a user owns in the accounts table - along with total count (balance) for each user + // The first time a user creates an instrument, create a record in the accounts table in this contract if (accountitr == _account.end()) { _account.emplace(_self, [&](auto &a) { @@ -129,7 +156,7 @@ ACTION instrument::createinst(name minter, name owner, uint64_t instrumentId, in accountitr = _account.find(owner.value); } - // writing to tokens table + // all instruments are stored in the tokens table _tokens.emplace(_self, [&](auto &a) { a.id = instrumentId; a.owner = owner; @@ -149,35 +176,38 @@ ACTION instrument::createinst(name minter, name owner, uint64_t instrumentId, in a.instruments.push_back(instrumentId); }); - print("minter", name{minter}); - - print("action:mint instrument:", instrumentId, " to:", name{owner}, "\n"); - - eosio_assert(is_account(owner), "to account does not exist"); + print("action:mint Created new instrument: type: " + instrument.instrument_class + " id: " + to_string(instrumentId) + " for: " + owner.to_string() + "\n"); // transfer 1 OREINST from the issuer account for OREINST to the owner account of instrument sub_balance(_self, asset(10000, symbol(symbol_code("OREINST"),4))); add_balance(owner, asset(10000, symbol(symbol_code("OREINST"),4)), _self); } +/* + Checks that the issuer and owner are authorized to issue an instrument that includes this right (either the owner or in whitelist) + This is called by the mint action - as part of a deferred transaction during the minting process + This is called once for each right to be added to the instrument + This can only be called within the instrument contract (requires _self for instr.ore) +*/ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id = 0) { - require_auth(_self); + //require_auth(_self); - //instantiating rights.ore contract + string msg; rights_registry rights_contract = rights_registry(_self,_code,_ds); - print("action:checkright:", name{rightname}, "\n"); - + // check that right exists in the rights registry auto rightitr = rights_contract.find_right_by_name(rightname); + if (rightitr.owner.value == 0) { if (deferred_transaction_id != 0) { - cancel_deferred(deferred_transaction_id); + cancel_deferred(deferred_transaction_id); } - eosio_assert(false, "right doesn't exist"); + msg = "right:" + rightname + " doesn't exist"; + eosio_assert(rightitr.owner.value != 0, string_to_char(msg)); } // check if the minter of the instrument is the issuer of the right @@ -185,30 +215,45 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 if (!minter_owns_right) { auto position_in_whitelist = std::find(rightitr.issuer_whitelist.begin(), rightitr.issuer_whitelist.end(), minter); - eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), "minter neither owns the right nor whitelisted for the right"); + + //if minter is not in whitelist, cancel the entire mint transaction + if (position_in_whitelist == rightitr.issuer_whitelist.end()) + { + if (deferred_transaction_id != 0) + { + cancel_deferred(deferred_transaction_id); + } + msg = "Attempt to create instrument with right: " + rightname + " by minter: " + minter.to_string() + " who isn't whitelisted or owner of right"; + eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), string_to_char(msg)); + } } + // check if the issuer of the instrument is the owner of the right bool issuer_owns_right = rightitr.owner == issuer; if (!issuer_owns_right) { auto issuer_in_whitelist = std::find(rightitr.issuer_whitelist.begin(), rightitr.issuer_whitelist.end(), issuer); + //if issuer is not in whitelist, cancel the entire mint transaction if (issuer_in_whitelist == rightitr.issuer_whitelist.end()) { if (deferred_transaction_id != 0) { cancel_deferred(deferred_transaction_id); } - eosio_assert(true, "instrument issuer neither holds the right nor whitelisted for the right"); + msg = "Attempt to create instrument with right: " + rightname + " by issuer: " + issuer.to_string() + " who isn't whitelisted or owner of right"; + eosio_assert(issuer_in_whitelist != rightitr.issuer_whitelist.end(), string_to_char(msg)); } } } -// updates an instrument -// NOTE: this should result in changes in the following table : -// tokens - the instrument token gets updated depending on the mutabiility -// if mutability is 1, start_time and/or end_time can be updated -// if mutability is 2, everything except the owner can be updated +/* + updates an instrument (in the tokens table) + the instrument token gets updated depending on the mutabiility + mutability = 0 - completely immutable + mutability = 1 - start_time and/or end_time can be updated + mutability = 2 - everything mutable except the owner can't be updated +*/ ACTION instrument::update(name updater, string instrument_template, instrument_data instrument = {}, uint64_t instrument_id = 0, uint64_t start_time = 0, uint64_t end_time = 0) { @@ -217,6 +262,8 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d uint64_t new_end; instrument::token item; + + //find existing instrument by id or template if (instrument_id != 0) { item = find_token_by_id(instrument_id); @@ -256,6 +303,7 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d new_end = item.end_time; } + // mutability = 1 - update dates if (item.instrument.mutability == 1) { // update the instrument token in the tokens table @@ -264,7 +312,9 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d a.end_time = new_end; }); } - else + + // mutability = 2 - update anything + if (item.instrument.mutability == 2) { item.instrument.issuer = instrument.issuer; item.instrument.instrument_class = instrument.instrument_class; @@ -291,7 +341,7 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d auto positionInWhitelist = std::find(rightitr.issuer_whitelist.begin(), rightitr.issuer_whitelist.end(), updater); auto updaterWhitelistedForRight = positionInWhitelist != rightitr.issuer_whitelist.end(); - //check if updater has to authorization over the rights + //check if updater has the authorization over the rights if (positionInWhitelist == rightitr.issuer_whitelist.end()) { eosio_assert((updaterOwnsRight), "updater doesn't own the right and is not on issuer's whitelist"); @@ -299,8 +349,8 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d } } - auto tokenitr = _tokens.find(item.id); // update the instrument token in the tokens table + auto tokenitr = _tokens.find(item.id); _tokens.modify(tokenitr, same_payer, [&](auto &a) { a.id = item.id; a.owner = item.owner; @@ -315,107 +365,99 @@ ACTION instrument::update(name updater, string instrument_template, instrument_d }); } - print("updater", name{updater}); - - print("action:update instrument:", instrument_id, "\n"); + print("action:update Updated instrument: type: " + instrument.instrument_class + " id: " + to_string(instrument_id) + " by: " + updater.to_string() + "\n"); } -// transfers an instrument -// NOTE: this should result in changes in the following tables : -// tokens - owner field of the token gets updated -// account - instrument owner's list of owned instruments get updated -// accounts - OREINST symbol balance gets updated -ACTION instrument::transfer(name sender, name to, uint64_t token_id) +/* + transfers an instrument (owner field for the instrument gets updated to the new owner in the tokens table) + */ +ACTION instrument::transfer(name sender, name to, uint64_t instrument_id) { + require_auth(sender); + string msg; + //find token - auto tokenitr = _tokens.find(token_id); - - eosio_assert(tokenitr->owner == sender, "Sender account is not allowed to transfer the instrument"); - - eosio_assert(tokenitr->revoked == false, "token is revoked"); - - eosio_assert(tokenitr != _tokens.end(), "Token doesn't exists"); - - // NOTE: Use in future if required - // Allows an "allowed" account from the allowance table to be able to do transfer on the instrument owner's behalf - // bool is_approved_sender = false; - // if (tokenitr->owner != sender) - // { - // allowances _allowances(_self, tokenitr->owner); - // auto allowanceitr = _allowances.find(token_id); - // eosio_assert(allowanceitr->to == sender, "Sender is not allowed"); - // _allowances.erase(allowanceitr); - // is_approved_sender = true; - // } - // increment/decrement balances - // if (is_approved_sender) - // { - // transfer_balances(sender, tokenitr->owner, to, token_id); - // sub_balance_from(sender, tokenitr->owner, asset(10000, symbol_type(S(4, OREINST)))); - // add_balance(to, asset(10000, symbol_type(S(4, OREINST))), sender); - // } - // else - // { - // transfer_balances(sender, sender, to, token_id); - // sub_balance(sender, asset(10000, symbol_type(S(4, OREINST)))); - // add_balance(to, asset(10000, symbol_type(S(4, OREINST))), sender); - // } - - transfer_balances(sender, to, token_id); + auto tokenitr = _tokens.find(instrument_id); + + msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; + eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); + msg = "Sender account is not allowed to transfer the instrument " + sender.to_string(); + eosio_assert(tokenitr->owner == sender, string_to_char(msg)); + + msg = "Instrument Id " + to_string(instrument_id) + " has been previously revoked"; + eosio_assert(tokenitr->revoked == false, string_to_char(msg)); + + // transfer balance in the accounts table + transfer_balances(sender, to, instrument_id); + + // transfer OREINST balance sub_balance(sender, asset(10000, symbol(symbol_code("OREINST"),4))); add_balance(to, asset(10000, symbol(symbol_code("OREINST"),4)), sender); - _tokens.modify(tokenitr, same_payer, [&](auto &a) { a.owner = to; }); } -ACTION instrument::revoke(name revoker, uint64_t token_id) +// revokes an instrument - A revoked instrument is no longer active and cannot be used +ACTION instrument::revoke(name revoker, uint64_t instrument_id) { require_auth(revoker); + string msg; + //Checking if the token exists. - auto tokenitr = _tokens.find(token_id); - eosio_assert(tokenitr != _tokens.end(), "Token doesn't exists"); + auto tokenitr = _tokens.find(instrument_id); + + msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; + eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); - eosio_assert(tokenitr->owner == revoker, "The revoker account doesn't have authority to revoke the instrument"); + msg = "The account " + revoker.to_string() + "doesn't have authority to revoke the instrument"; + eosio_assert(tokenitr->owner == revoker, string_to_char(msg)); - eosio_assert(tokenitr->revoked == false, "Token is already revoked"); + msg = "Instrument Id" + to_string(instrument_id) + "has been previously revoked"; + eosio_assert(tokenitr->revoked == false, string_to_char(msg)); _tokens.modify(tokenitr, same_payer, [&](auto &t) { t.revoked = true; }); } -// delets an instrument only if it's mutability is 2 -// NOTE: this should result in changes in the following tables : -// tokens - burnt token gets removed from the table -// account - instrument owner's list of owned instruments get updated -// accounts - OREINST symbol balance gets updated -ACTION instrument::burn(name burner, uint64_t token_id) +/* + deletes an instrument (from the tokens table) + deletes only if it's mutability is 2 ( as mutability 2 means we can change anything) +*/ +ACTION instrument::burn(name burner, uint64_t instrument_id) { require_auth(burner); + + string msg; bool from = false; // Checking if the token exists. - auto tokenitr = _tokens.find(token_id); - eosio_assert(tokenitr != _tokens.end(), "Token doesn't exists"); + auto tokenitr = _tokens.find(instrument_id); + + msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; + eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); - eosio_assert(tokenitr->owner == burner, "The burner account doesn't have authority to delete the instrument"); + msg = "The account " + burner.to_string() + "doesn't have authority to burn the instrument"; + eosio_assert(tokenitr->owner == burner, string_to_char(msg)); - eosio_assert(tokenitr->instrument.mutability == 2, "Instrument is not mutable"); + msg = "Instrument Id" + to_string(instrument_id) + "is not mutable and cannot be burned."; + eosio_assert(tokenitr->instrument.mutability == 2, string_to_char(msg)); - transfer_balances(burner, same_payer, token_id); + transfer_balances(burner, same_payer, instrument_id); sub_balance(burner, asset(10000, symbol(symbol_code("OREINST"),4))); _tokens.erase(tokenitr); } -// -CUSTOM_CODE-it replicates the create function of ore.standard_token -// Creates a new currency OREINST +/* + -CUSTOM_CODE- it replicates the create function of ore.standard_token + creates a new currency OREINST +*/ ACTION instrument::create(name issuer, asset maximum_supply) { @@ -441,8 +483,10 @@ ACTION instrument::create(name issuer, }); } -// -CUSTOM_CODE-it replicates the issue function of ore.standard_token except the inline transfer action present in ore.standard_token -// issue OREINST to an account +/* + -CUSTOM_CODE-it replicates the issue function of ore.standard_token except the inline transfer action present in ore.standard_token + issue OREINST to an account +*/ ACTION instrument::issue(name to, asset quantity, string memo) { auto sym = quantity.symbol; @@ -474,7 +518,10 @@ ACTION instrument::issue(name to, asset quantity, string memo) } } -// -CUSTOM_CODE-it replicates the sub_balance function of ore.standard_token +/* + -CUSTOM_CODE-it replicates the sub_balance function of ore.standard_token + removes OREINST from an account + */ void instrument::sub_balance(name owner, asset value) { accounts from_acnts(_self, owner.value); @@ -494,30 +541,10 @@ void instrument::sub_balance(name owner, asset value) } } -// -CUSTOM_CODE-it replicates the sub_balance_from function of ore.standard_token -// NOTE: Uncomment and use in future if required -// It is used by transfer_from account to specify the RAM payer as the "sender" account and not the "owner" account as in the sub_balance function -// NOTE: used by instrument::approve action -// void instrument::sub_balance_from(name sender, name owner, asset value) -// { -// accounts from_acnts(_self, owner); - -// const auto &from = from_acnts.get(value.symbol.name(), "no balance object found"); -// eosio_assert(from.balance.amount >= value.amount, "overdrawn balance"); - -// if (from.balance.amount == value.amount) -// { -// from_acnts.erase(from); -// } -// else -// { -// from_acnts.modify(from, sender, [&](auto &a) { -// a.balance -= value; -// }); -// } -// } - -// -CUSTOM_CODE-it replicates the add_balance function of ore.standard_token +/* + -CUSTOM_CODE-it replicates the add_balance function of ore.standard_token + adds OREINST to an account +*/ void instrument::add_balance(name owner, asset value, name ram_payer) { accounts to_acnts(_self, owner.value); diff --git a/contracts/ore.instrument/ore.instrument.hpp b/contracts/ore.instrument/ore.instrument.hpp index e72024f..d2007bb 100644 --- a/contracts/ore.instrument/ore.instrument.hpp +++ b/contracts/ore.instrument/ore.instrument.hpp @@ -6,6 +6,7 @@ #include "eosiolib/eosio.hpp" #include "eosiolib/asset.hpp" +#include "eosiolib/print.hpp" #include "eosiolib/transaction.hpp" #include "eosiolib/time.hpp" #include "../ore.rights_registry/ore.rights_registry.hpp" @@ -80,20 +81,6 @@ class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract typedef eosio::multi_index<"account"_n, accountdata> accountindex; accountindex _account; - // NOTE: Uncomment and use in future if required - // Schema for allowance feature like in ERC-721 - //@abi table allowances i64 - // struct allowancedata - // { - // uint64_t token_id; - // name to; - - // uint64_t primary_key() const { return token_id; } - - // EOSLIB_SERIALIZE(allowancedata, (token_id)(to)) - // }; - - // typedef eosio::multi_index allowances; private: TABLE accountbalance @@ -129,6 +116,7 @@ class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract uint64_t total_supply(); uint64_t balance_of(name owner); name owner_of(uint64_t token_id); + char *string_to_char(string str); inline static uint64_t hashStringToInt(const string &strkey) { @@ -203,6 +191,12 @@ uint64_t instrument::balance_of(name owner) return account->balance; } +char *instrument::string_to_char(string str) +{ + char cstr[str.size() + 1]; + return copy(str.begin(), str.end(), cstr); +} + // Returns who owns a token name instrument::owner_of(uint64_t token_id) { From 6860321e68fdfaf059691f233b52f438ea02f337 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 15:54:08 -0800 Subject: [PATCH 11/15] create ore_util and move helper function to ore_utils --- contracts/ore.instrument/ore.instrument.cpp | 30 ++++++++++----------- contracts/ore.instrument/ore.instrument.hpp | 11 +++----- contracts/ore_utils/ore_utils.hpp | 19 +++++++++++++ 3 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 contracts/ore_utils/ore_utils.hpp diff --git a/contracts/ore.instrument/ore.instrument.cpp b/contracts/ore.instrument/ore.instrument.cpp index f75b716..d82e41b 100644 --- a/contracts/ore.instrument/ore.instrument.cpp +++ b/contracts/ore.instrument/ore.instrument.cpp @@ -24,7 +24,7 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, require_auth(minter); string msg = "owner account does not exist " + owner.to_string(); - eosio_assert(is_account(owner), string_to_char(msg)); + eosio_assert(is_account(owner), ore_util.string_to_char(msg)); // if an instrument_template name is passed-in, look from an instrument with the same name on the chain // ...if one exists, the new instrument will be a copy of that one @@ -191,10 +191,10 @@ ACTION instrument::createinst(name minter, name owner, uint64_t instrumentId, in */ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64_t deferred_transaction_id = 0) { - - //require_auth(_self); + require_auth(_self); string msg; + rights_registry rights_contract = rights_registry(_self,_code,_ds); // check that right exists in the rights registry @@ -207,7 +207,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "right:" + rightname + " doesn't exist"; - eosio_assert(rightitr.owner.value != 0, string_to_char(msg)); + eosio_assert(rightitr.owner.value != 0, ore_util.string_to_char(msg)); } // check if the minter of the instrument is the issuer of the right @@ -224,7 +224,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "Attempt to create instrument with right: " + rightname + " by minter: " + minter.to_string() + " who isn't whitelisted or owner of right"; - eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), string_to_char(msg)); + eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), ore_util.string_to_char(msg)); } } @@ -242,7 +242,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "Attempt to create instrument with right: " + rightname + " by issuer: " + issuer.to_string() + " who isn't whitelisted or owner of right"; - eosio_assert(issuer_in_whitelist != rightitr.issuer_whitelist.end(), string_to_char(msg)); + eosio_assert(issuer_in_whitelist != rightitr.issuer_whitelist.end(), ore_util.string_to_char(msg)); } } } @@ -382,13 +382,13 @@ ACTION instrument::transfer(name sender, name to, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); msg = "Sender account is not allowed to transfer the instrument " + sender.to_string(); - eosio_assert(tokenitr->owner == sender, string_to_char(msg)); + eosio_assert(tokenitr->owner == sender, ore_util.string_to_char(msg)); msg = "Instrument Id " + to_string(instrument_id) + " has been previously revoked"; - eosio_assert(tokenitr->revoked == false, string_to_char(msg)); + eosio_assert(tokenitr->revoked == false, ore_util.string_to_char(msg)); // transfer balance in the accounts table transfer_balances(sender, to, instrument_id); @@ -412,13 +412,13 @@ ACTION instrument::revoke(name revoker, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); msg = "The account " + revoker.to_string() + "doesn't have authority to revoke the instrument"; - eosio_assert(tokenitr->owner == revoker, string_to_char(msg)); + eosio_assert(tokenitr->owner == revoker, ore_util.string_to_char(msg)); msg = "Instrument Id" + to_string(instrument_id) + "has been previously revoked"; - eosio_assert(tokenitr->revoked == false, string_to_char(msg)); + eosio_assert(tokenitr->revoked == false, ore_util.string_to_char(msg)); _tokens.modify(tokenitr, same_payer, [&](auto &t) { t.revoked = true; @@ -440,13 +440,13 @@ ACTION instrument::burn(name burner, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); msg = "The account " + burner.to_string() + "doesn't have authority to burn the instrument"; - eosio_assert(tokenitr->owner == burner, string_to_char(msg)); + eosio_assert(tokenitr->owner == burner, ore_util.string_to_char(msg)); msg = "Instrument Id" + to_string(instrument_id) + "is not mutable and cannot be burned."; - eosio_assert(tokenitr->instrument.mutability == 2, string_to_char(msg)); + eosio_assert(tokenitr->instrument.mutability == 2, ore_util.string_to_char(msg)); transfer_balances(burner, same_payer, instrument_id); sub_balance(burner, asset(10000, symbol(symbol_code("OREINST"),4))); diff --git a/contracts/ore.instrument/ore.instrument.hpp b/contracts/ore.instrument/ore.instrument.hpp index d2007bb..32d9797 100644 --- a/contracts/ore.instrument/ore.instrument.hpp +++ b/contracts/ore.instrument/ore.instrument.hpp @@ -9,6 +9,7 @@ #include "eosiolib/print.hpp" #include "eosiolib/transaction.hpp" #include "eosiolib/time.hpp" +#include "../ore_utils/ore_utils.hpp" #include "../ore.rights_registry/ore.rights_registry.hpp" using namespace eosio; @@ -82,6 +83,9 @@ class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract accountindex _account; + // ore_utils - a helper library for ore + ore_utils ore_util; + private: TABLE accountbalance { @@ -116,7 +120,6 @@ class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract uint64_t total_supply(); uint64_t balance_of(name owner); name owner_of(uint64_t token_id); - char *string_to_char(string str); inline static uint64_t hashStringToInt(const string &strkey) { @@ -191,12 +194,6 @@ uint64_t instrument::balance_of(name owner) return account->balance; } -char *instrument::string_to_char(string str) -{ - char cstr[str.size() + 1]; - return copy(str.begin(), str.end(), cstr); -} - // Returns who owns a token name instrument::owner_of(uint64_t token_id) { diff --git a/contracts/ore_utils/ore_utils.hpp b/contracts/ore_utils/ore_utils.hpp new file mode 100644 index 0000000..5b4849f --- /dev/null +++ b/contracts/ore_utils/ore_utils.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "eosiolib/transaction.hpp" +#include + +using namespace std; +using namespace eosio; + +class ore_utils +{ + public: + char* string_to_char(string str); +}; + +char* ore_utils::string_to_char(string str) +{ + char cstr[str.size() + 1]; + return copy(str.begin(), str.end(), cstr); +} \ No newline at end of file From a2fbdb6d1ec96f9cf748c93c52f27bfc2b899d29 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 17:20:41 -0800 Subject: [PATCH 12/15] add comments to the rights registry contract --- .../ore.rights_registry/ore.rights_registry.cpp | 15 ++++++++++----- .../ore.rights_registry/ore.rights_registry.hpp | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/contracts/ore.rights_registry/ore.rights_registry.cpp b/contracts/ore.rights_registry/ore.rights_registry.cpp index 4df390e..5d2c9d5 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.cpp +++ b/contracts/ore.rights_registry/ore.rights_registry.cpp @@ -19,16 +19,20 @@ ACTION rights_registry::upsertright(name owner, string &right_name, vectorowner == owner, "You are not the issuer of the existing right name. Update canceled!"); + string msg = "The account " + owner.to_string() + " is not the owner of the right " + right_name + " and cannot modify it."; + eosio_assert(itr->owner == owner, msg.c_str()); + _rights.modify(itr, owner, [&](auto &end) { end.urls = urls; end.issuer_whitelist = issuer_whitelist; }); - print("modified"); + + print("action:upsertright Right: " + right_name + " modified by: " + owner.to_string() + "\n"); } } @@ -38,8 +42,9 @@ ACTION rights_registry::deleteright(name owner, string &right_name) auto itr = _rights.find(hashStr(right_name)); - eosio_assert(itr != _rights.end(), "There is no right with that name"); - + string msg = "The right " + right_name + " doesn't exist "; + + eosio_assert(itr != _rights.end(), msg.c_str()); _rights.erase(itr); } diff --git a/contracts/ore.rights_registry/ore.rights_registry.hpp b/contracts/ore.rights_registry/ore.rights_registry.hpp index 2ff8eca..602a962 100644 --- a/contracts/ore.rights_registry/ore.rights_registry.hpp +++ b/contracts/ore.rights_registry/ore.rights_registry.hpp @@ -3,6 +3,7 @@ * @copyright defined in eos/LICENSE.txt */ #pragma once +#include #include "eosiolib/eosio.hpp" #include "../ore_types/ore_types.hpp" From 1bc6dcdd9c0fc9e0f6a9e80ec4c9f32a23de9a98 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 17:43:24 -0800 Subject: [PATCH 13/15] update ore.instrument contract to use c_str() to convert string to null terminated string as supported by eosio_assert --- contracts/ore.instrument/ore.instrument.cpp | 28 ++++++++++----------- contracts/ore.instrument/ore.instrument.hpp | 4 --- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/contracts/ore.instrument/ore.instrument.cpp b/contracts/ore.instrument/ore.instrument.cpp index d82e41b..0434c1a 100644 --- a/contracts/ore.instrument/ore.instrument.cpp +++ b/contracts/ore.instrument/ore.instrument.cpp @@ -24,7 +24,7 @@ ACTION instrument::mint(name minter, name owner, instrument_data instrument, require_auth(minter); string msg = "owner account does not exist " + owner.to_string(); - eosio_assert(is_account(owner), ore_util.string_to_char(msg)); + eosio_assert(is_account(owner), msg.c_str()); // if an instrument_template name is passed-in, look from an instrument with the same name on the chain // ...if one exists, the new instrument will be a copy of that one @@ -195,7 +195,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 string msg; - rights_registry rights_contract = rights_registry(_self,_code,_ds); + rights_registry rights_contract(_self,_code,_ds); // check that right exists in the rights registry auto rightitr = rights_contract.find_right_by_name(rightname); @@ -207,7 +207,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "right:" + rightname + " doesn't exist"; - eosio_assert(rightitr.owner.value != 0, ore_util.string_to_char(msg)); + eosio_assert(rightitr.owner.value != 0, msg.c_str()); } // check if the minter of the instrument is the issuer of the right @@ -224,7 +224,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "Attempt to create instrument with right: " + rightname + " by minter: " + minter.to_string() + " who isn't whitelisted or owner of right"; - eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), ore_util.string_to_char(msg)); + eosio_assert(position_in_whitelist != rightitr.issuer_whitelist.end(), msg.c_str()); } } @@ -242,7 +242,7 @@ ACTION instrument::checkright(name minter, name issuer, string rightname, uint64 cancel_deferred(deferred_transaction_id); } msg = "Attempt to create instrument with right: " + rightname + " by issuer: " + issuer.to_string() + " who isn't whitelisted or owner of right"; - eosio_assert(issuer_in_whitelist != rightitr.issuer_whitelist.end(), ore_util.string_to_char(msg)); + eosio_assert(issuer_in_whitelist != rightitr.issuer_whitelist.end(), msg.c_str()); } } } @@ -382,13 +382,13 @@ ACTION instrument::transfer(name sender, name to, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), msg.c_str()); msg = "Sender account is not allowed to transfer the instrument " + sender.to_string(); - eosio_assert(tokenitr->owner == sender, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->owner == sender, msg.c_str()); msg = "Instrument Id " + to_string(instrument_id) + " has been previously revoked"; - eosio_assert(tokenitr->revoked == false, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->revoked == false, msg.c_str()); // transfer balance in the accounts table transfer_balances(sender, to, instrument_id); @@ -412,13 +412,13 @@ ACTION instrument::revoke(name revoker, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), msg.c_str()); msg = "The account " + revoker.to_string() + "doesn't have authority to revoke the instrument"; - eosio_assert(tokenitr->owner == revoker, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->owner == revoker, msg.c_str()); msg = "Instrument Id" + to_string(instrument_id) + "has been previously revoked"; - eosio_assert(tokenitr->revoked == false, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->revoked == false, msg.c_str()); _tokens.modify(tokenitr, same_payer, [&](auto &t) { t.revoked = true; @@ -440,13 +440,13 @@ ACTION instrument::burn(name burner, uint64_t instrument_id) auto tokenitr = _tokens.find(instrument_id); msg = "Instrument Id" + to_string(instrument_id) + "doesn't exist"; - eosio_assert(tokenitr != _tokens.end(), ore_util.string_to_char(msg)); + eosio_assert(tokenitr != _tokens.end(), msg.c_str()); msg = "The account " + burner.to_string() + "doesn't have authority to burn the instrument"; - eosio_assert(tokenitr->owner == burner, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->owner == burner, msg.c_str()); msg = "Instrument Id" + to_string(instrument_id) + "is not mutable and cannot be burned."; - eosio_assert(tokenitr->instrument.mutability == 2, ore_util.string_to_char(msg)); + eosio_assert(tokenitr->instrument.mutability == 2, msg.c_str()); transfer_balances(burner, same_payer, instrument_id); sub_balance(burner, asset(10000, symbol(symbol_code("OREINST"),4))); diff --git a/contracts/ore.instrument/ore.instrument.hpp b/contracts/ore.instrument/ore.instrument.hpp index 32d9797..eb8c1ab 100644 --- a/contracts/ore.instrument/ore.instrument.hpp +++ b/contracts/ore.instrument/ore.instrument.hpp @@ -9,7 +9,6 @@ #include "eosiolib/print.hpp" #include "eosiolib/transaction.hpp" #include "eosiolib/time.hpp" -#include "../ore_utils/ore_utils.hpp" #include "../ore.rights_registry/ore.rights_registry.hpp" using namespace eosio; @@ -83,9 +82,6 @@ class [[eosio::contract("ore.instrument")]] instrument : public eosio::contract accountindex _account; - // ore_utils - a helper library for ore - ore_utils ore_util; - private: TABLE accountbalance { From 0c3d34a35ab427e29903ac3a13b3565396e54bbd Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 17:44:23 -0800 Subject: [PATCH 14/15] remove utils as we dont need the string to char method and can use .c_str in place of it --- contracts/ore_utils/ore_utils.hpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 contracts/ore_utils/ore_utils.hpp diff --git a/contracts/ore_utils/ore_utils.hpp b/contracts/ore_utils/ore_utils.hpp deleted file mode 100644 index 5b4849f..0000000 --- a/contracts/ore_utils/ore_utils.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "eosiolib/transaction.hpp" -#include - -using namespace std; -using namespace eosio; - -class ore_utils -{ - public: - char* string_to_char(string str); -}; - -char* ore_utils::string_to_char(string str) -{ - char cstr[str.size() + 1]; - return copy(str.begin(), str.end(), cstr); -} \ No newline at end of file From f7d564d228cccfa187ca569bd8fe88481f23e390 Mon Sep 17 00:00:00 2001 From: Surabhi Lodha Date: Fri, 7 Dec 2018 18:32:31 -0800 Subject: [PATCH 15/15] add comments and assert messages for usage log --- contracts/ore.usage_log/ore.usage_log.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contracts/ore.usage_log/ore.usage_log.cpp b/contracts/ore.usage_log/ore.usage_log.cpp index 43c6b32..3f1ad53 100644 --- a/contracts/ore.usage_log/ore.usage_log.cpp +++ b/contracts/ore.usage_log/ore.usage_log.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace eosio; using namespace std; @@ -23,6 +24,9 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract a.token_hash = hashStr(token_hash); a.timestamp = timestamp; }); + + print("action:createlog Log created for instrument id : " + to_string(instrument_id) + " and right name " + right_name + "\n"); + } // TODO: require authority of the reconciler @@ -31,9 +35,10 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract { auto itr = _logs.find(hashStr(token_hash)); - eosio_assert(itr != _logs.end(), "No log exist for the given pair or right and instrument"); + string msg = "No log exist for the given pair of instrument id " + to_string(instrument_id) + " and access token hash " + token_hash + "\n"; + eosio_assert(itr != _logs.end(), msg.c_str()); - print("token hash", itr->token_hash); + print("action:deletelog Log deleted for instrument id : " + to_string(instrument_id) + " and access token hash" + token_hash + "\n"); _logs.erase(itr); } @@ -64,6 +69,9 @@ class [[eosio::contract("ore.usage_log")]] usage_log : public eosio::contract a.total_cpu += cpu; }); } + + print("action:updatecount Call count updated for instrument id : " + to_string(instrument_id) + " and right name " + right_name + "\n"); + } private: