Skip to content

Commit

Permalink
Refined and simplified to split wraplock and wraptoken functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
andybets committed Jan 15, 2022
1 parent b005880 commit 3a63149
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 353 deletions.
109 changes: 21 additions & 88 deletions include/wraptoken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <eosio/asset.hpp>
#include <eosio/eosio.hpp>
#include <eosio/singleton.hpp>

#include <string>

Expand All @@ -11,45 +12,27 @@ namespace eosiosystem {

namespace eosio {

const name bridge_contract = "newbridge"_n;

using std::string;

class [[eosio::contract("wraptoken")]] token : public contract {
private:

struct st_create {
name issuer;
asset maximum_supply;
};

struct st_transfer {
name from;
name to;
asset quantity;
std::string memo;
};

struct [[eosio::table]] global {
checksum256 chain_id;
name bridge_contract;
checksum256 paired_chain_id;
name paired_wraplock_contract;
name paired_token_contract;
} globalrow;

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

uint64_t primary_key()const { return balance.symbol.code().raw(); }
};

struct [[eosio::table]] extaccount {
extended_asset balance;

uint64_t primary_key()const { return balance.quantity.symbol.code().raw(); }
};

struct [[eosio::table]] currency_stats {

//uniquely identify source information
name source_contract;
checksum256 source_chain_id;
symbol_code source_symbol;

asset supply;
asset max_supply;
name issuer;
Expand All @@ -58,33 +41,8 @@ namespace eosio {
};


struct [[eosio::table]] chain {

uint64_t id;

checksum256 chain_id;

name wrap_contract;

uint64_t primary_key()const { return id; }
checksum256 by_chain_id()const { return chain_id; }

EOSLIB_SERIALIZE( chain, (id)(chain_id)(wrap_contract))

};


/* void sub_balance( const name& owner, const asset& value );
void sub_balance( const name& owner, const asset& value );
void add_balance( const name& owner, const asset& value, const name& ram_payer );
*/
void sub_internal_balance( const name& owner, const asset& value );
void add_internal_balance( const name& owner, const asset& value, const name& ram_payer );

void sub_external_balance( const name& owner, const extended_asset& value );
void add_external_balance( const name& owner, const extended_asset& value, const name& ram_payer );

void sub_reserve(const extended_asset& value );
void add_reserve(const extended_asset& value );

public:
using contract::contract;
Expand Down Expand Up @@ -122,21 +80,16 @@ namespace eosio {
name beneficiary;
};

[[eosio::action]]
void create(const name& caller, const uint64_t proof_id, const asset& maximum_supply);

[[eosio::action]]
void issue(const name& caller, const uint64_t proof_id);


[[eosio::action]]
void lock(const name& owner, const extended_asset& quantity, const name& beneficiary );
void init(const checksum256& chain_id, const name& bridge_contract, const checksum256& paired_chain_id, const name& paired_wraptoken_contract, const name& paired_token_contract);

[[eosio::action]]
void withdraw(const name& caller, const uint64_t proof_id);

void issue(const name& caller, const checksum256 action_receipt_digest);


[[eosio::action]]
void retire(const name& owner, const asset& quantity, const name& beneficiary );
void retire(const name& owner, const asset& quantity, const name& beneficiary);


[[eosio::action]]
Expand All @@ -152,23 +105,12 @@ namespace eosio {
[[eosio::action]]
void close( const name& owner, const symbol& symbol );

[[eosio::action]]
void addchain(const checksum256& chain_id, const name& wrap_contract);

[[eosio::action]]
void delchain(const checksum256& chain_id);

[[eosio::action]]
void emitxfer(const token::xfer& xfer);

[[eosio::action]]
void test();

[[eosio::action]]
void clear();

[[eosio::on_notify("*::transfer")]] void deposit(name receiver, name code);

static asset get_supply( const name& token_contract_account, const symbol_code& sym_code )
{
stats statstable( token_contract_account, sym_code.raw() );
Expand All @@ -184,42 +126,33 @@ namespace eosio {
}


typedef eosio::multi_index< "extaccounts"_n, extaccount > extaccounts;
typedef eosio::multi_index< "reserves"_n, extaccount > reserves;

typedef eosio::multi_index< "accounts"_n, account > accounts;
typedef eosio::multi_index< "stat"_n, currency_stats > stats;

typedef eosio::multi_index< "chains"_n, chain,
indexed_by<"chainid"_n, const_mem_fun<chain, checksum256, &chain::by_chain_id>>> chainstable;

typedef eosio::multi_index< "proofs"_n, validproof,
indexed_by<"digest"_n, const_mem_fun<validproof, checksum256, &validproof::by_digest>>> proofstable;

typedef eosio::multi_index< "processed"_n, processed,
indexed_by<"digest"_n, const_mem_fun<processed, checksum256, &processed::by_digest>>> processedtable;


using globaltable = eosio::singleton<"global"_n, global>;

void add_or_assert(const validproof& proof, const name& prover);

validproof get_proof(const uint64_t proof_id);
validproof get_proof(const checksum256 action_receipt_digest);

globaltable global_config;

proofstable _proofstable;
processedtable _processedtable;
chainstable _chainstable;
reserves _reservestable;

token( name receiver, name code, datastream<const char*> ds ) :
contract(receiver, code, ds),
_proofstable(bridge_contract, bridge_contract.value),
_processedtable(_self, _self.value),
_chainstable(_self, _self.value),
_reservestable(_self, _self.value)
global_config(_self, _self.value),
_processedtable(_self, _self.value)
{

}

using create_action = eosio::action_wrapper<"create"_n, &token::create>;
using issue_action = eosio::action_wrapper<"issue"_n, &token::issue>;
using retire_action = eosio::action_wrapper<"retire"_n, &token::retire>;
using transfer_action = eosio::action_wrapper<"transfer"_n, &token::transfer>;
Expand Down
Loading

0 comments on commit 3a63149

Please sign in to comment.