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

Function GetAddressAndKey

tools/contract-admin/utils/utils.go:86–118  ·  view source on GitHub ↗
(keystoreFilePath, password string)

Source from the content-addressed store, hash-verified

84}
85
86func 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
120func PrepareCpclient(endpoint string) (*cpclient.Client, error) {
121 client, err := cpclient.Dial(endpoint)

Callers 1

PrepareAllFunction · 0.85

Calls 6

AccountsMethod · 0.95
GetDecryptedKeyMethod · 0.95
OpenMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected