diff --git a/.gitignore b/.gitignore index 8b3e06af..3da6aa02 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build/ config.local.yaml +Dockerfile # Coverage coverage.* vendor diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 35aeaaaf..00000000 --- a/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM golang:1.22-alpine as buildbase - -RUN apk add git build-base - -WORKDIR /go/src/github.com/forbole/callisto - -ENV GO111MODULE="on" -ENV CGO_ENABLED=1 -ENV GOOS="linux" -ENV GOPRIVATE=github.com/* -ENV GONOSUMDB=github.com/* -ENV GONOPROXY=github.com/* - -COPY ./go.mod ./go.sum ./ -# Read the CI_ACCESS_TOKEN from the .env file -ARG CI_ACCESS_TOKEN -RUN git config --global url."https://olegfomenkodev:${CI_ACCESS_TOKEN}@github.com/".insteadOf "https://github.com/" - -COPY . . - -RUN go build -mod=vendor -o /usr/local/bin/callisto /go/src/github.com/forbole/callisto/cmd/bdjuno - - -FROM alpine:3.9 - -COPY --from=buildbase /usr/local/bin/callisto /usr/local/bin/callisto - -RUN apk add --no-cache ca-certificates - -COPY ./genesis.json /genesis/genesis.json - -ENTRYPOINT ["callisto"] \ No newline at end of file diff --git a/database/accumulator.go b/database/accumulator.go index 922b781c..1ce4a3b9 100644 --- a/database/accumulator.go +++ b/database/accumulator.go @@ -30,7 +30,7 @@ func (db *Db) SaveAdmin(address string, vestingCount, lastVestingTime, vestingPe // ------------------------------------------------------------------------------------------------------------------- // SaveAccumulatorParams allows to store the given params inside the database -func (db *Db) SaveAccumulatorParams(params *types.MintParams) error { +func (db *Db) SaveAccumulatorParams(params *types.AccumulatorParams) error { paramsBz, err := json.Marshal(¶ms.Params) if err != nil { return fmt.Errorf("error while marshaling accumulator params: %s", err) @@ -52,3 +52,10 @@ func (db *Db) SaveAccumulatorParams(params *types.MintParams) error { return nil } + +// GetAdmins returns all the admins that are currently stored inside the database. +func (db *Db) GetAdmins() ([]dbtypes.AdminVestingRow, error) { + var rows []dbtypes.AdminVestingRow + err := db.Sqlx.Select(&rows, `SELECT * FROM admins_vesting WHERE last_vesting_time + INTERVAL '1 second' * vesting_time > NOW();`) + return rows, err +} diff --git a/database/schema/15-accumulator.sql b/database/schema/15-accumulator.sql index b24c03d6..7dbab0ff 100644 --- a/database/schema/15-accumulator.sql +++ b/database/schema/15-accumulator.sql @@ -15,6 +15,7 @@ CREATE TABLE accumulator_params ( one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY, params JSONB NOT NULL, + height BIGINT NOT NULL, CHECK (one_row_id) ); -- +migrate Down diff --git a/database/types/admin_vesting.go b/database/types/admin_vesting.go new file mode 100644 index 00000000..ee643e8c --- /dev/null +++ b/database/types/admin_vesting.go @@ -0,0 +1,30 @@ +package types + +type AdminVestingRow struct { + ID int64 `db:"id"` + Address string `db:"address"` + VestingPeriod int64 `db:"vesting_period"` + RewardsPerPeriod DbCoins `db:"reward_per_period"` + LastVestingTime int64 `db:"last_vesting_time"` + VestingCounter int64 `db:"vesting_counter"` + VestingPeriodsCount int64 `db:"vesting_periods_count"` + Denom string `db:"denom"` +} + +func NewAdminVestingRow(id int64, address string, vestingPeriod int64, rewardsPerPeriod DbCoins, lastVestingTime, vestingCounter int64, denom string) AdminVestingRow { + return AdminVestingRow{ + ID: id, + Address: address, + VestingPeriod: vestingPeriod, + RewardsPerPeriod: rewardsPerPeriod, + LastVestingTime: lastVestingTime, + VestingCounter: vestingCounter, + Denom: denom, + } +} + +func (r AdminVestingRow) Equal(s AdminVestingRow) bool { + return r.RewardsPerPeriod.Equal(&s.RewardsPerPeriod) && + r.ID == s.ID && + r.Address == s.Address +} diff --git a/go.mod b/go.mod index cc92feef..fb65e622 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/go-co-op/gocron v1.37.0 github.com/gogo/protobuf v1.3.3 github.com/golangci/golangci-lint v1.61.0 - github.com/hyle-team/bridgeless-core v0.0.0-20240822124409-90dc63eee926 + github.com/hyle-team/bridgeless-core/v12 v12.0.0-20241030111407-6377be1385ce github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.9 github.com/pelletier/go-toml v1.9.5 @@ -335,7 +335,7 @@ require ( replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 - github.com/cosmos/cosmos-sdk => github.com/hyle-team/cosmos-sdk v0.46.26 + github.com/cosmos/cosmos-sdk v0.46.13 => github.com/hyle-team/cosmos-sdk v0.46.26-0.20241030103636-3505e4eaa455 github.com/cosmos/ibc-go/v6 => github.com/hyle-team/ibc-go/v6 v6.1.6 github.com/forbole/juno/v4 => github.com/hyle-team/juno-bridgeless/v4 v4.0.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index f24aa68a..2be3fc14 100644 --- a/go.sum +++ b/go.sum @@ -765,10 +765,10 @@ github.com/holiman/uint256 v1.2.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= -github.com/hyle-team/bridgeless-core v0.0.0-20240822124409-90dc63eee926 h1:cfsHbvMmRxVjxoApli5nZxI1R0OJOhMDlM6goDaZW5c= -github.com/hyle-team/bridgeless-core v0.0.0-20240822124409-90dc63eee926/go.mod h1:E416XZ8/nZ4Te3gzqYFcasErEvv8JHXpR9nMBMdxLI8= -github.com/hyle-team/cosmos-sdk v0.46.26 h1:ZB88ZV3aK/6r7Echo6lZOrwvCsQZSRaEMt9udjLXwnw= -github.com/hyle-team/cosmos-sdk v0.46.26/go.mod h1:JkEh06V4aORJl8/nrLelLCzc5xKPoDuIYgaF8M6AwFw= +github.com/hyle-team/bridgeless-core/v12 v12.0.0-20241030111407-6377be1385ce h1:FeHsjb9clxOf2z73w0Pr10q1WheOHX2hjm0KzxrKTTE= +github.com/hyle-team/bridgeless-core/v12 v12.0.0-20241030111407-6377be1385ce/go.mod h1:aBCCdhgclu3iIsfrVpXbaEeRzkvLT1MXYGy1a6FPVBc= +github.com/hyle-team/cosmos-sdk v0.46.26-0.20241030103636-3505e4eaa455 h1:IPxGu1hNMxBs7vVipBPYB89eSUIyD3NxLkYKBijBgXc= +github.com/hyle-team/cosmos-sdk v0.46.26-0.20241030103636-3505e4eaa455/go.mod h1:JkEh06V4aORJl8/nrLelLCzc5xKPoDuIYgaF8M6AwFw= github.com/hyle-team/ibc-go/v6 v6.1.6 h1:vAkKQq1Ila+NscPDAjRiq9OvmoDxmHlkbycQh1ipng0= github.com/hyle-team/ibc-go/v6 v6.1.6/go.mod h1:UO7H/uWsmiOMeU54Fj9rspvISRGvylOIZYNnXBT4YY4= github.com/hyle-team/juno-bridgeless/v4 v4.0.0 h1:ECwMMCYYNdqNkuvKhqQ44GEhZZoxkhvMV88wKmbDPqE= diff --git a/modules/accumulator/handle_genesis.go b/modules/accumulator/handle_genesis.go new file mode 100644 index 00000000..05bd78e7 --- /dev/null +++ b/modules/accumulator/handle_genesis.go @@ -0,0 +1,33 @@ +package accumulator + +import ( + "encoding/json" + "fmt" + accumulatortypes "github.com/cosmos/cosmos-sdk/x/accumulator/types" + + tmtypes "github.com/tendermint/tendermint/types" + + "github.com/forbole/bdjuno/v4/types" + + "github.com/rs/zerolog/log" +) + +// HandleGenesis implements modules.Module +func (m *Module) HandleGenesis(doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error { + log.Debug().Str("module", "accumulator").Msg("parsing genesis") + + // Read the genesis state + var genState accumulatortypes.GenesisState + err := m.cdc.UnmarshalJSON(appState[accumulatortypes.ModuleName], &genState) + if err != nil { + return fmt.Errorf("error while reading mint genesis data: %s", err) + } + + // Save the params + err = m.db.SaveAccumulatorParams(types.NewAccumulatorParams(genState.Params, doc.InitialHeight)) + if err != nil { + return fmt.Errorf("error while storing genesis mint params: %s", err) + } + + return nil +} diff --git a/modules/accumulator/handle_msg.go b/modules/accumulator/handle_msg.go new file mode 100644 index 00000000..fff757dd --- /dev/null +++ b/modules/accumulator/handle_msg.go @@ -0,0 +1,41 @@ +package accumulator + +import ( + "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/rs/zerolog/log" + + sdk "github.com/cosmos/cosmos-sdk/types" + accumulator "github.com/cosmos/cosmos-sdk/x/accumulator/types" + juno "github.com/forbole/juno/v4/types" +) + +// HandleMsgExec implements modules.AuthzMessageModule +func (m *Module) HandleMsgExec(index int, _ *authz.MsgExec, _ int, executedMsg sdk.Msg, tx *juno.Tx) error { + return m.HandleMsg(index, executedMsg, tx) +} + +// HandleMsg implements modules.MessageModule +func (m *Module) HandleMsg(_ int, msg sdk.Msg, tx *juno.Tx) error { + log.Debug().Str("module", "accumulator").Msg("handle msg") + + switch cosmosMsg := msg.(type) { + case *accumulator.MsgAddAdmin: + return m.handleMsgAddAdmin(tx, cosmosMsg) + default: + break + } + + return nil +} + +// handleMsgAddAdmin save a new admin to db +func (m *Module) handleMsgAddAdmin(_ *juno.Tx, msg *accumulator.MsgAddAdmin) error { + return m.db.SaveAdmin( + msg.Address, + msg.VestingPeriodsCount, + 0, + msg.VestingPeriod, + msg.RewardPerPeriod, + msg.Denom, + ) +} diff --git a/modules/accumulator/handle_periodic_operations.go b/modules/accumulator/handle_periodic_operations.go index d77c7890..f26ce8a8 100644 --- a/modules/accumulator/handle_periodic_operations.go +++ b/modules/accumulator/handle_periodic_operations.go @@ -2,18 +2,13 @@ package accumulator import ( "fmt" - "github.com/cosmos/cosmos-sdk/types/query" "github.com/go-co-op/gocron" "github.com/rs/zerolog/log" - "math" ) // RegisterPeriodicOperations implements modules.Module func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", m.Name()).Msg("setting up periodic tasks") - pagination := &query.PageRequest{ - Limit: math.MaxInt32, - } logErr := log.Error().Str("module", m.Name()) @@ -25,16 +20,17 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return } - admins, err := m.keeper.GetAdmins(pagination, height) + admins, err := m.db.GetAdmins() if err != nil { - logErr.Err(err).Msg("unable to get nfts") + logErr.Err(err).Msg("unable to get admins") return } for _, admin := range admins { - err = m.db.SaveAdmin(admin.Address, admin.VestingPeriodsCount, admin.LastVestingTime, admin.VestingPeriod, admin.RewardPerPeriod, admin.Denom) + vestingInfo, err := m.keeper.GetAdminByAddress(admin.Address, height) + err = m.db.SaveAdmin(admin.Address, vestingInfo.VestingPeriodsCount, vestingInfo.LastVestingTime, vestingInfo.VestingPeriod, vestingInfo.RewardPerPeriod, admin.Denom) if err != nil { - logErr.Err(err).Msg("unable to save nft") + logErr.Err(err).Msg("unable to save admin vesting info") } } diff --git a/modules/accumulator/module.go b/modules/accumulator/module.go index 2d3bc131..2f154821 100644 --- a/modules/accumulator/module.go +++ b/modules/accumulator/module.go @@ -12,7 +12,8 @@ import ( ) var ( - _ modules.Module = &Module{} + _ modules.Module = &Module{} + _ modules.GenesisModule = &Module{} ) // Module represents the x/accumulator module diff --git a/modules/accumulator/source/local/source.go b/modules/accumulator/source/local/source.go index c30aef46..45d81ba7 100644 --- a/modules/accumulator/source/local/source.go +++ b/modules/accumulator/source/local/source.go @@ -1,12 +1,11 @@ package local import ( - "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" accumulatortypes "github.com/cosmos/cosmos-sdk/x/accumulator/types" - "github.com/forbole/juno/v4/node/local" - accumulatorkeeper "github.com/forbole/bdjuno/v4/modules/accumulator/source" + "github.com/forbole/juno/v4/node/local" ) var ( @@ -27,6 +26,20 @@ func NewSource(source *local.Source, nk accumulatortypes.QueryServer) *Source { } } +func (s Source) GetAdminByAddress(address string, height int64) (*accumulatortypes.Admin, error) { + ctx, err := s.LoadHeight(height) + if err != nil { + return nil, errors.Wrap(err, "failed to get height context") + } + + response, err := s.q.GetAdminByAddress(ctx, &accumulatortypes.QueryAdminByAddress{Address: address}) + if err != nil { + return nil, errors.Wrap(err, "failed to query all nfts") + } + + return &response.Admin, nil +} + func (s Source) GetAdmins(pagination *query.PageRequest, height int64) ([]accumulatortypes.Admin, error) { ctx, err := s.LoadHeight(height) if err != nil { diff --git a/modules/accumulator/source/remote/source.go b/modules/accumulator/source/remote/source.go index ef90ea0f..1d11d694 100644 --- a/modules/accumulator/source/remote/source.go +++ b/modules/accumulator/source/remote/source.go @@ -38,3 +38,16 @@ func (s Source) GetAdmins(pagination *query.PageRequest, height int64) ([]accumu return response.Admins, nil } + +func (s Source) GetAdminByAddress(address string, height int64) (*accumulatortypes.Admin, error) { + ctx := remote.GetHeightRequestContext(s.Ctx, height) + + response, err := s.accumulatorClient.GetAdminByAddress(ctx, &accumulatortypes.QueryAdminByAddress{ + Address: address, + }) + if err != nil { + return nil, errors.Wrap(err, "failed to query all nfts") + } + + return &response.Admin, nil +} diff --git a/modules/accumulator/source/source.go b/modules/accumulator/source/source.go index 69a05524..c5886759 100644 --- a/modules/accumulator/source/source.go +++ b/modules/accumulator/source/source.go @@ -7,4 +7,5 @@ import ( type Source interface { GetAdmins(req *query.PageRequest, height int64) ([]types.Admin, error) + GetAdminByAddress(address string, height int64) (*types.Admin, error) } diff --git a/modules/bridge/handle_msg.go b/modules/bridge/handle_msg.go index f9a0e93c..b2161068 100644 --- a/modules/bridge/handle_msg.go +++ b/modules/bridge/handle_msg.go @@ -2,7 +2,7 @@ package bridge import ( "github.com/cosmos/cosmos-sdk/x/authz" - bridge "github.com/hyle-team/bridgeless-core/x/bridge/types" + bridge "github.com/hyle-team/bridgeless-core/v12/x/bridge/types" "github.com/rs/zerolog/log" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,26 +19,26 @@ func (m *Module) HandleMsg(_ int, msg sdk.Msg, tx *juno.Tx) error { switch cosmosMsg := msg.(type) { case *bridge.MsgSubmitTransactions: - return nil + return m.handleMsgSubmitTransactions(tx, cosmosMsg) // chains case *bridge.MsgDeleteChain: - return nil + return m.handleMsgDeleteChain(tx, cosmosMsg) case *bridge.MsgInsertChain: - return nil + return m.handleMsgInsertChain(tx, cosmosMsg) // token info case *bridge.MsgAddTokenInfo: - return nil + return m.handleMsgAddTokenInfo(tx, cosmosMsg) case *bridge.MsgRemoveTokenInfo: - return nil + return m.handleMsgRemoveTokenInfo(tx, cosmosMsg) // token case *bridge.MsgUpdateToken: - return nil + return m.handleMsgUpdateToken(tx, cosmosMsg) case *bridge.MsgDeleteToken: - return nil + return m.handleMsgDeleteToken(tx, cosmosMsg) case *bridge.MsgInsertToken: - return nil + return m.handleMsgInsertToken(tx, cosmosMsg) default: break diff --git a/modules/bridge/handle_msg_chain.go b/modules/bridge/handle_msg_chain.go index a0622d56..5f24d631 100644 --- a/modules/bridge/handle_msg_chain.go +++ b/modules/bridge/handle_msg_chain.go @@ -2,7 +2,7 @@ package bridge import ( juno "github.com/forbole/juno/v4/types" - bridge "github.com/hyle-team/bridgeless-core/x/bridge/types" + bridge "github.com/hyle-team/bridgeless-core/v12/x/bridge/types" ) // handleMsgInsertChain allows to properly handle a MsgRemoveTokenInfo diff --git a/modules/bridge/handle_msg_token.go b/modules/bridge/handle_msg_token.go index 25ed6e0b..34ef70c2 100644 --- a/modules/bridge/handle_msg_token.go +++ b/modules/bridge/handle_msg_token.go @@ -2,7 +2,7 @@ package bridge import ( juno "github.com/forbole/juno/v4/types" - bridge "github.com/hyle-team/bridgeless-core/x/bridge/types" + bridge "github.com/hyle-team/bridgeless-core/v12/x/bridge/types" ) // handleMsgInsertToken allows to properly handle a MsgInsertToken @@ -14,3 +14,8 @@ func (m *Module) handleMsgInsertToken(tx *juno.Tx, msg *bridge.MsgInsertToken) e func (m *Module) handleMsgDeleteToken(tx *juno.Tx, msg *bridge.MsgDeleteToken) error { return nil } + +// handleMsgUpdateToken allows to properly handle a MsgUpdateToken +func (m *Module) handleMsgUpdateToken(tx *juno.Tx, msg *bridge.MsgUpdateToken) error { + return nil +} diff --git a/modules/bridge/handle_msg_token_info.go b/modules/bridge/handle_msg_token_info.go index cba52bb8..06f7dcf8 100644 --- a/modules/bridge/handle_msg_token_info.go +++ b/modules/bridge/handle_msg_token_info.go @@ -2,7 +2,7 @@ package bridge import ( juno "github.com/forbole/juno/v4/types" - bridge "github.com/hyle-team/bridgeless-core/x/bridge/types" + bridge "github.com/hyle-team/bridgeless-core/v12/x/bridge/types" ) // handleMsgAddTokenInfo allows to properly handle a MsgAddTokenInfo diff --git a/modules/bridge/handle_transaction.go b/modules/bridge/handle_transaction.go index f51a1b37..b012314d 100644 --- a/modules/bridge/handle_transaction.go +++ b/modules/bridge/handle_transaction.go @@ -2,7 +2,7 @@ package bridge import ( juno "github.com/forbole/juno/v4/types" - bridge "github.com/hyle-team/bridgeless-core/x/bridge/types" + bridge "github.com/hyle-team/bridgeless-core/v12/x/bridge/types" ) // handleMsgSubmitTransactions allows to properly handle a MsgSubmitTransactions diff --git a/types/config/encoding.go b/types/config/encoding.go index 13ca4e1f..97f6c11c 100644 --- a/types/config/encoding.go +++ b/types/config/encoding.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" - enccodec "github.com/hyle-team/bridgeless-core/encoding/codec" + enccodec "github.com/hyle-team/bridgeless-core/v12/encoding/codec" ) // MakeEncodingConfig creates an EncodingConfig to properly handle all the messages