-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathent.go
53 lines (40 loc) · 978 Bytes
/
ent.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
package main
import (
"errors"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"entrance/registry"
)
type Entrance struct {
Deployment [32]byte
client *ethclient.Client
contract *registry.EntranceManager
}
func NewEntrance(c string, client *ethclient.Client, address common.Address) (*Entrance, error) {
if c == "" {
return nil, errors.New("invalid deployment")
}
instance, err := registry.NewEntranceManager(address, client)
if err != nil {
return nil, err
}
d := [32]byte{}
copy(d[:], []byte(c))
return &Entrance{
Deployment: d,
client: client,
contract: instance,
}, nil
}
func (ent *Entrance) ListKey(user string) string {
u := [32]byte{}
copy(u[:], []byte(user))
keys, err := ent.contract.GetKey(&bind.CallOpts{}, ent.Deployment, u)
if err != nil {
return ""
}
output := strings.Join(keys, "\n")
return output
}