diff --git a/contracts/currency/currency.cpp b/contracts/currency/currency.cpp index 62c20a0e54f0cd237f64f895aa6020c142931d23..ebff6c8603523c42a42d73388b1713a2d2ae918f 100644 --- a/contracts/currency/currency.cpp +++ b/contracts/currency/currency.cpp @@ -18,11 +18,6 @@ struct CurrencyAccount { static Name tableId() { return Name("singlton"); } }; -void init() { - /// scope key value - Db::store( "currency", "account", CurrencyAccount( 1000ll*1000ll*1000ll ) ); -} - void apply_currency_transfer() { const auto& transfer = currentMessage(); @@ -47,5 +42,21 @@ void apply_currency_transfer() { Db::store( transfer.to, "account", to_account ); } - +export "C" { + void init() { + /// scope key value + Db::store( "currency", "account", CurrencyAccount( 1000ll*1000ll*1000ll ) ); + } + + +// void validate( uint64_t code, uint64_t action ) { } +// void precondition( uint64_t code, uint64_t action ) { } + /** + * The apply method implements the dispatch of events to this contract + */ + void apply( uint64_t code, uint64_t action ) { + assert( code == currentCode() ); + if( action == "transfer" ) apply_currency_transfer(); + } +} diff --git a/contracts/exchange/exchange.cpp b/contracts/exchange/exchange.cpp index d897fe14bdeb02bc1ab33324e518164c9b0d22ef..c7e6f6d7431a4f29cb9a62b215caf8d6ce973870 100644 --- a/contracts/exchange/exchange.cpp +++ b/contracts/exchange/exchange.cpp @@ -50,13 +50,6 @@ struct Account { }; -extern "C" { -void init() { - setAuthority( "currencya", "transfer", "anyone" ); - setAuthority( "currencyb", "transfer", "anyone" ); - registerHandler( "apply", "currencya", "transfer" ); - registerHandler( "apply", "currencyb", "transfer" ); -} /** * This method is called after the "transfer" action of code @@ -116,4 +109,26 @@ void apply_currencyb_transfer() { } } -} // extern "C" + +export "C" { + void init() { + setAuthority( "currencya", "transfer", "anyone" ); + setAuthority( "currencyb", "transfer", "anyone" ); + registerHandler( "apply", "currencya", "transfer" ); + registerHandler( "apply", "currencyb", "transfer" ); + } + +// void validate( uint64_t code, uint64_t action ) { } +// void precondition( uint64_t code, uint64_t action ) { } + /** + * The apply method implements the dispatch of events to this contract + */ + void apply( uint64_t code, uint64_t action ) { + if( code == "currencya" ) { + if( action == "transfer" ) apply_currencya_transfer(); + } else if( code == "currencyb" ) { + if( action == "transfer" ) apply_currencyb_transfer(); + } else { + } + } +}