Commit 86b5aa01 authored by vipwzw's avatar vipwzw

update oracle

parent 6aa5072a
...@@ -12,6 +12,7 @@ chain33_raft-1 ...@@ -12,6 +12,7 @@ chain33_raft-1
build/datadir build/datadir
build/bityuan* build/bityuan*
build/para build/para
build/cli
build/execblock build/execblock
build/relayd build/relayd
build/relayd.toml build/relayd.toml
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
_ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen _ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen _ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen _ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/oracle" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen _ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen _ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/privacy" //auto gen _ "github.com/33cn/plugin/plugin/dapp/privacy" //auto gen
......
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package commands
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
oraclety "github.com/33cn/plugin/plugin/dapp/oracle/types"
"github.com/spf13/cobra"
)
// OracleCmd 预言机命令行
func OracleCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle",
Short: "oracle management",
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(
OraclePublishEventRawTxCmd(),
OracleAbortEventRawTxCmd(),
OraclePrePublishResultRawTxCmd(),
OracleAbortPrePubResultRawTxCmd(),
OraclePublishResultRawTxCmd(),
OracleQueryRawTxCmd(),
)
return cmd
}
// OraclePublishEventRawTxCmd 发布事件
func OraclePublishEventRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "publish_event",
Short: "publish a new event",
Run: publishEvent,
}
addPublishEventFlags(cmd)
return cmd
}
func addPublishEventFlags(cmd *cobra.Command) {
cmd.Flags().StringP("type", "t", "", "event type, such as \"football\"")
cmd.MarkFlagRequired("type")
cmd.Flags().StringP("subtype", "s", "", "event subtype, such as \"Premier League\"")
cmd.MarkFlagRequired("subtype")
cmd.Flags().StringP("time", "m", "", "time that event result may be shown, such as \"2019-01-21 15:30:00\"")
cmd.MarkFlagRequired("time")
cmd.Flags().StringP("content", "c", "", "event content, such as '{\"team1\":\"ChelSea\", \"team2\":\"Manchester\",\"resultType\":\"score\"}'")
cmd.MarkFlagRequired("content")
cmd.Flags().StringP("introduction", "i", "", "event introduction, such as \"guess the sore result of football game between ChelSea and Manchester in 2019-01-21 14:00:00\"")
cmd.MarkFlagRequired("introduction")
}
func publishEvent(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ty, _ := cmd.Flags().GetString("type")
subType, _ := cmd.Flags().GetString("subtype")
introduction, _ := cmd.Flags().GetString("introduction")
timeString, _ := cmd.Flags().GetString("time")
content, _ := cmd.Flags().GetString("content")
layout := "2006-01-02 15:04:05"
t, err := time.Parse(layout, timeString)
if err != nil {
fmt.Printf("time error:%v\n", err.Error())
return
}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oraclety.OracleX),
ActionName: oraclety.CreateEventPublishTx,
Payload: []byte(fmt.Sprintf("{\"type\":\"%s\",\"subType\":\"%s\",\"time\":%d, \"content\":\"%s\", \"introduction\":\"%s\"}", ty, subType, t.Unix(), content, introduction)),
}
var res string
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// OracleAbortEventRawTxCmd 取消发布事件
func OracleAbortEventRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "abort_publish_event",
Short: "abort publish the event",
Run: abortPublishEvent,
}
addAbortPublishEventFlags(cmd)
return cmd
}
func addAbortPublishEventFlags(cmd *cobra.Command) {
cmd.Flags().StringP("eventID", "e", "", "eventID")
cmd.MarkFlagRequired("eventID")
}
func abortPublishEvent(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
eventID, _ := cmd.Flags().GetString("eventID")
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oraclety.OracleX),
ActionName: oraclety.CreateAbortEventPublishTx,
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\"}", eventID)),
}
var res string
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// OraclePrePublishResultRawTxCmd 预发布结果
func OraclePrePublishResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "prepublish_result",
Short: "pre publish result of a new event",
Run: prePublishResult,
}
addPrePublishResultFlags(cmd)
return cmd
}
func addPrePublishResultFlags(cmd *cobra.Command) {
cmd.Flags().StringP("eventID", "e", "", "eventID")
cmd.MarkFlagRequired("eventID")
cmd.Flags().StringP("source", "s", "", "source where result from")
cmd.MarkFlagRequired("source")
cmd.Flags().StringP("result", "r", "", "result string")
cmd.MarkFlagRequired("result")
}
func prePublishResult(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
eventID, _ := cmd.Flags().GetString("eventID")
source, _ := cmd.Flags().GetString("source")
result, _ := cmd.Flags().GetString("result")
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oraclety.OracleX),
ActionName: oraclety.CreatePrePublishResultTx,
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\", \"source\":\"%s\", \"result\":\"%s\"}", eventID, source, result)),
}
var res string
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// OracleAbortPrePubResultRawTxCmd 取消预发布的事件结果
func OracleAbortPrePubResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "abort_result",
Short: "abort result pre-published before",
Run: abortPrePubResult,
}
addAbortPrePubResultFlags(cmd)
return cmd
}
func addAbortPrePubResultFlags(cmd *cobra.Command) {
cmd.Flags().StringP("eventID", "e", "", "eventID")
cmd.MarkFlagRequired("eventID")
}
func abortPrePubResult(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
eventID, _ := cmd.Flags().GetString("eventID")
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oraclety.OracleX),
ActionName: oraclety.CreateAbortResultPrePublishTx,
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\"}", eventID)),
}
var res string
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// OraclePublishResultRawTxCmd 发布事件结果
func OraclePublishResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "publish_result",
Short: "publish final result event",
Run: publishResult,
}
addPublishResultFlags(cmd)
return cmd
}
func addPublishResultFlags(cmd *cobra.Command) {
cmd.Flags().StringP("eventID", "e", "", "eventID")
cmd.MarkFlagRequired("eventID")
cmd.Flags().StringP("source", "s", "", "source where result from")
cmd.MarkFlagRequired("source")
cmd.Flags().StringP("result", "r", "", "result string, such as \"{\"team1\":3, \"team2\":2}\"")
cmd.MarkFlagRequired("result")
}
func publishResult(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
eventID, _ := cmd.Flags().GetString("eventID")
source, _ := cmd.Flags().GetString("source")
result, _ := cmd.Flags().GetString("result")
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oraclety.OracleX),
ActionName: oraclety.CreateResultPublishTx,
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\", \"source\":\"%s\", \"result\":\"%s\"}", eventID, source, result)),
}
var res string
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// OracleQueryRawTxCmd 查询事件
func OracleQueryRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "query",
Short: "query event and event status",
Run: oracleQuery,
}
addOracleQueryFlags(cmd)
return cmd
}
func addOracleQueryFlags(cmd *cobra.Command) {
cmd.Flags().StringP("last_eventID", "l", "", "last eventID, to get next page data")
cmd.MarkFlagRequired("last_eventID")
cmd.Flags().StringP("type", "t", "", "event type, such as \"football\"")
cmd.MarkFlagRequired("type")
cmd.Flags().StringP("status", "s", "", "status, number 1-5")
cmd.MarkFlagRequired("status")
cmd.Flags().StringP("addr", "a", "", "address of event creator")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("eventIDs", "d", "", "eventIDs, used for query eventInfo, use comma between many ids")
cmd.MarkFlagRequired("eventIDs")
}
func oracleQuery(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
lastEventID, _ := cmd.Flags().GetString("last_eventID")
eventIDs, _ := cmd.Flags().GetString("eventIDs")
ty, _ := cmd.Flags().GetString("type")
statusStr, _ := cmd.Flags().GetString("status")
status, _ := strconv.ParseInt(statusStr, 10, 32)
addr, _ := cmd.Flags().GetString("addr")
var params rpctypes.Query4Jrpc
params.Execer = oraclety.OracleX
req := &oraclety.QueryEventID{
Status: int32(status),
Addr: addr,
Type: ty,
EventID: lastEventID,
}
params.Payload = types.MustPBToJSON(req)
if eventIDs != "" {
params.FuncName = oraclety.FuncNameQueryOracleListByIDs
var eIDs []string
ids := strings.Split(eventIDs, ",")
eIDs = append(eIDs, ids...)
req := &oraclety.QueryOracleInfos{EventID: eIDs}
params.Payload = types.MustPBToJSON(req)
var res oraclety.ReplyOracleStatusList
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else if statusStr != "" {
if status < 0 || status > 5 {
fmt.Println("Error: status must be 1-5")
cmd.Help()
return
} else if addr != "" {
params.FuncName = oraclety.FuncNameQueryEventIDByAddrAndStatus
} else if ty != "" {
params.FuncName = oraclety.FuncNameQueryEventIDByTypeAndStatus
} else {
params.FuncName = oraclety.FuncNameQueryEventIDByStatus
}
var res oraclety.ReplyEventIDs
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else {
fmt.Println("Error: requeres at least one of eventID, eventIDs, status")
cmd.Help()
}
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
/*
数据发布合约流程
1 由管理员通过manage合约增加问题发布者信息,数据预发布者信息,数据最终发布者信息
2 问题发布者发布问题
2.1 问题发布者撤销问题
3 数据预发布者预发布数据
3.1 数据预发布者撤销预发布数据
4 数据最终发布者发布数据
5 通过查询接口查询问题结果
*/
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
func (o *oracle) Exec_EventPublish(payload *oty.EventPublish, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newOracleAction(o, tx, index)
return action.eventPublish(payload)
}
func (o *oracle) Exec_EventAbort(payload *oty.EventAbort, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newOracleAction(o, tx, index)
return action.eventAbort(payload)
}
func (o *oracle) Exec_ResultPrePublish(payload *oty.ResultPrePublish, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newOracleAction(o, tx, index)
return action.resultPrePublish(payload)
}
func (o *oracle) Exec_ResultAbort(payload *oty.ResultAbort, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newOracleAction(o, tx, index)
return action.resultAbort(payload)
}
func (o *oracle) Exec_ResultPublish(payload *oty.ResultPublish, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newOracleAction(o, tx, index)
return action.resultPublish(payload)
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
func (o *oracle) execDelLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
table := oty.NewTable(o.GetLocalDB())
for _, item := range receipt.Logs {
var oraclelog oty.ReceiptOracle
err := types.Decode(item.Log, &oraclelog)
if err != nil {
return nil, err
}
//回滚时如果状态为EventPublished则删除记录,否则回滚至上一状态
if oraclelog.Status == oty.EventPublished {
err = table.Del([]byte(oraclelog.EventID))
if err != nil {
return nil, err
}
} else {
oraclelog.Status = oraclelog.PreStatus
err = table.Replace(&oraclelog)
if err != nil {
return nil, err
}
}
kvs, err := table.Save()
if err != nil {
return nil, err
}
set.KV = append(set.KV, kvs...)
}
return set, nil
}
func (o *oracle) ExecDelLocal_EventPublish(payload *oty.EventPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_EventAbort(payload *oty.EventAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultPrePublish(payload *oty.ResultPrePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultAbort(payload *oty.ResultAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultPublish(payload *oty.ResultPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
func (o *oracle) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
table := oty.NewTable(o.GetLocalDB())
for _, item := range receipt.Logs {
if item.Ty >= oty.TyLogEventPublish && item.Ty <= oty.TyLogResultPublish {
var oraclelog oty.ReceiptOracle
err := types.Decode(item.Log, &oraclelog)
if err != nil {
return nil, err
}
err = table.Replace(&oraclelog)
if err != nil {
return nil, err
}
kvs, err := table.Save()
if err != nil {
return nil, err
}
set.KV = append(set.KV, kvs...)
}
}
return set, nil
}
func (o *oracle) ExecLocal_EventPublish(payload *oty.EventPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execLocal(receiptData)
}
func (o *oracle) ExecLocal_EventAbort(payload *oty.EventAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execLocal(receiptData)
}
func (o *oracle) ExecLocal_ResultPrePublish(payload *oty.ResultPrePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execLocal(receiptData)
}
func (o *oracle) ExecLocal_ResultAbort(payload *oty.ResultAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execLocal(receiptData)
}
func (o *oracle) ExecLocal_ResultPublish(payload *oty.ResultPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execLocal(receiptData)
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
log "github.com/33cn/chain33/common/log/log15"
drivers "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
var olog = log.New("module", "execs.oracle")
var driverName = oty.OracleX
// Init 执行器初始化
func Init(name string, sub []byte) {
drivers.Register(newOracle().GetName(), newOracle, types.GetDappFork(driverName, "Enable"))
}
// GetName 获取oracle执行器名
func GetName() string {
return newOracle().GetName()
}
func newOracle() drivers.Driver {
t := &oracle{}
t.SetChild(t)
t.SetExecutorType(types.LoadExecutorType(driverName))
return t
}
func init() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&oracle{}))
}
// oracle driver
type oracle struct {
drivers.DriverBase
}
func (ora *oracle) GetDriverName() string {
return oty.OracleX
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
// operation key manage need define
const (
publishEventKey = "oracle-publish-event"
//prePublishResultKey = "oracle-prepublish-result"
//publishResultKey = "oracle-publish-result"
)
// OracleDB struct
type OracleDB struct {
oty.OracleStatus
}
// NewOracleDB instance
func NewOracleDB(eventID, addr, ty, subTy, content, introduction string, time int64, index int64) *OracleDB {
oracle := &OracleDB{}
oracle.EventID = eventID
oracle.Addr = addr
oracle.Type = ty
oracle.SubType = subTy
oracle.Content = content
oracle.Introduction = introduction
oracle.Time = time
oracle.Status = &oty.EventStatus{OpAddr: addr, Status: oty.EventPublished}
oracle.PreStatus = &oty.EventStatus{OpAddr: "", Status: oty.NoEvent}
return oracle
}
// GetKVSet for OracleDB
func (o *OracleDB) GetKVSet() (kvset []*types.KeyValue) {
value := types.Encode(&o.OracleStatus)
kvset = append(kvset, &types.KeyValue{Key: Key(o.EventID), Value: value})
return kvset
}
// Save for OracleDB
func (o *OracleDB) save(db dbm.KV) {
set := o.GetKVSet()
for i := 0; i < len(set); i++ {
db.Set(set[i].GetKey(), set[i].Value)
}
}
// Key for oracle
func Key(id string) (key []byte) {
key = append(key, []byte("mavl-"+oty.OracleX+"-")...)
key = append(key, []byte(id)...)
return key
}
type oracleAction struct {
db dbm.KV
txhash []byte
fromaddr string
blocktime int64
height int64
index int
}
func newOracleAction(o *oracle, tx *types.Transaction, index int) *oracleAction {
hash := tx.Hash()
fromaddr := tx.From()
return &oracleAction{o.GetStateDB(), hash, fromaddr,
o.GetBlockTime(), o.GetHeight(), index}
}
func (action *oracleAction) eventPublish(event *oty.EventPublish) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
var receipt *types.Receipt
eventID := common.ToHex(action.txhash)
// 事件结果公布事件必须大于区块时间
if event.Time <= action.blocktime {
return nil, oty.ErrTimeMustBeFuture
}
// 是否是事件发布者
if !isEventPublisher(action.fromaddr, action.db, false) {
return nil, oty.ErrNoPrivilege
}
_, err := findOracleStatus(action.db, eventID)
if err != types.ErrNotFound {
olog.Error("EventPublish", "EventPublish repeated eventID", eventID)
return nil, oty.ErrOracleRepeatHash
}
eventStatus := NewOracleDB(eventID, action.fromaddr, event.Type, event.SubType, event.Content, event.Introduction, event.Time, action.GetIndex())
olog.Debug("eventPublish", "PublisherAddr", eventStatus.Addr, "EventID", eventStatus.EventID, "Event", eventStatus.Content)
eventStatus.save(action.db)
kv = append(kv, eventStatus.GetKVSet()...)
receiptLog := action.getOracleCommonRecipt(&eventStatus.OracleStatus, oty.TyLogEventPublish)
logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
func (action *oracleAction) eventAbort(event *oty.EventAbort) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
var receipt *types.Receipt
//只有发布问题的人能取消问题
if !isEventPublisher(action.fromaddr, action.db, false) {
return nil, oty.ErrNoPrivilege
}
oracleStatus, err := findOracleStatus(action.db, event.EventID)
if err == types.ErrNotFound {
olog.Error("EventAbort", "EventAbort not found eventID", event.EventID)
return nil, oty.ErrEventIDNotFound
}
ora := &OracleDB{*oracleStatus}
if ora.Status.Status != oty.EventPublished && ora.Status.Status != oty.ResultAborted {
olog.Error("EventAbort", "EventAbort can not abort for status", ora.Status.Status)
return nil, oty.ErrEventAbortNotAllowed
}
updateStatus(ora, action.GetIndex(), action.fromaddr, oty.EventAborted)
ora.save(action.db)
kv = append(kv, ora.GetKVSet()...)
receiptLog := action.getOracleCommonRecipt(&ora.OracleStatus, oty.TyLogEventAbort)
logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
func (action *oracleAction) resultPrePublish(event *oty.ResultPrePublish) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
var receipt *types.Receipt
//只有发布问题的人能取消问题
if !isEventPublisher(action.fromaddr, action.db, false) {
return nil, oty.ErrNoPrivilege
}
oracleStatus, err := findOracleStatus(action.db, event.EventID)
if err == types.ErrNotFound {
olog.Error("ResultPrePublish", "ResultPrePublish not found eventID", event.EventID)
return nil, oty.ErrEventIDNotFound
}
ora := &OracleDB{*oracleStatus}
if ora.Status.Status != oty.EventPublished && ora.Status.Status != oty.ResultAborted {
olog.Error("ResultPrePublish", "ResultPrePublish can not pre-publish", ora.Status.Status)
return nil, oty.ErrResultPrePublishNotAllowed
}
updateStatus(ora, action.GetIndex(), action.fromaddr, oty.ResultPrePublished)
ora.Result = event.Result
ora.Source = event.Source
ora.save(action.db)
kv = append(kv, ora.GetKVSet()...)
receiptLog := action.getOracleCommonRecipt(&ora.OracleStatus, oty.TyLogResultPrePublish)
logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
func (action *oracleAction) resultAbort(event *oty.ResultAbort) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
var receipt *types.Receipt
//只有发布问题的人能取消预发布
if !isEventPublisher(action.fromaddr, action.db, false) {
return nil, oty.ErrNoPrivilege
}
oracleStatus, err := findOracleStatus(action.db, event.EventID)
if err == types.ErrNotFound {
olog.Error("ResultAbort", "ResultAbort not found eventID", event.EventID)
return nil, oty.ErrEventIDNotFound
}
ora := &OracleDB{*oracleStatus}
if ora.Status.Status != oty.ResultPrePublished {
olog.Error("ResultAbort", "ResultAbort can not abort", ora.Status.Status)
return nil, oty.ErrPrePublishAbortNotAllowed
}
updateStatus(ora, action.GetIndex(), action.fromaddr, oty.ResultAborted)
ora.Result = ""
ora.Source = ""
ora.save(action.db)
kv = append(kv, ora.GetKVSet()...)
receiptLog := action.getOracleCommonRecipt(&ora.OracleStatus, oty.TyLogResultAbort)
logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
func (action *oracleAction) resultPublish(event *oty.ResultPublish) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
var receipt *types.Receipt
//只有发布问题的人能取消预发布
if !isEventPublisher(action.fromaddr, action.db, false) {
return nil, oty.ErrNoPrivilege
}
oracleStatus, err := findOracleStatus(action.db, event.EventID)
if err == types.ErrNotFound {
olog.Error("ResultPublish", "ResultPublish not found eventID", event.EventID)
return nil, oty.ErrEventIDNotFound
}
ora := &OracleDB{*oracleStatus}
if ora.Status.Status != oty.ResultPrePublished {
olog.Error("ResultPublish", "ResultPublish can not abort", ora.Status.Status)
return nil, oty.ErrResultPublishNotAllowed
}
updateStatus(ora, action.GetIndex(), action.fromaddr, oty.ResultPublished)
ora.Result = event.Result
ora.Source = event.Source
ora.save(action.db)
kv = append(kv, ora.GetKVSet()...)
receiptLog := action.getOracleCommonRecipt(&ora.OracleStatus, oty.TyLogResultPublish)
logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
// GetIndex returns index in block
func (action *oracleAction) GetIndex() int64 {
return action.height*types.MaxTxsPerBlock + int64(action.index)
}
func (action *oracleAction) getOracleCommonRecipt(status *oty.OracleStatus, logTy int32) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = logTy
o := &oty.ReceiptOracle{}
o.EventID = status.EventID
o.Status = status.GetStatus().Status
o.Addr = status.Addr
o.Type = status.Type
o.PreStatus = status.GetPreStatus().Status
log.Log = types.Encode(o)
return log
}
func getManageKey(key string, db dbm.KV) ([]byte, error) {
manageKey := types.ManageKey(key)
value, err := db.Get([]byte(manageKey))
if err != nil {
return nil, err
}
return value, nil
}
func isEventPublisher(addr string, db dbm.KV, isSolo bool) bool {
if isSolo {
return true
}
value, err := getManageKey(publishEventKey, db)
if err != nil {
olog.Error("OracleEventPublish", "publishEventKey", publishEventKey)
return false
}
if value == nil {
olog.Error("OracleEventPublish found nil value")
return false
}
var item types.ConfigItem
err = types.Decode(value, &item)
if err != nil {
olog.Error("OracleEventPublish", "Decode", value)
return false
}
for _, op := range item.GetArr().Value {
if op == addr {
return true
}
}
return false
}
func findOracleStatus(db dbm.KV, eventID string) (*oty.OracleStatus, error) {
data, err := db.Get(Key(eventID))
if err != nil {
olog.Debug("findOracleStatus", "get", err)
return nil, err
}
var oracleStatus oty.OracleStatus
//decode
err = types.Decode(data, &oracleStatus)
if err != nil {
olog.Debug("findOracleStatus", "decode", err)
return nil, err
}
return &oracleStatus, nil
}
func updateStatus(ora *OracleDB, curIndex int64, addr string, status int32) {
ora.PreStatus.Status = ora.Status.Status
ora.PreStatus.OpAddr = ora.Status.OpAddr
ora.Status.OpAddr = addr
ora.Status.Status = status
}
// getOracleLisByIDs 获取eventinfo
func getOracleLisByIDs(db dbm.KV, infos *oty.QueryOracleInfos) (types.Message, error) {
if len(infos.EventID) == 0 {
return nil, oty.ErrParamNeedIDs
}
var status []*oty.OracleStatus
for i := 0; i < len(infos.EventID); i++ {
id := infos.EventID[i]
game, err := findOracleStatus(db, id)
if err != nil {
return nil, err
}
status = append(status, game)
}
return &oty.ReplyOracleStatusList{Status: status}, nil
}
func getEventIDListByStatus(db dbm.KVDB, status int32, eventID string) (types.Message, error) {
if status <= oty.NoEvent || status > oty.ResultPublished {
return nil, oty.ErrParamStatusInvalid
}
data := &oty.ReceiptOracle{
EventID: eventID,
Status: status,
}
return listData(db, data, oty.DefaultCount, oty.ListDESC)
}
func getEventIDListByAddrAndStatus(db dbm.KVDB, addr string, status int32, eventID string) (types.Message, error) {
if status <= oty.NoEvent || status > oty.ResultPublished {
return nil, oty.ErrParamStatusInvalid
}
if len(addr) == 0 {
return nil, oty.ErrParamAddressMustnotEmpty
}
data := &oty.ReceiptOracle{
EventID: eventID,
Status: status,
Addr: addr,
}
return listData(db, data, oty.DefaultCount, oty.ListDESC)
}
func getEventIDListByTypeAndStatus(db dbm.KVDB, ty string, status int32, eventID string) (types.Message, error) {
if status <= oty.NoEvent || status > oty.ResultPublished {
return nil, oty.ErrParamStatusInvalid
}
if len(ty) == 0 {
return nil, oty.ErrParamTypeMustNotEmpty
}
data := &oty.ReceiptOracle{
EventID: eventID,
Status: status,
Type: ty,
}
return listData(db, data, oty.DefaultCount, oty.ListDESC)
}
func listData(db dbm.KVDB, data *oty.ReceiptOracle, count, direction int32) (types.Message, error) {
query := oty.NewTable(db).GetQuery(db)
var primary []byte
if len(data.EventID) > 0 {
primary = []byte(data.EventID)
}
var rows []*table.Row
var err error
if len(data.Addr) > 0 {
rows, err = query.List("addr_status", data, primary, count, direction)
if err != nil {
return nil, err
}
} else if len(data.Type) > 0 {
rows, err = query.List("type_status", data, primary, count, direction)
if err != nil {
return nil, err
}
} else {
rows, err = query.List("status", data, primary, count, direction)
if err != nil {
return nil, err
}
}
var gameIds []string
for _, row := range rows {
gameIds = append(gameIds, string(row.Primary))
}
if len(gameIds) == 0 {
return nil, types.ErrNotFound
}
return &oty.ReplyEventIDs{EventID: gameIds}, nil
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/33cn/chain33/types"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
//从statedb 读取原始数据
func (o *oracle) Query_QueryOraclesByIDs(in *oty.QueryOracleInfos) (types.Message, error) {
return getOracleLisByIDs(o.GetStateDB(), in)
}
//通过状态查询ids
func (o *oracle) Query_QueryEventIDsByStatus(in *oty.QueryEventID) (types.Message, error) {
eventIds, err := getEventIDListByStatus(o.GetLocalDB(), in.Status, in.EventID)
if err != nil {
return nil, err
}
return eventIds, nil
}
//通过状态 和 地址查询
func (o *oracle) Query_QueryEventIDsByAddrAndStatus(in *oty.QueryEventID) (types.Message, error) {
eventIds, err := getEventIDListByAddrAndStatus(o.GetLocalDB(), in.Addr, in.Status, in.EventID)
if err != nil {
return nil, err
}
return eventIds, nil
}
//通过类型和状态查询
func (o *oracle) Query_QueryEventIDsByTypeAndStatus(in *oty.QueryEventID) (types.Message, error) {
eventIds, err := getEventIDListByTypeAndStatus(o.GetLocalDB(), in.Type, in.Status, in.EventID)
if err != nil {
return nil, err
}
return eventIds, nil
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package oracle
import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/oracle/commands"
"github.com/33cn/plugin/plugin/dapp/oracle/executor"
"github.com/33cn/plugin/plugin/dapp/oracle/types"
)
func init() {
pluginmgr.Register(&pluginmgr.PluginBase{
Name: types.OracleX,
ExecName: executor.GetName(),
Exec: executor.Init,
Cmd: commands.OracleCmd,
//RPC: rpc.Init,
})
}
all:
sh ./create_protobuf.sh
#!/bin/sh
protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="../../../../vendor/github.com/33cn/chain33/types/proto/"
syntax = "proto3";
package types;
//事件
message OracleStatus {
string eventID = 1; //事件ID
string addr = 2; //发布者地址
string type = 3; //游戏类别
string subType = 4; //游戏子类别
int64 time = 5; //结果公布参考时间
string content = 6; //事件内容
string introduction = 7; //事件描述
EventStatus status = 8; //操作状态
string source = 9; //数据来源
string result = 10; //事件结果
EventStatus preStatus=11; //上次操作后状态及操作者地址
}
// action
message OracleAction {
oneof value {
EventPublish eventPublish = 1;
EventAbort eventAbort = 2;
ResultPrePublish resultPrePublish = 3;
ResultPublish resultPublish = 4;
ResultAbort resultAbort = 5;
}
int32 Ty = 7;
}
message EventStatus {
string opAddr = 1; //修改事件状态的地址
int32 status = 2; //事件状态
}
message EventPublish {
string type = 2; //游戏类别
string subType = 3; //游戏子类别
int64 time = 4; //结果公布参考时间
string content = 5; //事件内容
string introduction = 6; //事件描述
}
message EventAbort {
string eventID = 2; //发布事件的ID
}
message ResultPrePublish {
string eventID = 2; //发布事件的ID
string source = 3; //数据来源
string result = 4; //发布数据
}
message ResultPublish {
string eventID = 2; //发布事件的ID
string source = 3; //数据来源
string result = 4; //发布数据
}
message ResultAbort {
string eventID = 2; //发布事件的ID
}
// localDB
message EventRecord {
string eventID = 1; //发布的事件的ID
}
message QueryOracleInfos {
repeated string eventID = 1; //发布的事件的ID
}
message ReplyEventIDs {
repeated string eventID = 1; //发布事件的ID
}
message QueryEventID {
int32 status = 1; //事件状态
string addr = 2; //事件发布者的地址
string type = 3; //事件类型
string eventID = 4; //事件ID
}
message ReceiptOracle {
string eventID = 1; //发布事件ID
int32 status = 2; //事件状态
string addr = 3; //事件发布者的地址
string type = 4; //事件类型
int32 preStatus = 6;//事件的前一个状态
}
message ReplyOracleStatusList {
repeated OracleStatus status = 1; //状态集
}
\ No newline at end of file
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package rpc_test
import (
"fmt"
"strings"
"testing"
"time"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
commonlog "github.com/33cn/chain33/common/log"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
)
func init() {
commonlog.SetLogLevel("error")
}
func TestJRPCChannel(t *testing.T) {
// 启动RPCmocker
mocker := testnode.New("--notset--", nil)
defer func() {
mocker.Close()
}()
mocker.Listen()
jrpcClient := mocker.GetJSONC()
assert.NotNil(t, jrpcClient)
testCases := []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testPublishEventRawCmd},
{fn: testAbortEventRawTxCmd},
{fn: testPrePublishResultRawTxCmd},
{fn: testAbortPrePubResultRawTxCmd},
{fn: testPublishResultRawTxCmd},
}
for index, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
if err == nil {
continue
}
assert.NotEqualf(t, err, types.ErrActionNotSupport, "test index %d", index)
if strings.Contains(err.Error(), "rpc: can't find") {
assert.FailNowf(t, err.Error(), "test index %d", index)
}
}
testCases = []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testQueryOracleListByIDsRawTxCmd},
{fn: testQueryEventIDByAddrAndStatusRawTxCmd},
{fn: testQueryEventIDByTypeAndStatusRawTxCmd},
{fn: testQueryEventIDByStatusRawTxCmd},
}
result := []error{
oty.ErrParamNeedIDs,
oty.ErrParamStatusInvalid,
types.ErrNotFound,
types.ErrNotFound,
}
for index, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
assert.Equal(t, result[index], err, fmt.Sprint(index))
}
}
func testPublishEventRawCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
timeStr := "2019-01-21 15:30:00"
layout := "2006-01-02 15:04:05"
ti, err := time.Parse(layout, timeStr)
if err != nil {
fmt.Printf("time error:%v\n", err.Error())
return errors.Errorf("time error:%v\n", err.Error())
}
payload := &oty.EventPublish{
Type: "football",
SubType: "Premier League",
Time: ti.Unix(),
Content: "{\"team1\":\"ChelSea\", \"team2\":\"Manchester\",\"resultType\":\"score\"}",
Introduction: "guess the sore result of football game between ChelSea and Manchester in 2019-01-21 14:00:00",
}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oty.OracleX),
ActionName: oty.CreateEventPublishTx,
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testAbortEventRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &oty.EventAbort{EventID: "123"}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oty.OracleX),
ActionName: oty.CreateAbortEventPublishTx,
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testPrePublishResultRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &oty.ResultPrePublish{
EventID: "123",
Source: "新浪体育",
Result: "{\"team1\":3, \"team2\":2}",
}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oty.OracleX),
ActionName: oty.CreatePrePublishResultTx,
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testAbortPrePubResultRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &oty.EventAbort{EventID: "123"}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oty.OracleX),
ActionName: oty.CreateAbortResultPrePublishTx,
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testPublishResultRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &oty.ResultPrePublish{
EventID: "123",
Source: "新浪体育",
Result: "{\"team1\":3, \"team2\":2}",
}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(oty.OracleX),
ActionName: oty.CreateResultPublishTx,
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testQueryOracleListByIDsRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &oty.QueryOracleInfos{}
params.Execer = oty.OracleX
params.FuncName = oty.FuncNameQueryOracleListByIDs
params.Payload = types.MustPBToJSON(req)
rep = &oty.ReplyOracleStatusList{}
return jrpc.Call("Chain33.Query", params, rep)
}
func testQueryEventIDByAddrAndStatusRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &oty.QueryEventID{}
params.Execer = oty.OracleX
params.FuncName = oty.FuncNameQueryEventIDByAddrAndStatus
params.Payload = types.MustPBToJSON(req)
rep = &oty.ReplyEventIDs{}
return jrpc.Call("Chain33.Query", params, rep)
}
func testQueryEventIDByTypeAndStatusRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &oty.QueryEventID{
Type: "football",
Status: 1,
Addr: "",
}
params.Execer = oty.OracleX
params.FuncName = oty.FuncNameQueryEventIDByTypeAndStatus
params.Payload = types.MustPBToJSON(req)
rep = &oty.ReplyEventIDs{}
return jrpc.Call("Chain33.Query", params, rep)
}
func testQueryEventIDByStatusRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &oty.QueryEventID{
Status: 1,
Type: "",
Addr: "",
}
params.Execer = oty.OracleX
params.FuncName = oty.FuncNameQueryEventIDByStatus
params.Payload = types.MustPBToJSON(req)
rep = &oty.ReplyEventIDs{}
return jrpc.Call("Chain33.Query", params, rep)
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
/*
操作说明:
1.sendAddPublisher 通过manage合约增加数据发布者地址
2.sendPublishEvent 发布一个事件
3.queryEventByeventID 通过事件ID查询事件状态
4.sendAbortPublishEvent 取消事件发布
5.sendPrePublishResult 预发布事件结果
6.sendAbortPublishResult 取消事件预发布结果
7.sendPublishResult 发布事件最终结果
测试步骤:
1.需要首先在配置文件中增加超级管理员账号,例如:
[exec.sub.manage]
superManager=["14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"]
2.TestPublishNomal 正常发布流程
3.TestAbortPublishEvent 取消事件发布
4.TestPrePublishResult 预发布结果
5.TestAbortPublishResult 取消结果预发布
6.TestPublishResult 发布结果
7.TestQueryEventIDByStatus 按状态查询
8.TestQueryEventIDByAddrAndStatus 按地址和状态查询
9.TestQueryEventIDByTypeAndStatus 按类型和状态查询
*/
package rpc_test
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
_ "github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
oty "github.com/33cn/plugin/plugin/dapp/oracle/types"
"github.com/stretchr/testify/assert"
)
var (
r *rand.Rand
)
func init() {
r = rand.New(rand.NewSource(types.Now().UnixNano()))
}
func getRPCClient(t *testing.T, mocker *testnode.Chain33Mock) *jsonclient.JSONClient {
jrpcClient := mocker.GetJSONC()
assert.NotNil(t, jrpcClient)
return jrpcClient
}
func getTx(t *testing.T, hex string) *types.Transaction {
data, err := common.FromHex(hex)
assert.Nil(t, err)
var tx types.Transaction
err = types.Decode(data, &tx)
assert.Nil(t, err)
return &tx
}
func TestPublishNomal(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
// publish event
eventID := sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
//pre publish result
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
//publish result
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
}
func TestPublishEvent(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
// publish event
// abort event
// publish event
eventID := sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
eventoldID := eventID
eventID = sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
assert.NotEqual(t, eventID, eventoldID)
// publish event
// pre publish result
// publish event
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
eventoldID = eventID
eventID = sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
assert.NotEqual(t, eventID, eventoldID)
// publish event
// pre publish result
// publilsh result
// publish event
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
eventoldID = eventID
eventID = sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
assert.NotEqual(t, eventID, eventoldID)
}
func TestAbortPublishEvent(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
// publish event
// abort event
// abort event
eventID := sendPublishEvent(t, jrpcClient, mocker)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, oty.ErrEventAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
// publish event
// pre publish result
// abort event
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, oty.ErrEventAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
// publish event
// pre publish result
// abort pre publilsh result
// abort event
sendAbortPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, oty.ErrEventAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
// publish event
// pre publish result
// publilsh result
// abort event
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, oty.ErrEventAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
}
func TestPrePublishResult(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
// publish event
// pre publish result
// pre publish result
eventID := sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
sendPrePublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPrePublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
// publish event
// abort event
// pre publish
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
sendPrePublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPrePublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
// publish event
// pre publish result
// abort pre publish result
// pre publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
//publish result
//pre publish result
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
sendPrePublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPrePublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
}
func TestAbortPublishResult(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
//publish event
//abort prepublish result
eventID := sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, oty.ErrPrePublishAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
// publish event
// abort event
// abort pre publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, oty.ErrPrePublishAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
// publish event
// pre publish result
// abort pre publish result
// abort pre publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPrePublished)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, oty.ErrPrePublishAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
// publish event
// pre publish result
// publish result
// abort pre publish result
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, oty.ErrPrePublishAbortNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
}
func TestPublishResult(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
//publish event
//publish result
eventID := sendPublishEvent(t, jrpcClient, mocker)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
sendPublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventPublished)
// publish event
// abort event
// publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
sendPublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.EventAborted)
// publish event
// pre publish result
// abort pre publish result
// publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
sendPublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultAborted)
// publish event
// pre publish result
// publish result
// publish result
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
sendPublishResult(eventID, t, jrpcClient, mocker, oty.ErrResultPublishNotAllowed)
queryEventByeventID(eventID, t, jrpcClient, oty.ResultPublished)
}
func createAllStatusEvent(t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock) {
//total loop*5
loop := int(oty.DefaultCount + 10)
for i := 0; i < loop; i++ {
//EventPublished
eventID := sendPublishEvent(t, jrpcClient, mocker)
assert.NotEqual(t, "", eventID)
//EventAborted
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendAbortPublishEvent(eventID, t, jrpcClient, mocker, nil)
//ResultPrePublished
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
//ResultAborted
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendAbortPublishResult(eventID, t, jrpcClient, mocker, nil)
//ResultPublished
eventID = sendPublishEvent(t, jrpcClient, mocker)
sendPrePublishResult(eventID, t, jrpcClient, mocker, nil)
sendPublishResult(eventID, t, jrpcClient, mocker, nil)
}
}
func TestQueryEventIDByStatus(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
createAllStatusEvent(t, jrpcClient, mocker)
queryEventByStatus(t, jrpcClient)
}
func TestQueryEventIDByAddrAndStatus(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
createAllStatusEvent(t, jrpcClient, mocker)
queryEventByStatusAndAddr(t, jrpcClient)
}
func TestQueryEventIDByTypeAndStatus(t *testing.T) {
mocker := testnode.New("--free--", nil)
defer mocker.Close()
mocker.Listen()
jrpcClient := getRPCClient(t, mocker)
sendAddPublisher(t, jrpcClient, mocker)
createAllStatusEvent(t, jrpcClient, mocker)
queryEventByStatusAndType(t, jrpcClient)
}
func sendAddPublisher(t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock) {
//1. 调用createrawtransaction 创建交易
req := &rpctypes.CreateTxIn{
Execer: "manage",
ActionName: "Modify",
Payload: []byte("{\"key\":\"oracle-publish-event\",\"op\":\"add\", \"value\":\"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv\"}"),
}
var res string
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
_, err = mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
}
func sendPublishEvent(t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock) (eventID string) {
timeString := "2019-01-21 15:30:00"
layout := "2006-01-02 15:04:05"
ti, err := time.Parse(layout, timeString)
assert.Nil(t, err)
//1. 调用createrawtransaction 创建交易
req := &rpctypes.CreateTxIn{
Execer: oty.OracleX,
ActionName: "EventPublish",
Payload: []byte(fmt.Sprintf("{\"type\":\"football\",\"subType\":\"Premier League\",\"time\":%d, \"content\":\"{\\\"team%d\\\":\\\"ChelSea\\\", \\\"team%d\\\":\\\"Manchester\\\",\\\"resultType\\\":\\\"score\\\"}\", \"introduction\":\"guess the sore result of football game between ChelSea and Manchester in 2019-01-21 14:00:00\"}", ti.Unix(), r.Int()%10, r.Int()%10)),
}
var res string
err = jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
result, err := mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
for _, log := range result.Receipt.Logs {
if log.Ty >= oty.TyLogEventPublish && log.Ty <= oty.TyLogResultPublish {
fmt.Println(log.TyName)
fmt.Println(string(log.Log))
status := oty.ReceiptOracle{}
logData, err := common.FromHex(log.RawLog)
assert.Nil(t, err)
err = types.Decode(logData, &status)
assert.Nil(t, err)
eventID = status.EventID
}
}
return eventID
}
func sendAbortPublishEvent(eventID string, t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock, expectErr error) {
req := &rpctypes.CreateTxIn{
Execer: oty.OracleX,
ActionName: "EventAbort",
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\"}", eventID)),
}
var res string
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
result, err := mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
fmt.Println(string(result.Tx.Payload))
for _, log := range result.Receipt.Logs {
if log.Ty >= oty.TyLogEventPublish && log.Ty <= oty.TyLogResultPublish {
fmt.Println(log.TyName)
fmt.Println(string(log.Log))
} else if log.Ty == 1 {
logData, err := common.FromHex(log.RawLog)
assert.Nil(t, err)
assert.Equal(t, expectErr.Error(), string(logData))
}
}
}
func sendPrePublishResult(eventID string, t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock, expectErr error) {
req := &rpctypes.CreateTxIn{
Execer: oty.OracleX,
ActionName: "ResultPrePublish",
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\", \"source\":\"sina sport\", \"result\":\"%d:%d\"}", eventID, r.Int()%10, r.Int()%10)),
}
var res string
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
result, err := mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
for _, log := range result.Receipt.Logs {
if log.Ty >= oty.TyLogEventPublish && log.Ty <= oty.TyLogResultPublish {
fmt.Println(log.TyName)
fmt.Println(string(log.Log))
} else if log.Ty == 1 {
logData, err := common.FromHex(log.RawLog)
assert.Nil(t, err)
assert.Equal(t, expectErr.Error(), string(logData))
}
}
}
func sendAbortPublishResult(eventID string, t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock, expectErr error) {
req := &rpctypes.CreateTxIn{
Execer: oty.OracleX,
ActionName: "ResultAbort",
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\"}", eventID)),
}
var res string
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
result, err := mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
for _, log := range result.Receipt.Logs {
if log.Ty >= oty.TyLogEventPublish && log.Ty <= oty.TyLogResultPublish {
fmt.Println(log.TyName)
fmt.Println(string(log.Log))
} else if log.Ty == 1 {
logData, err := common.FromHex(log.RawLog)
assert.Nil(t, err)
assert.Equal(t, expectErr.Error(), string(logData))
}
}
}
func sendPublishResult(eventID string, t *testing.T, jrpcClient *jsonclient.JSONClient, mocker *testnode.Chain33Mock, expectErr error) {
req := &rpctypes.CreateTxIn{
Execer: oty.OracleX,
ActionName: "ResultPublish",
Payload: []byte(fmt.Sprintf("{\"eventID\":\"%s\", \"source\":\"sina sport\", \"result\":\"%d:%d\"}", eventID, r.Int()%10, r.Int()%10)),
}
var res string
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
assert.Nil(t, err)
gen := mocker.GetHotKey()
tx := getTx(t, res)
tx.Sign(types.SECP256K1, gen)
reply, err := mocker.GetAPI().SendTx(tx)
assert.Nil(t, err)
result, err := mocker.WaitTx(reply.GetMsg())
assert.Nil(t, err)
for _, log := range result.Receipt.Logs {
if log.Ty >= oty.TyLogEventPublish && log.Ty <= oty.TyLogResultPublish {
fmt.Println(log.TyName)
fmt.Println(string(log.Log))
} else if log.Ty == 1 {
logData, err := common.FromHex(log.RawLog)
assert.Nil(t, err)
assert.Equal(t, expectErr.Error(), string(logData))
}
}
}
func queryEventByeventID(eventID string, t *testing.T, jrpcClient *jsonclient.JSONClient, expectedStatus int32) {
//按事件ID查询事件信息
params := rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryOracleListByIDs,
Payload: []byte(fmt.Sprintf("{\"eventID\":[\"%s\"]}", eventID)),
}
var resStatus oty.ReplyOracleStatusList
err := jrpcClient.Call("Chain33.Query", params, &resStatus)
assert.Nil(t, err)
assert.Equal(t, expectedStatus, resStatus.Status[0].Status.Status)
fmt.Println(resStatus.Status[0])
}
func queryEventByStatus(t *testing.T, jrpcClient *jsonclient.JSONClient) {
for i := 1; i <= 5; i++ {
//查询第一页
params := rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByStatus,
Payload: []byte(fmt.Sprintf("{\"status\":%d,\"addr\":\"\",\"type\":\"\",\"eventID\":\"\"}", i)),
}
var res oty.ReplyEventIDs
err := jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.EqualValues(t, oty.DefaultCount, len(res.EventID))
lastEventID := res.EventID[oty.DefaultCount-1]
//查询下一页
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByStatus,
Payload: []byte(fmt.Sprintf("{\"status\":%d,\"addr\":\"\",\"type\":\"\",\"eventID\":\"%s\"}", i, lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.Equal(t, 10, len(res.EventID))
lastEventID = res.EventID[9]
//查询最后一条后面的,应该查不到
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByStatus,
Payload: []byte(fmt.Sprintf("{\"status\":%d,\"addr\":\"\",\"type\":\"\",\"eventID\":\"%s\"}", i, lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Equal(t, types.ErrNotFound, err)
}
}
func queryEventByStatusAndAddr(t *testing.T, jrpcClient *jsonclient.JSONClient) {
//查询处于事件发布状态的事件
params := rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByAddrAndStatus,
Payload: []byte("{\"status\":1,\"addr\":\"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv\",\"type\":\"\",\"eventID\":\"\"}"),
}
var res oty.ReplyEventIDs
err := jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.EqualValues(t, oty.DefaultCount, len(res.EventID))
lastEventID := res.EventID[oty.DefaultCount-1]
//第二页
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByAddrAndStatus,
Payload: []byte(fmt.Sprintf("{\"status\":1,\"addr\":\"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv\",\"type\":\"\",\"eventID\":\"%s\"}", lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.Equal(t, 10, len(res.EventID))
lastEventID = res.EventID[9]
//最后一条以后查不到
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByAddrAndStatus,
Payload: []byte(fmt.Sprintf("{\"status\":1,\"addr\":\"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt\",\"type\":\"\",\"eventID\":\"%s\"}", lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Equal(t, types.ErrNotFound, err)
//查询另一个地址+状态,应该查不到
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByAddrAndStatus,
Payload: []byte("{\"status\":1,\"addr\":\"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt\",\"type\":\"\",\"eventID\":\"\"}"),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Equal(t, types.ErrNotFound, err)
}
func queryEventByStatusAndType(t *testing.T, jrpcClient *jsonclient.JSONClient) {
//查询处于事件发布状态的事件
params := rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByTypeAndStatus,
Payload: []byte("{\"status\":1,\"addr\":\"\",\"type\":\"football\",\"eventID\":\"\"}"),
}
var res oty.ReplyEventIDs
err := jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.EqualValues(t, oty.DefaultCount, len(res.EventID))
lastEventID := res.EventID[oty.DefaultCount-1]
//第二页
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByTypeAndStatus,
Payload: []byte(fmt.Sprintf("{\"status\":1,\"addr\":\"\",\"type\":\"football\",\"eventID\":\"%s\"}", lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Nil(t, err)
assert.Equal(t, 10, len(res.EventID))
lastEventID = res.EventID[9]
//最后一条以后查不到
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByTypeAndStatus,
Payload: []byte(fmt.Sprintf("{\"status\":1,\"addr\":\"\",\"type\":\"football\",\"eventID\":\"%s\"}", lastEventID)),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Equal(t, types.ErrNotFound, err)
//查询另一种类型+状态查不到
params = rpctypes.Query4Jrpc{
Execer: oty.OracleX,
FuncName: oty.FuncNameQueryEventIDByTypeAndStatus,
Payload: []byte("{\"status\":1,\"addr\":\"\",\"type\":\"gambling\",\"eventID\":\"\"}"),
}
err = jrpcClient.Call("Chain33.Query", params, &res)
assert.Equal(t, types.ErrNotFound, err)
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package types
import "errors"
var (
// OracleX oracle name
OracleX = "oracle"
)
// oracle action type
const (
ActionEventPublish = iota + 1 //事件发布
ActionResultPrePublish
ActionResultPublish
ActionEventAbort
ActionResultAbort
)
// oracle status
const (
NoEvent = iota
EventPublished
EventAborted
ResultPrePublished
ResultAborted
ResultPublished
)
// log type define
const (
TyLogEventPublish = 810
TyLogEventAbort = 811
TyLogResultPrePublish = 812
TyLogResultAbort = 813
TyLogResultPublish = 814
)
// executor action and function define
const (
// FuncNameQueryOracleListByIDs 根据ids查询OracleStatus
FuncNameQueryOracleListByIDs = "QueryOraclesByIDs"
// FuncNameQueryEventIDByStatus 根据状态查询eventID
FuncNameQueryEventIDByStatus = "QueryEventIDsByStatus"
// FuncNameQueryEventIDByAddrAndStatus 根据创建者地址和状态查询eventID
FuncNameQueryEventIDByAddrAndStatus = "QueryEventIDsByAddrAndStatus"
// FuncNameQueryEventIDByTypeAndStatus 根据事件类型和状态查询eventID
FuncNameQueryEventIDByTypeAndStatus = "QueryEventIDsByTypeAndStatus"
// CreateEventPublishTx 创建发布事件交易
CreateEventPublishTx = "EventPublish"
// CreateAbortEventPublishTx 创建取消发布事件交易
CreateAbortEventPublishTx = "EventAbort"
// CreatePrePublishResultTx 创建预发布事件结果交易
CreatePrePublishResultTx = "ResultPrePublish"
// CreateAbortResultPrePublishTx 创建取消预发布的事件结果交易
CreateAbortResultPrePublishTx = "ResultAbort"
// CreateResultPublishTx 创建预发布事件结果交易
CreateResultPublishTx = "ResultPublish"
)
// query param define
const (
// ListDESC 降序
ListDESC = int32(0)
// DefaultCount 默认一次取多少条记录
DefaultCount = int32(20)
)
// Errors for oracle
var (
ErrTimeMustBeFuture = errors.New("ErrTimeMustBeFuture")
ErrNoPrivilege = errors.New("ErrNoPrivilege")
ErrOracleRepeatHash = errors.New("ErrOracleRepeatHash")
ErrEventIDNotFound = errors.New("ErrEventIDNotFound")
ErrEventAbortNotAllowed = errors.New("ErrEventAbortNotAllowed")
ErrResultPrePublishNotAllowed = errors.New("ErrResultPrePublishNotAllowed")
ErrPrePublishAbortNotAllowed = errors.New("ErrPrePublishAbortNotAllowed")
ErrResultPublishNotAllowed = errors.New("ErrResultPublishNotAllowed")
ErrParamNeedIDs = errors.New("ErrParamNeedIDs")
ErrParamStatusInvalid = errors.New("ErrParamStatusInvalid")
ErrParamAddressMustnotEmpty = errors.New("ErrParamAddressMustnotEmpty")
ErrParamTypeMustNotEmpty = errors.New("ErrParamTypeMustNotEmpty")
)
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: oracle.proto
package types
import (
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
//事件
type OracleStatus struct {
EventID string `protobuf:"bytes,1,opt,name=eventID,proto3" json:"eventID,omitempty"`
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
SubType string `protobuf:"bytes,4,opt,name=subType,proto3" json:"subType,omitempty"`
Time int64 `protobuf:"varint,5,opt,name=time,proto3" json:"time,omitempty"`
Content string `protobuf:"bytes,6,opt,name=content,proto3" json:"content,omitempty"`
Introduction string `protobuf:"bytes,7,opt,name=introduction,proto3" json:"introduction,omitempty"`
Status *EventStatus `protobuf:"bytes,8,opt,name=status,proto3" json:"status,omitempty"`
Source string `protobuf:"bytes,9,opt,name=source,proto3" json:"source,omitempty"`
Result string `protobuf:"bytes,10,opt,name=result,proto3" json:"result,omitempty"`
PreStatus *EventStatus `protobuf:"bytes,11,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *OracleStatus) Reset() { *m = OracleStatus{} }
func (m *OracleStatus) String() string { return proto.CompactTextString(m) }
func (*OracleStatus) ProtoMessage() {}
func (*OracleStatus) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{0}
}
func (m *OracleStatus) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_OracleStatus.Unmarshal(m, b)
}
func (m *OracleStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_OracleStatus.Marshal(b, m, deterministic)
}
func (m *OracleStatus) XXX_Merge(src proto.Message) {
xxx_messageInfo_OracleStatus.Merge(m, src)
}
func (m *OracleStatus) XXX_Size() int {
return xxx_messageInfo_OracleStatus.Size(m)
}
func (m *OracleStatus) XXX_DiscardUnknown() {
xxx_messageInfo_OracleStatus.DiscardUnknown(m)
}
var xxx_messageInfo_OracleStatus proto.InternalMessageInfo
func (m *OracleStatus) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
func (m *OracleStatus) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *OracleStatus) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *OracleStatus) GetSubType() string {
if m != nil {
return m.SubType
}
return ""
}
func (m *OracleStatus) GetTime() int64 {
if m != nil {
return m.Time
}
return 0
}
func (m *OracleStatus) GetContent() string {
if m != nil {
return m.Content
}
return ""
}
func (m *OracleStatus) GetIntroduction() string {
if m != nil {
return m.Introduction
}
return ""
}
func (m *OracleStatus) GetStatus() *EventStatus {
if m != nil {
return m.Status
}
return nil
}
func (m *OracleStatus) GetSource() string {
if m != nil {
return m.Source
}
return ""
}
func (m *OracleStatus) GetResult() string {
if m != nil {
return m.Result
}
return ""
}
func (m *OracleStatus) GetPreStatus() *EventStatus {
if m != nil {
return m.PreStatus
}
return nil
}
// action
type OracleAction struct {
// Types that are valid to be assigned to Value:
// *OracleAction_EventPublish
// *OracleAction_EventAbort
// *OracleAction_ResultPrePublish
// *OracleAction_ResultPublish
// *OracleAction_ResultAbort
Value isOracleAction_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,7,opt,name=Ty,proto3" json:"Ty,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *OracleAction) Reset() { *m = OracleAction{} }
func (m *OracleAction) String() string { return proto.CompactTextString(m) }
func (*OracleAction) ProtoMessage() {}
func (*OracleAction) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{1}
}
func (m *OracleAction) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_OracleAction.Unmarshal(m, b)
}
func (m *OracleAction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_OracleAction.Marshal(b, m, deterministic)
}
func (m *OracleAction) XXX_Merge(src proto.Message) {
xxx_messageInfo_OracleAction.Merge(m, src)
}
func (m *OracleAction) XXX_Size() int {
return xxx_messageInfo_OracleAction.Size(m)
}
func (m *OracleAction) XXX_DiscardUnknown() {
xxx_messageInfo_OracleAction.DiscardUnknown(m)
}
var xxx_messageInfo_OracleAction proto.InternalMessageInfo
type isOracleAction_Value interface {
isOracleAction_Value()
}
type OracleAction_EventPublish struct {
EventPublish *EventPublish `protobuf:"bytes,1,opt,name=eventPublish,proto3,oneof"`
}
type OracleAction_EventAbort struct {
EventAbort *EventAbort `protobuf:"bytes,2,opt,name=eventAbort,proto3,oneof"`
}
type OracleAction_ResultPrePublish struct {
ResultPrePublish *ResultPrePublish `protobuf:"bytes,3,opt,name=resultPrePublish,proto3,oneof"`
}
type OracleAction_ResultPublish struct {
ResultPublish *ResultPublish `protobuf:"bytes,4,opt,name=resultPublish,proto3,oneof"`
}
type OracleAction_ResultAbort struct {
ResultAbort *ResultAbort `protobuf:"bytes,5,opt,name=resultAbort,proto3,oneof"`
}
func (*OracleAction_EventPublish) isOracleAction_Value() {}
func (*OracleAction_EventAbort) isOracleAction_Value() {}
func (*OracleAction_ResultPrePublish) isOracleAction_Value() {}
func (*OracleAction_ResultPublish) isOracleAction_Value() {}
func (*OracleAction_ResultAbort) isOracleAction_Value() {}
func (m *OracleAction) GetValue() isOracleAction_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *OracleAction) GetEventPublish() *EventPublish {
if x, ok := m.GetValue().(*OracleAction_EventPublish); ok {
return x.EventPublish
}
return nil
}
func (m *OracleAction) GetEventAbort() *EventAbort {
if x, ok := m.GetValue().(*OracleAction_EventAbort); ok {
return x.EventAbort
}
return nil
}
func (m *OracleAction) GetResultPrePublish() *ResultPrePublish {
if x, ok := m.GetValue().(*OracleAction_ResultPrePublish); ok {
return x.ResultPrePublish
}
return nil
}
func (m *OracleAction) GetResultPublish() *ResultPublish {
if x, ok := m.GetValue().(*OracleAction_ResultPublish); ok {
return x.ResultPublish
}
return nil
}
func (m *OracleAction) GetResultAbort() *ResultAbort {
if x, ok := m.GetValue().(*OracleAction_ResultAbort); ok {
return x.ResultAbort
}
return nil
}
func (m *OracleAction) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*OracleAction) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _OracleAction_OneofMarshaler, _OracleAction_OneofUnmarshaler, _OracleAction_OneofSizer, []interface{}{
(*OracleAction_EventPublish)(nil),
(*OracleAction_EventAbort)(nil),
(*OracleAction_ResultPrePublish)(nil),
(*OracleAction_ResultPublish)(nil),
(*OracleAction_ResultAbort)(nil),
}
}
func _OracleAction_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*OracleAction)
// value
switch x := m.Value.(type) {
case *OracleAction_EventPublish:
b.EncodeVarint(1<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.EventPublish); err != nil {
return err
}
case *OracleAction_EventAbort:
b.EncodeVarint(2<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.EventAbort); err != nil {
return err
}
case *OracleAction_ResultPrePublish:
b.EncodeVarint(3<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ResultPrePublish); err != nil {
return err
}
case *OracleAction_ResultPublish:
b.EncodeVarint(4<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ResultPublish); err != nil {
return err
}
case *OracleAction_ResultAbort:
b.EncodeVarint(5<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.ResultAbort); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("OracleAction.Value has unexpected type %T", x)
}
return nil
}
func _OracleAction_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*OracleAction)
switch tag {
case 1: // value.eventPublish
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(EventPublish)
err := b.DecodeMessage(msg)
m.Value = &OracleAction_EventPublish{msg}
return true, err
case 2: // value.eventAbort
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(EventAbort)
err := b.DecodeMessage(msg)
m.Value = &OracleAction_EventAbort{msg}
return true, err
case 3: // value.resultPrePublish
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ResultPrePublish)
err := b.DecodeMessage(msg)
m.Value = &OracleAction_ResultPrePublish{msg}
return true, err
case 4: // value.resultPublish
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ResultPublish)
err := b.DecodeMessage(msg)
m.Value = &OracleAction_ResultPublish{msg}
return true, err
case 5: // value.resultAbort
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(ResultAbort)
err := b.DecodeMessage(msg)
m.Value = &OracleAction_ResultAbort{msg}
return true, err
default:
return false, nil
}
}
func _OracleAction_OneofSizer(msg proto.Message) (n int) {
m := msg.(*OracleAction)
// value
switch x := m.Value.(type) {
case *OracleAction_EventPublish:
s := proto.Size(x.EventPublish)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *OracleAction_EventAbort:
s := proto.Size(x.EventAbort)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *OracleAction_ResultPrePublish:
s := proto.Size(x.ResultPrePublish)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *OracleAction_ResultPublish:
s := proto.Size(x.ResultPublish)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *OracleAction_ResultAbort:
s := proto.Size(x.ResultAbort)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
type EventStatus struct {
OpAddr string `protobuf:"bytes,1,opt,name=opAddr,proto3" json:"opAddr,omitempty"`
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventStatus) Reset() { *m = EventStatus{} }
func (m *EventStatus) String() string { return proto.CompactTextString(m) }
func (*EventStatus) ProtoMessage() {}
func (*EventStatus) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{2}
}
func (m *EventStatus) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventStatus.Unmarshal(m, b)
}
func (m *EventStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventStatus.Marshal(b, m, deterministic)
}
func (m *EventStatus) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventStatus.Merge(m, src)
}
func (m *EventStatus) XXX_Size() int {
return xxx_messageInfo_EventStatus.Size(m)
}
func (m *EventStatus) XXX_DiscardUnknown() {
xxx_messageInfo_EventStatus.DiscardUnknown(m)
}
var xxx_messageInfo_EventStatus proto.InternalMessageInfo
func (m *EventStatus) GetOpAddr() string {
if m != nil {
return m.OpAddr
}
return ""
}
func (m *EventStatus) GetStatus() int32 {
if m != nil {
return m.Status
}
return 0
}
type EventPublish struct {
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
SubType string `protobuf:"bytes,3,opt,name=subType,proto3" json:"subType,omitempty"`
Time int64 `protobuf:"varint,4,opt,name=time,proto3" json:"time,omitempty"`
Content string `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
Introduction string `protobuf:"bytes,6,opt,name=introduction,proto3" json:"introduction,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventPublish) Reset() { *m = EventPublish{} }
func (m *EventPublish) String() string { return proto.CompactTextString(m) }
func (*EventPublish) ProtoMessage() {}
func (*EventPublish) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{3}
}
func (m *EventPublish) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventPublish.Unmarshal(m, b)
}
func (m *EventPublish) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventPublish.Marshal(b, m, deterministic)
}
func (m *EventPublish) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventPublish.Merge(m, src)
}
func (m *EventPublish) XXX_Size() int {
return xxx_messageInfo_EventPublish.Size(m)
}
func (m *EventPublish) XXX_DiscardUnknown() {
xxx_messageInfo_EventPublish.DiscardUnknown(m)
}
var xxx_messageInfo_EventPublish proto.InternalMessageInfo
func (m *EventPublish) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *EventPublish) GetSubType() string {
if m != nil {
return m.SubType
}
return ""
}
func (m *EventPublish) GetTime() int64 {
if m != nil {
return m.Time
}
return 0
}
func (m *EventPublish) GetContent() string {
if m != nil {
return m.Content
}
return ""
}
func (m *EventPublish) GetIntroduction() string {
if m != nil {
return m.Introduction
}
return ""
}
type EventAbort struct {
EventID string `protobuf:"bytes,2,opt,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventAbort) Reset() { *m = EventAbort{} }
func (m *EventAbort) String() string { return proto.CompactTextString(m) }
func (*EventAbort) ProtoMessage() {}
func (*EventAbort) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{4}
}
func (m *EventAbort) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventAbort.Unmarshal(m, b)
}
func (m *EventAbort) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventAbort.Marshal(b, m, deterministic)
}
func (m *EventAbort) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventAbort.Merge(m, src)
}
func (m *EventAbort) XXX_Size() int {
return xxx_messageInfo_EventAbort.Size(m)
}
func (m *EventAbort) XXX_DiscardUnknown() {
xxx_messageInfo_EventAbort.DiscardUnknown(m)
}
var xxx_messageInfo_EventAbort proto.InternalMessageInfo
func (m *EventAbort) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
type ResultPrePublish struct {
EventID string `protobuf:"bytes,2,opt,name=eventID,proto3" json:"eventID,omitempty"`
Source string `protobuf:"bytes,3,opt,name=source,proto3" json:"source,omitempty"`
Result string `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ResultPrePublish) Reset() { *m = ResultPrePublish{} }
func (m *ResultPrePublish) String() string { return proto.CompactTextString(m) }
func (*ResultPrePublish) ProtoMessage() {}
func (*ResultPrePublish) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{5}
}
func (m *ResultPrePublish) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ResultPrePublish.Unmarshal(m, b)
}
func (m *ResultPrePublish) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ResultPrePublish.Marshal(b, m, deterministic)
}
func (m *ResultPrePublish) XXX_Merge(src proto.Message) {
xxx_messageInfo_ResultPrePublish.Merge(m, src)
}
func (m *ResultPrePublish) XXX_Size() int {
return xxx_messageInfo_ResultPrePublish.Size(m)
}
func (m *ResultPrePublish) XXX_DiscardUnknown() {
xxx_messageInfo_ResultPrePublish.DiscardUnknown(m)
}
var xxx_messageInfo_ResultPrePublish proto.InternalMessageInfo
func (m *ResultPrePublish) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
func (m *ResultPrePublish) GetSource() string {
if m != nil {
return m.Source
}
return ""
}
func (m *ResultPrePublish) GetResult() string {
if m != nil {
return m.Result
}
return ""
}
type ResultPublish struct {
EventID string `protobuf:"bytes,2,opt,name=eventID,proto3" json:"eventID,omitempty"`
Source string `protobuf:"bytes,3,opt,name=source,proto3" json:"source,omitempty"`
Result string `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ResultPublish) Reset() { *m = ResultPublish{} }
func (m *ResultPublish) String() string { return proto.CompactTextString(m) }
func (*ResultPublish) ProtoMessage() {}
func (*ResultPublish) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{6}
}
func (m *ResultPublish) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ResultPublish.Unmarshal(m, b)
}
func (m *ResultPublish) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ResultPublish.Marshal(b, m, deterministic)
}
func (m *ResultPublish) XXX_Merge(src proto.Message) {
xxx_messageInfo_ResultPublish.Merge(m, src)
}
func (m *ResultPublish) XXX_Size() int {
return xxx_messageInfo_ResultPublish.Size(m)
}
func (m *ResultPublish) XXX_DiscardUnknown() {
xxx_messageInfo_ResultPublish.DiscardUnknown(m)
}
var xxx_messageInfo_ResultPublish proto.InternalMessageInfo
func (m *ResultPublish) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
func (m *ResultPublish) GetSource() string {
if m != nil {
return m.Source
}
return ""
}
func (m *ResultPublish) GetResult() string {
if m != nil {
return m.Result
}
return ""
}
type ResultAbort struct {
EventID string `protobuf:"bytes,2,opt,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ResultAbort) Reset() { *m = ResultAbort{} }
func (m *ResultAbort) String() string { return proto.CompactTextString(m) }
func (*ResultAbort) ProtoMessage() {}
func (*ResultAbort) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{7}
}
func (m *ResultAbort) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ResultAbort.Unmarshal(m, b)
}
func (m *ResultAbort) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ResultAbort.Marshal(b, m, deterministic)
}
func (m *ResultAbort) XXX_Merge(src proto.Message) {
xxx_messageInfo_ResultAbort.Merge(m, src)
}
func (m *ResultAbort) XXX_Size() int {
return xxx_messageInfo_ResultAbort.Size(m)
}
func (m *ResultAbort) XXX_DiscardUnknown() {
xxx_messageInfo_ResultAbort.DiscardUnknown(m)
}
var xxx_messageInfo_ResultAbort proto.InternalMessageInfo
func (m *ResultAbort) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
// localDB
type EventRecord struct {
EventID string `protobuf:"bytes,1,opt,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *EventRecord) Reset() { *m = EventRecord{} }
func (m *EventRecord) String() string { return proto.CompactTextString(m) }
func (*EventRecord) ProtoMessage() {}
func (*EventRecord) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{8}
}
func (m *EventRecord) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_EventRecord.Unmarshal(m, b)
}
func (m *EventRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_EventRecord.Marshal(b, m, deterministic)
}
func (m *EventRecord) XXX_Merge(src proto.Message) {
xxx_messageInfo_EventRecord.Merge(m, src)
}
func (m *EventRecord) XXX_Size() int {
return xxx_messageInfo_EventRecord.Size(m)
}
func (m *EventRecord) XXX_DiscardUnknown() {
xxx_messageInfo_EventRecord.DiscardUnknown(m)
}
var xxx_messageInfo_EventRecord proto.InternalMessageInfo
func (m *EventRecord) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
type QueryOracleInfos struct {
EventID []string `protobuf:"bytes,1,rep,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *QueryOracleInfos) Reset() { *m = QueryOracleInfos{} }
func (m *QueryOracleInfos) String() string { return proto.CompactTextString(m) }
func (*QueryOracleInfos) ProtoMessage() {}
func (*QueryOracleInfos) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{9}
}
func (m *QueryOracleInfos) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryOracleInfos.Unmarshal(m, b)
}
func (m *QueryOracleInfos) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryOracleInfos.Marshal(b, m, deterministic)
}
func (m *QueryOracleInfos) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryOracleInfos.Merge(m, src)
}
func (m *QueryOracleInfos) XXX_Size() int {
return xxx_messageInfo_QueryOracleInfos.Size(m)
}
func (m *QueryOracleInfos) XXX_DiscardUnknown() {
xxx_messageInfo_QueryOracleInfos.DiscardUnknown(m)
}
var xxx_messageInfo_QueryOracleInfos proto.InternalMessageInfo
func (m *QueryOracleInfos) GetEventID() []string {
if m != nil {
return m.EventID
}
return nil
}
type ReplyEventIDs struct {
EventID []string `protobuf:"bytes,1,rep,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReplyEventIDs) Reset() { *m = ReplyEventIDs{} }
func (m *ReplyEventIDs) String() string { return proto.CompactTextString(m) }
func (*ReplyEventIDs) ProtoMessage() {}
func (*ReplyEventIDs) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{10}
}
func (m *ReplyEventIDs) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReplyEventIDs.Unmarshal(m, b)
}
func (m *ReplyEventIDs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReplyEventIDs.Marshal(b, m, deterministic)
}
func (m *ReplyEventIDs) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReplyEventIDs.Merge(m, src)
}
func (m *ReplyEventIDs) XXX_Size() int {
return xxx_messageInfo_ReplyEventIDs.Size(m)
}
func (m *ReplyEventIDs) XXX_DiscardUnknown() {
xxx_messageInfo_ReplyEventIDs.DiscardUnknown(m)
}
var xxx_messageInfo_ReplyEventIDs proto.InternalMessageInfo
func (m *ReplyEventIDs) GetEventID() []string {
if m != nil {
return m.EventID
}
return nil
}
type QueryEventID struct {
Status int32 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
EventID string `protobuf:"bytes,4,opt,name=eventID,proto3" json:"eventID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *QueryEventID) Reset() { *m = QueryEventID{} }
func (m *QueryEventID) String() string { return proto.CompactTextString(m) }
func (*QueryEventID) ProtoMessage() {}
func (*QueryEventID) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{11}
}
func (m *QueryEventID) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryEventID.Unmarshal(m, b)
}
func (m *QueryEventID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryEventID.Marshal(b, m, deterministic)
}
func (m *QueryEventID) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryEventID.Merge(m, src)
}
func (m *QueryEventID) XXX_Size() int {
return xxx_messageInfo_QueryEventID.Size(m)
}
func (m *QueryEventID) XXX_DiscardUnknown() {
xxx_messageInfo_QueryEventID.DiscardUnknown(m)
}
var xxx_messageInfo_QueryEventID proto.InternalMessageInfo
func (m *QueryEventID) GetStatus() int32 {
if m != nil {
return m.Status
}
return 0
}
func (m *QueryEventID) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *QueryEventID) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *QueryEventID) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
type ReceiptOracle struct {
EventID string `protobuf:"bytes,1,opt,name=eventID,proto3" json:"eventID,omitempty"`
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
Addr string `protobuf:"bytes,3,opt,name=addr,proto3" json:"addr,omitempty"`
Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"`
PreStatus int32 `protobuf:"varint,6,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReceiptOracle) Reset() { *m = ReceiptOracle{} }
func (m *ReceiptOracle) String() string { return proto.CompactTextString(m) }
func (*ReceiptOracle) ProtoMessage() {}
func (*ReceiptOracle) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{12}
}
func (m *ReceiptOracle) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReceiptOracle.Unmarshal(m, b)
}
func (m *ReceiptOracle) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReceiptOracle.Marshal(b, m, deterministic)
}
func (m *ReceiptOracle) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReceiptOracle.Merge(m, src)
}
func (m *ReceiptOracle) XXX_Size() int {
return xxx_messageInfo_ReceiptOracle.Size(m)
}
func (m *ReceiptOracle) XXX_DiscardUnknown() {
xxx_messageInfo_ReceiptOracle.DiscardUnknown(m)
}
var xxx_messageInfo_ReceiptOracle proto.InternalMessageInfo
func (m *ReceiptOracle) GetEventID() string {
if m != nil {
return m.EventID
}
return ""
}
func (m *ReceiptOracle) GetStatus() int32 {
if m != nil {
return m.Status
}
return 0
}
func (m *ReceiptOracle) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *ReceiptOracle) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *ReceiptOracle) GetPreStatus() int32 {
if m != nil {
return m.PreStatus
}
return 0
}
type ReplyOracleStatusList struct {
Status []*OracleStatus `protobuf:"bytes,1,rep,name=status,proto3" json:"status,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReplyOracleStatusList) Reset() { *m = ReplyOracleStatusList{} }
func (m *ReplyOracleStatusList) String() string { return proto.CompactTextString(m) }
func (*ReplyOracleStatusList) ProtoMessage() {}
func (*ReplyOracleStatusList) Descriptor() ([]byte, []int) {
return fileDescriptor_b544994cdab50f02, []int{13}
}
func (m *ReplyOracleStatusList) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReplyOracleStatusList.Unmarshal(m, b)
}
func (m *ReplyOracleStatusList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReplyOracleStatusList.Marshal(b, m, deterministic)
}
func (m *ReplyOracleStatusList) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReplyOracleStatusList.Merge(m, src)
}
func (m *ReplyOracleStatusList) XXX_Size() int {
return xxx_messageInfo_ReplyOracleStatusList.Size(m)
}
func (m *ReplyOracleStatusList) XXX_DiscardUnknown() {
xxx_messageInfo_ReplyOracleStatusList.DiscardUnknown(m)
}
var xxx_messageInfo_ReplyOracleStatusList proto.InternalMessageInfo
func (m *ReplyOracleStatusList) GetStatus() []*OracleStatus {
if m != nil {
return m.Status
}
return nil
}
func init() {
proto.RegisterType((*OracleStatus)(nil), "types.OracleStatus")
proto.RegisterType((*OracleAction)(nil), "types.OracleAction")
proto.RegisterType((*EventStatus)(nil), "types.EventStatus")
proto.RegisterType((*EventPublish)(nil), "types.EventPublish")
proto.RegisterType((*EventAbort)(nil), "types.EventAbort")
proto.RegisterType((*ResultPrePublish)(nil), "types.ResultPrePublish")
proto.RegisterType((*ResultPublish)(nil), "types.ResultPublish")
proto.RegisterType((*ResultAbort)(nil), "types.ResultAbort")
proto.RegisterType((*EventRecord)(nil), "types.EventRecord")
proto.RegisterType((*QueryOracleInfos)(nil), "types.QueryOracleInfos")
proto.RegisterType((*ReplyEventIDs)(nil), "types.ReplyEventIDs")
proto.RegisterType((*QueryEventID)(nil), "types.QueryEventID")
proto.RegisterType((*ReceiptOracle)(nil), "types.ReceiptOracle")
proto.RegisterType((*ReplyOracleStatusList)(nil), "types.ReplyOracleStatusList")
}
func init() { proto.RegisterFile("oracle.proto", fileDescriptor_b544994cdab50f02) }
var fileDescriptor_b544994cdab50f02 = []byte{
// 579 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4d, 0x8b, 0xdb, 0x3c,
0x10, 0x8e, 0x3f, 0xf7, 0xdd, 0xb1, 0xf7, 0x25, 0x55, 0xbf, 0x74, 0xe8, 0x21, 0xf8, 0xd0, 0x4d,
0x3f, 0x08, 0x25, 0x0b, 0x85, 0x42, 0x7b, 0x48, 0xd9, 0x40, 0x16, 0x0a, 0xdd, 0xaa, 0xb9, 0x14,
0x7a, 0x49, 0x1c, 0x95, 0x35, 0xa4, 0x96, 0x91, 0xe5, 0x85, 0xfc, 0x82, 0xde, 0xfa, 0xc3, 0x7a,
0xee, 0x0f, 0x2a, 0x1a, 0x29, 0x89, 0x9c, 0x4d, 0x02, 0x85, 0xde, 0x34, 0x33, 0x8f, 0x1e, 0xcf,
0xc7, 0xa3, 0x31, 0xa4, 0x42, 0xce, 0xf2, 0x25, 0x1f, 0x54, 0x52, 0x28, 0x41, 0x22, 0xb5, 0xaa,
0x78, 0x9d, 0xfd, 0xf2, 0x21, 0xfd, 0x88, 0xfe, 0xcf, 0x6a, 0xa6, 0x9a, 0x9a, 0x50, 0x38, 0xe1,
0xb7, 0xbc, 0x54, 0x57, 0x97, 0xd4, 0xeb, 0x79, 0xfd, 0x53, 0xb6, 0x36, 0x09, 0x81, 0x70, 0xb6,
0x58, 0x48, 0xea, 0xa3, 0x1b, 0xcf, 0xda, 0xa7, 0x79, 0x68, 0x60, 0x7c, 0xfa, 0xac, 0x19, 0xea,
0x66, 0x3e, 0xd5, 0xee, 0xd0, 0x30, 0x58, 0x13, 0xd1, 0xc5, 0x77, 0x4e, 0xa3, 0x9e, 0xd7, 0x0f,
0x18, 0x9e, 0x35, 0x3a, 0x17, 0xa5, 0xe2, 0xa5, 0xa2, 0xb1, 0x41, 0x5b, 0x93, 0x64, 0x90, 0x16,
0xa5, 0x92, 0x62, 0xd1, 0xe4, 0xaa, 0x10, 0x25, 0x3d, 0xc1, 0x70, 0xcb, 0x47, 0x9e, 0x43, 0x5c,
0x63, 0xde, 0xf4, 0xbf, 0x9e, 0xd7, 0x4f, 0x86, 0x64, 0x80, 0x65, 0x0d, 0xc6, 0x3a, 0x67, 0x53,
0x11, 0xb3, 0x08, 0xf2, 0x08, 0xe2, 0x5a, 0x34, 0x32, 0xe7, 0xf4, 0x14, 0x99, 0xac, 0xa5, 0xfd,
0x92, 0xd7, 0xcd, 0x52, 0x51, 0x30, 0x7e, 0x63, 0x91, 0x57, 0x70, 0x5a, 0x49, 0xdb, 0x16, 0x9a,
0x1c, 0xa4, 0xdf, 0x82, 0xb2, 0xdf, 0x9b, 0x66, 0x8e, 0x4c, 0x7a, 0x6f, 0x20, 0xc5, 0xee, 0x5d,
0x37, 0xf3, 0x65, 0x51, 0xdf, 0x60, 0x47, 0x93, 0xe1, 0x7d, 0x97, 0xc5, 0x86, 0x26, 0x1d, 0xd6,
0x82, 0x92, 0x0b, 0x00, 0xb4, 0x47, 0x73, 0x21, 0x15, 0xf6, 0x3c, 0x19, 0xde, 0x73, 0x2f, 0x62,
0x60, 0xd2, 0x61, 0x0e, 0x8c, 0x8c, 0xa1, 0x6b, 0x92, 0xbf, 0x96, 0x7c, 0xfd, 0xcd, 0x00, 0xaf,
0x3e, 0xb6, 0x57, 0xd9, 0x4e, 0x78, 0xd2, 0x61, 0x77, 0xae, 0x90, 0xb7, 0x70, 0x66, 0x7d, 0x96,
0x23, 0x44, 0x8e, 0x07, 0x6d, 0x8e, 0x0d, 0x41, 0x1b, 0x4c, 0x5e, 0x43, 0x62, 0x1c, 0x26, 0xf5,
0xa8, 0xd5, 0x39, 0xb6, 0x8d, 0x4c, 0x3a, 0xcc, 0x05, 0x92, 0xff, 0xc1, 0x9f, 0xae, 0x70, 0xca,
0x11, 0xf3, 0xa7, 0xab, 0xf7, 0x27, 0x10, 0xdd, 0xce, 0x96, 0x0d, 0xcf, 0xde, 0x41, 0xe2, 0x34,
0x5c, 0xcf, 0x4b, 0x54, 0x23, 0xad, 0x44, 0x23, 0x50, 0x6b, 0xe1, 0x7c, 0xcd, 0xb0, 0x7c, 0xe4,
0xb0, 0x56, 0xf6, 0xd3, 0x83, 0xd4, 0x6d, 0xf5, 0x46, 0xb4, 0xfe, 0x7e, 0xd1, 0x06, 0xfb, 0x45,
0x1b, 0xee, 0x17, 0x6d, 0x74, 0x5c, 0xb4, 0xf1, 0x5d, 0xd1, 0x66, 0x4f, 0x01, 0xb6, 0x13, 0x74,
0x1f, 0x9c, 0xdf, 0x7a, 0x70, 0xd9, 0x57, 0xe8, 0xee, 0x8e, 0xeb, 0x30, 0xda, 0x91, 0x77, 0x70,
0x40, 0xde, 0xa1, 0x2b, 0xef, 0xec, 0x0b, 0x9c, 0xb5, 0x06, 0xf9, 0x0f, 0xa9, 0xcf, 0x21, 0x71,
0xe6, 0x7c, 0xa4, 0xc2, 0x73, 0x3b, 0x59, 0xc6, 0x73, 0x21, 0x17, 0x87, 0x77, 0x4f, 0xf6, 0x12,
0xba, 0x9f, 0x1a, 0x2e, 0x57, 0xe6, 0x75, 0x5d, 0x95, 0xdf, 0xc4, 0xce, 0xa6, 0x0a, 0x5c, 0xf4,
0x33, 0x5d, 0x5a, 0xb5, 0x5c, 0x8d, 0x8d, 0x7d, 0x0c, 0x7a, 0x03, 0x29, 0x12, 0x8f, 0x9d, 0x52,
0x8d, 0x88, 0x3c, 0x57, 0x44, 0x7f, 0xb3, 0xfc, 0xd6, 0x5f, 0x0a, 0xdb, 0x25, 0xfc, 0xf0, 0x74,
0x56, 0x39, 0x2f, 0x2a, 0x65, 0xaa, 0x38, 0xb2, 0x6a, 0x0f, 0x48, 0x79, 0x93, 0x45, 0xb0, 0x27,
0x8b, 0xd0, 0xc9, 0xe2, 0x89, 0xbb, 0xba, 0x62, 0xa4, 0x70, 0xd6, 0xd4, 0x25, 0x3c, 0xc4, 0xf6,
0xb8, 0x7b, 0xff, 0x43, 0x51, 0x2b, 0xf2, 0xc2, 0x29, 0x3e, 0x70, 0x16, 0x95, 0x0b, 0x5c, 0xe7,
0x32, 0x8f, 0xf1, 0x3f, 0x72, 0xf1, 0x27, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xd5, 0xe6, 0xbc, 0x57,
0x06, 0x00, 0x00,
}
package types
import (
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
)
/*
table struct
data: oracle
index: addr,status,index,type
*/
var opt = &table.Option{
Prefix: "LODB",
Name: "oracle",
Primary: "eventid",
Index: []string{"status", "addr_status", "type_status"},
}
//NewTable 新建表
func NewTable(kvdb db.KV) *table.Table {
rowmeta := NewOracleRow()
table, err := table.NewTable(rowmeta, kvdb, opt)
if err != nil {
panic(err)
}
return table
}
//OracleRow table meta 结构
type OracleRow struct {
*ReceiptOracle
}
//NewOracleRow 新建一个meta 结构
func NewOracleRow() *OracleRow {
return &OracleRow{ReceiptOracle: &ReceiptOracle{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存eventid)
func (tx *OracleRow) CreateRow() *table.Row {
return &table.Row{Data: &ReceiptOracle{}}
}
//SetPayload 设置数据
func (tx *OracleRow) SetPayload(data types.Message) error {
if txdata, ok := data.(*ReceiptOracle); ok {
tx.ReceiptOracle = txdata
return nil
}
return types.ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func (tx *OracleRow) Get(key string) ([]byte, error) {
if key == "eventid" {
return []byte(tx.EventID), nil
} else if key == "status" {
return []byte(fmt.Sprintf("%2d", tx.Status)), nil
} else if key == "addr_status" {
return []byte(fmt.Sprintf("%s:%2d", tx.Addr, tx.Status)), nil
} else if key == "type_status" {
return []byte(fmt.Sprintf("%s:%2d", tx.Type, tx.Status)), nil
}
return nil, types.ErrNotFound
}
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package types
import (
"reflect"
"github.com/33cn/chain33/types"
)
func init() {
// init executor type
types.AllowUserExec = append(types.AllowUserExec, []byte(OracleX))
types.RegistorExecutor(OracleX, NewType())
types.RegisterDappFork(OracleX, "Enable", 0)
}
// OracleType 预言机执行器类型
type OracleType struct {
types.ExecTypeBase
}
// NewType 创建执行器类型
func NewType() *OracleType {
c := &OracleType{}
c.SetChild(c)
return c
}
// GetName 获取执行器名称
func (o *OracleType) GetName() string {
return OracleX
}
// GetPayload 获取oracle action
func (o *OracleType) GetPayload() types.Message {
return &OracleAction{}
}
// GetTypeMap 获取类型map
func (o *OracleType) GetTypeMap() map[string]int32 {
return map[string]int32{
"EventPublish": ActionEventPublish,
"EventAbort": ActionEventAbort,
"ResultPrePublish": ActionResultPrePublish,
"ResultAbort": ActionResultAbort,
"ResultPublish": ActionResultPublish,
}
}
// GetLogMap 获取日志map
func (o *OracleType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{
TyLogEventPublish: {Ty: reflect.TypeOf(ReceiptOracle{}), Name: "LogEventPublish"},
TyLogEventAbort: {Ty: reflect.TypeOf(ReceiptOracle{}), Name: "LogEventAbort"},
TyLogResultPrePublish: {Ty: reflect.TypeOf(ReceiptOracle{}), Name: "LogResultPrePublish"},
TyLogResultAbort: {Ty: reflect.TypeOf(ReceiptOracle{}), Name: "LogResultAbort"},
TyLogResultPublish: {Ty: reflect.TypeOf(ReceiptOracle{}), Name: "LogResultPublish"},
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment