forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (55 loc) · 1.96 KB
/
main.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
package federation
import (
"net/http"
"net/url"
hc "github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/clients/stellartoml"
proto "github.com/stellar/go/protocols/federation"
)
// FederationResponseMaxSize is the maximum size of response from a federation server
const FederationResponseMaxSize = 100 * 1024
// DefaultTestNetClient is a default federation client for testnet
var DefaultTestNetClient = &Client{
HTTP: http.DefaultClient,
Horizon: hc.DefaultTestNetClient,
StellarTOML: stellartoml.DefaultClient,
}
// DefaultPublicNetClient is a default federation client for pubnet
var DefaultPublicNetClient = &Client{
HTTP: http.DefaultClient,
Horizon: hc.DefaultPublicNetClient,
StellarTOML: stellartoml.DefaultClient,
}
// Client represents a client that is capable of resolving a federation request
// using the internet.
type Client struct {
StellarTOML StellarTOML
HTTP HTTP
Horizon Horizon
AllowHTTP bool
}
type ClientInterface interface {
LookupByAddress(addy string) (*proto.NameResponse, error)
LookupByAccountID(aid string) (*proto.IDResponse, error)
ForwardRequest(domain string, fields url.Values) (*proto.NameResponse, error)
}
// Horizon represents a horizon client that can be consulted for data when
// needed as part of the federation protocol
type Horizon interface {
HomeDomainForAccount(aid string) (string, error)
}
// HTTP represents the http client that a federation client uses to make http
// requests.
type HTTP interface {
Get(url string) (*http.Response, error)
}
// StellarTOML represents a client that can resolve a given domain name to
// stellar.toml file. The response is used to find the federation server that a
// query should be made against.
type StellarTOML interface {
GetStellarToml(domain string) (*stellartoml.Response, error)
}
// confirm interface conformity
var _ StellarTOML = stellartoml.DefaultClient
var _ HTTP = http.DefaultClient
var _ ClientInterface = &Client{}