This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
76 lines (64 loc) · 2.12 KB
/
client.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
package aptos
import (
"context"
"errors"
"github.com/coming-chat/go-aptos/aptosclient"
xc "github.com/jumpcrypto/crosschain"
)
// TxInput for Aptos
type TxInput struct {
xc.TxInputEnvelope
}
// NewTxInput returns a new Aptos TxInput
func NewTxInput() *TxInput {
return &TxInput{
TxInputEnvelope: *xc.NewTxInputEnvelope(xc.DriverAptos),
}
}
// Client for Aptos
type Client struct {
Asset *xc.AssetConfig
AptosClient *aptosclient.RestClient
}
var _ xc.FullClient = &Client{}
// NewClient returns a new Aptos Client
func NewClient(cfgI xc.ITask) (*Client, error) {
asset := cfgI.GetAssetConfig()
cfg := cfgI.GetNativeAsset()
client, err := aptosclient.Dial(context.Background(), cfg.URL)
return &Client{
Asset: asset,
AptosClient: client,
}, err
}
// FetchTxInput returns tx input for a Aptos tx
func (client *Client) FetchTxInput(ctx context.Context, from xc.Address, _ xc.Address) (xc.TxInput, error) {
return &TxInput{}, errors.New("not implemented")
}
// SubmitTx submits a Aptos tx
func (client *Client) SubmitTx(ctx context.Context, txInput xc.Tx) error {
return errors.New("not implemented")
}
// FetchTxInfo returns tx info for a Aptos tx
func (client *Client) FetchTxInfo(ctx context.Context, txHash xc.TxHash) (xc.TxInfo, error) {
return xc.TxInfo{}, errors.New("not implemented")
}
// FetchBalance fetches balance for an Aptos address
func (client *Client) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error) {
if client.Asset.Type == xc.AssetTypeNative {
return client.FetchNativeBalance(ctx, address)
}
balance, err := client.AptosClient.BalanceOf(string(address), client.Asset.Contract)
if err != nil {
return xc.NewAmountBlockchainFromUint64(0), err
}
return xc.AmountBlockchain(*balance), nil
}
// FetchNativeBalance fetches the native asset balance for an Aptos address
func (client *Client) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error) {
balance, err := client.AptosClient.AptosBalanceOf(string(address))
if err != nil {
return xc.NewAmountBlockchainFromUint64(0), err
}
return xc.AmountBlockchain(*balance), nil
}