Skip to content

Commit

Permalink
Merge branch 'v2/cosmos/stargate' of https://github.com/forbole/bdjuno
Browse files Browse the repository at this point in the history
…into v2/cosmos/v0.44.x
  • Loading branch information
MonikaCat committed Feb 18, 2022
2 parents 681fa7c + 55d4b15 commit 94a459c
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v3.6.0
- uses: amannn/action-semantic-pull-request@v4.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 14 additions & 1 deletion cmd/actions/actionscmd.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
package actions

import (
"fmt"
"log"
"net/http"

"github.com/forbole/juno/v2/cmd/parse"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v2/cmd/actions/handlers"
actionstypes "github.com/forbole/bdjuno/v2/cmd/actions/types"
)

// NewActionsCmd returns the Cobra command allowing to activate hasura actions
func NewActionsCmd(parseCfg *parse.Config) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "hasura-actions",
Short: "Activate hasura actions",
PreRunE: parse.ReadConfig(parseCfg),
RunE: func(cmd *cobra.Command, args []string) error {

fmt.Printf(
"Hasura Action is running on the node(s):\n rpc: %s \n grpc: %s\n secure connection: %v\n",
actionstypes.FlagRPC,
actionstypes.FlagGRPC,
actionstypes.FlagSecure,
)

// HTTP server for the handlers
mux := http.NewServeMux()

Expand Down Expand Up @@ -49,4 +58,8 @@ func NewActionsCmd(parseCfg *parse.Config) *cobra.Command {
return nil
},
}

actionstypes.AddNodeFlagsToCmd(cmd)

return cmd
}
14 changes: 12 additions & 2 deletions cmd/actions/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/forbole/bdjuno/v2/types/config"
"github.com/forbole/juno/v2/cmd/parse"
"github.com/forbole/juno/v2/modules/messages"
junoconfig "github.com/forbole/juno/v2/types/config"

nodeconfig "github.com/forbole/juno/v2/node/config"
"github.com/forbole/juno/v2/node/remote"
)

func getCtxAndSources() (*parse.Context, *modules.Sources, error) {
Expand All @@ -30,7 +32,15 @@ func getCtxAndSources() (*parse.Context, *modules.Sources, error) {
return nil, nil, err
}

sources, err := modules.BuildSources(junoconfig.Cfg.Node, parseCtx.EncodingConfig)
node := nodeconfig.NewConfig(
nodeconfig.TypeRemote,
remote.NewDetails(
remote.NewRPCConfig("hasura-actions", actionstypes.FlagRPC, 100),
remote.NewGrpcConfig(actionstypes.FlagGRPC, !actionstypes.FlagSecure),
),
)

sources, err := modules.BuildSources(node, parseCtx.EncodingConfig)
if err != nil {
return nil, nil, err
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/actions/types/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package types

import (
"github.com/spf13/cobra"
)

var (
FlagRPC string
FlagGRPC string
FlagSecure bool
)

// AddNodeFlagsToCmd adds node flags to hasura actions.
func AddNodeFlagsToCmd(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&FlagRPC, "rpc", "http://127.0.0.1:26657", "RPC listen address. Port required")
cmd.PersistentFlags().StringVar(&FlagGRPC, "grpc", "http://127.0.0.1:9090", "GRPC listen address. Port required")

cmd.PersistentFlags().BoolVar(&FlagSecure, "secure", false, "Activate secure connections")
}
22 changes: 22 additions & 0 deletions database/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ func (db *Db) storeVestingAccount(account exported.VestingAccount) (int, error)
return vestingAccountRowID, nil
}

func (db *Db) StoreBaseVestingAccountFromMsg(bva *vestingtypes.BaseVestingAccount, txTimestamp time.Time) error {
stmt := `
INSERT INTO vesting_account (type, address, original_vesting, start_time, end_time)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (address) DO UPDATE
SET type = excluded.type,
original_vesting = excluded.original_vesting,
start_time = excluded.start_time,
end_time = excluded.end_time`

_, err := db.Sql.Exec(stmt,
proto.MessageName(bva),
bva.GetAddress().String(),
pq.Array(dbtypes.NewDbCoins(bva.OriginalVesting)),
txTimestamp,
time.Unix(bva.EndTime, 0))
if err != nil {
return fmt.Errorf("error while storing vesting account: %s", err)
}
return nil
}

// storeVestingPeriods handles storing the vesting periods of PeriodicVestingAccount type
func (db *Db) storeVestingPeriods(id int, vestingPeriods []vestingtypes.Period) error {
// Delete already existing periods
Expand Down
4 changes: 3 additions & 1 deletion database/pricefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func (db *Db) GetTokensPriceID() ([]string, error) {

var units []string
for _, unit := range dbUnits {
units = append(units, unit.PriceID.String)
if unit.PriceID.String != "" {
units = append(units, unit.PriceID.String)
}
}

return units, nil
Expand Down
43 changes: 43 additions & 0 deletions modules/auth/handle_msg.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package auth

import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
juno "github.com/forbole/juno/v2/types"
"github.com/gogo/protobuf/proto"
"github.com/rs/zerolog/log"

authttypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

"github.com/forbole/bdjuno/v2/modules/utils"
"github.com/forbole/bdjuno/v2/types"
)

// HandleMsg implements modules.MessageModule
Expand All @@ -18,5 +25,41 @@ func (m *Module) HandleMsg(_ int, msg sdk.Msg, tx *juno.Tx) error {
Msgf("error while refreshing accounts after message of type %s", proto.MessageName(msg))
}

if cosmosMsg, ok := msg.(*vestingtypes.MsgCreateVestingAccount); ok {
// Store tx timestamp as start_time of the created vesting account
timestamp, err := time.Parse(time.RFC3339, tx.Timestamp)
if err != nil {
return fmt.Errorf("error while parsing time: %s", err)
}

err = m.handleMsgCreateVestingAccount(cosmosMsg, timestamp)
if err != nil {
return fmt.Errorf("error while handling MsgCreateVestingAccount %s", err)
}
}

return m.RefreshAccounts(tx.Height, utils.FilterNonAccountAddresses(addresses))
}

func (m *Module) handleMsgCreateVestingAccount(msg *vestingtypes.MsgCreateVestingAccount, txTimestamp time.Time) error {

accAddress, err := sdk.AccAddressFromBech32(msg.ToAddress)
if err != nil {
return fmt.Errorf("error while converting account address %s", err)
}

// store account in database
err = m.db.SaveAccounts([]types.Account{types.NewAccount(accAddress.String())})
if err != nil {
return fmt.Errorf("error while storing vesting account: %s", err)
}

bva := vestingtypes.NewBaseVestingAccount(
authttypes.NewBaseAccountWithAddress(accAddress), msg.Amount, msg.EndTime,
)
err = m.db.StoreBaseVestingAccountFromMsg(bva, txTimestamp)
if err != nil {
return fmt.Errorf("error while storing base vesting account from msg %s", err)
}
return nil
}
3 changes: 1 addition & 2 deletions modules/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package distribution

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/forbole/juno/v2/types/config"

distrsource "github.com/forbole/bdjuno/v2/modules/distribution/source"

Expand All @@ -26,7 +25,7 @@ type Module struct {
}

// NewModule returns a new Module instance
func NewModule(cfg config.Config, source distrsource.Source, cdc codec.Codec, db *database.Db) *Module {
func NewModule(source distrsource.Source, cdc codec.Codec, db *database.Db) *Module {
return &Module{
cdc: cdc,
db: db,
Expand Down
2 changes: 1 addition & 1 deletion modules/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
authModule := auth.NewModule(r.parser, cdc, db)
bankModule := bank.NewModule(r.parser, sources.BankSource, cdc, db)
consensusModule := consensus.NewModule(db)
distrModule := distribution.NewModule(ctx.JunoConfig, sources.DistrSource, cdc, db)
distrModule := distribution.NewModule(sources.DistrSource, cdc, db)
feegrantModule := feegrant.NewModule(cdc, db)
historyModule := history.NewModule(ctx.JunoConfig.Chain, r.parser, cdc, db)
mintModule := mint.NewModule(sources.MintSource, cdc, db)
Expand Down

0 comments on commit 94a459c

Please sign in to comment.