Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
justfortest2 committed Aug 8, 2020
1 parent 041993b commit 72e4511
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 9 additions & 1 deletion ibc.proxy/include/ibc.proxy/ibc.proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace eosio {
[[eosio::action]]
void transfer( name from, name to, asset quantity, string memo );

[[eosio::action]]
void mvtotrash( transaction_id_type orig_trx_id );

struct [[eosio::table("globals")]] global_state {
global_state(){}
name ibc_token_account;
Expand Down Expand Up @@ -61,7 +64,12 @@ namespace eosio {
};
eosio::multi_index< "proxytrxs"_n, proxy_trx_info,
indexed_by<"trxid"_n, const_mem_fun<proxy_trx_info, fixed_bytes<32>, &proxy_trx_info::by_trx_id> >
> _proxytrxs;
> _proxytrxs;

eosio::multi_index< "proxytrxs2"_n, proxy_trx_info,
indexed_by<"trxid"_n, const_mem_fun<proxy_trx_info, fixed_bytes<32>, &proxy_trx_info::by_trx_id> >
> _proxytrxs2;

};

} /// namespace eosio
22 changes: 20 additions & 2 deletions ibc.proxy/src/ibc.proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace eosio {
proxy::proxy( name s, name code, datastream<const char*> ds ):
contract( s, code, ds ),
_global_state( _self, _self.value ),
_proxytrxs( _self, _self.value )
_proxytrxs( _self, _self.value ),
_proxytrxs2( _self, _self.value )
{
_gstate = _global_state.exists() ? _global_state.get() : global_state{};
}
Expand Down Expand Up @@ -95,13 +96,30 @@ namespace eosio {
_proxytrxs.erase( *trx_p );
}

void proxy::mvtotrash( transaction_id_type orig_trx_id ){

auto idx = _proxytrxs.get_index<"trxid"_n>();
const auto& trx_p = idx.find(fixed_bytes<32>(orig_trx_id.hash));
eosio_assert( trx_p != idx.end(), "transaction not found in table proxytrx.");

auto duration = 3600*2*12; // half a day
eosio_assert( get_block_time_slot() - trx_p->block_time_slot > duration, "you can't move this proxy transaction to trash within half a day");

auto idx2 = _proxytrxs2.get_index<"trxid"_n>();
const auto& trx_p2 = idx2.find(fixed_bytes<32>(orig_trx_id.hash));
eosio_assert( trx_p2 == idx2.end(), "transaction already exist in table proxytrx2");

_proxytrxs2.emplace( _self, [&]( auto& r ){ r = *trx_p; });
_proxytrxs.erase( *trx_p );
}

} /// namespace eosio

extern "C" {
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
if( code == receiver ) {
switch( action ) {
EOSIO_DISPATCH_HELPER( eosio::proxy, (setglobal)(transfer))
EOSIO_DISPATCH_HELPER( eosio::proxy, (setglobal)(transfer)(mvtotrash))
}
return;
}
Expand Down

0 comments on commit 72e4511

Please sign in to comment.