Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinssgh committed Mar 13, 2024
1 parent 8a370e7 commit 638b814
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/zetatool/filterdeposit/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func init() {
Cmd.AddCommand(btcCmd)
}

// FilterBTCTransactions is a command that queries the bitcoin explorer for inbound transactions that qualify for
// cross chain transactions.
func FilterBTCTransactions(cmd *cobra.Command, _ []string) {
configFile, err := cmd.Flags().GetString(config.Flag)
fmt.Println("config file name: ", configFile)
Expand All @@ -39,6 +41,7 @@ func FilterBTCTransactions(cmd *cobra.Command, _ []string) {
CheckForCCTX(list, cfg)
}

// getHashList is called by FilterBTCTransactions to help query and filter inbound transactions on btc
func getHashList(cfg *config.Config) []Deposit {
var list []Deposit
lastHash := ""
Expand Down Expand Up @@ -66,6 +69,9 @@ func getHashList(cfg *config.Config) []Deposit {
log.Fatal(closeErr)
}

// NOTE: decoding json from request dynamically is not ideal, however there isn't a detailed, defined data structure
// provided by blockstream. Will need to create one in the future using following definition:
// https://github.com/Blockstream/esplora/blob/master/API.md#transaction-format
var txns []map[string]interface{}
err := json.Unmarshal(body, &txns)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/zetatool/filterdeposit/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func init() {
Cmd.AddCommand(evmCmd)
}

// FilterEVMTransactions is a command that queries an EVM explorer and Contracts for inbound transactions that qualify
// for cross chain transactions.
func FilterEVMTransactions(cmd *cobra.Command, _ []string) {
configFile, err := cmd.Flags().GetString(config.Flag)
if err != nil {
Expand All @@ -47,6 +49,7 @@ func FilterEVMTransactions(cmd *cobra.Command, _ []string) {
CheckForCCTX(list, cfg)
}

// GetEthHashList is a helper function querying total inbound txns in segments of blocks in ranges defined by the config
func GetEthHashList(cfg *config.Config) []Deposit {
startBlock := cfg.EvmStartBlock
client, err := ethclient.Dial(cfg.EthRPC)
Expand Down Expand Up @@ -78,6 +81,7 @@ func GetEthHashList(cfg *config.Config) []Deposit {
return deposits
}

// GetHashListSegment queries and filters deposits for a given range
func GetHashListSegment(client *ethclient.Client, startBlock uint64, endBlock uint64, cfg *config.Config) []Deposit {
deposits := make([]Deposit, 0)

Expand Down Expand Up @@ -148,6 +152,7 @@ func GetHashListSegment(client *ethclient.Client, startBlock uint64, endBlock ui
return deposits
}

// getTSSDeposits more specifically queries and filters deposits based on direct transfers the TSS address.
func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64) ([]Deposit, error) {
client := etherscan.New(etherscan.Mainnet, "S3AVTNXDJQZQQUVXJM4XVIPBRYECGK88VX")
deposits := make([]Deposit, 0)
Expand Down Expand Up @@ -182,6 +187,7 @@ func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64) ([]De
return deposits, nil
}

// CheckEvmTxLog is a helper function used to validate receipts, logic is taken from zetaclient.
func CheckEvmTxLog(vLog *ethtypes.Log, wantAddress common.Address, wantHash string, wantTopics int) error {
if vLog.Removed {
return fmt.Errorf("log is removed, chain reorg?")
Expand Down
6 changes: 5 additions & 1 deletion cmd/zetatool/filterdeposit/filterdeposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ var Cmd = &cobra.Command{
Short: "filter missing inbound deposits",
}

// Deposit is a data structure for keeping track of inbound transactions
type Deposit struct {
TxID string
Amount uint64
}

// CheckForCCTX is querying zeta core for a cctx associated with a confirmed transaction hash. If the cctx is not found,
// then the transaction hash is added to the list of missed inbound transactions.
func CheckForCCTX(list []Deposit, cfg *config.Config) {
var missedList []Deposit

Expand Down Expand Up @@ -52,9 +55,10 @@ func CheckForCCTX(list []Deposit, cfg *config.Config) {
fmt.Println("error unmarshalling: ", err.Error())
}

// successful query of the given cctx will not contain a "code" field, therefore if it exists then the cctx
// was not found and is added to the missing list.
if _, ok := cctx["code"]; ok {
missedList = append(missedList, entry)
//fmt.Println("appending to missed list: ", entry)
}
}

Expand Down

0 comments on commit 638b814

Please sign in to comment.