/
node.go
77 lines (69 loc) · 1.57 KB
/
node.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package aeternity
import (
apiclient "github.com/aeternity/aepp-sdk-go/generated/client"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// Ae the aeternity client
type Ae struct {
*apiclient.Node
*Wallet
*Aens
*Contract
*Oracle
}
// Wallet high level abstraction for operation on a wallet
type Wallet struct {
nodeClient *apiclient.Node
owner *Account
}
// Aens abstractions for aens operations
type Aens struct {
nodeClient *apiclient.Node
owner *Account
name string
preClaimSalt []byte
}
// Contract abstractions for contracts
type Contract struct {
nodeClient *apiclient.Node
owner *Account
source string
}
// Oracle abstractions for oracles
type Oracle struct {
nodeClient *apiclient.Node
owner *Account
}
// NewCli obtain a new nodeClient instance
func NewCli(nodeURL string, debug bool) *Ae {
// create the transport
host, schemas := urlComponents(nodeURL)
transport := httptransport.New(host, "/v2", schemas)
transport.SetDebug(debug)
// create the API client, with the transport
openAPIClient := apiclient.New(transport, strfmt.Default)
aecli := &Ae{
Node: openAPIClient,
Wallet: &Wallet{
nodeClient: openAPIClient,
},
Aens: &Aens{
nodeClient: openAPIClient,
},
Contract: &Contract{
nodeClient: openAPIClient,
},
Oracle: &Oracle{
nodeClient: openAPIClient,
},
}
return aecli
}
// WithAccount associate a Account with the client
func (ae *Ae) WithAccount(account *Account) *Ae {
ae.Wallet.owner = account
ae.Aens.owner = account
ae.Contract.owner = account
return ae
}