Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CUDOS manifest cli command [3] #400

Merged
merged 15 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/upgrade_0_11_4_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ func (app *App) DeleteContractStates(ctx types.Context, networkInfo *NetworkConf

contractsToWipe = networkInfo.Contracts.Reconciliation.GetContracts(contractsToWipe)

// NOTE(jv): Commented out intentionally
//contractsToWipe = networkInfo.Contracts.Almanac.GetContracts(contractsToWipe)
//contractsToWipe = networkInfo.Contracts.AName.GetContracts(contractsToWipe)
contractsToWipe = networkInfo.Contracts.Almanac.GetContracts(contractsToWipe)
contractsToWipe = networkInfo.Contracts.AName.GetContracts(contractsToWipe)

for _, contract := range contractsToWipe {
err := app.DeleteContractState(ctx, contract, manifest)
Expand Down
25 changes: 25 additions & 0 deletions app/upgrade_v_11_4_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"io"
"os"
"path"
)
Expand Down Expand Up @@ -254,6 +255,30 @@ func SaveManifestToPath(manifest *UpgradeManifest, manifestFilePath string) erro
return nil
}

func LoadManifestFromPath(manifestFilePath string) (*UpgradeManifest, error) {
var manifest UpgradeManifest

// Open the file
file, err := os.Open(manifestFilePath)
if err != nil {
return nil, fmt.Errorf("failed to open file \"%s\": %w", manifestFilePath, err)
}
defer file.Close()

// Read the file contents
fileContents, err := io.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("failed to read file \"%s\": %w", manifestFilePath, err)
}

// Unmarshal the JSON content into the manifest
if err := json.Unmarshal(fileContents, &manifest); err != nil {
return nil, fmt.Errorf("failed to unmarshal manifest from file \"%s\": %w", manifestFilePath, err)
}

return &manifest, nil
}

func RegisterVestingCollision(manifest *UpgradeManifest, originalAccount *AccountInfo, targetAccountFunds types.Coins, targetAccount authtypes.AccountI) error {
if manifest.VestingCollision == nil {
manifest.VestingCollision = &UpgradeVestingCollision{}
Expand Down
133 changes: 133 additions & 0 deletions cmd/fetchd/cmd/cudos_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ It utilizes the provided network merge config and genesis JSON files to perform
networkMergeCmd.AddCommand(cmd)
}

func AddCommandManifestAddressInfo(networkMergeCmd *cobra.Command) {
cmd := &cobra.Command{
Use: "manifest-address-info [manifest_file_path] [address]",
Short: "Extracts balance information for a specific address",
Long: `This command retrieves all balance information for a given address from almanac, including the amount delegated to validators, and rewards.`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := client.GetClientContextFromCmd(cmd)

manifestFilePath := args[0]
address := args[1]

// Call a function to extract address info
err := AlmanacAddressInfo(manifestFilePath, address, ctx)
if err != nil {
return err
}
return nil
},
}

networkMergeCmd.AddCommand(cmd)
}

func utilNetworkMergeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "network-merge",
Expand All @@ -127,6 +151,8 @@ func utilNetworkMergeCommand() *cobra.Command {

AddCommandVerify(cmd)
AddCommandExtractAddressInfo(cmd)
AddCommandManifestAddressInfo(cmd)

return cmd
}

Expand Down Expand Up @@ -414,3 +440,110 @@ func printAccInfo(genesisData *app.GenesisData, address string, ctx client.Conte

return nil
}

type ManifestData struct {
InitialBalances *app.OrderedMap[string, app.UpgradeBalances]
MovedBalances *app.OrderedMap[string, app.UpgradeBalances]
}

func parseManifestData(manifest *app.UpgradeManifest) (*ManifestData, error) {
manifestData := ManifestData{}

manifestData.InitialBalances = app.NewOrderedMap[string, app.UpgradeBalances]()
for _, initialBalanceEntry := range manifest.InitialBalances {
manifestData.InitialBalances.SetNew(initialBalanceEntry.Address, initialBalanceEntry)
}

manifestData.MovedBalances = app.NewOrderedMap[string, app.UpgradeBalances]()
for _, movedBalanceEntry := range manifest.MovedBalances {
manifestData.MovedBalances.SetNew(movedBalanceEntry.Address, movedBalanceEntry)
}

return &manifestData, nil
}

func printBalancesEntry(upgradeBalances app.UpgradeBalances, ctx client.Context) error {
if !upgradeBalances.BankBalance.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Bank balance: %s\n", upgradeBalances.BankBalance))
if err != nil {
return err
}
}

if !upgradeBalances.VestedBalance.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Vested balance: %s\n", upgradeBalances.VestedBalance))
if err != nil {
return err
}
}

if !upgradeBalances.BondedStakingBalance.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Bonded staking balance: %s\n", upgradeBalances.BondedStakingBalance))
if err != nil {
return err
}
}

if !upgradeBalances.UnbondedStakingBalance.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Unbonded staking balance: %s\n", upgradeBalances.UnbondedStakingBalance))
if err != nil {
return err
}
}

if !upgradeBalances.UnbondingStakingBalance.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Unbonding staking balance: %s\n", upgradeBalances.UnbondingStakingBalance))
if err != nil {
return err
}
}

if !upgradeBalances.DistributionRewards.IsZero() {
err := ctx.PrintString(fmt.Sprintf("Distribution rewards: %s\n", upgradeBalances.DistributionRewards))
if err != nil {
return err
}
}

return nil
}

func AlmanacAddressInfo(almanacFilePath string, address string, ctx client.Context) error {
manifest := app.NewUpgradeManifest()

manifest, err := app.LoadManifestFromPath(almanacFilePath)
if err != nil {
return err
}

manifestData, err := parseManifestData(manifest)
if err != nil {
return err
}

err = ctx.PrintString("Initial balances:\n")
if err != nil {
return err
}

if InitialBalances, exists := manifestData.InitialBalances.Get(address); exists {
err = printBalancesEntry(InitialBalances, ctx)
if err != nil {
return err
}
}

err = ctx.PrintString("Moved balances:\n")
if err != nil {
return err
}

if MovedBalances, exists := manifestData.MovedBalances.Get(address); exists {
err = printBalancesEntry(MovedBalances, ctx)
if err != nil {
return err
}
}

return nil
}
Loading