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/issue badge non can account #9

Merged
merged 6 commits into from
Apr 21, 2020
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
48 changes: 27 additions & 21 deletions example/create_badge_through_governance_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example session using cleos with can test net
* Endpoint network:

Use one of the following:
http://network-endpoint:8888
https://history.stagenet.canfoundation.io

* Contract name: cryptobadge2

Expand All @@ -27,7 +27,13 @@ navigate to contracts/crypto.badge and run those commands to complie and deploy
````bash
eosio-cpp -abigen -I include -contract cryptobadge -R ricardian -o cryptobadge.wasm src/cryptobadge.cpp

cleos -u http://network-endpoint:8888 set contract cryptobadge5 . cryptobadge.wasm cryptobadge.abi -p cryptobadge5
cleos -u https://history.stagenet.canfoundation.io set contract cryptobadge5 . cryptobadge.wasm cryptobadge.abi -p cryptobadge5

cleos -u https://history.stagenet.canfoundation.io push action cryptobadge5 setconfig '["ram.can", "governance"]' -p cryptobadge5

# set contract account permission
cleos -u https://history.stagenet.canfoundation.io set account permission governance23 active '{"threshold": 1,"keys": [{"key": "EOS7syfoU8p7aD4pxjVZ8Y3rtj1sKYp2aaLTDCAJKuk8fYecouJMy","weight": 1}],"accounts": [{"permission":{"actor":"governance23","permission":"eosio.code"},"weight":1}]}' owner -p governance23

````

##### pre-process information data
Expand Down Expand Up @@ -93,11 +99,11 @@ Json hash256: https://emn178.github.io/online-tools/sha256.html

````bash

$ cleos -u http://network-endpoint:8888 push action cryptobadge5 regissuer '[badgeissuer1, 74e202709e5e36075b72f23e6b7c253d998685014571ba10e362cc634ffdac18]' -p badgeissuer1
$ cleos -u https://history.stagenet.canfoundation.io push action cryptobadge5 regissuer '[badgeissuer1, 74e202709e5e36075b72f23e6b7c253d998685014571ba10e362cc634ffdac18]' -p badgeissuer1

$ cleos -u http://network-endpoint:8888 push action cryptobadge5 updateissuer '[badgeissuer1, 74e202709e5e36075b72f23e6b7c253d998685014571ba10e362cc634ffdac18]' -p badgeissuer1
$ cleos -u https://history.stagenet.canfoundation.io push action cryptobadge5 updateissuer '[badgeissuer1, 74e202709e5e36075b72f23e6b7c253d998685014571ba10e362cc634ffdac18]' -p badgeissuer1

$ cleos -u http://network-endpoint:8888 get table cryptobadge5 cryptobadge5 issuers
$ cleos -u https://history.stagenet.canfoundation.io get table cryptobadge5 cryptobadge5 v1.issuers
{
"rows": [{
"issuer": "badgeissuer1",
Expand All @@ -113,10 +119,10 @@ $ cleos -u http://network-endpoint:8888 get table cryptobadge5 cryptobadge5 issu

```bash
// transfer token to create new community account, memo is the name of community account
cleos -u http://network-endpoint:8888 transfer creator.can governance23 "20.0000 CAT" "community145" -p creator.can
cleos -u https://history.stagenet.canfoundation.io transfer creator.can governance23 "20.0000 CAT" "community145" -p creator.can

// update community infomation
cleos -u http://network-endpoint:8888 push action governance23 create '[creator.can, community145, "Test", [], "test-v.com", "Testing vo", 1]' -p creator.can
cleos -u https://history.stagenet.canfoundation.io push action governance23 create '[creator.can, community145, "Test", [], "test-v.com", "Testing vo", 1]' -p creator.can
```


Expand Down Expand Up @@ -163,9 +169,9 @@ cleos -u http://18.182.95.163:8888 get table governance23 community145 codes

2. create proposal for transaction create badge use eosio.msig contract:
```bash
cleos -u http://network-endpoint:8888 multisig propose newbadge1111 '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' cryptobadge5 createbadge '{"issuer":"community145", "badge_id":1, "version":100, "name":"CryptoBadge", "image_url":"http://cryptobadge.app/image.img", "path":"cryptobadge", "description":"cryptobadge application", "criteria":"cryptobadge criteria"}' cryptobadge5 12
cleos -u https://history.stagenet.canfoundation.io multisig propose newbadge1111 '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' cryptobadge5 createbadge '{"issuer":"community145", "badge_id":1, "version":100, "name":"CryptoBadge", "image_url":"http://cryptobadge.app/image.img", "path":"cryptobadge", "description":"cryptobadge application", "criteria":"cryptobadge criteria"}' cryptobadge5 12

cleos -u http://network-endpoint:8888 multisig review cryptobadge5 newbadge1111
cleos -u https://history.stagenet.canfoundation.io multisig review cryptobadge5 newbadge1111
{
"proposer": "badge",
"proposal_name": "newbadge1111",
Expand Down Expand Up @@ -211,7 +217,7 @@ cleos -u http://network-endpoint:8888 multisig review cryptobadge5 newbadge1111
3. use cryptobadge smart contract account to sign this proposal:

```bash
cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approvals2 -U newbadge1111 -L newbadge1111
cleos -u https://history.stagenet.canfoundation.io get table eosio.msig cryptobadge5 approvals2 -U newbadge1111 -L newbadge1111
{
"rows": [{
"version": 1,
Expand All @@ -236,9 +242,9 @@ cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approval
"more": false
}

cleos -u http://network-endpoint:8888 multisig approve cryptobadge5 newbadge1111 '{"actor": "cryptobadge5", "permission": "active"}' -p cryptobadge5
cleos -u https://history.stagenet.canfoundation.io multisig approve cryptobadge5 newbadge1111 '{"actor": "cryptobadge5", "permission": "active"}' -p cryptobadge5

cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approvals2 -U newbadge1111 -L newbadge1111
cleos -u https://history.stagenet.canfoundation.io get table eosio.msig cryptobadge5 approvals2 -U newbadge1111 -L newbadge1111
{
"rows": [{
"version": 1,
Expand Down Expand Up @@ -275,7 +281,7 @@ cleos -u http://18.182.95.163:8888 convert pack_action_data governance23 createb
cleos -u http://18.182.95.163:8888 push action governance23 execcode '[community145, creator.can, badge, createbadge, "5048f0d94d2d25451042088a2573b89a"]' -p creator.can

// verify in state data
cleos -u http://network-endpoint:8888 get table cryptobadge5 community145 cbadges
cleos -u https://history.stagenet.canfoundation.io get table cryptobadge5 community145 cbadges
{
"rows": [{
"badge_id": 1,
Expand All @@ -293,9 +299,9 @@ Do the same flow with create badge

1. create proposal for transaction create certification (issue badge) use eosio.msig contract:
```bash
cleos -u http://network-endpoint:8888 multisig propose newcert1111 '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' cryptobadge5 issuebadge '{"issuer":"community145", "owner":"community145", "badge_id":1, "badge_revision":100, "cert_id": 1, "encrypted_data":"abc123abcqweqweqr", "require_claim":0}' cryptobadge5 12
cleos -u https://history.stagenet.canfoundation.io multisig propose newcert1111 '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' '[{"actor": "cryptobadge5", "permission": "active"},{"actor": "community145", "permission": "active"}]' cryptobadge5 issuebadge '{"issuer":"community145", "owner":"community145", "badge_id":1, "badge_revision":100, "cert_id": 1, "encrypted_data":"abc123abcqweqweqr", "require_claim":0}' cryptobadge5 12

cleos -u http://network-endpoint:8888 multisig review cryptobadge5 newcert1111
cleos -u https://history.stagenet.canfoundation.io multisig review cryptobadge5 newcert1111
{
"proposer": "cryptobadge5",
"proposal_name": "newcert1111",
Expand Down Expand Up @@ -340,7 +346,7 @@ cleos -u http://network-endpoint:8888 multisig review cryptobadge5 newcert1111
3. use cryptobadge smart contract account to sign this proposal:

```bash
cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approvals2 -U newcert1111 -L newcert1111
cleos -u https://history.stagenet.canfoundation.io get table eosio.msig cryptobadge5 approvals2 -U newcert1111 -L newcert1111
{
"rows": [{
"version": 1,
Expand All @@ -365,9 +371,9 @@ cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approval
"more": false
}

cleos -u http://network-endpoint:8888 multisig approve cryptobadge5 newcert1111 '{"actor": "cryptobadge5", "permission": "active"}' -p cryptobadge5
cleos -u https://history.stagenet.canfoundation.io multisig approve cryptobadge5 newcert1111 '{"actor": "cryptobadge5", "permission": "active"}' -p cryptobadge5

cleos -u http://network-endpoint:8888 get table eosio.msig cryptobadge5 approvals2 -U newcert1111 -L newcert1111
cleos -u https://history.stagenet.canfoundation.io get table eosio.msig cryptobadge5 approvals2 -U newcert1111 -L newcert1111
{
"rows": [{
"version": 1,
Expand Down Expand Up @@ -404,7 +410,7 @@ cleos -u http://18.182.95.163:8888 convert pack_action_data governance23 issueba
cleos -u http://18.182.95.163:8888 push action governance23 execcode '[community145, creator.can, badge, issuebadge, "5048f0d94d2d2545004208215f85b89a"]' -p creator.can

// verify in state data
cleos -u http://network-endpoint:8888 get table cryptobadge5 community145 ccerts
cleos -u https://history.stagenet.canfoundation.io get table cryptobadge5 community145 ccerts
{
"rows": [{
"badge_id": 1,
Expand All @@ -420,7 +426,7 @@ base on `require_claim` parameter use corresponding command to verify certificat

```bash
// require_claim is false
cleos -u http://network-endpoint:8888 get table cryptobadge5 community145 ccerts
cleos -u https://history.stagenet.canfoundation.io get table cryptobadge5 community145 ccerts
{
"rows": [{
"id": 1,
Expand All @@ -434,6 +440,6 @@ cleos -u http://network-endpoint:8888 get table cryptobadge5 community145 ccerts
}

// require_claim is true
cleos -u http://network-endpoint:8888 get table cryptobadge5 cryptobadge5 offers
cleos -u https://history.stagenet.canfoundation.io get table cryptobadge5 cryptobadge5 offers
```

135 changes: 55 additions & 80 deletions include/cryptobadge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class[[eosio::contract]] cryptobadge : public contract

public:
//using contract::contract;
cryptobadge(name receiver, name code, datastream<const char *> ds) : contract(receiver, code, ds) {}
cryptobadge(name receiver, name code, datastream<const char *> ds) : contract(receiver, code, ds),_global(_self, _self.value) {}

/*
* New issuer registration. issuer is required to create new badge. Markets *may* choose to use information here
Expand Down Expand Up @@ -104,57 +104,37 @@ class[[eosio::contract]] cryptobadge : public contract
* claimer - account claiming the badge;
* cert_ids - array of cert_id's to claim;
*/
ACTION claimcert(name claimer, std::vector<uint64_t> & cert_ids);

/*
* Cancel and remove offer. Available for the certification owner.
*
* issuer - current certification issuer account;
* cert_ids - array of cert_id's to cancel from offer;
*/
ACTION canceloffer(name issuer, std::vector<uint64_t> & cert_ids);

/*
* Remove certification {{cert_id}}. This action is only available for the certification owner. After executing, the
* certification will disappear forever, and RAM used for certification will be released.
*
* owner - current certification owner account;
* cert_ids - array of cert_id's to remove;
* memo - memo for remove action;
*/
ACTION removecert(name owner, std::vector<uint64_t> & cert_ids, string memo);
ACTION claimbadge(name claimer, name issuer, uint64_t cert_ids);

/*
* Empty action. Used by create action to log cert_id so that third party explorers can
* easily get new certification ids and other information.
*/
ACTION createlog(name issuer, name owner, checksum256 & idata, uint64_t cert_id, bool require_claim);
ACTION issuelog(name issuer, name owner, uint64_t cert_id, const checksum256 & issued_tx_id);


/*
* Set global config for badge contract
*
*/
ACTION setconfig(name governance_contract_name);
ACTION setconfig(name ram_payer_account, name governance_design);

private:
enum CertificationState
{
CERTIFIED = 0,
EXPIRED,
REVOKED
REVOKED
};

uint64_t getid(uint64_t gindex);

template <typename... Args>
void sendEvent(name issuer, name rampayer, name seaction, const std::tuple<Args...> &tup);
checksum256 gettrxid();

/*
* issuers table. Can be used by badge markets, badge explorers, or wallets for correct badge
* data presentation.
* Scope: self
*/
TABLE cissuer
TABLE v1_issuer
{
name issuer;
checksum256 data;
Expand All @@ -164,13 +144,13 @@ class[[eosio::contract]] cryptobadge : public contract
return issuer.value;
}
};
typedef multi_index<"v1.issuers"_n, cissuer> issuers;
typedef multi_index<"v1.issuers"_n, v1_issuer> v1_issuers;

/*
* Badges table which stores information about simple badges.
* Scope: badge owner
*/
TABLE cbadge
TABLE v1_badge
{
uint64_t badge_id;
name issuer;
Expand All @@ -180,15 +160,15 @@ class[[eosio::contract]] cryptobadge : public contract
uint64_t by_issuer() const { return issuer.value; }
};

typedef eosio::multi_index<"v1.badges"_n, cbadge,
eosio::indexed_by<"issuer"_n, eosio::const_mem_fun<cbadge, uint64_t, &cbadge::by_issuer>>>
cbadges;
typedef eosio::multi_index<"v1.badges"_n, v1_badge,
eosio::indexed_by<"issuer"_n, eosio::const_mem_fun<v1_badge, uint64_t, &v1_badge::by_issuer>>>
v1_badges;

/*
* Certification table which stores information about certifications.
* Scope: certification owner
*/
TABLE ccert
TABLE v1_cert
{
uint64_t id;
uint64_t badge_id;
Expand All @@ -211,86 +191,81 @@ class[[eosio::contract]] cryptobadge : public contract
}
};

typedef eosio::multi_index<"v1.certs"_n, ccert,
eosio::indexed_by<"badgeid"_n, eosio::const_mem_fun<ccert, uint64_t, &ccert::by_badge_id>>,
eosio::indexed_by<"owner"_n, eosio::const_mem_fun<ccert, uint64_t, &ccert::by_owner>>>
ccerts;
typedef eosio::multi_index<"v1.certs"_n, v1_cert,
eosio::indexed_by<"badgeid"_n, eosio::const_mem_fun<v1_cert, uint64_t, &v1_cert::by_badge_id>>,
eosio::indexed_by<"owner"_n, eosio::const_mem_fun<v1_cert, uint64_t, &v1_cert::by_owner>>>
v1_certs;

/*
* Certification table which stores information about certifications.
* Scope: certification owner
*/
TABLE ccertinfo
TABLE v1_issuing_cert
{
uint64_t cert_id;
string cert_content;
uint64_t id;
uint64_t badge_id;
uint64_t badge_revision;
name owner;
uint64_t state;
uint64_t expire_at;
checksum256 issued_tx_id;

auto primary_key() const
{
return cert_id;
return id;
}
uint64_t by_badge_id() const
{
return badge_id;
}
uint64_t by_owner() const
{
return owner.value;
}
};

typedef eosio::multi_index<"v1.certinfo"_n, ccertinfo> ccertinfos;

typedef eosio::multi_index<"v1.issuing"_n, v1_issuing_cert,
eosio::indexed_by<"badgeid"_n, eosio::const_mem_fun<v1_issuing_cert, uint64_t, &v1_issuing_cert::by_badge_id>>,
eosio::indexed_by<"owner"_n, eosio::const_mem_fun<v1_issuing_cert, uint64_t, &v1_issuing_cert::by_owner>>>
v1_issuing_certs;

/*
* Offers table keeps records of open offers of certifications (ie. certifications waiting to be claimed by their
* intendend recipients.
*
* Scope: self
* Certification table which stores information about certifications.
* Scope: certification owner
*/
TABLE coffer
TABLE v1_certinfo
{
uint64_t cert_id;
name owner;
name offered_to;
time_point date;
string cert_content;

auto primary_key() const
{
return cert_id;
}
uint64_t by_owner() const
{
return owner.value;
}
uint64_t by_offered_to() const
{
return offered_to.value;
}
};

typedef eosio::multi_index<"v1.offers"_n, coffer,
eosio::indexed_by<"owner"_n, eosio::const_mem_fun<coffer, uint64_t, &coffer::by_owner>>,
eosio::indexed_by<"offeredto"_n, eosio::const_mem_fun<coffer, uint64_t, &coffer::by_offered_to>>>
offers;
typedef eosio::multi_index<"v1.certinfos"_n, v1_certinfo> v1_certinfos;

/*
* global singelton table, used for cert_id building
* Scope: self
*/
TABLE global
TABLE v1_global
{

global() {}
uint64_t defer_id = 10000000000000;
uint64_t cert_id = 100000;
uint64_t badge_id = 0;
name governance_contract_name = "governance"_n;
v1_global() {}
name ram_payer_account = "ram.can"_n;
name governance_design = "governance"_n;

EOSLIB_SERIALIZE(global, (defer_id)(cert_id)(badge_id)(governance_contract_name))
EOSLIB_SERIALIZE(v1_global, (ram_payer_account)(governance_design))
};

typedef eosio::singleton<"v1.global"_n, global> conf;
typedef eosio::multi_index<"v1.global"_n, global> fconf;
global _cstate;
typedef eosio::singleton<"v1.global"_n, v1_global> v1_global_table;
typedef eosio::multi_index<"v1.global"_n, v1_global> fv1_global_table;
// v1_global _cstate;

enum gindex : uint8_t
{
DEFER = 0,
CERT = 1,
BADGE = 2,
};
v1_global_table _global;


//refer govenance design
TABLE communityf
Expand Down
Loading