diff --git a/api/api.gen.go b/api/api.gen.go index 2898adf..7a61911 100644 --- a/api/api.gen.go +++ b/api/api.gen.go @@ -1,6 +1,6 @@ -// sequence-api v0.4.0 24814ebb88457c0545aa80e8388cb0f08ec59bec +// sequence-api v0.4.0 4a02ceb2c7cde0102368fe22f1435af952c3fc21 // -- -// Code generated by webrpc-gen@v0.20.3 with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with golang generator. DO NOT EDIT. // // webrpc-gen -schema=api.ridl -target=golang -pkg=api -client -out=./clients/api.gen.go package api @@ -14,11 +14,16 @@ import ( "io" "net/http" "net/url" + "strings" "time" "github.com/0xsequence/go-sequence/lib/prototyp" ) +const WebrpcHeader = "Webrpc" + +const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;sequence-api@v0.4.0" + // WebRPC description and code-gen version func WebRPCVersion() string { return "v1" @@ -31,7 +36,58 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "24814ebb88457c0545aa80e8388cb0f08ec59bec" + return "4a02ceb2c7cde0102368fe22f1435af952c3fc21" +} + +type WebrpcGenVersions struct { + WebrpcGenVersion string + CodeGenName string + CodeGenVersion string + SchemaName string + SchemaVersion string +} + +func VersionFromHeader(h http.Header) (*WebrpcGenVersions, error) { + if h.Get(WebrpcHeader) == "" { + return nil, fmt.Errorf("header is empty or missing") + } + + versions, err := parseWebrpcGenVersions(h.Get(WebrpcHeader)) + if err != nil { + return nil, fmt.Errorf("webrpc header is invalid: %w", err) + } + + return versions, nil +} + +func parseWebrpcGenVersions(header string) (*WebrpcGenVersions, error) { + versions := strings.Split(header, ";") + if len(versions) < 3 { + return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %v", header) + } + + _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") + if !ok { + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) + } + + tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") + if !ok { + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) + } + + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) + } + + return &WebrpcGenVersions{ + WebrpcGenVersion: webrpcGenVersion, + CodeGenName: tmplTarget, + CodeGenVersion: tmplVersion, + SchemaName: schemaName, + SchemaVersion: schemaVersion, + }, nil } // @@ -669,350 +725,357 @@ type AdoptedChildWallet struct { Address string `json:"address"` } -var ( - methods = map[string]method{ - "/rpc/API/Ping": { - Name: "Ping", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/Version": { - Name: "Version", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/RuntimeStatus": { - Name: "RuntimeStatus", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/Clock": { - Name: "Clock", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetSequenceContext": { - Name: "GetSequenceContext", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetAuthToken": { - Name: "GetAuthToken", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetAuthToken2": { - Name: "GetAuthToken2", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SendPasswordlessLink": { - Name: "SendPasswordlessLink", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/RegisterPublicKey": { - Name: "RegisterPublicKey", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetPublicKey": { - Name: "GetPublicKey", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/FriendList": { - Name: "FriendList", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetFriendByAddress": { - Name: "GetFriendByAddress", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SearchFriends": { - Name: "SearchFriends", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/AddFriend": { - Name: "AddFriend", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UpdateFriendNickname": { - Name: "UpdateFriendNickname", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/RemoveFriend": { - Name: "RemoveFriend", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ContractCall": { - Name: "ContractCall", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/DecodeContractCall": { - Name: "DecodeContractCall", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/LookupContractCallSelectors": { - Name: "LookupContractCallSelectors", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UserStorageFetch": { - Name: "UserStorageFetch", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UserStorageSave": { - Name: "UserStorageSave", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UserStorageDelete": { - Name: "UserStorageDelete", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UserStorageFetchAll": { - Name: "UserStorageFetchAll", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetMoonpayLink": { - Name: "GetMoonpayLink", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ResolveENSAddress": { - Name: "ResolveENSAddress", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/IsValidSignature": { - Name: "IsValidSignature", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/IsValidMessageSignature": { - Name: "IsValidMessageSignature", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/IsValidTypedDataSignature": { - Name: "IsValidTypedDataSignature", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/IsValidETHAuthProof": { - Name: "IsValidETHAuthProof", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/SardineGetClientToken": { - Name: "SardineGetClientToken", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetNFTCheckoutToken": { - Name: "SardineGetNFTCheckoutToken", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetNFTCheckoutOrderStatus": { - Name: "SardineGetNFTCheckoutOrderStatus", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetSupportedRegions": { - Name: "SardineGetSupportedRegions", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetSupportedFiatCurrencies": { - Name: "SardineGetSupportedFiatCurrencies", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetSupportedTokens": { - Name: "SardineGetSupportedTokens", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetEnabledTokens": { - Name: "SardineGetEnabledTokens", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/SardineGetQuote": { - Name: "SardineGetQuote", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetSardineClientToken": { - Name: "GetSardineClientToken", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetSardineNFTCheckoutToken": { - Name: "GetSardineNFTCheckoutToken", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetSardineNFTCheckoutOrderStatus": { - Name: "GetSardineNFTCheckoutOrderStatus", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetCoinPrices": { - Name: "GetCoinPrices", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetCollectiblePrices": { - Name: "GetCollectiblePrices", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetExchangeRate": { - Name: "GetExchangeRate", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/MemoryStore": { - Name: "MemoryStore", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/MemoryLoad": { - Name: "MemoryLoad", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetInviteInfo": { - Name: "GetInviteInfo", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/IsValidAccessCode": { - Name: "IsValidAccessCode", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/InternalClaimAccessCode": { - Name: "InternalClaimAccessCode", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/BlockNumberAtTime": { - Name: "BlockNumberAtTime", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/PaperSessionSecret": { - Name: "PaperSessionSecret", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/PaperSessionSecret2": { - Name: "PaperSessionSecret2", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/LinkWallet": { - Name: "LinkWallet", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/GetLinkedWallets": { - Name: "GetLinkedWallets", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/RemoveLinkedWallet": { - Name: "RemoveLinkedWallet", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/GenerateWaaSVerificationURL": { - Name: "GenerateWaaSVerificationURL", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ValidateWaaSVerificationNonce": { - Name: "ValidateWaaSVerificationNonce", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ListAdoptedWallets": { - Name: "ListAdoptedWallets", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetSwapPrice": { - Name: "GetSwapPrice", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/GetSwapPrices": { - Name: "GetSwapPrices", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/GetSwapQuote": { - Name: "GetSwapQuote", - Service: "API", - Annotations: map[string]string{"public": ""}, - }, - "/rpc/API/ListCurrencyGroups": { - Name: "ListCurrencyGroups", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/AddOffchainInventory": { - Name: "AddOffchainInventory", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/GetOffchainInventory": { - Name: "GetOffchainInventory", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ListOffchainInventories": { - Name: "ListOffchainInventories", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/UpdateOffchainInventory": { - Name: "UpdateOffchainInventory", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/DeleteOffchainInventory": { - Name: "DeleteOffchainInventory", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/RequestOffchainPayment": { - Name: "RequestOffchainPayment", - Service: "API", - Annotations: map[string]string{}, - }, - "/rpc/API/ListOffchainPayments": { - Name: "ListOffchainPayments", - Service: "API", - Annotations: map[string]string{}, - }, +var methods = map[string]method{ + "/rpc/API/Ping": { + Name: "Ping", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/Version": { + Name: "Version", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/RuntimeStatus": { + Name: "RuntimeStatus", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/Clock": { + Name: "Clock", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetSequenceContext": { + Name: "GetSequenceContext", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetAuthToken": { + Name: "GetAuthToken", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetAuthToken2": { + Name: "GetAuthToken2", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SendPasswordlessLink": { + Name: "SendPasswordlessLink", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/RegisterPublicKey": { + Name: "RegisterPublicKey", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetPublicKey": { + Name: "GetPublicKey", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/FriendList": { + Name: "FriendList", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetFriendByAddress": { + Name: "GetFriendByAddress", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SearchFriends": { + Name: "SearchFriends", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/AddFriend": { + Name: "AddFriend", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UpdateFriendNickname": { + Name: "UpdateFriendNickname", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/RemoveFriend": { + Name: "RemoveFriend", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ContractCall": { + Name: "ContractCall", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/DecodeContractCall": { + Name: "DecodeContractCall", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/LookupContractCallSelectors": { + Name: "LookupContractCallSelectors", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UserStorageFetch": { + Name: "UserStorageFetch", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UserStorageSave": { + Name: "UserStorageSave", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UserStorageDelete": { + Name: "UserStorageDelete", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UserStorageFetchAll": { + Name: "UserStorageFetchAll", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetMoonpayLink": { + Name: "GetMoonpayLink", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ResolveENSAddress": { + Name: "ResolveENSAddress", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/IsValidSignature": { + Name: "IsValidSignature", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/IsValidMessageSignature": { + Name: "IsValidMessageSignature", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/IsValidTypedDataSignature": { + Name: "IsValidTypedDataSignature", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/IsValidETHAuthProof": { + Name: "IsValidETHAuthProof", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/SardineGetClientToken": { + Name: "SardineGetClientToken", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetNFTCheckoutToken": { + Name: "SardineGetNFTCheckoutToken", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetNFTCheckoutOrderStatus": { + Name: "SardineGetNFTCheckoutOrderStatus", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetSupportedRegions": { + Name: "SardineGetSupportedRegions", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetSupportedFiatCurrencies": { + Name: "SardineGetSupportedFiatCurrencies", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetSupportedTokens": { + Name: "SardineGetSupportedTokens", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetEnabledTokens": { + Name: "SardineGetEnabledTokens", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/SardineGetQuote": { + Name: "SardineGetQuote", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetSardineClientToken": { + Name: "GetSardineClientToken", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetSardineNFTCheckoutToken": { + Name: "GetSardineNFTCheckoutToken", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetSardineNFTCheckoutOrderStatus": { + Name: "GetSardineNFTCheckoutOrderStatus", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetCoinPrices": { + Name: "GetCoinPrices", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetCollectiblePrices": { + Name: "GetCollectiblePrices", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetExchangeRate": { + Name: "GetExchangeRate", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/MemoryStore": { + Name: "MemoryStore", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/MemoryLoad": { + Name: "MemoryLoad", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetInviteInfo": { + Name: "GetInviteInfo", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/IsValidAccessCode": { + Name: "IsValidAccessCode", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/InternalClaimAccessCode": { + Name: "InternalClaimAccessCode", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/BlockNumberAtTime": { + Name: "BlockNumberAtTime", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/PaperSessionSecret": { + Name: "PaperSessionSecret", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/PaperSessionSecret2": { + Name: "PaperSessionSecret2", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/LinkWallet": { + Name: "LinkWallet", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/GetLinkedWallets": { + Name: "GetLinkedWallets", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/RemoveLinkedWallet": { + Name: "RemoveLinkedWallet", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/GenerateWaaSVerificationURL": { + Name: "GenerateWaaSVerificationURL", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ValidateWaaSVerificationNonce": { + Name: "ValidateWaaSVerificationNonce", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ListAdoptedWallets": { + Name: "ListAdoptedWallets", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetSwapPrice": { + Name: "GetSwapPrice", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/GetSwapPrices": { + Name: "GetSwapPrices", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/GetSwapQuote": { + Name: "GetSwapQuote", + Service: "API", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/API/ListCurrencyGroups": { + Name: "ListCurrencyGroups", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/AddOffchainInventory": { + Name: "AddOffchainInventory", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/GetOffchainInventory": { + Name: "GetOffchainInventory", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ListOffchainInventories": { + Name: "ListOffchainInventories", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/UpdateOffchainInventory": { + Name: "UpdateOffchainInventory", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/DeleteOffchainInventory": { + Name: "DeleteOffchainInventory", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/RequestOffchainPayment": { + Name: "RequestOffchainPayment", + Service: "API", + Annotations: map[string]string{}, + }, + "/rpc/API/ListOffchainPayments": { + Name: "ListOffchainPayments", + Service: "API", + Annotations: map[string]string{}, + }, +} + +func WebrpcMethods() map[string]method { + res := make(map[string]method, len(methods)) + for k, v := range methods { + res[k] = v } -) + + return res +} var WebRPCServices = map[string][]string{ "API": { @@ -1451,7 +1514,7 @@ func (c *aPIClient) Ping(ctx context.Context) (bool, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1467,7 +1530,7 @@ func (c *aPIClient) Version(ctx context.Context) (*Version, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1483,7 +1546,7 @@ func (c *aPIClient) RuntimeStatus(ctx context.Context) (*RuntimeStatus, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1499,7 +1562,7 @@ func (c *aPIClient) Clock(ctx context.Context) (time.Time, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1515,7 +1578,7 @@ func (c *aPIClient) GetSequenceContext(ctx context.Context) (*SequenceContext, e if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1538,7 +1601,7 @@ func (c *aPIClient) GetAuthToken(ctx context.Context, ewtString string, testnetM if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1561,7 +1624,7 @@ func (c *aPIClient) GetAuthToken2(ctx context.Context, ewtString string, chainID if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1582,7 +1645,7 @@ func (c *aPIClient) SendPasswordlessLink(ctx context.Context, email string, redi if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1601,7 +1664,7 @@ func (c *aPIClient) RegisterPublicKey(ctx context.Context, publicKey *PublicKey) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1620,7 +1683,7 @@ func (c *aPIClient) GetPublicKey(ctx context.Context, id string) (*PublicKey, er if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1641,7 +1704,7 @@ func (c *aPIClient) FriendList(ctx context.Context, nickname *string, page *Page if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1661,7 +1724,7 @@ func (c *aPIClient) GetFriendByAddress(ctx context.Context, friendAddress string if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1681,7 +1744,7 @@ func (c *aPIClient) SearchFriends(ctx context.Context, filterUsername string, pa if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1702,7 +1765,7 @@ func (c *aPIClient) AddFriend(ctx context.Context, friendAddress string, optiona if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1723,7 +1786,7 @@ func (c *aPIClient) UpdateFriendNickname(ctx context.Context, friendAddress stri if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1742,7 +1805,7 @@ func (c *aPIClient) RemoveFriend(ctx context.Context, friendAddress string) (boo if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1765,7 +1828,7 @@ func (c *aPIClient) ContractCall(ctx context.Context, chainID string, contract s if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1784,7 +1847,7 @@ func (c *aPIClient) DecodeContractCall(ctx context.Context, callData string) (*C if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1803,7 +1866,7 @@ func (c *aPIClient) LookupContractCallSelectors(ctx context.Context, selectors [ if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1822,7 +1885,7 @@ func (c *aPIClient) UserStorageFetch(ctx context.Context, key string) (interface if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1842,7 +1905,7 @@ func (c *aPIClient) UserStorageSave(ctx context.Context, key string, object inte if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1861,7 +1924,7 @@ func (c *aPIClient) UserStorageDelete(ctx context.Context, key string) (bool, er if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1880,7 +1943,7 @@ func (c *aPIClient) UserStorageFetchAll(ctx context.Context, keys []string) (map if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1899,7 +1962,7 @@ func (c *aPIClient) GetMoonpayLink(ctx context.Context, url string) (string, err if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1919,7 +1982,7 @@ func (c *aPIClient) ResolveENSAddress(ctx context.Context, ens string) (string, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1941,7 +2004,7 @@ func (c *aPIClient) IsValidSignature(ctx context.Context, chainId string, wallet if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1963,7 +2026,7 @@ func (c *aPIClient) IsValidMessageSignature(ctx context.Context, chainId string, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -1985,7 +2048,7 @@ func (c *aPIClient) IsValidTypedDataSignature(ctx context.Context, chainId strin if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2006,7 +2069,7 @@ func (c *aPIClient) IsValidETHAuthProof(ctx context.Context, chainId string, wal if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2022,7 +2085,7 @@ func (c *aPIClient) SardineGetClientToken(ctx context.Context) (string, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2041,7 +2104,7 @@ func (c *aPIClient) SardineGetNFTCheckoutToken(ctx context.Context, params *Sard if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2060,7 +2123,7 @@ func (c *aPIClient) SardineGetNFTCheckoutOrderStatus(ctx context.Context, orderI if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2076,7 +2139,7 @@ func (c *aPIClient) SardineGetSupportedRegions(ctx context.Context) ([]*SardineR if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2092,7 +2155,7 @@ func (c *aPIClient) SardineGetSupportedFiatCurrencies(ctx context.Context) ([]*S if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2108,7 +2171,7 @@ func (c *aPIClient) SardineGetSupportedTokens(ctx context.Context) ([]*SardineSu if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2124,7 +2187,7 @@ func (c *aPIClient) SardineGetEnabledTokens(ctx context.Context) ([]*SardineEnab if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2143,7 +2206,7 @@ func (c *aPIClient) SardineGetQuote(ctx context.Context, params *SardineGetQuote if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2159,7 +2222,7 @@ func (c *aPIClient) GetSardineClientToken(ctx context.Context) (string, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2178,7 +2241,7 @@ func (c *aPIClient) GetSardineNFTCheckoutToken(ctx context.Context, params *Sard if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2197,7 +2260,7 @@ func (c *aPIClient) GetSardineNFTCheckoutOrderStatus(ctx context.Context, orderI if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2216,7 +2279,7 @@ func (c *aPIClient) GetCoinPrices(ctx context.Context, tokens []*Token) ([]*Toke if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2235,7 +2298,7 @@ func (c *aPIClient) GetCollectiblePrices(ctx context.Context, tokens []*Token) ( if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2254,7 +2317,7 @@ func (c *aPIClient) GetExchangeRate(ctx context.Context, toCurrency string) (*Ex if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2274,7 +2337,7 @@ func (c *aPIClient) MemoryStore(ctx context.Context, key string, value string) ( if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2293,7 +2356,7 @@ func (c *aPIClient) MemoryLoad(ctx context.Context, key string) (string, error) if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2309,7 +2372,7 @@ func (c *aPIClient) GetInviteInfo(ctx context.Context) (*InviteInfo, error) { if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2328,7 +2391,7 @@ func (c *aPIClient) IsValidAccessCode(ctx context.Context, accessCode string) (b if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2348,7 +2411,7 @@ func (c *aPIClient) InternalClaimAccessCode(ctx context.Context, address string, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2368,7 +2431,7 @@ func (c *aPIClient) BlockNumberAtTime(ctx context.Context, chainId uint64, times if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2390,7 +2453,7 @@ func (c *aPIClient) PaperSessionSecret(ctx context.Context, chainName string, co if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2412,7 +2475,7 @@ func (c *aPIClient) PaperSessionSecret2(ctx context.Context, chainName string, c if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2438,7 +2501,7 @@ func (c *aPIClient) LinkWallet(ctx context.Context, parentWalletAddress string, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2460,7 +2523,7 @@ func (c *aPIClient) GetLinkedWallets(ctx context.Context, parentWalletAddress st if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2483,7 +2546,7 @@ func (c *aPIClient) RemoveLinkedWallet(ctx context.Context, parentWalletAddress if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2503,7 +2566,7 @@ func (c *aPIClient) GenerateWaaSVerificationURL(ctx context.Context, walletAddre if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2525,7 +2588,7 @@ func (c *aPIClient) ValidateWaaSVerificationNonce(ctx context.Context, nonce str if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2545,7 +2608,7 @@ func (c *aPIClient) ListAdoptedWallets(ctx context.Context, page *Page) (*Page, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2568,7 +2631,7 @@ func (c *aPIClient) GetSwapPrice(ctx context.Context, buyCurrencyAddress string, if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2591,7 +2654,7 @@ func (c *aPIClient) GetSwapPrices(ctx context.Context, userAddress string, buyCu if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2616,7 +2679,7 @@ func (c *aPIClient) GetSwapQuote(ctx context.Context, userAddress string, buyCur if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2632,7 +2695,7 @@ func (c *aPIClient) ListCurrencyGroups(ctx context.Context) ([]*CurrencyGroup, e if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2651,7 +2714,7 @@ func (c *aPIClient) AddOffchainInventory(ctx context.Context, inventory *Offchai if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2670,7 +2733,7 @@ func (c *aPIClient) GetOffchainInventory(ctx context.Context, inventoryId uint64 if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2689,7 +2752,7 @@ func (c *aPIClient) ListOffchainInventories(ctx context.Context, projectId uint6 if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2705,7 +2768,7 @@ func (c *aPIClient) UpdateOffchainInventory(ctx context.Context, inventory *Offc if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2724,7 +2787,7 @@ func (c *aPIClient) DeleteOffchainInventory(ctx context.Context, inventoryId uin if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2746,7 +2809,7 @@ func (c *aPIClient) RequestOffchainPayment(ctx context.Context, inventoryId uint if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2767,7 +2830,7 @@ func (c *aPIClient) ListOffchainPayments(ctx context.Context, inventoryId uint64 if resp != nil { cerr := resp.Body.Close() if err == nil && cerr != nil { - err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr)) + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } @@ -2804,6 +2867,7 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType } req.Header.Set("Accept", contentType) req.Header.Set("Content-Type", contentType) + req.Header.Set(WebrpcHeader, WebrpcHeaderValue) if headers, ok := HTTPRequestHeaders(ctx); ok { for k := range headers { for _, v := range headers[k] { @@ -2818,15 +2882,15 @@ func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out interface{}) (*http.Response, error) { reqBody, err := json.Marshal(in) if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to marshal JSON body: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("failed to marshal JSON body: %w", err) } if err = ctx.Err(); err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("aborted because context was done: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("aborted because context was done: %w", err) } req, err := newRequest(ctx, url, bytes.NewBuffer(reqBody), "application/json") if err != nil { - return nil, ErrWebrpcRequestFailed.WithCause(fmt.Errorf("could not build request: %w", err)) + return nil, ErrWebrpcRequestFailed.WithCausef("could not build request: %w", err) } resp, err := client.Do(req) @@ -2837,12 +2901,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if resp.StatusCode != 200 { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read server error response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read server error response body: %w", err) } var rpcErr WebRPCError if err := json.Unmarshal(respBody, &rpcErr); err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal server error: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal server error: %w", err) } if rpcErr.Cause != "" { rpcErr.cause = errors.New(rpcErr.Cause) @@ -2853,12 +2917,12 @@ func doHTTPRequest(ctx context.Context, client HTTPClient, url string, in, out i if out != nil { respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to read response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to read response body: %w", err) } err = json.Unmarshal(respBody, &out) if err != nil { - return nil, ErrWebrpcBadResponse.WithCause(fmt.Errorf("failed to unmarshal JSON response body: %w", err)) + return nil, ErrWebrpcBadResponse.WithCausef("failed to unmarshal JSON response body: %w", err) } } @@ -3020,13 +3084,28 @@ var ( // Schema errors var ( - ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} - ErrPermissionDenied = WebRPCError{Code: 1001, Name: "PermissionDenied", Message: "Permission denied", HTTPStatus: 403} - ErrSessionExpired = WebRPCError{Code: 1002, Name: "SessionExpired", Message: "Session expired", HTTPStatus: 403} - ErrAborted = WebRPCError{Code: 1005, Name: "Aborted", Message: "Request aborted", HTTPStatus: 400} - ErrGeoblocked = WebRPCError{Code: 1006, Name: "Geoblocked", Message: "Geoblocked region", HTTPStatus: 451} - ErrInvalidArgument = WebRPCError{Code: 2000, Name: "InvalidArgument", Message: "Invalid argument", HTTPStatus: 400} - ErrUnavailable = WebRPCError{Code: 2002, Name: "Unavailable", Message: "Unavailable resource", HTTPStatus: 400} - ErrQueryFailed = WebRPCError{Code: 2003, Name: "QueryFailed", Message: "Query failed", HTTPStatus: 400} - ErrNotFound = WebRPCError{Code: 3000, Name: "NotFound", Message: "Resource not found", HTTPStatus: 400} + ErrUnauthorized = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401} + ErrPermissionDenied = WebRPCError{Code: 1001, Name: "PermissionDenied", Message: "Permission denied", HTTPStatus: 403} + ErrSessionExpired = WebRPCError{Code: 1002, Name: "SessionExpired", Message: "Session expired", HTTPStatus: 403} + ErrMethodNotFound = WebRPCError{Code: 1003, Name: "MethodNotFound", Message: "Method not found", HTTPStatus: 404} + ErrRequestConflict = WebRPCError{Code: 1004, Name: "RequestConflict", Message: "Conflict with target resource", HTTPStatus: 409} + ErrAborted = WebRPCError{Code: 1005, Name: "Aborted", Message: "Request aborted", HTTPStatus: 400} + ErrGeoblocked = WebRPCError{Code: 1006, Name: "Geoblocked", Message: "Geoblocked region", HTTPStatus: 451} + ErrRateLimited = WebRPCError{Code: 1007, Name: "RateLimited", Message: "Rate-limited. Please slow down.", HTTPStatus: 429} + ErrProjectNotFound = WebRPCError{Code: 1008, Name: "ProjectNotFound", Message: "Project not found", HTTPStatus: 401} + ErrAccessKeyNotFound = WebRPCError{Code: 1101, Name: "AccessKeyNotFound", Message: "Access key not found", HTTPStatus: 401} + ErrAccessKeyMismatch = WebRPCError{Code: 1102, Name: "AccessKeyMismatch", Message: "Access key mismatch", HTTPStatus: 409} + ErrInvalidOrigin = WebRPCError{Code: 1103, Name: "InvalidOrigin", Message: "Invalid origin for Access Key", HTTPStatus: 403} + ErrInvalidService = WebRPCError{Code: 1104, Name: "InvalidService", Message: "Service not enabled for Access key", HTTPStatus: 403} + ErrUnauthorizedUser = WebRPCError{Code: 1105, Name: "UnauthorizedUser", Message: "Unauthorized user", HTTPStatus: 403} + ErrQuotaExceeded = WebRPCError{Code: 1200, Name: "QuotaExceeded", Message: "Quota request exceeded", HTTPStatus: 429} + ErrQuotaRateLimit = WebRPCError{Code: 1201, Name: "QuotaRateLimit", Message: "Quota rate limit exceeded", HTTPStatus: 429} + ErrNoDefaultKey = WebRPCError{Code: 1300, Name: "NoDefaultKey", Message: "No default access key found", HTTPStatus: 403} + ErrMaxAccessKeys = WebRPCError{Code: 1301, Name: "MaxAccessKeys", Message: "Access keys limit reached", HTTPStatus: 403} + ErrAtLeastOneKey = WebRPCError{Code: 1302, Name: "AtLeastOneKey", Message: "You need at least one Access Key", HTTPStatus: 403} + ErrTimeout = WebRPCError{Code: 1900, Name: "Timeout", Message: "Request timed out", HTTPStatus: 408} + ErrInvalidArgument = WebRPCError{Code: 2000, Name: "InvalidArgument", Message: "Invalid argument", HTTPStatus: 400} + ErrUnavailable = WebRPCError{Code: 2002, Name: "Unavailable", Message: "Unavailable resource", HTTPStatus: 400} + ErrQueryFailed = WebRPCError{Code: 2003, Name: "QueryFailed", Message: "Query failed", HTTPStatus: 400} + ErrNotFound = WebRPCError{Code: 3000, Name: "NotFound", Message: "Resource not found", HTTPStatus: 400} )