/
codec.go
41 lines (34 loc) · 1.14 KB
/
codec.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
package types
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)
// ModuleCdc references the global interchain queries module codec. Note, the codec
// should ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to interchain queries and
// defined at the application level.
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
func SerializeCosmosQuery(reqs []abci.RequestQuery) (bz []byte, err error) {
q := &CosmosQuery{
Requests: reqs,
}
return ModuleCdc.Marshal(q)
}
func DeserializeCosmosQuery(bz []byte) (reqs []abci.RequestQuery, err error) {
var q CosmosQuery
err = ModuleCdc.Unmarshal(bz, &q)
return q.Requests, err
}
func SerializeCosmosResponse(resps []abci.ResponseQuery) (bz []byte, err error) {
r := &CosmosResponse{
Responses: resps,
}
return ModuleCdc.Marshal(r)
}
func DeserializeCosmosResponse(bz []byte) (resps []abci.ResponseQuery, err error) {
var r CosmosResponse
err = ModuleCdc.Unmarshal(bz, &r)
return r.Responses, err
}