提交 4bf688ba 编写于 作者: D Daniel Larimer

add dispatch method to contract

上级 898947fc
......@@ -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<Transfer>();
......@@ -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();
}
}
......@@ -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 {
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册