Skip to content

Commit 4917760

Browse files
init contract without import
1 parent 13e8dba commit 4917760

File tree

5 files changed

+97
-30
lines changed

5 files changed

+97
-30
lines changed

cmd/blockchaincmd/add_validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Testnet or Mainnet.`,
121121
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "(for Subnets, not L1s) file path of the add validator tx")
122122
cmd.Flags().BoolVar(&waitForTxAcceptance, "wait-for-tx-acceptance", true, "(for Subnets, not L1s) just issue the add validator tx, without waiting for its acceptance")
123123
cmd.Flags().Uint16Var(&delegationFee, "delegation-fee", 100, "(PoS only) delegation fee (in bips)")
124-
cmd.Flags().StringVar(&subnetIDstr, "subnet-id", "", "subnet ID (only if blockchain name is not provided)")
124+
cmd.Flags().StringVar(&blockchainIDStr, "blockchain-id", "", "blockchain ID (only if blockchain name is not provided)")
125125
cmd.Flags().StringVar(&validatorManagerOwnerAddress, "validator-manager-owner", "", "validator manager owner address (only if blockchain name is not provided)")
126126
cmd.Flags().Uint64Var(&weight, validatorWeightFlag, uint64(constants.DefaultStakeWeight), "set the weight of the validator")
127127

cmd/blockchaincmd/import_public.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,11 @@ func importL1(blockchainIDStr string, rpcURL string, network models.Network) (mo
245245
if err != nil {
246246
return models.Sidecar{}, err
247247
}
248+
fmt.Printf("obtained subnetInfo %s \n", subnetInfo)
248249
if subnetInfo.IsPermissioned {
249250
return models.Sidecar{}, fmt.Errorf("unable to import non sovereign Subnets")
250251
}
251252
validatorManagerAddress = "0x" + hex.EncodeToString(subnetInfo.ManagerAddress)
252-
fmt.Printf("obtained blockchainid %s \n", blockchainID.String())
253-
fmt.Printf("obtained subnetid %s \n", subnetID.String())
254-
255-
fmt.Printf("obtained validatorManagerAddress %s \n", validatorManagerAddress)
256253

257254
// add validator without blockchain arg is only for l1s
258255
sc = models.Sidecar{

cmd/blockchaincmd/remove_validator.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ validating your deployed Blockchain.
4949
To remove the validator from the Subnet's allow list, provide the validator's unique NodeID. You can bypass
5050
these prompts by providing the values with flags.`,
5151
RunE: removeValidator,
52-
Args: cobrautils.ExactArgs(1),
52+
Args: cobrautils.MaximumNArgs(1),
5353
}
5454
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, false, networkoptions.DefaultSupportedNetworkOptions)
5555
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji deploy only]")
@@ -66,28 +66,34 @@ these prompts by providing the values with flags.`,
6666
cmd.Flags().BoolVar(&aggregatorLogToStdout, "aggregator-log-to-stdout", false, "use stdout for signature aggregator logs")
6767
cmd.Flags().Uint64Var(&uptimeSec, "uptime", 0, "validator's uptime in seconds. If not provided, it will be automatically calculated")
6868
cmd.Flags().BoolVar(&force, "force", false, "force validator removal even if it's not getting rewarded")
69+
cmd.Flags().StringVar(&blockchainIDStr, "blockchain-id", "", "blockchain ID (only if blockchain name is not provided)")
70+
6971
return cmd
7072
}
7173

7274
func removeValidator(_ *cobra.Command, args []string) error {
73-
blockchainName := args[0]
74-
_, err := ValidateSubnetNameAndGetChains([]string{blockchainName})
75-
if err != nil {
76-
return err
77-
}
78-
79-
sc, err := app.LoadSidecar(blockchainName)
80-
if err != nil {
81-
return err
75+
blockchainName := ""
76+
var sc models.Sidecar
77+
networkOption := networkoptions.DefaultSupportedNetworkOptions
78+
if len(args) == 1 {
79+
blockchainName = args[0]
80+
_, err := ValidateSubnetNameAndGetChains([]string{blockchainName})
81+
if err != nil {
82+
return err
83+
}
84+
sc, err = app.LoadSidecar(blockchainName)
85+
if err != nil {
86+
return fmt.Errorf("failed to load sidecar: %w", err)
87+
}
88+
networkOption = networkoptions.GetNetworkFromSidecar(sc, networkOption)
8289
}
83-
8490
network, err := networkoptions.GetNetworkFromCmdLineFlags(
8591
app,
8692
"",
8793
globalNetworkFlags,
8894
true,
8995
false,
90-
networkoptions.GetNetworkFromSidecar(sc, networkoptions.DefaultSupportedNetworkOptions),
96+
networkOption,
9197
"",
9298
)
9399
if err != nil {
@@ -97,7 +103,20 @@ func removeValidator(_ *cobra.Command, args []string) error {
97103
network = models.ConvertClusterToNetwork(network)
98104
}
99105

100-
// TODO: will estimate fee in subsecuent PR
106+
if len(args) == 0 {
107+
if rpcURL == "" {
108+
rpcURL, err = app.Prompt.CaptureURL("What is the RPC endpoint?", false)
109+
if err != nil {
110+
return err
111+
}
112+
}
113+
sc, err = importL1(blockchainIDStr, rpcURL, network)
114+
if err != nil {
115+
return err
116+
}
117+
}
118+
119+
// TODO: will estimate fee in subsequent PR
101120
fee := uint64(0)
102121
kc, err := keychain.GetKeychainFromCmdLineFlags(
103122
app,

cmd/contractcmd/init_validator_manager.go

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newInitValidatorManagerCmd() *cobra.Command {
6161
Short: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS) Validator Manager on a given Network and Blockchain",
6262
Long: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS)Validator Manager contract on a Blockchain and sets up initial validator set on the Blockchain. For more info on Validator Manager, please head to https://github.com/ava-labs/icm-contracts/tree/main/contracts/validator-manager",
6363
RunE: initValidatorManager,
64-
Args: cobrautils.ExactArgs(1),
64+
Args: cobrautils.MaximumNArgs(1),
6565
}
6666
networkoptions.AddNetworkFlagsToCmd(cmd, &validatorManagerFlags.Network, true, networkoptions.DefaultSupportedNetworkOptions)
6767
validatorManagerFlags.PrivateKeyFlags.AddToCmd(cmd, "as contract deployer")
@@ -82,17 +82,32 @@ func newInitValidatorManagerCmd() *cobra.Command {
8282
}
8383

8484
func initValidatorManager(_ *cobra.Command, args []string) error {
85-
blockchainName := args[0]
85+
blockchainName := ""
86+
var sc models.Sidecar
87+
networkOption := networkoptions.DefaultSupportedNetworkOptions
88+
8689
chainSpec := contract.ChainSpec{
8790
BlockchainName: blockchainName,
8891
}
92+
if len(args) == 1 {
93+
blockchainName = args[0]
94+
//_, err := ValidateSubnetNameAndGetChains([]string{blockchainName})
95+
//if err != nil {
96+
// return err
97+
//}
98+
sc, err := app.LoadSidecar(blockchainName)
99+
if err != nil {
100+
return fmt.Errorf("failed to load sidecar: %w", err)
101+
}
102+
networkOption = networkoptions.GetNetworkFromSidecar(sc, networkOption)
103+
}
89104
network, err := networkoptions.GetNetworkFromCmdLineFlags(
90105
app,
91106
"",
92107
validatorManagerFlags.Network,
93108
true,
94109
false,
95-
networkoptions.DefaultSupportedNetworkOptions,
110+
networkOption,
96111
"",
97112
)
98113
if err != nil {
@@ -101,6 +116,35 @@ func initValidatorManager(_ *cobra.Command, args []string) error {
101116
if network.ClusterName != "" {
102117
network = models.ConvertClusterToNetwork(network)
103118
}
119+
//if len(args) == 0 {
120+
// if rpcURL == "" {
121+
// rpcURL, err = app.Prompt.CaptureURL("What is the RPC endpoint?", false)
122+
// if err != nil {
123+
// return err
124+
// }
125+
// }
126+
// sc, err = importL1(blockchainIDStr, rpcURL, network)
127+
// if err != nil {
128+
// return err
129+
// }
130+
//}
131+
subnetID, _ := ids.FromString("m1T2ePf8QE2hhjo4N1Jt1Pn2khX3wTUnefJqPrsigCQNCQR6Y")
132+
fmt.Printf("subnetID %s \n", subnetID)
133+
subnetInfo, err := blockchain.GetSubnet(subnetID, network)
134+
if err != nil {
135+
return err
136+
}
137+
fmt.Printf("obtained subnetInfo %s \n", subnetInfo)
138+
// Get NodeIDs of all validators on the subnet
139+
validators, err := blockchain.GetSubnetValidators(subnetID, network)
140+
if err != nil {
141+
return err
142+
}
143+
fmt.Printf("obtained validators %s \n", validators)
144+
145+
//if subnetInfo.IsPermissioned {
146+
// return models.Sidecar{}, fmt.Errorf("unable to import non sovereign Subnets")
147+
//}
104148
if validatorManagerFlags.rpcEndpoint == "" {
105149
validatorManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints(
106150
app,
@@ -139,10 +183,7 @@ func initValidatorManager(_ *cobra.Command, args []string) error {
139183
return err
140184
}
141185
}
142-
sc, err := app.LoadSidecar(chainSpec.BlockchainName)
143-
if err != nil {
144-
return fmt.Errorf("failed to load sidecar: %w", err)
145-
}
186+
146187
if sc.Networks[network.Name()].ValidatorManagerAddress == "" {
147188
return fmt.Errorf("unable to find Validator Manager address")
148189
}
@@ -172,11 +213,11 @@ func initValidatorManager(_ *cobra.Command, args []string) error {
172213
if err != nil {
173214
return err
174215
}
175-
subnetID, err := contract.GetSubnetID(
176-
app,
177-
network,
178-
chainSpec,
179-
)
216+
//subnetID, err := contract.GetSubnetID(
217+
// app,
218+
// network,
219+
// chainSpec,
220+
//)
180221
if err != nil {
181222
return err
182223
}

pkg/blockchain/helper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,22 @@ func GetBlockchainTimestamp(network models.Network) (time.Time, error) {
146146

147147
func GetSubnet(subnetID ids.ID, network models.Network) (platformvm.GetSubnetClientResponse, error) {
148148
api := network.Endpoint
149+
fmt.Printf("GetSubnet api %s \n", api)
149150
pClient := platformvm.NewClient(api)
150151
ctx, cancel := utils.GetAPIContext()
151152
defer cancel()
152153
return pClient.GetSubnet(ctx, subnetID)
153154
}
154155

156+
func GetSubnetValidators(subnetID ids.ID, network models.Network) ([]platformvm.ClientPermissionlessValidator, error) {
157+
api := network.Endpoint
158+
pClient := platformvm.NewClient(api)
159+
ctx, cancel := utils.GetAPIContext()
160+
defer cancel()
161+
162+
return pClient.GetCurrentValidators(ctx, subnetID, nil)
163+
}
164+
155165
func GetSubnetIDFromBlockchainID(blockchainID ids.ID, network models.Network) (ids.ID, error) {
156166
api := network.Endpoint
157167
pClient := platformvm.NewClient(api)

0 commit comments

Comments
 (0)