Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math"
|
|
|
|
"cosmossdk.io/collections"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/query"
|
|
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
)
|
|
|
|
// InitGenesis initializes the bank module's state from a given genesis state.
|
|
func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisState) {
|
|
if err := k.SetParams(ctx, genState.Params); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for _, se := range genState.GetAllSendEnabled() {
|
|
k.SetSendEnabled(ctx, se.Denom, se.Enabled)
|
|
}
|
|
totalSupplyMap := sdk.NewMapCoins(sdk.Coins{})
|
|
|
|
genState.Balances = types.SanitizeGenesisBalances(genState.Balances)
|
|
|
|
for _, balance := range genState.Balances {
|
|
addr := balance.GetAddress()
|
|
bz, err := k.ak.AddressCodec().StringToBytes(addr)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for _, coin := range balance.Coins {
|
|
err := k.Balances.Set(ctx, collections.Join(sdk.AccAddress(bz), coin.Denom), coin.Amount)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
totalSupplyMap.Add(balance.Coins...)
|
|
}
|
|
totalSupply := totalSupplyMap.ToCoins()
|
|
|
|
if !genState.Supply.Empty() && !genState.Supply.Equal(totalSupply) {
|
|
panic(fmt.Errorf("genesis supply is incorrect, expected %v, got %v", genState.Supply, totalSupply))
|
|
}
|
|
|
|
for _, supply := range totalSupply {
|
|
k.setSupply(ctx, supply)
|
|
}
|
|
|
|
for _, meta := range genState.DenomMetadata {
|
|
k.SetDenomMetaData(ctx, meta)
|
|
}
|
|
}
|
|
|
|
// ExportGenesis returns the bank module's genesis state.
|
|
func (k BaseKeeper) ExportGenesis(ctx context.Context) *types.GenesisState {
|
|
totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: math.MaxUint64})
|
|
if err != nil {
|
|
panic(fmt.Errorf("unable to fetch total supply %w", err))
|
|
}
|
|
|
|
rv := types.NewGenesisState(
|
|
k.GetParams(ctx),
|
|
k.GetAccountsBalances(ctx),
|
|
totalSupply,
|
|
k.GetAllDenomMetaData(ctx),
|
|
k.GetAllSendEnabledEntries(ctx),
|
|
)
|
|
return rv
|
|
}
|