-
Notifications
You must be signed in to change notification settings - Fork 1
/
querier.go
executable file
·41 lines (32 loc) · 1.03 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
package keeper
import (
"fmt"
cTypes "github.com/cosmos/cosmos-sdk/types"
abciTypes "github.com/tendermint/tendermint/abci/types"
"github.com/commitHub/commitBlockchain/codec"
)
const (
QueryReputation = "reputationQuery"
)
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 QueryReputation:
return queryReputation(ctx, path[1:], k)
default:
return nil, cTypes.ErrUnknownRequest("unknown negotiation query endpoint")
}
}
}
func queryReputation(ctx cTypes.Context, path []string, k Keeper) ([]byte, cTypes.Error) {
address, err := cTypes.AccAddressFromBech32(path[0])
if err != nil {
return nil, cTypes.ErrInternal(fmt.Sprintf("failed to parse the address %s", err))
}
account := k.GetAccountReputation(ctx, address)
res, err := codec.MarshalJSONIndent(k.cdc, account)
if err != nil {
return nil, cTypes.ErrInternal(fmt.Sprintf("failed to marshal data %s", err.Error()))
}
return res, nil
}