(endpoint string)
| 118 | } |
| 119 | |
| 120 | func 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 | |
| 151 | func GetPassword() string { |
| 152 | // get password and unlock keystore file, then update `key` |
no test coverage detected