-
Notifications
You must be signed in to change notification settings - Fork 46
/
packet.go
58 lines (52 loc) · 1.88 KB
/
packet.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
package packet
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewOracleRequestPacketData contructs a new OracleRequestPacketData instance
func NewOracleRequestPacketData(
clientID string, oracleScriptID int64, calldata []byte, askCount uint64, minCount uint64, feeLimit sdk.Coins, requestKey string, prepareGas uint64, executeGas uint64,
) OracleRequestPacketData {
return OracleRequestPacketData{
ClientID: clientID,
OracleScriptID: oracleScriptID,
Calldata: calldata,
AskCount: askCount,
MinCount: minCount,
FeeLimit: feeLimit,
RequestKey: requestKey,
PrepareGas: prepareGas,
ExecuteGas: executeGas,
}
}
// GetBytes is a helper for serialising
func (p OracleRequestPacketData) GetBytes() []byte {
cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
return sdk.MustSortJSON(cdc.MustMarshalJSON(&p))
}
func NewOracleRequestPacketAcknowledgement(requestID int64) *OracleRequestPacketAcknowledgement {
return &OracleRequestPacketAcknowledgement{
RequestID: requestID,
}
}
// NewOracleResponsePacketData contructs a new OracleResponsePacketData instance
func NewOracleResponsePacketData(
clientID string, requestID int64, ansCount uint64, requestTime int64,
resolveTime int64, resolveStatus ResolveStatus, result []byte,
) OracleResponsePacketData {
return OracleResponsePacketData{
ClientID: clientID,
RequestID: requestID,
AnsCount: ansCount,
RequestTime: requestTime,
ResolveTime: resolveTime,
ResolveStatus: resolveStatus,
Result: result,
}
}
// GetBytes returns the bytes representation of this oracle response packet data.
func (p OracleResponsePacketData) GetBytes() []byte {
cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
return sdk.MustSortJSON(cdc.MustMarshalJSON(&p))
}