Skip to content

Commit

Permalink
able to compile and fix decoder emitter test
Browse files Browse the repository at this point in the history
  • Loading branch information
taobun committed Sep 17, 2024
1 parent b95c82f commit fd80b04
Show file tree
Hide file tree
Showing 20 changed files with 673 additions and 563 deletions.
2 changes: 2 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func appModules(
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(oracletypes.ModuleName),
app.hooks,
),
app.TransferModule,
app.ICAModule,
Expand Down Expand Up @@ -234,6 +235,7 @@ func simulationModules(
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(oracletypes.ModuleName),
app.hooks,
),
ibc.NewAppModule(app.IBCKeeper),
app.TransferModule,
Expand Down
1 change: 1 addition & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"

cosmosdb "github.com/cosmos/cosmos-db"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down
221 changes: 111 additions & 110 deletions cmd/faucet/handler.go
Original file line number Diff line number Diff line change
@@ -1,112 +1,113 @@
package main

import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

band "github.com/bandprotocol/chain/v3/app"
)

type Request struct {
Address string `json:"address" binding:"required"`
}

type Response struct {
TxHash string `json:"txHash"`
}

func handleRequest(gc *gin.Context, c *Context) {
key := <-c.keys
defer func() {
c.keys <- key
}()

var req Request
if err := gc.ShouldBindBodyWith(&req, binding.JSON); err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
to, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

address, err := key.GetAddress()
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

msg := banktypes.NewMsgSend(address, to, c.amount)

clientCtx := client.Context{
Client: c.client,
Codec: cdc,
TxConfig: band.MakeEncodingConfig().TxConfig,
BroadcastMode: "async",
InterfaceRegistry: band.MakeEncodingConfig().InterfaceRegistry,
}
accountRetriever := authtypes.AccountRetriever{}
acc, err := accountRetriever.GetAccount(clientCtx, address)
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

txf := tx.Factory{}.
WithAccountNumber(acc.GetAccountNumber()).
WithSequence(acc.GetSequence()).
WithTxConfig(band.MakeEncodingConfig().TxConfig).
WithGas(200000).WithGasAdjustment(1).
WithChainID(cfg.ChainID).
WithMemo("").
WithGasPrices(c.gasPrices.String()).
WithKeybase(keybase).
WithAccountRetriever(clientCtx.AccountRetriever)

txb, err := txf.BuildUnsignedTx(msg)
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

err = tx.Sign(txf, key.Name, txb, true)
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

txBytes, err := clientCtx.TxConfig.TxEncoder()(txb.GetTx())
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

// broadcast to a Tendermint node
res, err := clientCtx.BroadcastTxSync(txBytes)
if err != nil {
gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if res.Code != 0 {
gc.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf(":exploding_head: Tx returned nonzero code %d with log %s, tx hash: %s",
res.Code, res.RawLog, res.TxHash,
),
})
return
}
gc.JSON(200, Response{
TxHash: res.TxHash,
})
}
// import (
// "context"
// "fmt"
// "net/http"

// "github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/tx"
// sdk "github.com/cosmos/cosmos-sdk/types"
// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
// banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
// "github.com/gin-gonic/gin"
// "github.com/gin-gonic/gin/binding"

// band "github.com/bandprotocol/chain/v3/app"
// )

// type Request struct {
// Address string `json:"address" binding:"required"`
// }

// type Response struct {
// TxHash string `json:"txHash"`
// }

// func handleRequest(gc *gin.Context, c *Context) {
// key := <-c.keys
// defer func() {
// c.keys <- key
// }()

// var req Request
// if err := gc.ShouldBindBodyWith(&req, binding.JSON); err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }
// to, err := sdk.AccAddressFromBech32(req.Address)
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// address, err := key.GetAddress()
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// msg := banktypes.NewMsgSend(address, to, c.amount)

// clientCtx := client.Context{
// Client: c.client,
// Codec: cdc,
// TxConfig: band.MakeEncodingConfig().TxConfig,
// BroadcastMode: "async",
// InterfaceRegistry: band.MakeEncodingConfig().InterfaceRegistry,
// }
// accountRetriever := authtypes.AccountRetriever{}
// acc, err := accountRetriever.GetAccount(clientCtx, address)
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// txf := tx.Factory{}.
// WithAccountNumber(acc.GetAccountNumber()).
// WithSequence(acc.GetSequence()).
// WithTxConfig(band.MakeEncodingConfig().TxConfig).
// WithGas(200000).WithGasAdjustment(1).
// WithChainID(cfg.ChainID).
// WithMemo("").
// WithGasPrices(c.gasPrices.String()).
// WithKeybase(keybase).
// WithAccountRetriever(clientCtx.AccountRetriever)

// txb, err := txf.BuildUnsignedTx(msg)
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// err = tx.Sign(context.Background(), txf, key.Name, txb, true)
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// txBytes, err := clientCtx.TxConfig.TxEncoder()(txb.GetTx())
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// // broadcast to a Tendermint node
// res, err := clientCtx.BroadcastTxSync(txBytes)
// if err != nil {
// gc.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// if res.Code != 0 {
// gc.JSON(http.StatusInternalServerError, gin.H{
// "error": fmt.Sprintf(":exploding_head: Tx returned nonzero code %d with log %s, tx hash: %s",
// res.Code, res.RawLog, res.TxHash,
// ),
// })
// return
// }
// gc.JSON(200, Response{
// TxHash: res.TxHash,
// })
// }
Loading

0 comments on commit fd80b04

Please sign in to comment.