/
api.go
89 lines (75 loc) · 3.37 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package roothash
import (
"fmt"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
)
const (
// AppID is the unique application identifier.
AppID uint8 = 0x02
// AppName is the ABCI application name.
AppName string = "999_roothash"
)
var (
// EventType is the ABCI event type for roothash events.
EventType = api.EventTypeForApp(AppName)
// QueryApp is a query for filtering transactions processed by the
// roothash application.
QueryApp = api.QueryForApp(AppName)
// KeyRuntimeID is an ABCI event attribute key for specifying event
// runtime (value is Base64-encoded runtime ID).
KeyRuntimeID = []byte("runtime-id")
// KeyExecutorCommitted is an ABCI event attribute key for executor
// commit events (value is CBOR-serialized ValueExecutorCommitted).
KeyExecutorCommitted = []byte("executor-commit")
// KeyMergeCommitted is an ABCI event attribute key for merge
// commit events (value is CBOR-serialized ValueMergeCommitted).
KeyMergeCommitted = []byte("merge-commit")
// KeyMergeDiscrepancyDetected is an ABCI event attribute key for
// merge discrepancy detected events (value is a CBOR serialized
// ValueMergeDiscrepancyDetected).
KeyMergeDiscrepancyDetected = []byte("merge-discrepancy")
// KeyExecutionDiscrepancyDetected is an ABCI event attribute key for
// merge discrepancy detected events (value is a CBOR serialized
// ValueExecutionDiscrepancyDetected).
KeyExecutionDiscrepancyDetected = []byte("execution-discrepancy")
// KeyFinalized is an ABCI event attribute key for finalized blocks
// (value is a CBOR serialized ValueFinalized).
KeyFinalized = []byte("finalized")
// KeyMessage is an ABCI event attribute key for message result events
// (value is a CBOR serialized ValueMessage).
KeyMessage = []byte("message")
)
// QueryForRuntime returns a query for filtering transactions processed by the roothash application
// limited to a specific runtime.
func QueryForRuntime(runtimeID common.Namespace) tmpubsub.Query {
return tmquery.MustParse(fmt.Sprintf("%s AND %s.%s='%s'", QueryApp, EventType, KeyRuntimeID, ValueRuntimeID(runtimeID)))
}
// ValueRuntimeID returns the value that should be stored under KeyRuntimeID.
func ValueRuntimeID(runtimeID common.Namespace) []byte {
// This needs to be a text field as Tendermint does not support non-text queries.
return []byte(runtimeID.Base64())
}
// ValueExecutorCommitted is the value component of a KeyExecutorCommitted.
type ValueExecutorCommitted struct {
ID common.Namespace `json:"id"`
Event roothash.ExecutorCommittedEvent `json:"event"`
}
// ValueFinalized is the value component of a TagFinalized.
type ValueFinalized struct {
ID common.Namespace `json:"id"`
Event roothash.FinalizedEvent `json:"event"`
}
// ValueExecutionDiscrepancyDetected is the value component of a KeyMergeDiscrepancyDetected.
type ValueExecutionDiscrepancyDetected struct {
ID common.Namespace `json:"id"`
Event roothash.ExecutionDiscrepancyDetectedEvent `json:"event"`
}
// ValueMessage is the value component of a KeyMessage.
type ValueMessage struct {
ID common.Namespace `json:"id"`
Event roothash.MessageEvent `json:"event"`
}