-
Notifications
You must be signed in to change notification settings - Fork 142
/
nodeclient.go
56 lines (46 loc) · 1.57 KB
/
nodeclient.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
package testutil
import (
"time"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
nodeapi "github.com/iotaledger/goshimmer/dapps/waspconn/packages/apilib"
"github.com/iotaledger/goshimmer/dapps/waspconn/packages/utxodb"
"github.com/iotaledger/wasp/packages/nodeclient"
)
const RequestFundsAmount = utxodb.RequestFundsAmount
type utxodbclient struct {
goshimmerHost string
}
func NewGoshimmerUtxodbClient(host string) nodeclient.NodeClient {
return &utxodbclient{host}
}
func (api *utxodbclient) RequestFunds(targetAddress *address.Address) error {
return nodeapi.RequestFunds(api.goshimmerHost, targetAddress)
}
func (api *utxodbclient) GetConfirmedAccountOutputs(address *address.Address) (map[transaction.OutputID][]*balance.Balance, error) {
return nodeapi.GetAccountOutputs(api.goshimmerHost, address)
}
func (api *utxodbclient) PostTransaction(tx *transaction.Transaction) error {
return nodeapi.PostTransaction(api.goshimmerHost, tx)
}
func (api *utxodbclient) PostAndWaitForConfirmation(tx *transaction.Transaction) error {
err := nodeapi.PostTransaction(api.goshimmerHost, tx)
if err != nil {
return err
}
return api.WaitForConfirmation(tx.ID())
}
func (api *utxodbclient) WaitForConfirmation(txid transaction.ID) error {
for {
conf, err := nodeapi.IsConfirmed(api.goshimmerHost, &txid)
if err != nil {
return err
}
if conf {
break
}
time.Sleep(1 * time.Second)
}
return nil
}