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

Admin cli commands #251

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Admin cli commands #251

wants to merge 13 commits into from

Conversation

dulicd
Copy link
Contributor

@dulicd dulicd commented Mar 27, 2025

No description provided.

return nil, err
}

_, _ = outputter.Write([]byte(fmt.Sprintf("-Addresses on %s chain (retrieved from validator data): \n", chainID)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove - prefix

@igorcrevar
Copy link
Contributor

Add number of unfiltered utxos (for both cases) like this too

_, _ = outputter.Write([]byte(fmt.Sprintf("All UTXOs = %d\n", len(multisigUtxos)))

```shell
$ apex-bridge bridge-admin get-validators-data \
--bridge-url http://localhost:12013 \
--bridging-addr 0xeefcd00000000000000000000000000000000022 \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this flag is bridge-addr

if !ethcommon.IsHexAddress(v.bridgeSCAddr) {
return fmt.Errorf("invalid --%s flag", bridgeSCAddrFlag)
}

Copy link
Collaborator

@babinskizoltan babinskizoltan Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also validate that v.config is not empty and that the file exists

nexusWalletAddressFlag = "nexus-wallet-addr"
indexerDbsPathFlag = "indexer-dbs-path"

primeWalletAddressFlagDesc = "prime wallet address"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"prime hot wallet/bridging/multisig address"

indexerDbsPathFlag = "indexer-dbs-path"

primeWalletAddressFlagDesc = "prime wallet address"
vectorWalletAddressFlagDesc = "vector wallet address"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"vector hot wallet/bridging/multisig address"


primeWalletAddressFlagDesc = "prime wallet address"
vectorWalletAddressFlagDesc = "vector wallet address"
nexusWalletAddressFlagDesc = "nexus wallet address"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"nexus NativeTokenWallet Proxy sc address"

}

if b.config == "" {
return fmt.Errorf("invalid config path: --%s", indexerDbsPathFlag)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configFlag instead of indexerDbsPathFlag

return fmt.Errorf("invalid address: --%s", nexusWalletAddressFlag)
}

if b.config == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also validate for b.config that the file exists

if b.config == "" {
return fmt.Errorf("invalid config path: --%s", indexerDbsPathFlag)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also validate:
if b.indexerDbsPath != "" && dirNotExists(b.indexerDbsPath) { error }

// Retrieve UTXOs for Cardano BridgingAddresses from the DB
for chainID, cardanoIndexerDB := range cardanoIndexerDbs {
var bridgingAddress string
if chainID == common.ChainIDStrPrime {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above if, create:
chainWalletAddr map[string]string{
common.ChainIDStrPrime: b.primeWalletAddress,
common.ChainIDStrVector : b.vectorWalletAddress,
common.ChainIDStrNexus: b.nexusWalletAddress,
}

and use bridgingAddr := chainWalletAddr[chainID], instead of:
var bridgingAddress string
if chainID == common.ChainIDStrPrime {
bridgingAddress = b.primeWalletAddress
} else if chainID == common.ChainIDStrVector {
bridgingAddress = b.vectorWalletAddress
}

return nil, err
}

var (
Copy link
Collaborator

@babinskizoltan babinskizoltan Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract in a private func:

		var (
			multisigBalance uint64
			filteredCount   int
		)

		for _, utxo := range multisigUtxos {
			if len(utxo.Tokens) == 0 {
				multisigBalance += utxo.Amount
				filteredCount++
			}
		}

		_, _ = outputter.Write([]byte(fmt.Sprintf("Balances on %s chain: \n", chainID)))
		_, _ = outputter.Write([]byte(fmt.Sprintf("Bridging Address = %s\n", bridgingAddress)))
		_, _ = outputter.Write([]byte(fmt.Sprintf("Balance = %d\n", multisigBalance)))
		_, _ = outputter.Write([]byte(fmt.Sprintf("All UTXOs = %d\n", len(multisigUtxos))))
		_, _ = outputter.Write([]byte(fmt.Sprintf("Filtered UTXOs = %d\n", filteredCount)))
		outputter.WriteOutput()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this is repeated code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can first only store the utxos in a map[chainId]UTxO[], and later iterate over appConfig.CardanoChains, and print out the balances

cardanoIndexerDbs := make(map[string]indexer.Database, len(appConfig.CardanoChains))

// Open connections to the DB for Cardano chains
for chainID := range appConfig.CardanoChains {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after you are finished using the dbs, iterate over them, and close them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants