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

CLI command to list tBTC deposits #3545

Merged
merged 12 commits into from
May 8, 2023
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
PingCommand,
EthereumCommand,
MaintainerCommand,
CoordinatorCommand,
)
}

Expand Down
138 changes: 138 additions & 0 deletions cmd/coordinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/keep-network/keep-core/config"
"github.com/keep-network/keep-core/pkg/bitcoin/electrum"
"github.com/keep-network/keep-core/pkg/chain/ethereum"
"github.com/keep-network/keep-core/pkg/coordinator"
)

var (
walletFlagName = "wallet"
hideSweptFlagName = "hide-swept"
sortByAmountFlagName = "sort-amount"
headFlagName = "head"
tailFlagName = "tail"
)

// CoordinatorCommand contains the definition of tBTC Wallet Coordinator tools.
var CoordinatorCommand = &cobra.Command{
Use: "coordinator",
Short: "tBTC Wallet Coordinator Tools",
Long: "The tool exposes commands for interactions with tBTC wallets.",
TraverseChildren: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := clientConfig.ReadConfig(
configFilePath,
cmd.Flags(),
config.General, config.Ethereum, config.BitcoinElectrum,
); err != nil {
logger.Fatalf("error reading config: %v", err)
}
},
}

var depositsCommand = cobra.Command{
Use: "deposits",
Short: "get list of deposits",
Long: "Gets tBTC deposits details from the chain and prints them.",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

wallet, err := cmd.Flags().GetString(walletFlagName)
if err != nil {
return fmt.Errorf("failed to find wallet flag: %v", err)
}

hideSwept, err := cmd.Flags().GetBool(hideSweptFlagName)
if err != nil {
return fmt.Errorf("failed to find show swept flag: %v", err)
}

sortByAmount, err := cmd.Flags().GetBool(sortByAmountFlagName)
if err != nil {
return fmt.Errorf("failed to find show swept flag: %v", err)
}

head, err := cmd.Flags().GetInt(headFlagName)
if err != nil {
return fmt.Errorf("failed to find head flag: %v", err)
}

tail, err := cmd.Flags().GetInt(tailFlagName)
if err != nil {
return fmt.Errorf("failed to find tail flag: %v", err)
}

_, tbtcChain, _, _, _, err := ethereum.Connect(ctx, clientConfig.Ethereum)
if err != nil {
return fmt.Errorf(
"could not connect to Ethereum chain: [%v]",
err,
)
}

btcChain, err := electrum.Connect(ctx, clientConfig.Bitcoin.Electrum)
if err != nil {
return fmt.Errorf("could not connect to Electrum chain: [%v]", err)
}

return coordinator.ListDeposits(
tbtcChain,
btcChain,
wallet,
hideSwept,
sortByAmount,
head,
tail,
)
},
}

func init() {
initFlags(
CoordinatorCommand,
&configFilePath,
clientConfig,
config.General, config.Ethereum, config.BitcoinElectrum,
)

// Coordinator Command
CoordinatorCommand.PersistentFlags().String(
walletFlagName,
"",
"wallet public key hash",
)

// Deposits Subcommand
depositsCommand.Flags().Bool(
hideSweptFlagName,
false,
"hide swept deposits",
)

depositsCommand.Flags().Bool(
sortByAmountFlagName,
false,
"sort by deposit amount",
)

depositsCommand.Flags().Int(
headFlagName,
0,
"get head of deposits",
)

depositsCommand.Flags().Int(
tailFlagName,
0,
"get tail of deposits",
)

CoordinatorCommand.AddCommand(&depositsCommand)
}
11 changes: 9 additions & 2 deletions pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ func (tc *TbtcChain) IsDKGResultValid(
// a boolean indicating whether the result is valid or not. The outcome parameter
// must be a pointer to a struct containing a boolean flag as the first field.
//
// TODO: Find a better way to get the validity flag. This would require
// changes in the contracts binding generator.
// TODO: Find a better way to get the validity flag. This would require changes
// in the contracts binding generator.
func parseDkgResultValidationOutcome(
outcome interface{},
) (bool, error) {
Expand Down Expand Up @@ -1091,6 +1091,13 @@ func computeMainUtxoHash(mainUtxo *bitcoin.UnspentTransactionOutput) [32]byte {
return mainUtxoHash
}

func (tc *TbtcChain) BuildDepositKey(
fundingTxHash bitcoin.Hash,
fundingOutputIndex uint32,
) *big.Int {
return buildDepositKey(fundingTxHash, fundingOutputIndex)
}

func buildDepositKey(
fundingTxHash bitcoin.Hash,
fundingOutputIndex uint32,
Expand Down
7 changes: 7 additions & 0 deletions pkg/coordinator/coordinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package coordinator

import (
"github.com/ipfs/go-log"
)

var logger = log.Logger("keep-coordinator")
Loading