-
Notifications
You must be signed in to change notification settings - Fork 1
/
querier.go
executable file
·45 lines (36 loc) · 1.13 KB
/
querier.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
package keeper
import (
"fmt"
cTypes "github.com/cosmos/cosmos-sdk/types"
abciTypes "github.com/tendermint/tendermint/abci/types"
"github.com/commitHub/commitBlockchain/codec"
"github.com/commitHub/commitBlockchain/types"
)
const (
QueryFiat = "queryFiat"
)
func NewQuerier(k Keeper) cTypes.Querier {
return func(ctx cTypes.Context, path []string, req abciTypes.RequestQuery) (res []byte, err cTypes.Error) {
switch path[0] {
case QueryFiat:
return queryFiat(ctx, path[1:], k)
default:
return nil, cTypes.ErrUnknownRequest("unknown fiatFactory query endpoint")
}
}
}
func queryFiat(ctx cTypes.Context, path []string, keeper Keeper) ([]byte, cTypes.Error) {
pegHashHex, err := types.GetAssetPegHashHex(path[1])
if err != nil {
return nil, cTypes.ErrInternal(fmt.Sprintf("failed to parse the pegHash %s", err))
}
fiatPeg, err := keeper.GetFiatPeg(ctx, pegHashHex)
if err != nil {
return nil, cTypes.ErrInternal(fmt.Sprintf("%s", err))
}
res, err := codec.MarshalJSONIndent(keeper.cdc, fiatPeg)
if err != nil {
return nil, cTypes.ErrInternal(fmt.Sprintf("failed to marshal data %s", err.Error()))
}
return res, nil
}