diff --git a/database/feegrant_test.go b/database/feegrant_test.go index 41af193c0..0f329a543 100644 --- a/database/feegrant_test.go +++ b/database/feegrant_test.go @@ -37,7 +37,7 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveFeeGrantAllowance() { suite.Require().Equal(rows[0].Height, int64(121622)) var stored feegranttypes.FeeAllowanceI - err = suite.database.EncodingConfig.Marshaler.UnmarshalInterfaceJSON([]byte(rows[0].Allowance), &stored) + err = suite.database.Cdc.UnmarshalInterfaceJSON([]byte(rows[0].Allowance), &stored) suite.Require().NoError(err) suite.Require().Equal(allowance, stored) } diff --git a/database/gov_test.go b/database/gov_test.go index 61267fb57..6661a1583 100644 --- a/database/gov_test.go +++ b/database/gov_test.go @@ -104,7 +104,7 @@ func (suite *DbTestSuite) encodeProposalContent(content govtypes.Content) string anyContent, err := codectypes.NewAnyWithValue(protoContent) suite.Require().NoError(err) - contentBz, err := suite.database.EncodingConfig.Marshaler.MarshalJSON(anyContent) + contentBz, err := suite.database.Cdc.MarshalJSON(anyContent) suite.Require().NoError(err) return string(contentBz) diff --git a/modules/bank/source/local/source.go b/modules/bank/source/local/source.go index 25c346a7d..1eacba49a 100644 --- a/modules/bank/source/local/source.go +++ b/modules/bank/source/local/source.go @@ -1,98 +1,98 @@ package local -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/types/query" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/forbole/juno/v5/node/local" - - "github.com/forbole/bdjuno/v4/modules/bank/source" - "github.com/forbole/bdjuno/v4/types" -) - -var ( - _ source.Source = &Source{} -) - -// Source represents the implementation of the bank keeper that works on a local node -type Source struct { - *local.Source - q banktypes.QueryServer -} - -// NewSource builds a new Source instance -func NewSource(source *local.Source, bk banktypes.QueryServer) *Source { - return &Source{ - Source: source, - q: bk, - } -} - -// GetBalances implements keeper.Source -func (s Source) GetBalances(addresses []string, height int64) ([]types.AccountBalance, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - var balances []types.AccountBalance - for _, address := range addresses { - res, err := s.q.AllBalances(sdk.WrapSDKContext(ctx), &banktypes.QueryAllBalancesRequest{Address: address}) - if err != nil { - return nil, err - } - - balances = append(balances, types.NewAccountBalance(address, res.Balances, height)) - } - - return balances, nil -} - -// GetSupply implements bankkeeper.Source -func (s Source) GetSupply(height int64) (sdk.Coins, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - var coins []sdk.Coin - var nextKey []byte - var stop = false - for !stop { - res, err := s.q.TotalSupply( - sdk.WrapSDKContext(ctx), - &banktypes.QueryTotalSupplyRequest{ - Pagination: &query.PageRequest{ - Key: nextKey, - Limit: 100, // Query 100 supplies at time - }, - }) - if err != nil { - return nil, fmt.Errorf("error while getting total supply: %s", err) - } - - nextKey = res.Pagination.NextKey - stop = len(res.Pagination.NextKey) == 0 - coins = append(coins, res.Supply...) - } - - return coins, nil -} - -// GetAccountBalances implements bankkeeper.Source -func (s Source) GetAccountBalance(address string, height int64) ([]sdk.Coin, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - balRes, err := s.q.AllBalances(sdk.WrapSDKContext(ctx), &banktypes.QueryAllBalancesRequest{Address: address}) - if err != nil { - return nil, fmt.Errorf("error while getting all balances: %s", err) - } - - return balRes.Balances, nil -} +// import ( +// "fmt" + +// "github.com/cosmos/cosmos-sdk/types/query" +// banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// "github.com/forbole/juno/v5/node/local" + +// "github.com/forbole/bdjuno/v4/modules/bank/source" +// "github.com/forbole/bdjuno/v4/types" +// ) + +// var ( +// _ source.Source = &Source{} +// ) + +// // Source represents the implementation of the bank keeper that works on a local node +// type Source struct { +// *local.Source +// q banktypes.QueryServer +// } + +// // NewSource builds a new Source instance +// func NewSource(source *local.Source, bk banktypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// q: bk, +// } +// } + +// // GetBalances implements keeper.Source +// func (s Source) GetBalances(addresses []string, height int64) ([]types.AccountBalance, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// var balances []types.AccountBalance +// for _, address := range addresses { +// res, err := s.q.AllBalances(sdk.WrapSDKContext(ctx), &banktypes.QueryAllBalancesRequest{Address: address}) +// if err != nil { +// return nil, err +// } + +// balances = append(balances, types.NewAccountBalance(address, res.Balances, height)) +// } + +// return balances, nil +// } + +// // GetSupply implements bankkeeper.Source +// func (s Source) GetSupply(height int64) (sdk.Coins, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// var coins []sdk.Coin +// var nextKey []byte +// var stop = false +// for !stop { +// res, err := s.q.TotalSupply( +// sdk.WrapSDKContext(ctx), +// &banktypes.QueryTotalSupplyRequest{ +// Pagination: &query.PageRequest{ +// Key: nextKey, +// Limit: 100, // Query 100 supplies at time +// }, +// }) +// if err != nil { +// return nil, fmt.Errorf("error while getting total supply: %s", err) +// } + +// nextKey = res.Pagination.NextKey +// stop = len(res.Pagination.NextKey) == 0 +// coins = append(coins, res.Supply...) +// } + +// return coins, nil +// } + +// // GetAccountBalances implements bankkeeper.Source +// func (s Source) GetAccountBalance(address string, height int64) ([]sdk.Coin, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// balRes, err := s.q.AllBalances(sdk.WrapSDKContext(ctx), &banktypes.QueryAllBalancesRequest{Address: address}) +// if err != nil { +// return nil, fmt.Errorf("error while getting all balances: %s", err) +// } + +// return balRes.Balances, nil +// } diff --git a/modules/distribution/source/local/source.go b/modules/distribution/source/local/source.go index 42ccd311b..3eee039d2 100644 --- a/modules/distribution/source/local/source.go +++ b/modules/distribution/source/local/source.go @@ -1,112 +1,112 @@ package local -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/forbole/juno/v5/node/local" - - distrsource "github.com/forbole/bdjuno/v4/modules/distribution/source" -) - -var ( - _ distrsource.Source = &Source{} -) - -// Source implements distrsource.Source reading the data from a local node -type Source struct { - *local.Source - q distrtypes.QueryServer -} - -func NewSource(source *local.Source, keeper distrtypes.QueryServer) *Source { - return &Source{ - Source: source, - q: keeper, - } -} - -// ValidatorCommission implements distrsource.Source -func (s Source) ValidatorCommission(valOperAddr string, height int64) (sdk.DecCoins, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.ValidatorCommission( - sdk.WrapSDKContext(ctx), - &distrtypes.QueryValidatorCommissionRequest{ValidatorAddress: valOperAddr}, - ) - if err != nil { - return nil, err - } - - return res.Commission.Commission, nil -} - -// DelegatorTotalRewards implements distrsource.Source -func (s Source) DelegatorTotalRewards(delegator string, height int64) ([]distrtypes.DelegationDelegatorReward, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.DelegationTotalRewards( - sdk.WrapSDKContext(ctx), - &distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegator}, - ) - if err != nil { - return nil, err - } - - return res.Rewards, nil -} - -// DelegatorWithdrawAddress implements distrsource.Source -func (s Source) DelegatorWithdrawAddress(delegator string, height int64) (string, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return "", fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.DelegatorWithdrawAddress( - sdk.WrapSDKContext(ctx), - &distrtypes.QueryDelegatorWithdrawAddressRequest{DelegatorAddress: delegator}, - ) - if err != nil { - return "", err - } - - return res.WithdrawAddress, nil -} - -// CommunityPool implements distrsource.Source -func (s Source) CommunityPool(height int64) (sdk.DecCoins, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.CommunityPool(sdk.WrapSDKContext(ctx), &distrtypes.QueryCommunityPoolRequest{}) - if err != nil { - return nil, err - } - - return res.Pool, nil -} - -// Params implements distrsource.Source -func (s Source) Params(height int64) (distrtypes.Params, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return distrtypes.Params{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Params(sdk.WrapSDKContext(ctx), &distrtypes.QueryParamsRequest{}) - if err != nil { - return distrtypes.Params{}, err - } - - return res.Params, nil -} +// import ( +// "fmt" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" +// "github.com/forbole/juno/v5/node/local" + +// distrsource "github.com/forbole/bdjuno/v4/modules/distribution/source" +// ) + +// var ( +// _ distrsource.Source = &Source{} +// ) + +// // Source implements distrsource.Source reading the data from a local node +// type Source struct { +// *local.Source +// q distrtypes.QueryServer +// } + +// func NewSource(source *local.Source, keeper distrtypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// q: keeper, +// } +// } + +// // ValidatorCommission implements distrsource.Source +// func (s Source) ValidatorCommission(valOperAddr string, height int64) (sdk.DecCoins, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.ValidatorCommission( +// sdk.WrapSDKContext(ctx), +// &distrtypes.QueryValidatorCommissionRequest{ValidatorAddress: valOperAddr}, +// ) +// if err != nil { +// return nil, err +// } + +// return res.Commission.Commission, nil +// } + +// // DelegatorTotalRewards implements distrsource.Source +// func (s Source) DelegatorTotalRewards(delegator string, height int64) ([]distrtypes.DelegationDelegatorReward, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.DelegationTotalRewards( +// sdk.WrapSDKContext(ctx), +// &distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegator}, +// ) +// if err != nil { +// return nil, err +// } + +// return res.Rewards, nil +// } + +// // DelegatorWithdrawAddress implements distrsource.Source +// func (s Source) DelegatorWithdrawAddress(delegator string, height int64) (string, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return "", fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.DelegatorWithdrawAddress( +// sdk.WrapSDKContext(ctx), +// &distrtypes.QueryDelegatorWithdrawAddressRequest{DelegatorAddress: delegator}, +// ) +// if err != nil { +// return "", err +// } + +// return res.WithdrawAddress, nil +// } + +// // CommunityPool implements distrsource.Source +// func (s Source) CommunityPool(height int64) (sdk.DecCoins, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.CommunityPool(sdk.WrapSDKContext(ctx), &distrtypes.QueryCommunityPoolRequest{}) +// if err != nil { +// return nil, err +// } + +// return res.Pool, nil +// } + +// // Params implements distrsource.Source +// func (s Source) Params(height int64) (distrtypes.Params, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return distrtypes.Params{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Params(sdk.WrapSDKContext(ctx), &distrtypes.QueryParamsRequest{}) +// if err != nil { +// return distrtypes.Params{}, err +// } + +// return res.Params, nil +// } diff --git a/modules/feegrant/handle_block.go b/modules/feegrant/handle_block.go index fae8cb787..97808f89b 100644 --- a/modules/feegrant/handle_block.go +++ b/modules/feegrant/handle_block.go @@ -43,7 +43,7 @@ func (m *Module) removeExpiredFeeGrantAllowances(height int64, events []abci.Eve if err != nil { return fmt.Errorf("error while getting fee grant grantee address: %s", err) } - err = m.db.DeleteFeeGrantAllowance(types.NewGrantRemoval(string(granteeAddress.Value), string(granterAddress.Value), height)) + err = m.db.DeleteFeeGrantAllowance(types.NewGrantRemoval(granteeAddress.Value, granterAddress.Value, height)) if err != nil { return fmt.Errorf("error while deleting fee grant allowance: %s", err) diff --git a/modules/gov/source/local/source.go b/modules/gov/source/local/source.go index e45fac789..b5080fcae 100644 --- a/modules/gov/source/local/source.go +++ b/modules/gov/source/local/source.go @@ -1,119 +1,119 @@ package local -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/forbole/juno/v5/node/local" - - govsource "github.com/forbole/bdjuno/v4/modules/gov/source" -) - -var ( - _ govsource.Source = &Source{} -) - -// Source implements govsource.Source by using a local node -type Source struct { - *local.Source - q govtypes.QueryServer -} - -// NewSource returns a new Source instance -func NewSource(source *local.Source, govKeeper govtypes.QueryServer) *Source { - return &Source{ - Source: source, - q: govKeeper, - } -} - -// Proposal implements govsource.Source -func (s Source) Proposal(height int64, id uint64) (govtypes.Proposal, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.Proposal{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Proposal(sdk.WrapSDKContext(ctx), &govtypes.QueryProposalRequest{ProposalId: id}) - if err != nil { - return govtypes.Proposal{}, err - } - - return res.Proposal, nil -} - -// ProposalDeposit implements govsource.Source -func (s Source) ProposalDeposit(height int64, id uint64, depositor string) (govtypes.Deposit, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.Deposit{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Deposit(sdk.WrapSDKContext(ctx), &govtypes.QueryDepositRequest{ProposalId: id, Depositor: depositor}) - if err != nil { - return govtypes.Deposit{}, err - } - - return res.Deposit, nil -} - -// TallyResult implements govsource.Source -func (s Source) TallyResult(height int64, proposalID uint64) (govtypes.TallyResult, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.TallyResult{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.TallyResult(sdk.WrapSDKContext(ctx), &govtypes.QueryTallyResultRequest{ProposalId: proposalID}) - if err != nil { - return govtypes.TallyResult{}, err - } - - return res.Tally, nil -} - -// DepositParams implements govsource.Source -func (s Source) DepositParams(height int64) (govtypes.DepositParams, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.DepositParams{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamDeposit}) - if err != nil { - return govtypes.DepositParams{}, err - } - - return res.DepositParams, nil -} - -// VotingParams implements govsource.Source -func (s Source) VotingParams(height int64) (govtypes.VotingParams, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.VotingParams{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamVoting}) - if err != nil { - return govtypes.VotingParams{}, err - } - - return res.VotingParams, nil -} - -// TallyParams implements govsource.Source -func (s Source) TallyParams(height int64) (govtypes.TallyParams, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return govtypes.TallyParams{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamTallying}) - if err != nil { - return govtypes.TallyParams{}, err - } - - return res.TallyParams, nil -} +// import ( +// "fmt" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" +// "github.com/forbole/juno/v5/node/local" + +// govsource "github.com/forbole/bdjuno/v4/modules/gov/source" +// ) + +// var ( +// _ govsource.Source = &Source{} +// ) + +// // Source implements govsource.Source by using a local node +// type Source struct { +// *local.Source +// q govtypes.QueryServer +// } + +// // NewSource returns a new Source instance +// func NewSource(source *local.Source, govKeeper govtypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// q: govKeeper, +// } +// } + +// // Proposal implements govsource.Source +// func (s Source) Proposal(height int64, id uint64) (govtypes.Proposal, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.Proposal{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Proposal(sdk.WrapSDKContext(ctx), &govtypes.QueryProposalRequest{ProposalId: id}) +// if err != nil { +// return govtypes.Proposal{}, err +// } + +// return res.Proposal, nil +// } + +// // ProposalDeposit implements govsource.Source +// func (s Source) ProposalDeposit(height int64, id uint64, depositor string) (govtypes.Deposit, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.Deposit{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Deposit(sdk.WrapSDKContext(ctx), &govtypes.QueryDepositRequest{ProposalId: id, Depositor: depositor}) +// if err != nil { +// return govtypes.Deposit{}, err +// } + +// return res.Deposit, nil +// } + +// // TallyResult implements govsource.Source +// func (s Source) TallyResult(height int64, proposalID uint64) (govtypes.TallyResult, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.TallyResult{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.TallyResult(sdk.WrapSDKContext(ctx), &govtypes.QueryTallyResultRequest{ProposalId: proposalID}) +// if err != nil { +// return govtypes.TallyResult{}, err +// } + +// return res.Tally, nil +// } + +// // DepositParams implements govsource.Source +// func (s Source) DepositParams(height int64) (govtypes.DepositParams, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.DepositParams{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamDeposit}) +// if err != nil { +// return govtypes.DepositParams{}, err +// } + +// return res.DepositParams, nil +// } + +// // VotingParams implements govsource.Source +// func (s Source) VotingParams(height int64) (govtypes.VotingParams, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.VotingParams{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamVoting}) +// if err != nil { +// return govtypes.VotingParams{}, err +// } + +// return res.VotingParams, nil +// } + +// // TallyParams implements govsource.Source +// func (s Source) TallyParams(height int64) (govtypes.TallyParams, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return govtypes.TallyParams{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Params(sdk.WrapSDKContext(ctx), &govtypes.QueryParamsRequest{ParamsType: govtypes.ParamTallying}) +// if err != nil { +// return govtypes.TallyParams{}, err +// } + +// return res.TallyParams, nil +// } diff --git a/modules/mint/source/local/source.go b/modules/mint/source/local/source.go index 56b74a789..67789fbc4 100644 --- a/modules/mint/source/local/source.go +++ b/modules/mint/source/local/source.go @@ -1,59 +1,59 @@ package local -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/forbole/juno/v5/node/local" - - mintsource "github.com/forbole/bdjuno/v4/modules/mint/source" -) - -var ( - _ mintsource.Source = &Source{} -) - -// Source implements mintsource.Source using a local node -type Source struct { - *local.Source - querier minttypes.QueryServer -} - -// NewSource returns a new Source instance -func NewSource(source *local.Source, querier minttypes.QueryServer) *Source { - return &Source{ - Source: source, - querier: querier, - } -} - -// GetInflation implements mintsource.Source -func (s Source) GetInflation(height int64) (sdk.Dec, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return sdk.Dec{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.querier.Inflation(sdk.WrapSDKContext(ctx), &minttypes.QueryInflationRequest{}) - if err != nil { - return sdk.Dec{}, err - } - - return res.Inflation, nil -} - -// Params implements mintsource.Source -func (s Source) Params(height int64) (minttypes.Params, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return minttypes.Params{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.querier.Params(sdk.WrapSDKContext(ctx), &minttypes.QueryParamsRequest{}) - if err != nil { - return minttypes.Params{}, err - } - - return res.Params, nil -} +// import ( +// "fmt" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" +// "github.com/forbole/juno/v5/node/local" + +// mintsource "github.com/forbole/bdjuno/v4/modules/mint/source" +// ) + +// var ( +// _ mintsource.Source = &Source{} +// ) + +// // Source implements mintsource.Source using a local node +// type Source struct { +// *local.Source +// querier minttypes.QueryServer +// } + +// // NewSource returns a new Source instance +// func NewSource(source *local.Source, querier minttypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// querier: querier, +// } +// } + +// // GetInflation implements mintsource.Source +// func (s Source) GetInflation(height int64) (sdk.Dec, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return sdk.Dec{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.querier.Inflation(sdk.WrapSDKContext(ctx), &minttypes.QueryInflationRequest{}) +// if err != nil { +// return sdk.Dec{}, err +// } + +// return res.Inflation, nil +// } + +// // Params implements mintsource.Source +// func (s Source) Params(height int64) (minttypes.Params, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return minttypes.Params{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.querier.Params(sdk.WrapSDKContext(ctx), &minttypes.QueryParamsRequest{}) +// if err != nil { +// return minttypes.Params{}, err +// } + +// return res.Params, nil +// } diff --git a/modules/slashing/source/local/source.go b/modules/slashing/source/local/source.go index 95271bead..e8a89f60e 100644 --- a/modules/slashing/source/local/source.go +++ b/modules/slashing/source/local/source.go @@ -1,98 +1,98 @@ package local -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/forbole/juno/v5/node/local" - - slashingsource "github.com/forbole/bdjuno/v4/modules/slashing/source" -) - -var ( - _ slashingsource.Source = &Source{} -) - -// Source implements slashingsource.Source using a local node -type Source struct { - *local.Source - querier slashingtypes.QueryServer -} - -// NewSource implements a new Source instance -func NewSource(source *local.Source, querier slashingtypes.QueryServer) *Source { - return &Source{ - Source: source, - querier: querier, - } -} - -// GetSigningInfos implements slashingsource.Source -func (s Source) GetSigningInfos(height int64) ([]slashingtypes.ValidatorSigningInfo, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - var signingInfos []slashingtypes.ValidatorSigningInfo - var nextKey []byte - var stop = false - for !stop { - res, err := s.querier.SigningInfos( - sdk.WrapSDKContext(ctx), - &slashingtypes.QuerySigningInfosRequest{ - Pagination: &query.PageRequest{ - Key: nextKey, - Limit: 1000, // Query 1000 signing infos at a time - }, - }, - ) - if err != nil { - return nil, err - } - - nextKey = res.Pagination.NextKey - stop = len(res.Pagination.NextKey) == 0 - signingInfos = append(signingInfos, res.Info...) - } - - return signingInfos, nil -} - -// GetParams implements slashingsource.Source -func (s Source) GetParams(height int64) (slashingtypes.Params, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return slashingtypes.Params{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.querier.Params(sdk.WrapSDKContext(ctx), &slashingtypes.QueryParamsRequest{}) - if err != nil { - return slashingtypes.Params{}, nil - } - - return res.Params, nil -} - -// GetSigningInfo implements slashingsource.GetSigningInfo -func (s Source) GetSigningInfo(height int64, consAddr sdk.ConsAddress) (slashingtypes.ValidatorSigningInfo, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return slashingtypes.ValidatorSigningInfo{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.querier.SigningInfo( - sdk.WrapSDKContext(ctx), - &slashingtypes.QuerySigningInfoRequest{ - ConsAddress: consAddr.String(), - }, - ) - - if err != nil { - return slashingtypes.ValidatorSigningInfo{}, err - } - - return res.ValSigningInfo, nil -} +// import ( +// "fmt" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// "github.com/cosmos/cosmos-sdk/types/query" +// slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" +// "github.com/forbole/juno/v5/node/local" + +// slashingsource "github.com/forbole/bdjuno/v4/modules/slashing/source" +// ) + +// var ( +// _ slashingsource.Source = &Source{} +// ) + +// // Source implements slashingsource.Source using a local node +// type Source struct { +// *local.Source +// querier slashingtypes.QueryServer +// } + +// // NewSource implements a new Source instance +// func NewSource(source *local.Source, querier slashingtypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// querier: querier, +// } +// } + +// // GetSigningInfos implements slashingsource.Source +// func (s Source) GetSigningInfos(height int64) ([]slashingtypes.ValidatorSigningInfo, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// var signingInfos []slashingtypes.ValidatorSigningInfo +// var nextKey []byte +// var stop = false +// for !stop { +// res, err := s.querier.SigningInfos( +// sdk.WrapSDKContext(ctx), +// &slashingtypes.QuerySigningInfosRequest{ +// Pagination: &query.PageRequest{ +// Key: nextKey, +// Limit: 1000, // Query 1000 signing infos at a time +// }, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// nextKey = res.Pagination.NextKey +// stop = len(res.Pagination.NextKey) == 0 +// signingInfos = append(signingInfos, res.Info...) +// } + +// return signingInfos, nil +// } + +// // GetParams implements slashingsource.Source +// func (s Source) GetParams(height int64) (slashingtypes.Params, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return slashingtypes.Params{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.querier.Params(sdk.WrapSDKContext(ctx), &slashingtypes.QueryParamsRequest{}) +// if err != nil { +// return slashingtypes.Params{}, nil +// } + +// return res.Params, nil +// } + +// // GetSigningInfo implements slashingsource.GetSigningInfo +// func (s Source) GetSigningInfo(height int64, consAddr sdk.ConsAddress) (slashingtypes.ValidatorSigningInfo, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return slashingtypes.ValidatorSigningInfo{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.querier.SigningInfo( +// sdk.WrapSDKContext(ctx), +// &slashingtypes.QuerySigningInfoRequest{ +// ConsAddress: consAddr.String(), +// }, +// ) + +// if err != nil { +// return slashingtypes.ValidatorSigningInfo{}, err +// } + +// return res.ValSigningInfo, nil +// } diff --git a/modules/staking/source/local/source.go b/modules/staking/source/local/source.go index d1d1825fb..d9837f8d8 100644 --- a/modules/staking/source/local/source.go +++ b/modules/staking/source/local/source.go @@ -1,227 +1,227 @@ package local -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/forbole/juno/v5/node/local" - - stakingsource "github.com/forbole/bdjuno/v4/modules/staking/source" -) - -var ( - _ stakingsource.Source = &Source{} -) - -// Source implements stakingsource.Source using a local node -type Source struct { - *local.Source - q stakingtypes.QueryServer -} - -// NewSource returns a new Source instance -func NewSource(source *local.Source, querier stakingtypes.QueryServer) *Source { - return &Source{ - Source: source, - q: querier, - } -} - -// GetValidator implements stakingsource.Source -func (s Source) GetValidator(height int64, valOper string) (stakingtypes.Validator, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return stakingtypes.Validator{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Validator(sdk.WrapSDKContext(ctx), &stakingtypes.QueryValidatorRequest{ValidatorAddr: valOper}) - if err != nil { - return stakingtypes.Validator{}, fmt.Errorf("error while reading validator: %s", err) - } - - return res.Validator, nil -} - -// GetDelegationsWithPagination implements stakingsource.Source -func (s Source) GetDelegationsWithPagination(height int64, delegator string, pagination *query.PageRequest) (*stakingtypes.QueryDelegatorDelegationsResponse, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.DelegatorDelegations( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryDelegatorDelegationsRequest{ - DelegatorAddr: delegator, - Pagination: &query.PageRequest{ - Limit: pagination.GetLimit(), - Offset: pagination.GetOffset(), - CountTotal: pagination.GetCountTotal(), - }, - }, - ) - if err != nil { - return nil, err - } - - return res, nil -} - -// GetRedelegations implements stakingsource.Source -func (s Source) GetRedelegations(height int64, request *stakingtypes.QueryRedelegationsRequest) (*stakingtypes.QueryRedelegationsResponse, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - redelegations, err := s.q.Redelegations(sdk.WrapSDKContext(ctx), request) - if err != nil { - return nil, err - } - - return redelegations, nil -} - -// GetValidatorsWithStatus implements stakingsource.Source -func (s Source) GetValidatorsWithStatus(height int64, status string) ([]stakingtypes.Validator, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - var validators []stakingtypes.Validator - var nextKey []byte - var stop = false - for !stop { - res, err := s.q.Validators( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryValidatorsRequest{ - Status: status, - Pagination: &query.PageRequest{ - Key: nextKey, - Limit: 100, // Query 100 validators at time - }, - }, - ) - if err != nil { - return nil, err - } - - nextKey = res.Pagination.NextKey - stop = len(res.Pagination.NextKey) == 0 - validators = append(validators, res.Validators...) - } - - return validators, nil -} - -// GetPool implements stakingsource.Source -func (s Source) GetPool(height int64) (stakingtypes.Pool, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return stakingtypes.Pool{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Pool( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryPoolRequest{}, - ) - if err != nil { - return stakingtypes.Pool{}, err - } - - return res.Pool, nil -} - -// GetParams implements stakingsource.Source -func (s Source) GetParams(height int64) (stakingtypes.Params, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return stakingtypes.Params{}, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.Params( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryParamsRequest{}, - ) - if err != nil { - return stakingtypes.Params{}, nil - } - - return res.Params, nil -} - -// GetUnbondingDelegations implements stakingsource.Source -func (s Source) GetUnbondingDelegations(height int64, delegator string, pagination *query.PageRequest) (*stakingtypes.QueryDelegatorUnbondingDelegationsResponse, error) { - - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - unbondingDelegations, err := s.q.DelegatorUnbondingDelegations( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{ - DelegatorAddr: delegator, - Pagination: &query.PageRequest{ - Limit: pagination.GetLimit(), - Offset: pagination.GetOffset(), - CountTotal: pagination.GetCountTotal(), - }, - }, - ) - if err != nil { - return nil, err - } - - return unbondingDelegations, nil - -} - -// GetValidatorDelegationsWithPagination implements stakingsource.Source -func (s Source) GetValidatorDelegationsWithPagination( - height int64, validator string, pagination *query.PageRequest, -) (*stakingtypes.QueryValidatorDelegationsResponse, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - res, err := s.q.ValidatorDelegations( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryValidatorDelegationsRequest{ - ValidatorAddr: validator, - Pagination: pagination, - }, - ) - if err != nil { - return nil, err - } - - return res, nil -} - -// GetUnbondingDelegationsFromValidator implements stakingsource.Source -func (s Source) GetUnbondingDelegationsFromValidator( - height int64, validator string, pagination *query.PageRequest, -) (*stakingtypes.QueryValidatorUnbondingDelegationsResponse, error) { - ctx, err := s.LoadHeight(height) - if err != nil { - return nil, fmt.Errorf("error while loading height: %s", err) - } - - unbondingDelegations, err := s.q.ValidatorUnbondingDelegations( - sdk.WrapSDKContext(ctx), - &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ - ValidatorAddr: validator, - Pagination: pagination, - }, - ) - if err != nil { - return nil, err - } - - return unbondingDelegations, nil -} +// import ( +// "fmt" + +// sdk "github.com/cosmos/cosmos-sdk/types" +// "github.com/cosmos/cosmos-sdk/types/query" +// stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +// "github.com/forbole/juno/v5/node/local" + +// stakingsource "github.com/forbole/bdjuno/v4/modules/staking/source" +// ) + +// var ( +// _ stakingsource.Source = &Source{} +// ) + +// // Source implements stakingsource.Source using a local node +// type Source struct { +// *local.Source +// q stakingtypes.QueryServer +// } + +// // NewSource returns a new Source instance +// func NewSource(source *local.Source, querier stakingtypes.QueryServer) *Source { +// return &Source{ +// Source: source, +// q: querier, +// } +// } + +// // GetValidator implements stakingsource.Source +// func (s Source) GetValidator(height int64, valOper string) (stakingtypes.Validator, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return stakingtypes.Validator{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Validator(sdk.WrapSDKContext(ctx), &stakingtypes.QueryValidatorRequest{ValidatorAddr: valOper}) +// if err != nil { +// return stakingtypes.Validator{}, fmt.Errorf("error while reading validator: %s", err) +// } + +// return res.Validator, nil +// } + +// // GetDelegationsWithPagination implements stakingsource.Source +// func (s Source) GetDelegationsWithPagination(height int64, delegator string, pagination *query.PageRequest) (*stakingtypes.QueryDelegatorDelegationsResponse, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.DelegatorDelegations( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryDelegatorDelegationsRequest{ +// DelegatorAddr: delegator, +// Pagination: &query.PageRequest{ +// Limit: pagination.GetLimit(), +// Offset: pagination.GetOffset(), +// CountTotal: pagination.GetCountTotal(), +// }, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// return res, nil +// } + +// // GetRedelegations implements stakingsource.Source +// func (s Source) GetRedelegations(height int64, request *stakingtypes.QueryRedelegationsRequest) (*stakingtypes.QueryRedelegationsResponse, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// redelegations, err := s.q.Redelegations(sdk.WrapSDKContext(ctx), request) +// if err != nil { +// return nil, err +// } + +// return redelegations, nil +// } + +// // GetValidatorsWithStatus implements stakingsource.Source +// func (s Source) GetValidatorsWithStatus(height int64, status string) ([]stakingtypes.Validator, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// var validators []stakingtypes.Validator +// var nextKey []byte +// var stop = false +// for !stop { +// res, err := s.q.Validators( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryValidatorsRequest{ +// Status: status, +// Pagination: &query.PageRequest{ +// Key: nextKey, +// Limit: 100, // Query 100 validators at time +// }, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// nextKey = res.Pagination.NextKey +// stop = len(res.Pagination.NextKey) == 0 +// validators = append(validators, res.Validators...) +// } + +// return validators, nil +// } + +// // GetPool implements stakingsource.Source +// func (s Source) GetPool(height int64) (stakingtypes.Pool, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return stakingtypes.Pool{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Pool( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryPoolRequest{}, +// ) +// if err != nil { +// return stakingtypes.Pool{}, err +// } + +// return res.Pool, nil +// } + +// // GetParams implements stakingsource.Source +// func (s Source) GetParams(height int64) (stakingtypes.Params, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return stakingtypes.Params{}, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.Params( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryParamsRequest{}, +// ) +// if err != nil { +// return stakingtypes.Params{}, nil +// } + +// return res.Params, nil +// } + +// // GetUnbondingDelegations implements stakingsource.Source +// func (s Source) GetUnbondingDelegations(height int64, delegator string, pagination *query.PageRequest) (*stakingtypes.QueryDelegatorUnbondingDelegationsResponse, error) { + +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// unbondingDelegations, err := s.q.DelegatorUnbondingDelegations( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{ +// DelegatorAddr: delegator, +// Pagination: &query.PageRequest{ +// Limit: pagination.GetLimit(), +// Offset: pagination.GetOffset(), +// CountTotal: pagination.GetCountTotal(), +// }, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// return unbondingDelegations, nil + +// } + +// // GetValidatorDelegationsWithPagination implements stakingsource.Source +// func (s Source) GetValidatorDelegationsWithPagination( +// height int64, validator string, pagination *query.PageRequest, +// ) (*stakingtypes.QueryValidatorDelegationsResponse, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// res, err := s.q.ValidatorDelegations( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryValidatorDelegationsRequest{ +// ValidatorAddr: validator, +// Pagination: pagination, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// return res, nil +// } + +// // GetUnbondingDelegationsFromValidator implements stakingsource.Source +// func (s Source) GetUnbondingDelegationsFromValidator( +// height int64, validator string, pagination *query.PageRequest, +// ) (*stakingtypes.QueryValidatorUnbondingDelegationsResponse, error) { +// ctx, err := s.LoadHeight(height) +// if err != nil { +// return nil, fmt.Errorf("error while loading height: %s", err) +// } + +// unbondingDelegations, err := s.q.ValidatorUnbondingDelegations( +// sdk.WrapSDKContext(ctx), +// &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ +// ValidatorAddr: validator, +// Pagination: pagination, +// }, +// ) +// if err != nil { +// return nil, err +// } + +// return unbondingDelegations, nil +// }