@@ -3,9 +3,11 @@ package main
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
"strconv"
7
8
"strings"
8
9
10
+ "cosmossdk.io/errors"
9
11
"github.com/btcsuite/btcd/rpcclient"
10
12
sdk "github.com/cosmos/cosmos-sdk/types"
11
13
ethcommon "github.com/ethereum/go-ethereum/common"
@@ -14,10 +16,8 @@ import (
14
16
"github.com/rs/zerolog"
15
17
"github.com/spf13/cobra"
16
18
17
- "github.com/zeta-chain/zetacore/pkg/chains"
18
19
"github.com/zeta-chain/zetacore/pkg/coin"
19
20
"github.com/zeta-chain/zetacore/testutil/sample"
20
- observertypes "github.com/zeta-chain/zetacore/x/observer/types"
21
21
btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer"
22
22
evmobserver "github.com/zeta-chain/zetacore/zetaclient/chains/evm/observer"
23
23
"github.com/zeta-chain/zetacore/zetaclient/config"
@@ -35,11 +35,14 @@ type debugArguments struct {
35
35
}
36
36
37
37
func init () {
38
- RootCmd .AddCommand (DebugCmd ())
39
- DebugCmd ().Flags ().
40
- StringVar (& debugArgs .zetaCoreHome , "core-home" , "/Users/tanmay/.zetacored" , "peer address, e.g. /dns/tss1/tcp/6668/ipfs/16Uiu2HAmACG5DtqmQsHtXg4G2sLS65ttv84e7MrL4kapkjfmhxAp" )
41
- DebugCmd ().Flags ().StringVar (& debugArgs .zetaNode , "node" , "46.4.15.110" , "public ip address" )
42
- DebugCmd ().Flags ().StringVar (& debugArgs .zetaChainID , "chain-id" , "athens_7001-1" , "pre-params file path" )
38
+ defaultHomeDir := os .ExpandEnv ("$HOME/.zetacored" )
39
+
40
+ cmd := DebugCmd ()
41
+ cmd .Flags ().StringVar (& debugArgs .zetaCoreHome , "core-home" , defaultHomeDir , "zetacore home directory" )
42
+ cmd .Flags ().StringVar (& debugArgs .zetaNode , "node" , "46.4.15.110" , "public ip address" )
43
+ cmd .Flags ().StringVar (& debugArgs .zetaChainID , "chain-id" , "athens_7001-1" , "pre-params file path" )
44
+
45
+ RootCmd .AddCommand (cmd )
43
46
}
44
47
45
48
func DebugCmd () * cobra.Command {
@@ -54,20 +57,16 @@ func debugCmd(_ *cobra.Command, args []string) error {
54
57
cobra .ExactArgs (2 )
55
58
cfg , err := config .Load (debugArgs .zetaCoreHome )
56
59
if err != nil {
57
- return err
60
+ return errors . Wrap ( err , "failed to load config" )
58
61
}
59
62
60
- appContext := zctx .New (cfg , zerolog .Nop ())
61
- ctx := zctx .WithAppContext (context .Background (), appContext )
63
+ inboundHash := args [0 ]
62
64
63
65
chainID , err := strconv .ParseInt (args [1 ], 10 , 64 )
64
66
if err != nil {
65
- return err
67
+ return errors . Wrap ( err , "failed to parse chain id" )
66
68
}
67
69
68
- inboundHash := args [0 ]
69
- var ballotIdentifier string
70
-
71
70
// create a new zetacore client
72
71
client , err := zetacore .NewClient (
73
72
& keys.Keys {OperatorAddress : sdk .MustAccAddressFromBech32 (sample .AccAddress ())},
@@ -80,21 +79,30 @@ func debugCmd(_ *cobra.Command, args []string) error {
80
79
if err != nil {
81
80
return err
82
81
}
83
- chainParams , err := client .GetChainParams (ctx )
84
- if err != nil {
85
- return err
82
+
83
+ appContext := zctx .New (cfg , zerolog .Nop ())
84
+ ctx := zctx .WithAppContext (context .Background (), appContext )
85
+
86
+ if err := client .UpdateAppContext (ctx , appContext , zerolog .Nop ()); err != nil {
87
+ return errors .Wrap (err , "failed to update app context" )
86
88
}
89
+
90
+ var ballotIdentifier string
91
+
87
92
tssEthAddress , err := client .GetEVMTSSAddress (ctx )
88
93
if err != nil {
89
94
return err
90
95
}
91
- chain , found := chains .GetChainFromChainID (chainID , appContext .GetAdditionalChains ())
92
- if ! found {
93
- return fmt .Errorf ("invalid chain id" )
96
+
97
+ chain , err := appContext .GetChain (chainID )
98
+ if err != nil {
99
+ return err
94
100
}
95
101
102
+ chainProto := chain .RawChain ()
103
+
96
104
// get ballot identifier according to the chain type
97
- if chains . IsEVMChain ( chain .ChainId , appContext . GetAdditionalChains () ) {
105
+ if chain .IsEVM ( ) {
98
106
evmObserver := evmobserver.Observer {}
99
107
evmObserver .WithZetacoreClient (client )
100
108
var ethRPC * ethrpc.EthRPC
@@ -109,43 +117,34 @@ func debugCmd(_ *cobra.Command, args []string) error {
109
117
}
110
118
evmObserver .WithEvmClient (client )
111
119
evmObserver .WithEvmJSONRPC (ethRPC )
112
- evmObserver .WithChain (chain )
120
+ evmObserver .WithChain (* chainProto )
113
121
}
114
122
}
115
123
hash := ethcommon .HexToHash (inboundHash )
116
124
tx , isPending , err := evmObserver .TransactionByHash (inboundHash )
117
125
if err != nil {
118
- return fmt .Errorf ("tx not found on chain %s , %d" , err .Error (), chain .ChainId )
126
+ return fmt .Errorf ("tx not found on chain %s, %d" , err .Error (), chain .ID () )
119
127
}
128
+
120
129
if isPending {
121
130
return fmt .Errorf ("tx is still pending" )
122
131
}
132
+
123
133
receipt , err := client .TransactionReceipt (context .Background (), hash )
124
134
if err != nil {
125
- return fmt .Errorf ("tx receipt not found on chain %s, %d" , err .Error (), chain .ChainId )
135
+ return fmt .Errorf ("tx receipt not found on chain %s, %d" , err .Error (), chain .ID () )
126
136
}
127
137
128
- for _ , chainParams := range chainParams {
129
- if chainParams .ChainId == chainID {
130
- evmObserver .SetChainParams (observertypes.ChainParams {
131
- ChainId : chainID ,
132
- ConnectorContractAddress : chainParams .ConnectorContractAddress ,
133
- ZetaTokenContractAddress : chainParams .ZetaTokenContractAddress ,
134
- Erc20CustodyContractAddress : chainParams .Erc20CustodyContractAddress ,
135
- })
136
- evmChainParams , found := appContext .GetEVMChainParams (chainID )
137
- if ! found {
138
- return fmt .Errorf ("missing chain params for chain %d" , chainID )
139
- }
140
- evmChainParams .ZetaTokenContractAddress = chainParams .ZetaTokenContractAddress
141
- if strings .EqualFold (tx .To , chainParams .ConnectorContractAddress ) {
142
- coinType = coin .CoinType_Zeta
143
- } else if strings .EqualFold (tx .To , chainParams .Erc20CustodyContractAddress ) {
144
- coinType = coin .CoinType_ERC20
145
- } else if strings .EqualFold (tx .To , tssEthAddress ) {
146
- coinType = coin .CoinType_Gas
147
- }
148
- }
138
+ params := chain .Params ()
139
+
140
+ evmObserver .SetChainParams (* params )
141
+
142
+ if strings .EqualFold (tx .To , params .ConnectorContractAddress ) {
143
+ coinType = coin .CoinType_Zeta
144
+ } else if strings .EqualFold (tx .To , params .Erc20CustodyContractAddress ) {
145
+ coinType = coin .CoinType_ERC20
146
+ } else if strings .EqualFold (tx .To , tssEthAddress ) {
147
+ coinType = coin .CoinType_Gas
149
148
}
150
149
151
150
switch coinType {
@@ -170,10 +169,10 @@ func debugCmd(_ *cobra.Command, args []string) error {
170
169
fmt .Println ("CoinType not detected" )
171
170
}
172
171
fmt .Println ("CoinType : " , coinType )
173
- } else if chains . IsBitcoinChain ( chain .ChainId , appContext . GetAdditionalChains () ) {
172
+ } else if chain .IsUTXO ( ) {
174
173
btcObserver := btcobserver.Observer {}
175
174
btcObserver .WithZetacoreClient (client )
176
- btcObserver .WithChain (chain )
175
+ btcObserver .WithChain (* chainProto )
177
176
connCfg := & rpcclient.ConnConfig {
178
177
Host : cfg .BitcoinConfig .RPCHost ,
179
178
User : cfg .BitcoinConfig .RPCUsername ,
0 commit comments