/
tx.go
100 lines (90 loc) · 2.78 KB
/
tx.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
90
91
92
93
94
95
96
97
98
99
100
package tx
import (
"errors"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/client/context"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/codec"
anytypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/codec/types"
sdktypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
types "github.com/evoblockchain/evochain/libs/cosmos-sdk/types/ibc-adapter"
"github.com/golang/protobuf/ptypes/wrappers"
)
var (
_ context.TxRequest = (*BroadcastTxRequest)(nil)
_ context.TxResponse = (*BroadcastTxResponse)(nil)
_ context.CodecSensitive = (*BroadcastTxResponse)(nil)
errMarshalSensitive = errors.New("error for Marshal Sensitive")
)
func (t *BroadcastTxRequest) GetModeDetail() int32 {
return int32(t.Mode)
}
func (t *BroadcastTxRequest) GetData() []byte {
return t.GetTxBytes()
}
func (t *BroadcastTxResponse) HandleResponse(codec *codec.CodecProxy, data interface{}) interface{} {
resp := data.(sdktypes.TxResponse)
logs := convEvoLogs2Proto(resp.Logs)
t.TxResponse = &types.TxResponse{
Height: resp.Height,
TxHash: resp.TxHash,
Codespace: resp.Codespace,
Code: resp.Code,
Data: resp.Data,
RawLog: resp.RawLog,
Logs: logs,
Info: resp.Info,
GasWanted: resp.GasWanted,
GasUsed: resp.GasUsed,
Timestamp: resp.Timestamp,
}
respWrapper := AminoBroadCastTxResponse{resp}
dataBytes, err := codec.GetCdc().MarshalJSON(respWrapper)
if nil == err {
bytesWrapper := &wrappers.BytesValue{Value: dataBytes}
if any, err := anytypes.NewAnyWithValue(bytesWrapper); nil == err {
t.TxResponse.Tx = any
}
}
return t
}
func convEvoLogs2Proto(ls sdktypes.ABCIMessageLogs) types.ABCIMessageLogs {
logs := make(types.ABCIMessageLogs, 0)
for _, l := range ls {
es := make(types.StringEvents, 0)
for _, e := range l.Events {
attrs := make([]types.Attribute, 0)
for _, a := range e.Attributes {
attrs = append(attrs, types.Attribute{
Key: a.Key,
Value: a.Value,
})
}
es = append(es, types.StringEvent{
Type: e.Type,
Attributes: attrs,
})
}
logs = append(logs, types.ABCIMessageLog{
MsgIndex: uint32(l.MsgIndex),
Log: l.Log,
Events: es,
})
}
return logs
}
type AminoBroadCastTxResponse struct {
TxResponse sdktypes.TxResponse `protobuf:"bytes,1,opt,name=tx_response,json=txResponse,proto3" json:"tx_response,omitempty"`
}
func (t *BroadcastTxResponse) MarshalSensitive(proxy *codec.CodecProxy) ([]byte, error) {
if t.TxResponse == nil {
return nil, errMarshalSensitive
}
internalV := t.TxResponse.Tx.GetCachedValue()
if nil == internalV {
return nil, errMarshalSensitive
}
resp, ok := internalV.(*wrappers.BytesValue)
if !ok {
return nil, errMarshalSensitive
}
return resp.Value, nil
}