Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/gitlab#127 contract owner should be able to set governance contract name #14

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions include/cryptobadge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions ricardian/cryptobadge.contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,16 @@ icon: https://ddnb1wizcm1i5.cloudfront.net/fd91d4bdbcfbb8fc528b0cc8d7b11fa5.svg#

{{updater}} update certification with ID {{cert_id}} of {{owner}} to expired.

<h1 class="contract">setconfig</h1>

---
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.



32 changes: 24 additions & 8 deletions src/cryptobadge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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" );
}
Expand Down Expand Up @@ -207,7 +214,6 @@ ACTION cryptobadge::claimcert( name claimer, std::vector<uint64_t>& cert_ids) {
}
}


ACTION cryptobadge::canceloffer( name issuer, std::vector<uint64_t>& cert_ids){

require_auth( issuer );
Expand Down Expand Up @@ -250,14 +256,24 @@ ACTION cryptobadge::removecert( name owner, std::vector<uint64_t>& 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) {
Expand Down Expand Up @@ -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))