Smart Contract (assets)¶
We will now describe the set of actions and table structures to implement the dGoods standard. In this section we focus on assets-related actions and tables. In the next section we will talk about dGoods’ built-in decentralized exchange.
Tables¶
-
class
dgoods
¶ -
TABLE
tokenconfigs
¶
[source] // scope is self eosio::symbol_code symbol; eosio::name standard; string version; uint64_t category_name_id;
The first table created and must be initialized with
setconfig()
before any tokens can be created.tokenconfigs
is a singleton which holds the basic information for the contract includingsymbol
for the contractstandard
andversion
that let wallets know what they need to support for this contractcategory_name_id
which is like a global id forcategory:token_name
pairs; the value will increment by one every timecreate()
is successfully executed
-
TABLE
dgoodstats
¶
[source] // scope is category bool fungible; bool burnable; bool sellable; bool transferable; eosio::name issuer; eosio::name token_name; // primary key uint64_t category_name_id; eosio::asset max_supply; eosio::asset current_supply; eosio::asset issued_supply; eosio::name rev_partner; double rev_split; string base_uri;
Saves token info such as
if the token is
fungible
,burnable
,sellable
andtransferable
the
issuer
account who is authorized to issue the tokencategory
(as table scope) andtoken_name
to determine token classfication; the paircategory:token_name
must be uniquecategory_name_id
which is like a global id forcategory:token_name
max_supply
,current_supply
,issued_supply
given aseosio::asset
; for NFTs the precision must be integer;issued_supply
is used to keep track of unique id’s when tokens are burned as it never decreasesrev_partner
andrev_split
which are used to determine how to split the income when the token is sold in the built-in Decentralized Exchangebase_uri
will be used together withrelative_uri
from tabledgood
to provide extra metadata for the token, usually as one of metadata templates
Info is written when a token is created. The
category
is used as table scope andtoken_name
is the primary key, so it ensures eachcategory:token_name
pair is unique.
-
TABLE
categoryinfo
¶
[source] // scope is self eosio::name category; // primary key
Holds all category names for easy querying.
-
TABLE
dgood
¶
[source] // scope is self uint64_t id; // primary key uint64_t serial_number; eosio::name owner; // secondary key eosio::name category; eosio::name token_name; std::optional<string> relative_uri;
The global list for non and semi-fungible tokens. Fungible tokens are not be saved in this table. Secondary indices are used to search by
owner
.relative_uri
will be used together withbase_uri
from tabledgoodstats
to provide extra metadata for the token, usually as one of metadata templates
-
TABLE
accounts
¶
[source] // scope is owner uint64_t category_name_id; // primary key eosio::name category; eosio::name token_name; eosio::asset amount;
Holds account information. For fungible tokens
amount
is the token balance while for NFTs it is the number of owned NFTs. Users need to query tabledgood
to find information for each NFT they own.
-
TABLE
Actions¶
-
class
dgoods
-
ACTION
setconfig
(eosio::symbol_code sym, string version)¶
[source] Must be called first to initialize table
tokenconfigs
with a symbol and version of dGoods spec. It also initializescategory_name_id
to zero. Can be called again to update the version but the symbol will not change.
-
ACTION
create
(eosio::name issuer, eosio::name rev_partner, eosio::name category, eosio::name token_name, bool fungible, bool burnable, bool sellable, bool transferable, double rev_split, string base_uri, eosio::asset max_supply)¶
[source] Defines a type of token before any tokens can be issued. See table
dgoodstats
of how properties are defined.
-
ACTION
issue
(eosio::name to, eosio::name category, eosio::name token_name, eosio::asset quantity, string relative_uri, string memo)¶
[source] Mints a token and gives ownership to the
to
account. The tokencategory:token_name
must be created first.quantity
must match the symbol and precision ofmax_supply
.fixme
For NFTs, can issue up to 100 at one time.
-
ACTION
transferft
(eosio::name from, eosio::name to, eosio::name category, eosio::name token_name, eosio::asset quantity, string memo)¶
[source] Transfer the fungible tokens
category:token_name
. Only applicable if the token istransferable
. Thequantity
must match the symbol and precision ofmax_supply
.
-
ACTION
transfernft
(eosio::name from, eosio::name to, vector<uint64_t> dgood_ids, string memo)¶
[source] Transfer non-fungible tokens. Only applicable if the token is
transferable
and not be locked (see tablelockednfts
).dgood_ids
are from tabledgood
.
-
ACTION
burnft
(eosio::name owner, uint64_t category_name_id, eosio::asset quantity)¶
[source] Destroys fungible tokens and frees the RAM if all tokens are deleted from the account. Only applicable if the token is
burnable
. Only the owner may call this action. Thequantity
must match the symbol and precision ofmax_supply
. Thecategory_name_id
is from tabledgoodstats
.
-
ACTION
burnnft
(eosio::name owner, vector<uint64_t> dgood_ids)¶
[source] Destroys specified non-fungible tokens and frees the RAM. Only applicable if the token is
burnable
and not be locked (see tablelockednfts
). Only the owner may call this action.dgood_ids
are from tabledgood
.
-
ACTION
pausexfer
(bool pause)¶ Pauses all transfers of all tokens. Only callable by the contract. If pause is true, will pause. If pause is false will unpause transfers.
-
ACTION