Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ func NewClient(config NetworkConfig) (client *Client, err error) {
if err != nil {
return nil, err
}

httpIndexerClient, err := NewHttpClient(config.NodeUrl, config.ChainId)
if err != nil {
return nil, err
}

// Indexer may not be present
var indexerClient *IndexerClient = nil
if config.IndexerUrl != "" {
indexerClient = NewIndexerClient(nodeClient.client, config.IndexerUrl)
indexerClient = NewIndexerClient(httpIndexerClient, config.IndexerUrl)
}

// Faucet may not be present
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module github.com/aptos-labs/aptos-go-sdk

go 1.22

toolchain go1.22.7

require (
github.com/cucumber/godog v0.14.1
github.com/ethereum/go-ethereum v1.14.5
github.com/gorilla/http v1.0.0
github.com/hasura/go-graphql-client v0.12.1
github.com/hdevalence/ed25519consensus v0.2.0
github.com/stretchr/testify v1.9.0
Expand All @@ -13,6 +16,7 @@ require (

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cucumber/gherkin/go/v26 v26.2.0 // indirect
github.com/cucumber/messages/go/v21 v21.0.1 // indirect
Expand All @@ -24,9 +28,12 @@ require (
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.11 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ensb7o3sC0=
github.com/btcsuite/btcd/btcec/v2 v2.3.3/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand Down Expand Up @@ -27,6 +29,8 @@ github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+C
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/http v1.0.0 h1:IUVGpUJizpjJsfDoJlOFkt4YXm3ypJlTCzymVBHggtY=
github.com/gorilla/http v1.0.0/go.mod h1:I7WZNkKf2qPN94e0txUhxrVAdQ1tuxTPp6zkedisckU=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
Expand All @@ -45,6 +49,8 @@ github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3s
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand All @@ -70,6 +76,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
Expand Down
30 changes: 17 additions & 13 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package aptos

import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/valyala/fasthttp"
)

// HttpErrSummaryLength is the maximum length of the body to include in the error message
Expand All @@ -16,21 +16,25 @@ type HttpError struct {
StatusCode int // HTTP status code e.g. 200
Header http.Header // HTTP headers
Method string // HTTP method e.g. "GET"
RequestUrl url.URL // URL of the request
RequestUrl string // URL of the request
Body []byte // Body of the response
}

// NewHttpError creates a new HttpError from a http.Response
func NewHttpError(response *http.Response) *HttpError {
body, _ := io.ReadAll(response.Body)
_ = response.Body.Close()
func NewHttpError(response *fasthttp.Response, request *fasthttp.Request) *HttpError {
body := response.Body()
var headers http.Header = make(map[string][]string)
response.Header.VisitAll(func(key, value []byte) {
headers[string(key)] = []string{string(value)}
})

return &HttpError{
Status: response.Status,
StatusCode: response.StatusCode,
Header: response.Header,
Status: string(response.Header.StatusMessage()),
StatusCode: response.StatusCode(),
Header: headers,
Body: body,
Method: response.Request.Method,
RequestUrl: *response.Request.URL,
Method: string(request.Header.Method()),
RequestUrl: string(request.URI().FullURI()),
}
}

Expand All @@ -41,13 +45,13 @@ func NewHttpError(response *http.Response) *HttpError {
func (he *HttpError) Error() string {
if len(he.Body) < HttpErrSummaryLength {
return fmt.Sprintf("HttpError %s %#v -> %#v %#v",
he.Method, he.RequestUrl.String(), he.Status,
he.Method, he.RequestUrl, he.Status,
string(he.Body),
)
} else {
// Trim if the error is too long
return fmt.Sprintf("HttpError %s %#v -> %#v %s %#v...[+%d]",
he.Method, he.RequestUrl.String(), he.Status,
he.Method, he.RequestUrl, he.Status,
he.Header.Get("Content-Type"),
string(he.Body)[:HttpErrSummaryLength-10], len(he.Body)-(HttpErrSummaryLength-10),
)
Expand Down
Loading