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
56 lines (42 loc) · 1.75 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
package crosschain
import "context"
// Client is a client that can fetch data and submit tx to a public blockchain
type Client interface {
FetchTxInput(ctx context.Context, from Address, to Address) (TxInput, error)
FetchTxInfo(ctx context.Context, txHash TxHash) (TxInfo, error)
SubmitTx(ctx context.Context, tx Tx) error
}
type EstimateGasFunc func(native NativeAsset) (AmountBlockchain, error)
// GasEstimator is a specific Client that can estimate gas - not implemented yet
type GasEstimator interface {
EstimateGas(ctx context.Context) (AmountBlockchain, error)
RegisterEstimateGasCallback(fn EstimateGasFunc)
}
// ClientBalance is a specific Client that can fetch balances
type ClientBalance interface {
// Fetch the balance of the asset that this client is configured for
FetchBalance(ctx context.Context, address Address) (AmountBlockchain, error)
FetchNativeBalance(ctx context.Context, address Address) (AmountBlockchain, error)
}
type FullClient interface {
Client
ClientBalance
}
type FullClientWithGas interface {
Client
ClientBalance
GasEstimator
}
type ClientError string
// A transaction terminally failed due to no balance
const NoBalance ClientError = "NoBalance"
// A transaction terminally failed due to no balance after accounting for gas cost
const NoBalanceForGas ClientError = "NoBalanceForGas"
// A transaction terminally failed due to another reason
const TransactionFailure ClientError = "TransactionFailure"
// A transaction failed to submit because it already exists
const TransactionExists ClientError = "TransactionExists"
// A network error occured -- there may be nothing wrong with the transaction
const NetworkError ClientError = "NetworkError"
// No outcome for this error known
const UnknownError ClientError = "UnknownError"