Skip to content

Commit

Permalink
add new table stat and sync function
Browse files Browse the repository at this point in the history
  • Loading branch information
vonhenry committed Oct 10, 2019
1 parent 45f7cd2 commit 33ec196
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project(ibc_contract VERSION 2.0.0)

set(EOSIO_CDT_VERSION_MIN "1.5")
set(EOSIO_CDT_VERSION_SOFT_MAX "1.5")
set(EOSIO_CDT_VERSION_MIN "3.0.1")
set(EOSIO_CDT_VERSION_SOFT_MAX "3.0.1")
#set(EOSIO_CDT_VERSION_HARD_MAX "")

find_package(eosio.cdt)
Expand Down
12 changes: 12 additions & 0 deletions ibc.token/include/ibc.token/ibc.token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ namespace eosio {
};
typedef eosio::multi_index< "accounts"_n, account > accounts;

// table stat is just used for command 'cleos get currency stats ...' compatibility
// code,scope (_self,sym_code)
struct [[eosio::table]] currency_stats2 {
asset supply;
asset max_supply;
name issuer;

uint64_t primary_key()const { return supply.symbol.code().raw(); }
};
typedef eosio::multi_index< "stat"_n, currency_stats2 > stats2;

void update_stats2( symbol_code sym_code );

// use to record accepted transfer and withdraw transactions
// code,scope(_self,peerchain_name.value)
Expand Down
31 changes: 31 additions & 0 deletions ibc.token/src/ibc.token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ namespace eosio {
r.total_withdraw_times = 0;
r.active = active;
});

update_stats2( max_supply.symbol.code() );
}

void token::setpegasset( symbol_code symcode, string which, asset quantity ) {
Expand All @@ -336,6 +338,7 @@ namespace eosio {
if ( which == "max_supply" ){
eosio_assert( quantity.amount >= st.supply.amount, "max_supply.amount should not less then supply.amount");
_stats.modify( st, same_payer, [&]( auto& r ) { r.max_supply = quantity; });
update_stats2( quantity.symbol.code() );
return;
}
if ( which == "min_once_withdraw" ){
Expand Down Expand Up @@ -655,6 +658,8 @@ namespace eosio {
add_balance( _self, quantity, _self ); // not burn token here, burn at cash_confirm()

origtrxs_emplace( peerchain_name, transfer_action_info{ _self, from, quantity } );

update_stats2( quantity.symbol.code() );
}

void token::verify_merkle_path( const std::vector<digest_type>& merkle_path, digest_type check ) {
Expand Down Expand Up @@ -777,6 +782,8 @@ namespace eosio {
transfer_action_type action_data{ _self, to, new_quantity, new_memo };
action( permission_level{ _self, "active"_n }, _self, "transfer"_n, action_data ).send();
}

update_stats2( st.supply.symbol.code() );
} else { // withdraw accepted token to user
const auto& acpt = get_currency_accept_by_peg_token_symbol( quantity.symbol.code() );
eosio_assert( acpt.active, "not active");
Expand Down Expand Up @@ -957,6 +964,8 @@ namespace eosio {
transfer_action_type action_data{ _self, action_info.from, final_quantity, memo };
action( permission_level{ _self, "active"_n }, _self, "transfer"_n, action_data ).send();
}

update_stats2( st.supply.symbol.code() );
}

_origtrxs.erase( _origtrxs.find(it->id) );
Expand Down Expand Up @@ -1019,6 +1028,8 @@ namespace eosio {
transfer_action_type action_data{ _self, action_info.from, action_info.quantity, memo };
action( permission_level{ _self, "active"_n }, _self, "transfer"_n, action_data ).send();
}

update_stats2( st.supply.symbol.code() );
}
_origtrxs.erase( record );
}
Expand Down Expand Up @@ -1271,6 +1282,26 @@ namespace eosio {
return true;
}

void token::update_stats2( symbol_code sym_code ){
const auto& st1 = get_currency_stats( sym_code );

stats2 _stats2( _self, sym_code.raw() );
auto itr = _stats2.find( sym_code.raw() );

if ( itr == _stats2.end() ){
_stats2.emplace( _self, [&]( auto& s ) {
s.supply = st1.supply;
s.max_supply = st1.max_supply;
s.issuer = _self;
});
} else {
_stats2.modify( itr, same_payer, [&]( auto& s ) {
s.supply = st1.supply;
s.max_supply = st1.max_supply;
});
}
}

} /// namespace eosio

extern "C" {
Expand Down

0 comments on commit 33ec196

Please sign in to comment.