(keystoreFilePath, password string)
| 84 | } |
| 85 | |
| 86 | func GetAddressAndKey(keystoreFilePath, password string) (common.Address, *keystore.Key) { |
| 87 | |
| 88 | // Open keystore file. |
| 89 | file, err := os.Open(keystoreFilePath) |
| 90 | if err != nil { |
| 91 | log.Fatal(err.Error()) |
| 92 | } |
| 93 | keyPath, err := filepath.Abs(filepath.Dir(file.Name())) |
| 94 | if err != nil { |
| 95 | log.Fatal(err.Error()) |
| 96 | } |
| 97 | |
| 98 | // Create keystore and get account. |
| 99 | kst := keystore.NewKeyStore(keyPath, 2, 1) |
| 100 | account := kst.Accounts()[0] |
| 101 | account, key, err := kst.GetDecryptedKey(account, password) |
| 102 | if err != nil { |
| 103 | log.Fatal(err.Error()) |
| 104 | } |
| 105 | |
| 106 | // Get private and public keys. |
| 107 | privateKey := key.PrivateKey |
| 108 | publicKey := privateKey.Public() |
| 109 | publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) |
| 110 | if !ok { |
| 111 | log.Fatal("error casting public key to ECDSA") |
| 112 | } |
| 113 | |
| 114 | // Get contractAddress. |
| 115 | fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) |
| 116 | |
| 117 | return fromAddress, key |
| 118 | } |
| 119 | |
| 120 | func PrepareCpclient(endpoint string) (*cpclient.Client, error) { |
| 121 | client, err := cpclient.Dial(endpoint) |
no test coverage detected