Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
change get_supply to get_token
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Aug 12, 2023
1 parent 7d50e7a commit c14035f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/antelope.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Antelope CDT

on: [push]

jobs:
release:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Antelope CDT
run: wget https://github.com/AntelopeIO/cdt/releases/download/v3.1.0/cdt_3.1.0_amd64.deb && sudo apt install ./cdt_3.1.0_amd64.deb

- name: Compile WASM
run: cdt-cpp claim.pomelo.cpp -I include

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
*.abi
*.wasm
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@ cleos push action claim.pomelo approve '[101, "grant1", true]' -p claim.pomelo
cleos push action claim.pomelo cancel '[101, "grant1"]' -p claim.pomelo
```

## Testing
## Build

```bash
# build contracts
$ ./scripts/build.sh

# restart node, create EOSIO users, deploy contracts, issue tokens
$ ./scripts/restart

# run basic tests
$ ./scripts/test.sh
$ cdt-cpp claim.pomelo.cpp -I include
```

## HTTP requests
Expand Down
4 changes: 2 additions & 2 deletions claim.pomelo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void claimpomelo::setclaim( const uint16_t round_id, const name grant_id, const
// check if token is valid
check( is_account( claim.contract ), "claim.pomelo::setclaim: [claim] token contract does not exists");
const symbol sym = claim.quantity.symbol;
const asset supply = token::get_supply(claim.contract, sym.code() );
check( supply.symbol == sym, "claim.pomelo::setclaim: [claim] has invalid supply symbol");
const asset balance = token::get_balance(claim.contract, get_self(), sym.code() );
check( balance.symbol == sym, "claim.pomelo::setclaim: [claim] has invalid balance symbol");

_claims.emplace( get_self(), [&]( auto& row ) {
row.funding_account = grant.funding_account;
Expand Down
21 changes: 11 additions & 10 deletions include/eosio.token/eosio.token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ namespace eosio {
using std::string;

/**
* eosio.token contract defines the structures and actions that allow users to create, issue, and manage
* tokens on eosio based blockchains.
* The `eosio.token` sample system contract defines the structures and actions that allow users to create, issue, and manage tokens for EOSIO based blockchains. It demonstrates one way to implement a smart contract which allows for creation and management of tokens. It is possible for one to create a similar contract which suits different needs. However, it is recommended that if one only needs a token with the below listed actions, that one uses the `eosio.token` contract instead of developing their own.
*
* The `eosio.token` contract class also implements two useful public static methods: `get_supply` and `get_balance`. The first allows one to check the total supply of a specified token, created by an account and the second allows one to check the balance of a token for a specified account (the token creator account has to be specified as well).
*
* The `eosio.token` contract manages the set of tokens, accounts and their corresponding balances, by using two internal multi-index structures: the `accounts` and `stats`. The `accounts` multi-index table holds, for each row, instances of `account` object and the `account` object holds information about the balance of one token. The `accounts` table is scoped to an EOSIO account, and it keeps the rows indexed based on the token's symbol. This means that when one queries the `accounts` multi-index table for an account name the result is all the tokens that account holds at the moment.
*
* Similarly, the `stats` multi-index table, holds instances of `currency_stats` objects for each row, which contains information about current supply, maximum supply, and the creator account for a symbol token. The `stats` table is scoped to the token symbol. Therefore, when one queries the `stats` table for a token symbol the result is one single entry/row corresponding to the queried symbol token if it was previously created, or nothing, otherwise.
*/
class [[eosio::contract("eosio.token")]] token : public contract {
public:
Expand All @@ -39,7 +44,7 @@ namespace eosio {
* This action issues to `to` account a `quantity` of tokens.
*
* @param to - the account to issue tokens to, it must be the same as the issuer,
* @param quntity - the amount of tokens to be issued,
* @param quantity - the amount of tokens to be issued,
* @memo - the memo string that accompanies the token issue transaction.
*/
[[eosio::action]]
Expand Down Expand Up @@ -96,20 +101,17 @@ namespace eosio {
[[eosio::action]]
void close( const name& owner, const symbol& symbol );

[[eosio::action]]
void closesupply( const symbol_code symcode );

static asset get_supply( const name& token_contract_account, const symbol_code& sym_code )
{
stats statstable( token_contract_account, sym_code.raw() );
const auto& st = statstable.get( sym_code.raw() );
const auto& st = statstable.get( sym_code.raw(), "invalid supply symbol code" );
return st.supply;
}

static asset get_balance( const name& token_contract_account, const name& owner, const symbol_code& sym_code )
{
accounts accountstable( token_contract_account, owner.value );
const auto& ac = accountstable.get( sym_code.raw() );
const auto& ac = accountstable.get( sym_code.raw(), "no balance with specified symbol" );
return ac.balance;
}

Expand All @@ -119,7 +121,7 @@ namespace eosio {
using transfer_action = eosio::action_wrapper<"transfer"_n, &token::transfer>;
using open_action = eosio::action_wrapper<"open"_n, &token::open>;
using close_action = eosio::action_wrapper<"close"_n, &token::close>;

private:
struct [[eosio::table]] account {
asset balance;

Expand All @@ -137,7 +139,6 @@ namespace eosio {
typedef eosio::multi_index< "accounts"_n, account > accounts;
typedef eosio::multi_index< "stat"_n, currency_stats > stats;

private:
void sub_balance( const name& owner, const asset& value );
void add_balance( const name& owner, const asset& value, const name& ram_payer );
};
Expand Down
5 changes: 2 additions & 3 deletions scripts/setclaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ const session = new Session({
try {
await session.transact({actions});
console.log("OK")
} catch (e: any) {
const message = e.error.details[0].message;
console.error("ERROR", message)
} catch (error) {
console.error("ERROR", error)
}
})();

0 comments on commit c14035f

Please sign in to comment.