-
Notifications
You must be signed in to change notification settings - Fork 7
/
query.go
48 lines (42 loc) · 1.25 KB
/
query.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
package rest
import (
"fmt"
"net/http"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/anathatech/project-anatha/x/genutil/types"
)
// QueryGenesisTxs writes the genesis transactions to the response if no error
// occurs.
func QueryGenesisTxs(cliCtx context.CLIContext, w http.ResponseWriter) {
resultGenesis, err := cliCtx.Client.Genesis()
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to retrieve genesis from client: %s", err),
)
return
}
appState, err := types.GenesisStateFromGenDoc(cliCtx.Codec, *resultGenesis.Genesis)
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to decode genesis doc: %s", err),
)
return
}
genState := types.GetGenesisStateFromAppState(cliCtx.Codec, appState)
genTxs := make([]sdk.Tx, len(genState.GenTxs))
for i, tx := range genState.GenTxs {
err := cliCtx.Codec.UnmarshalJSON(tx, &genTxs[i])
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to decode genesis transaction: %s", err),
)
return
}
}
rest.PostProcessResponseBare(w, cliCtx, genTxs)
}