mukan-sdk/x/genutil/gentx.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
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
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

115 lines
3.4 KiB
Go

package genutil
import (
"encoding/json"
"fmt"
"strings"
abci "git.cw.tr/mukan-network/mukan-consensus/abci/types"
"cosmossdk.io/core/genesis"
"git.cw.tr/mukan-network/mukan-sdk/client"
"git.cw.tr/mukan-network/mukan-sdk/codec"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
bankexported "git.cw.tr/mukan-network/mukan-sdk/x/bank/exported"
"git.cw.tr/mukan-network/mukan-sdk/x/genutil/types"
stakingtypes "git.cw.tr/mukan-network/mukan-sdk/x/staking/types"
)
// SetGenTxsInAppGenesisState - sets the genesis transactions in the app genesis state
func SetGenTxsInAppGenesisState(
cdc codec.JSONCodec, txJSONEncoder sdk.TxEncoder, appGenesisState map[string]json.RawMessage, genTxs []sdk.Tx,
) (map[string]json.RawMessage, error) {
genesisState := types.GetGenesisStateFromAppState(cdc, appGenesisState)
genTxsBz := make([]json.RawMessage, 0, len(genTxs))
for _, genTx := range genTxs {
txBz, err := txJSONEncoder(genTx)
if err != nil {
return appGenesisState, err
}
genTxsBz = append(genTxsBz, txBz)
}
genesisState.GenTxs = genTxsBz
return types.SetGenesisStateInAppState(cdc, appGenesisState, genesisState), nil
}
// ValidateAccountInGenesis checks that the provided account has a sufficient
// balance in the set of genesis accounts.
func ValidateAccountInGenesis(
appGenesisState map[string]json.RawMessage, genBalIterator types.GenesisBalancesIterator,
addr sdk.Address, coins sdk.Coins, cdc codec.JSONCodec,
) error {
var stakingData stakingtypes.GenesisState
cdc.MustUnmarshalJSON(appGenesisState[stakingtypes.ModuleName], &stakingData)
bondDenom := stakingData.Params.BondDenom
var err error
accountIsInGenesis := false
genBalIterator.IterateGenesisBalances(cdc, appGenesisState,
func(bal bankexported.GenesisBalance) (stop bool) {
accAddress := bal.GetAddress()
accCoins := bal.GetCoins()
// ensure that account is in genesis
if strings.EqualFold(accAddress, addr.String()) {
// ensure account contains enough funds of default bond denom
if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) {
err = fmt.Errorf(
"account %s has a balance in genesis, but it only has %v%s available to stake, not %v%s",
addr, accCoins.AmountOf(bondDenom), bondDenom, coins.AmountOf(bondDenom), bondDenom,
)
return true
}
accountIsInGenesis = true
return true
}
return false
},
)
if err != nil {
return err
}
if !accountIsInGenesis {
return fmt.Errorf("account %s does not have a balance in the genesis state", addr)
}
return nil
}
// DeliverGenTxs iterates over all genesis txs, decodes each into a Tx and
// invokes the provided deliverTxfn with the decoded Tx. It returns the result
// of the staking module's ApplyAndReturnValidatorSetUpdates.
func DeliverGenTxs(
ctx sdk.Context, genTxs []json.RawMessage,
stakingKeeper types.StakingKeeper, deliverTx genesis.TxHandler,
txEncodingConfig client.TxEncodingConfig,
) ([]abci.ValidatorUpdate, error) {
for _, genTx := range genTxs {
tx, err := txEncodingConfig.TxJSONDecoder()(genTx)
if err != nil {
return nil, fmt.Errorf("failed to decode GenTx '%s': %w", genTx, err)
}
bz, err := txEncodingConfig.TxEncoder()(tx)
if err != nil {
return nil, fmt.Errorf("failed to encode GenTx '%s': %w", genTx, err)
}
err = deliverTx.ExecuteGenesisTx(bz)
if err != nil {
return nil, fmt.Errorf("failed to execute DeliverTx for '%s': %w", genTx, err)
}
}
return stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
}