MCPcopy Create free account
hub / github.com/CPChain/chain / PrepareCpclient

Function PrepareCpclient

tools/contract-admin/utils/utils.go:120–149  ·  view source on GitHub ↗
(endpoint string)

Source from the content-addressed store, hash-verified

118}
119
120func PrepareCpclient(endpoint string) (*cpclient.Client, error) {
121 client, err := cpclient.Dial(endpoint)
122 if err != nil {
123 log.Info("Failed to dial given endpoint", "endpoint", endpoint, "err", err)
124 return &cpclient.Client{}, errors.New("Failed to dial given endpoint")
125 }
126
127 chainConfig, err := client.ChainConfig()
128 if err != nil {
129 log.Info(err.Error())
130 return &cpclient.Client{}, err
131 }
132 chainId, runMode := chainConfig.ChainID.Uint64(), configs.Mainnet
133 switch chainId {
134 case configs.DevChainId:
135 runMode = configs.Dev
136 case configs.MainnetChainId:
137 runMode = configs.Mainnet
138 case configs.TestMainnetChainId:
139 runMode = configs.TestMainnet
140 case configs.TestnetChainId:
141 runMode = configs.Testnet
142 default:
143 log.Info("unknown chain id")
144 return &cpclient.Client{}, errors.New("unknown chain id")
145 }
146 configs.SetRunMode(runMode)
147
148 return client, nil
149}
150
151func GetPassword() string {
152 // get password and unlock keystore file, then update `key`

Callers 1

PrepareAllFunction · 0.85

Calls 4

Uint64Method · 0.80
InfoMethod · 0.65
ChainConfigMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected