package executor

import (
	"github.com/33cn/chain33/types"
	brokertypes "github.com/33cn/plugin/plugin/dapp/broker/types"
)

/*
 * 实现交易的链上执行接口
 * 关键数据上链（statedb）并生成交易回执（log）
 */

func (b *broker) Exec_Init(payload *brokertypes.Init,tx *types.Transaction, index int)(*types.Receipt, error){
	db := newBrokerDB(b,tx,index)
	return db.initBroker(payload)
}

func (b *broker) Exec_RegisterExector(payload *brokertypes.RegisterExector, tx *types.Transaction, index int) (*types.Receipt, error) {
	db := newBrokerDB(b,tx,index)
	return db.register(payload)
}

func (b *broker) Exec_Audit(payload *brokertypes.Audit, tx *types.Transaction, index int) (*types.Receipt, error) {
	db := newBrokerDB(b,tx,index)
	//implement code 1.授权执行器  2.跨链账户是否需要授权
	return db.audit(payload)
}

func (b *broker) Exec_UpdateIndex(payload *brokertypes.UpdateIndex, tx *types.Transaction, index int) (*types.Receipt, error) {
	db := newBrokerDB(b,tx,index)
	return db.updateIndex(payload)
}
func (b *broker) Exec_EmitInterchainEvent(payload *brokertypes.InterchainEvent, tx *types.Transaction, index int) (*types.Receipt, error) {
	db := newBrokerDB(b,tx,index)
	return db.emitInterchainEvent(payload)
}
