From f4cd0397204ef0a32bfd3fe90dcad5bc93cc467b Mon Sep 17 00:00:00 2001 From: danielAlvess Date: Mon, 13 Apr 2020 11:13:23 +0700 Subject: [PATCH] feat/gitlab#127 contract owner should be able to set governance contract name --- include/cryptobadge.hpp | 16 +++++++++++---- ricardian/cryptobadge.contracts.md | 11 ++++++++++ src/cryptobadge.cpp | 32 ++++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/include/cryptobadge.hpp b/include/cryptobadge.hpp index 5546e0e..79f0de5 100644 --- a/include/cryptobadge.hpp +++ b/include/cryptobadge.hpp @@ -130,6 +130,12 @@ class[[eosio::contract]] cryptobadge : public contract */ ACTION createlog(name issuer, name owner, checksum256 & idata, uint64_t cert_id, bool require_claim); + /* + * Set global config for badge contract + * + */ + ACTION setconfig(name governance_contract_name); + private: enum CertificationState { @@ -267,14 +273,16 @@ class[[eosio::contract]] cryptobadge : public contract { global() {} - uint64_t defer_id = 100000000000000; - uint64_t cert_id = 1000000; - uint64_t badge_id = 0000000; + uint64_t defer_id = 10000000000000; + uint64_t cert_id = 100000; + uint64_t badge_id = 0; + name governance_contract_name = "governance"_n; - EOSLIB_SERIALIZE(global, (defer_id)(cert_id)(badge_id)) + EOSLIB_SERIALIZE(global, (defer_id)(cert_id)(badge_id)(governance_contract_name)) }; typedef eosio::singleton<"v1.global"_n, global> conf; + typedef eosio::multi_index<"v1.global"_n, global> fconf; global _cstate; enum gindex : uint8_t diff --git a/ricardian/cryptobadge.contracts.md b/ricardian/cryptobadge.contracts.md index a329d4a..f90a540 100644 --- a/ricardian/cryptobadge.contracts.md +++ b/ricardian/cryptobadge.contracts.md @@ -142,5 +142,16 @@ icon: https://ddnb1wizcm1i5.cloudfront.net/fd91d4bdbcfbb8fc528b0cc8d7b11fa5.svg# {{updater}} update certification with ID {{cert_id}} of {{owner}} to expired. +

setconfig

+ +--- +spec_version: "0.1.0" +title: Update Certification state to expire +summary: 'Update Certification state to expire' +icon: https://ddnb1wizcm1i5.cloudfront.net/fd91d4bdbcfbb8fc528b0cc8d7b11fa5.svg#a4148806780c5b0a2ed0e1e44a36b1947dd932f653184964d9e44e5dae084a9f +--- + +set configuration for badge contract. + diff --git a/src/cryptobadge.cpp b/src/cryptobadge.cpp index 5e9573a..16f25f5 100644 --- a/src/cryptobadge.cpp +++ b/src/cryptobadge.cpp @@ -2,7 +2,6 @@ #include "../include/cryptobadge.hpp" const uint64_t BADGE_SCHEMA_V1 = 1000; -const name GOVERNANCE_DESIGN = "governance"_n; ACTION cryptobadge::regissuer( name issuer, checksum256& data) { @@ -37,10 +36,14 @@ ACTION cryptobadge::updateissuer( name issuer, checksum256& data) { ACTION cryptobadge::createbadge(name issuer, uint64_t badge_id, string name, string image_url, string path, string description, string criteria) { require_auth( issuer ); require_auth( _self ); + + conf config(_self, _self.value); + _cstate = config.exists() ? config.get() : global{}; + const eosio::name governance_contract_name = _cstate.governance_contract_name; // TODO check if issuer is community account issuers _issuer(_self, _self.value); - community_table _community(GOVERNANCE_DESIGN, GOVERNANCE_DESIGN.value); + community_table _community(governance_contract_name, governance_contract_name.value); auto issuer_itr = _issuer.find( issuer.value ); if(issuer_itr == _issuer.end()){ auto community_itr = _community.find( issuer.value ); @@ -78,12 +81,16 @@ ACTION cryptobadge::issuebadge( name issuer, name owner, uint64_t badge_id, uint require_auth( issuer ); require_auth( _self ); + conf config(_self, _self.value); + _cstate = config.exists() ? config.get() : global{}; + const name governance_contract_name = _cstate.governance_contract_name; + check( is_account( owner ), "owner account does not exist"); issuers _issuer(_self, _self.value); - community_table _community(GOVERNANCE_DESIGN, GOVERNANCE_DESIGN.value); + community_table _community(governance_contract_name, governance_contract_name.value); auto issuer_itr = _issuer.find( issuer.value ); - if(issuer_itr == _issuer.end()){ + if(issuer_itr == _issuer.end()) { auto community_itr = _community.find( issuer.value ); check ( community_itr != _community.end(), "issuer does not exist" ); } @@ -207,7 +214,6 @@ ACTION cryptobadge::claimcert( name claimer, std::vector& cert_ids) { } } - ACTION cryptobadge::canceloffer( name issuer, std::vector& cert_ids){ require_auth( issuer ); @@ -250,14 +256,24 @@ ACTION cryptobadge::removecert( name owner, std::vector& cert_ids, str } +ACTION cryptobadge::setconfig(name governance_contract_name) { + require_auth( _self ); + + conf config(_self, _self.value); + _cstate = config.get_or_create(_self ); + + _cstate.governance_contract_name = governance_contract_name; + + config.set(_cstate, _self); +} + /* * Increment, save and return id for a new certification. */ uint64_t cryptobadge::getid(uint64_t gindex){ conf config(_self, _self.value); - _cstate = config.exists() ? config.get() : global{}; - + _cstate = config.get(); uint64_t resid; if (gindex == DEFER) { @@ -286,4 +302,4 @@ void cryptobadge::sendEvent(name issuer, name rampayer, name seaction, const std } -EOSIO_DISPATCH( cryptobadge, (regissuer)(updateissuer)(createbadge)(updatebadge)(issuebadge)(createlog)(removecert)(canceloffer)(claimcert)(revokecert)(expirecert)) +EOSIO_DISPATCH( cryptobadge, (regissuer)(updateissuer)(createbadge)(updatebadge)(issuebadge)(createlog)(removecert)(canceloffer)(claimcert)(revokecert)(expirecert)(setconfig))