-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.go
82 lines (71 loc) · 1.76 KB
/
handler.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
package sdk
import (
"math/big"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/common"
)
const (
// ModuleNameBase is the module name for internal functionality
ModuleNameBase = "base"
// ChainKey is the option key for setting the chain id
ChainKey = "chain_id"
)
type Result interface {
GetData() []byte
}
// CheckResult captures any non-error abci result
// to make sure people use error for error cases
type CheckResult struct {
Data []byte
Log string
// GasAllocated is the maximum units of work we allow this tx to perform
GasAllocated int64
// GasPayment is the total fees for this tx (or other source of payment)
GasPayment int64
}
// NewCheck sets the gas used and the response data but no more info
// these are the most common info needed to be set by the Handler
func NewCheck(gasAllocated int64, log string) CheckResult {
return CheckResult{
GasAllocated: gasAllocated,
Log: log,
}
}
func (c CheckResult) ToABCI() abci.ResponseCheckTx {
return abci.ResponseCheckTx{
Data: c.Data,
Log: c.Log,
GasUsed: c.GasAllocated,
}
}
func (c CheckResult) GetData() []byte {
return c.Data
}
// DeliverResult captures any non-error abci result
// to make sure people use error for error cases
type DeliverResult struct {
Data []byte
Log string
Diff []*abci.Validator
GasUsed int64 // unused
GasFee *big.Int
}
func (d DeliverResult) ToABCI() abci.ResponseDeliverTx {
var fee = common.KI64Pair{}
if d.GasFee.Cmp(big.NewInt(0)) > 0 {
fee = common.KI64Pair{
Key: []byte("GasFee"),
Value: d.GasFee.Int64(),
}
}
return abci.ResponseDeliverTx{
Data: d.Data,
Log: d.Log,
Tags: nil,
GasUsed: d.GasUsed,
Fee: fee,
}
}
func (d DeliverResult) GetData() []byte {
return d.Data
}