-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
59 lines (45 loc) · 1.18 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package wallet_handler
import (
"context"
"encoding/hex"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/types"
ecies "github.com/ecies/go/v2"
filetreetypes "github.com/jackalLabs/canine-chain/v3/x/filetree/types"
)
func (w *WalletHandler) GetChainID() string {
return w.clientCtx.ChainID
}
func (w *WalletHandler) GetAddress() string {
return w.address
}
func (w *WalletHandler) GetPubKey() types.PubKey {
return w.key.PubKey()
}
func (w *WalletHandler) GetECIESPubKey() *ecies.PublicKey {
return w.eciesKey.PublicKey
}
func (w *WalletHandler) getPrivKey() types.PrivKey {
return w.key
}
func (w *WalletHandler) GetClientCtx() client.Context {
return w.clientCtx
}
func (w *WalletHandler) FindPubKey(address string) (*ecies.PublicKey, error) {
cli := filetreetypes.NewQueryClient(w.clientCtx)
req := filetreetypes.QueryPubkeyRequest{Address: address}
res, err := cli.Pubkey(context.Background(), &req)
if err != nil {
return nil, err
}
r := res.Pubkey.Key
hexKey, err := hex.DecodeString(r)
if err != nil {
return nil, err
}
newPkey, err := ecies.NewPublicKeyFromBytes(hexKey)
if err != nil {
return nil, err
}
return newPkey, nil
}