-
Notifications
You must be signed in to change notification settings - Fork 1
/
execute.go
executable file
·72 lines (57 loc) · 2.01 KB
/
execute.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package rest
import (
"net/http"
"github.com/cosmos/cosmos-sdk/client/context"
cTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/commitHub/commitBlockchain/types"
rest2 "github.com/commitHub/commitBlockchain/client/rest"
fiatFactoryTypes "github.com/commitHub/commitBlockchain/modules/fiatFactory/internal/types"
)
type executeFiatReq struct {
BaseReq rest.BaseReq
OwnerAddress string `json:"ownerAddress" `
To string `json:"to"`
AssetPegHash string `json:"assetPegHash"`
FiatPegHash string `json:"fiatPegHash" `
Amount int64 `json:"amount" `
Password string `json:"password"`
Mode string `json:"mode"`
}
func ExecuteFiatHandlerFunction(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req executeFiatReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
fromAddr, name, err := context.GetFromFields(req.BaseReq.From, false)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
cliCtx = cliCtx.WithFromAddress(fromAddr)
cliCtx = cliCtx.WithFromName(name)
toAddr, err := cTypes.AccAddressFromBech32(req.To)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
ownerAddr, err := cTypes.AccAddressFromBech32(req.OwnerAddress)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
assetPegHashHex, err := types.GetAssetPegHashHex(req.AssetPegHash)
fiatPegHashHex, err := types.GetFiatPegHashHex(req.FiatPegHash)
fiatPeg := types.BaseFiatPeg{
PegHash: fiatPegHashHex,
TransactionAmount: req.Amount,
}
msg := fiatFactoryTypes.BuildExecuteFiatMsg(fromAddr, ownerAddr, toAddr, assetPegHashHex, types.FiatPegWallet{fiatPeg})
rest2.SignAndBroadcast(req.BaseReq, cliCtx, req.Mode, req.Password, []cTypes.Msg{msg})
}
}