diff --git a/relayer/proto/relayer.gen.go b/relayer/proto/relayer.gen.go index 4d685591..fd9ae966 100644 --- a/relayer/proto/relayer.gen.go +++ b/relayer/proto/relayer.gen.go @@ -1,6 +1,6 @@ -// sequence-relayer v0.4.1 e4df7ceb0987a6b6fd6a61d65e57a0a072b101aa +// sequence-relayer v0.4.1 da20208d66be29ad86d2662ca38c4425bc5910f8 // -- -// Code generated by webrpc-gen@v0.18.7 with golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with golang generator. DO NOT EDIT. // // webrpc-gen -schema=relayer.ridl -target=golang -pkg=proto -client -out=./clients/relayer.gen.go package proto @@ -14,12 +14,17 @@ import ( "io" "net/http" "net/url" + "strings" "time" "github.com/0xsequence/go-sequence/lib/prototyp" "github.com/shopspring/decimal" ) +const WebrpcHeader = "Webrpc" + +const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;sequence-relayer@v0.4.1" + // WebRPC description and code-gen version func WebRPCVersion() string { return "v1" @@ -32,7 +37,58 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "e4df7ceb0987a6b6fd6a61d65e57a0a072b101aa" + return "da20208d66be29ad86d2662ca38c4425bc5910f8" +} + +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 } // @@ -252,16 +308,16 @@ type Version struct { type RuntimeStatus struct { // overall status, true/false - HealthOK bool `json:"healthOK"` - StartTime time.Time `json:"startTime"` - Uptime uint64 `json:"uptime"` - Ver string `json:"ver"` - Branch string `json:"branch"` - CommitHash string `json:"commitHash"` - UseEIP1559 bool `json:"useEIP1559"` - Senders []*SenderStatus `json:"senders"` - Checks *RuntimeChecks `json:"checks"` - NumTxnsRelayed *NumTxnsRelayed `json:"numTxnsRelayed"` + HealthOK bool `json:"healthOK"` + StartTime time.Time `json:"startTime"` + Uptime uint64 `json:"uptime"` + Ver string `json:"ver"` + Branch string `json:"branch"` + CommitHash string `json:"commitHash"` + ChainID uint64 `json:"chainID"` + UseEIP1559 bool `json:"useEIP1559"` + Senders []*SenderStatus `json:"senders"` + Checks *RuntimeChecks `json:"checks"` } type SenderStatus struct { @@ -274,12 +330,6 @@ type SenderStatus struct { type RuntimeChecks struct { } -type NumTxnsRelayed struct { - Prev uint64 `json:"prev"` - Current uint64 `json:"current"` - Period uint64 `json:"period"` -} - type SequenceContext struct { Factory string `json:"factory"` MainModule string `json:"mainModule"` @@ -290,6 +340,7 @@ type SequenceContext struct { type GasTank struct { ID uint64 `json:"id" db:"id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id,omitempty"` Name string `json:"name" db:"name"` CurrentBalance decimal.Decimal `json:"currentBalance" db:"current_balance"` Unlimited bool `json:"unlimited" db:"unlimited"` @@ -311,6 +362,7 @@ type GasSponsor struct { ID uint64 `json:"id" db:"id,omitempty"` GasTankID uint64 `json:"gasTankId" db:"gas_tank_id,omitempty"` ProjectID uint64 `json:"projectId" db:"project_id"` + ChainID uint64 `json:"chainId" db:"chain_id,omitempty"` Address prototyp.Hash `json:"address" db:"address"` Name string `json:"name" db:"name"` Active bool `json:"active" db:"active"` @@ -344,6 +396,7 @@ type MetaTxn struct { // TODO: review type MetaTxnLog struct { ID uint64 `json:"id" db:"id,omitempty"` + ChainID uint64 `json:"chainId" db:"chain_id,omitempty"` ProjectID uint64 `json:"projectId" db:"project_id"` // this is optional, but we don't specify txnHash?: string, // otherwise it sets go.field.type to pointer-type which we dont want. @@ -373,6 +426,7 @@ type MetaTxnLog struct { GasFeeMarkup *uint64 `json:"gasFeeMarkup" db:"gas_fee_markup"` UsdRate prototyp.BigInt `json:"usdRate" db:"usd_rate"` CreditsUsed uint64 `json:"creditsUsed" db:"credits_used"` + Cost decimal.Decimal `json:"cost" db:"-"` IsWhitelisted bool `json:"isWhitelisted" db:"is_whitelisted,omitempty"` GasSponsor *uint64 `json:"gasSponsor" db:"gas_sponsor_id,omitempty"` GasTank *uint64 `json:"gasTank" db:"gas_tank_id,omitempty"` @@ -380,18 +434,6 @@ type MetaTxnLog struct { CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"` } -// TODO: review -type MetaTxnEntry struct { - ID uint64 `json:"id" db:"id,omitempty"` - MetaTxnID string `json:"metaTxnID" db:"metatx_logs_id"` - TxnStatus ETHTxnStatus `json:"txnStatus" db:"status"` - TxnRevertReason string `json:"txnRevertReason" db:"revert_reason"` - Index uint64 `json:"index" db:"index"` - Logs []interface{} `json:"logs" db:"logs,omitempty"` - UpdatedAt *time.Time `json:"updatedAt" db:"updated_at,omitempty"` - CreatedAt *time.Time `json:"createdAt" db:"created_at,omitempty"` -} - type MetaTxnReceipt struct { ID string `json:"id"` Status string `json:"status"` @@ -477,15 +519,15 @@ type Page struct { Page *uint32 `json:"page"` More *bool `json:"more"` // Number of total items on this query. - TotalRecords *uint64 `json:"totalRecords"` + TotalRecords *uint64 `json:"total_records,omitempty"` // Cursor: column to compare before/after to - Column *string `json:"column"` + Column *string `json:"column,omitempty"` // Cursor: return column < before - include to get previous page - Before *interface{} `json:"before"` + Before *interface{} `json:"before,omitempty"` // Cursor: return column > after - include to get next page - After *interface{} `json:"after"` + After *interface{} `json:"after,omitempty"` // Sorting filter - Sort []*SortBy `json:"sort"` + Sort []*SortBy `json:"sort,omitempty"` } type SortBy struct { @@ -493,6 +535,178 @@ type SortBy struct { Order SortOrder `json:"order"` } +var methods = map[string]method{ + "/rpc/Relayer/Ping": { + Name: "Ping", + Service: "Relayer", + Annotations: map[string]string{"internal": ""}, + }, + "/rpc/Relayer/Version": { + Name: "Version", + Service: "Relayer", + Annotations: map[string]string{"internal": ""}, + }, + "/rpc/Relayer/RuntimeStatus": { + Name: "RuntimeStatus", + Service: "Relayer", + Annotations: map[string]string{"internal": ""}, + }, + "/rpc/Relayer/GetSequenceContext": { + Name: "GetSequenceContext", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetChainID": { + Name: "GetChainID", + Service: "Relayer", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/Relayer/SendMetaTxn": { + Name: "SendMetaTxn", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetMetaTxnNonce": { + Name: "GetMetaTxnNonce", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetMetaTxnReceipt": { + Name: "GetMetaTxnReceipt", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/Simulate": { + Name: "Simulate", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/UpdateMetaTxnGasLimits": { + Name: "UpdateMetaTxnGasLimits", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/FeeTokens": { + Name: "FeeTokens", + Service: "Relayer", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/Relayer/FeeOptions": { + Name: "FeeOptions", + Service: "Relayer", + Annotations: map[string]string{"public": ""}, + }, + "/rpc/Relayer/GetMetaTxnNetworkFeeOptions": { + Name: "GetMetaTxnNetworkFeeOptions", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetMetaTransactions": { + Name: "GetMetaTransactions", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetTransactionCost": { + Name: "GetTransactionCost", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/SentTransactions": { + Name: "SentTransactions", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/PendingTransactions": { + Name: "PendingTransactions", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetGasTank": { + Name: "GetGasTank", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/AddGasTank": { + Name: "AddGasTank", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/UpdateGasTank": { + Name: "UpdateGasTank", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/NextGasTankBalanceAdjustmentNonce": { + Name: "NextGasTankBalanceAdjustmentNonce", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/AdjustGasTankBalance": { + Name: "AdjustGasTankBalance", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetGasTankBalanceAdjustment": { + Name: "GetGasTankBalanceAdjustment", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/ListGasTankBalanceAdjustments": { + Name: "ListGasTankBalanceAdjustments", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/ListGasSponsors": { + Name: "ListGasSponsors", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetGasSponsor": { + Name: "GetGasSponsor", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/AddGasSponsor": { + Name: "AddGasSponsor", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/UpdateGasSponsor": { + Name: "UpdateGasSponsor", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/RemoveGasSponsor": { + Name: "RemoveGasSponsor", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/AddressGasSponsors": { + Name: "AddressGasSponsors", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/GetProjectBalance": { + Name: "GetProjectBalance", + Service: "Relayer", + Annotations: map[string]string{}, + }, + "/rpc/Relayer/AdjustProjectBalance": { + Name: "AdjustProjectBalance", + Service: "Relayer", + 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{ "Relayer": { "Ping", @@ -509,22 +723,24 @@ var WebRPCServices = map[string][]string{ "FeeOptions", "GetMetaTxnNetworkFeeOptions", "GetMetaTransactions", + "GetTransactionCost", "SentTransactions", "PendingTransactions", "GetGasTank", "AddGasTank", "UpdateGasTank", - "GetGasSponsor", - "AddressGasSponsors", - "ListGasSponsors", - "AddGasSponsor", - "UpdateGasSponsor", - "RemoveGasSponsor", - "ReportGasSponsorUsage", "NextGasTankBalanceAdjustmentNonce", "AdjustGasTankBalance", "GetGasTankBalanceAdjustment", "ListGasTankBalanceAdjustments", + "ListGasSponsors", + "GetGasSponsor", + "AddGasSponsor", + "UpdateGasSponsor", + "RemoveGasSponsor", + "AddressGasSponsors", + "GetProjectBalance", + "AdjustProjectBalance", }, } @@ -537,14 +753,14 @@ type Relayer interface { Version(ctx context.Context) (*Version, error) RuntimeStatus(ctx context.Context) (*RuntimeStatus, error) GetSequenceContext(ctx context.Context) (*SequenceContext, error) - // TODO: return a string instead GetChainID(ctx context.Context) (uint64, error) // // Transactions // // TODO (future): rename this to just, 'SendTransaction(txn: MetaTransaction)' or 'SendTransaction(txn: SignedTransaction)', or something.. + // Project ID is only used by service and admin calls. Other clients must have projectID passed via the context // TODO: rename return txnHash: string to metaTxnID: string - SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error) + SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string, projectID *uint64) (bool, string, error) GetMetaTxnNonce(ctx context.Context, walletContractAddress string, space *string) (string, error) // TODO: one day, make GetMetaTxnReceipt respond immediately with receipt or not // and add WaitTransactionReceipt method, which will block and wait, similar to how GetMetaTxnReceipt @@ -560,26 +776,33 @@ type Relayer interface { FeeOptions(ctx context.Context, wallet string, to string, data string, simulate *bool) ([]*FeeOption, bool, *string, error) // TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date GetMetaTxnNetworkFeeOptions(ctx context.Context, walletConfig interface{}, payload string) ([]*FeeOption, error) - GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error) + GetMetaTransactions(ctx context.Context, projectId uint64, page *Page) (*Page, []*MetaTxnLog, error) + GetTransactionCost(ctx context.Context, projectId uint64, from time.Time, to time.Time) (float64, error) // Sent transactions from an account. If filter is omitted then it will return all transactions. SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error) // Pending transactions waiting to be mined for an account. This endpoint is just a sugar of `SentTransactions` // with the filter set to pending: true. PendingTransactions(ctx context.Context, page *Page) (*Page, []*Transaction, error) + // Legacy Gas Tank GetGasTank(ctx context.Context, id uint64) (*GasTank, error) AddGasTank(ctx context.Context, name string, feeMarkupFactor float64, unlimited *bool) (bool, *GasTank, error) UpdateGasTank(ctx context.Context, id uint64, name *string, feeMarkupFactor *float64, unlimited *bool) (bool, *GasTank, error) - GetGasSponsor(ctx context.Context, id uint64) (*GasSponsor, error) - AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) - ListGasSponsors(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*GasSponsor, error) - AddGasSponsor(ctx context.Context, projectId uint64, gasTankId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) - UpdateGasSponsor(ctx context.Context, id uint64, name *string, active *bool) (bool, *GasSponsor, error) - RemoveGasSponsor(ctx context.Context, id uint64) (bool, error) - ReportGasSponsorUsage(ctx context.Context, projectId uint64, gasTankId uint64, startTime *time.Time, endTime *time.Time) ([]*GasSponsorUsage, error) + // Legacy Gas Adjustment NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error) AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error) GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error) ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error) + // Gas Sponsorship + ListGasSponsors(ctx context.Context, projectId uint64, page *Page) (*Page, []*GasSponsor, error) + GetGasSponsor(ctx context.Context, projectId uint64, id uint64) (*GasSponsor, error) + AddGasSponsor(ctx context.Context, projectId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) + UpdateGasSponsor(ctx context.Context, projectId uint64, id uint64, name *string, active *bool) (bool, *GasSponsor, error) + RemoveGasSponsor(ctx context.Context, projectId uint64, id uint64) (bool, error) + // Gas Sponsor Lookup + AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) + // Project Balance + GetProjectBalance(ctx context.Context, projectId uint64) (float64, error) + AdjustProjectBalance(ctx context.Context, projectId uint64, amount float64, identifier string) (float64, error) } // @@ -591,14 +814,14 @@ type RelayerClient interface { Version(ctx context.Context) (*Version, error) RuntimeStatus(ctx context.Context) (*RuntimeStatus, error) GetSequenceContext(ctx context.Context) (*SequenceContext, error) - // TODO: return a string instead GetChainID(ctx context.Context) (uint64, error) // // Transactions // // TODO (future): rename this to just, 'SendTransaction(txn: MetaTransaction)' or 'SendTransaction(txn: SignedTransaction)', or something.. + // Project ID is only used by service and admin calls. Other clients must have projectID passed via the context // TODO: rename return txnHash: string to metaTxnID: string - SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error) + SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string, projectID *uint64) (bool, string, error) GetMetaTxnNonce(ctx context.Context, walletContractAddress string, space *string) (string, error) // TODO: one day, make GetMetaTxnReceipt respond immediately with receipt or not // and add WaitTransactionReceipt method, which will block and wait, similar to how GetMetaTxnReceipt @@ -614,26 +837,33 @@ type RelayerClient interface { FeeOptions(ctx context.Context, wallet string, to string, data string, simulate *bool) ([]*FeeOption, bool, *string, error) // TODO: deprecated, to be removed by https://github.com/0xsequence/stack/pull/356 at a later date GetMetaTxnNetworkFeeOptions(ctx context.Context, walletConfig interface{}, payload string) ([]*FeeOption, error) - GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error) + GetMetaTransactions(ctx context.Context, projectId uint64, page *Page) (*Page, []*MetaTxnLog, error) + GetTransactionCost(ctx context.Context, projectId uint64, from time.Time, to time.Time) (float64, error) // Sent transactions from an account. If filter is omitted then it will return all transactions. SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error) // Pending transactions waiting to be mined for an account. This endpoint is just a sugar of `SentTransactions` // with the filter set to pending: true. PendingTransactions(ctx context.Context, page *Page) (*Page, []*Transaction, error) + // Legacy Gas Tank GetGasTank(ctx context.Context, id uint64) (*GasTank, error) AddGasTank(ctx context.Context, name string, feeMarkupFactor float64, unlimited *bool) (bool, *GasTank, error) UpdateGasTank(ctx context.Context, id uint64, name *string, feeMarkupFactor *float64, unlimited *bool) (bool, *GasTank, error) - GetGasSponsor(ctx context.Context, id uint64) (*GasSponsor, error) - AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) - ListGasSponsors(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*GasSponsor, error) - AddGasSponsor(ctx context.Context, projectId uint64, gasTankId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) - UpdateGasSponsor(ctx context.Context, id uint64, name *string, active *bool) (bool, *GasSponsor, error) - RemoveGasSponsor(ctx context.Context, id uint64) (bool, error) - ReportGasSponsorUsage(ctx context.Context, projectId uint64, gasTankId uint64, startTime *time.Time, endTime *time.Time) ([]*GasSponsorUsage, error) + // Legacy Gas Adjustment NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error) AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error) GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error) ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error) + // Gas Sponsorship + ListGasSponsors(ctx context.Context, projectId uint64, page *Page) (*Page, []*GasSponsor, error) + GetGasSponsor(ctx context.Context, projectId uint64, id uint64) (*GasSponsor, error) + AddGasSponsor(ctx context.Context, projectId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) + UpdateGasSponsor(ctx context.Context, projectId uint64, id uint64, name *string, active *bool) (bool, *GasSponsor, error) + RemoveGasSponsor(ctx context.Context, projectId uint64, id uint64) (bool, error) + // Gas Sponsor Lookup + AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) + // Project Balance + GetProjectBalance(ctx context.Context, projectId uint64) (float64, error) + AdjustProjectBalance(ctx context.Context, projectId uint64, amount float64, identifier string) (float64, error) } // @@ -644,12 +874,12 @@ const RelayerPathPrefix = "/rpc/Relayer/" type relayerClient struct { client HTTPClient - urls [30]string + urls [32]string } func NewRelayerClient(addr string, client HTTPClient) RelayerClient { prefix := urlBase(addr) + RelayerPathPrefix - urls := [30]string{ + urls := [32]string{ prefix + "Ping", prefix + "Version", prefix + "RuntimeStatus", @@ -664,22 +894,24 @@ func NewRelayerClient(addr string, client HTTPClient) RelayerClient { prefix + "FeeOptions", prefix + "GetMetaTxnNetworkFeeOptions", prefix + "GetMetaTransactions", + prefix + "GetTransactionCost", prefix + "SentTransactions", prefix + "PendingTransactions", prefix + "GetGasTank", prefix + "AddGasTank", prefix + "UpdateGasTank", - prefix + "GetGasSponsor", - prefix + "AddressGasSponsors", - prefix + "ListGasSponsors", - prefix + "AddGasSponsor", - prefix + "UpdateGasSponsor", - prefix + "RemoveGasSponsor", - prefix + "ReportGasSponsorUsage", prefix + "NextGasTankBalanceAdjustmentNonce", prefix + "AdjustGasTankBalance", prefix + "GetGasTankBalanceAdjustment", prefix + "ListGasTankBalanceAdjustments", + prefix + "ListGasSponsors", + prefix + "GetGasSponsor", + prefix + "AddGasSponsor", + prefix + "UpdateGasSponsor", + prefix + "RemoveGasSponsor", + prefix + "AddressGasSponsors", + prefix + "GetProjectBalance", + prefix + "AdjustProjectBalance", } return &relayerClient{ client: client, @@ -696,7 +928,7 @@ func (c *relayerClient) 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) } } @@ -712,7 +944,7 @@ func (c *relayerClient) 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) } } @@ -728,7 +960,7 @@ func (c *relayerClient) RuntimeStatus(ctx context.Context) (*RuntimeStatus, erro 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) } } @@ -744,7 +976,7 @@ func (c *relayerClient) GetSequenceContext(ctx context.Context) (*SequenceContex 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) } } @@ -760,18 +992,19 @@ func (c *relayerClient) GetChainID(ctx context.Context) (uint64, 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) } } return out.Ret0, err } -func (c *relayerClient) SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string) (bool, string, error) { +func (c *relayerClient) SendMetaTxn(ctx context.Context, call *MetaTxn, quote *string, projectID *uint64) (bool, string, error) { in := struct { Arg0 *MetaTxn `json:"call"` Arg1 *string `json:"quote"` - }{call, quote} + Arg2 *uint64 `json:"projectID"` + }{call, quote, projectID} out := struct { Ret0 bool `json:"status"` Ret1 string `json:"txnHash"` @@ -781,7 +1014,7 @@ func (c *relayerClient) SendMetaTxn(ctx context.Context, call *MetaTxn, quote *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) } } @@ -801,7 +1034,7 @@ func (c *relayerClient) GetMetaTxnNonce(ctx context.Context, walletContractAddre 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) } } @@ -820,7 +1053,7 @@ func (c *relayerClient) GetMetaTxnReceipt(ctx context.Context, metaTxID 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) } } @@ -840,7 +1073,7 @@ func (c *relayerClient) Simulate(ctx context.Context, wallet string, transaction 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) } } @@ -861,7 +1094,7 @@ func (c *relayerClient) UpdateMetaTxnGasLimits(ctx context.Context, walletAddres 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) } } @@ -878,7 +1111,7 @@ func (c *relayerClient) FeeTokens(ctx context.Context) (bool, []*FeeToken, 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) } } @@ -902,7 +1135,7 @@ func (c *relayerClient) FeeOptions(ctx context.Context, wallet string, to 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) } } @@ -922,19 +1155,18 @@ func (c *relayerClient) GetMetaTxnNetworkFeeOptions(ctx context.Context, walletC 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) } } return out.Ret0, err } -func (c *relayerClient) GetMetaTransactions(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*MetaTxnLog, error) { +func (c *relayerClient) GetMetaTransactions(ctx context.Context, projectId uint64, page *Page) (*Page, []*MetaTxnLog, error) { in := struct { Arg0 uint64 `json:"projectId"` - Arg1 uint64 `json:"gasTankId"` - Arg2 *Page `json:"page"` - }{projectId, gasTankId, page} + Arg1 *Page `json:"page"` + }{projectId, page} out := struct { Ret0 *Page `json:"page"` Ret1 []*MetaTxnLog `json:"transactions"` @@ -944,13 +1176,34 @@ func (c *relayerClient) GetMetaTransactions(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) } } return out.Ret0, out.Ret1, err } +func (c *relayerClient) GetTransactionCost(ctx context.Context, projectId uint64, from time.Time, to time.Time) (float64, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 time.Time `json:"from"` + Arg2 time.Time `json:"to"` + }{projectId, from, to} + out := struct { + Ret0 float64 `json:"cost"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[14], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) + } + } + + return out.Ret0, err +} + func (c *relayerClient) SentTransactions(ctx context.Context, filter *SentTransactionsFilter, page *Page) (*Page, []*Transaction, error) { in := struct { Arg0 *SentTransactionsFilter `json:"filter"` @@ -961,11 +1214,11 @@ func (c *relayerClient) SentTransactions(ctx context.Context, filter *SentTransa Ret1 []*Transaction `json:"transactions"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[14], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[15], in, &out) 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) } } @@ -981,11 +1234,11 @@ func (c *relayerClient) PendingTransactions(ctx context.Context, page *Page) (*P Ret1 []*Transaction `json:"transactions"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[15], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[16], in, &out) 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) } } @@ -1000,11 +1253,11 @@ func (c *relayerClient) GetGasTank(ctx context.Context, id uint64) (*GasTank, er Ret0 *GasTank `json:"gasTank"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[16], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[17], in, &out) 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) } } @@ -1022,11 +1275,11 @@ func (c *relayerClient) AddGasTank(ctx context.Context, name string, feeMarkupFa Ret1 *GasTank `json:"gasTank"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[17], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[18], in, &out) 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) } } @@ -1045,246 +1298,265 @@ func (c *relayerClient) UpdateGasTank(ctx context.Context, id uint64, name *stri Ret1 *GasTank `json:"gasTank"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[18], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[19], in, &out) 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) } } return out.Ret0, out.Ret1, err } -func (c *relayerClient) GetGasSponsor(ctx context.Context, id uint64) (*GasSponsor, error) { +func (c *relayerClient) NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error) { in := struct { Arg0 uint64 `json:"id"` }{id} out := struct { - Ret0 *GasSponsor `json:"gasSponsor"` + Ret0 uint64 `json:"nonce"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[19], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[20], in, &out) 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) } } return out.Ret0, err } -func (c *relayerClient) AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) { +func (c *relayerClient) AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error) { in := struct { - Arg0 string `json:"address"` - Arg1 *Page `json:"page"` - }{address, page} + Arg0 uint64 `json:"id"` + Arg1 uint64 `json:"nonce"` + Arg2 float64 `json:"amount"` + }{id, nonce, amount} out := struct { - Ret0 *Page `json:"page"` - Ret1 []*GasSponsor `json:"gasSponsors"` + Ret0 bool `json:"status"` + Ret1 *GasTankBalanceAdjustment `json:"adjustment"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[20], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[21], in, &out) 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) } } return out.Ret0, out.Ret1, err } -func (c *relayerClient) ListGasSponsors(ctx context.Context, projectId uint64, gasTankId uint64, page *Page) (*Page, []*GasSponsor, error) { +func (c *relayerClient) GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 uint64 `json:"gasTankId"` - Arg2 *Page `json:"page"` - }{projectId, gasTankId, page} + Arg0 uint64 `json:"id"` + Arg1 uint64 `json:"nonce"` + }{id, nonce} out := struct { - Ret0 *Page `json:"page"` - Ret1 []*GasSponsor `json:"gasSponsors"` + Ret0 *GasTankBalanceAdjustment `json:"adjustment"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[21], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[22], in, &out) 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) } } - return out.Ret0, out.Ret1, err + return out.Ret0, err } -func (c *relayerClient) AddGasSponsor(ctx context.Context, projectId uint64, gasTankId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) { +func (c *relayerClient) ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 uint64 `json:"gasTankId"` - Arg2 string `json:"address"` - Arg3 *string `json:"name"` - Arg4 *bool `json:"active"` - }{projectId, gasTankId, address, name, active} + Arg0 uint64 `json:"id"` + Arg1 *Page `json:"page"` + }{id, page} out := struct { - Ret0 bool `json:"status"` - Ret1 *GasSponsor `json:"gasSponsor"` + Ret0 *Page `json:"page"` + Ret1 []*GasTankBalanceAdjustment `json:"adjustments"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[22], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[23], in, &out) 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) } } return out.Ret0, out.Ret1, err } -func (c *relayerClient) UpdateGasSponsor(ctx context.Context, id uint64, name *string, active *bool) (bool, *GasSponsor, error) { +func (c *relayerClient) ListGasSponsors(ctx context.Context, projectId uint64, page *Page) (*Page, []*GasSponsor, error) { in := struct { - Arg0 uint64 `json:"id"` - Arg1 *string `json:"name"` - Arg2 *bool `json:"active"` - }{id, name, active} + Arg0 uint64 `json:"projectId"` + Arg1 *Page `json:"page"` + }{projectId, page} out := struct { - Ret0 bool `json:"status"` - Ret1 *GasSponsor `json:"gasSponsor"` + Ret0 *Page `json:"page"` + Ret1 []*GasSponsor `json:"gasSponsors"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[23], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[24], in, &out) 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) } } return out.Ret0, out.Ret1, err } -func (c *relayerClient) RemoveGasSponsor(ctx context.Context, id uint64) (bool, error) { +func (c *relayerClient) GetGasSponsor(ctx context.Context, projectId uint64, id uint64) (*GasSponsor, error) { in := struct { - Arg0 uint64 `json:"id"` - }{id} + Arg0 uint64 `json:"projectId"` + Arg1 uint64 `json:"id"` + }{projectId, id} out := struct { - Ret0 bool `json:"status"` + Ret0 *GasSponsor `json:"gasSponsor"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[24], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[25], in, &out) 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) } } return out.Ret0, err } -func (c *relayerClient) ReportGasSponsorUsage(ctx context.Context, projectId uint64, gasTankId uint64, startTime *time.Time, endTime *time.Time) ([]*GasSponsorUsage, error) { +func (c *relayerClient) AddGasSponsor(ctx context.Context, projectId uint64, address string, name *string, active *bool) (bool, *GasSponsor, error) { in := struct { - Arg0 uint64 `json:"projectId"` - Arg1 uint64 `json:"gasTankId"` - Arg2 *time.Time `json:"startTime"` - Arg3 *time.Time `json:"endTime"` - }{projectId, gasTankId, startTime, endTime} + Arg0 uint64 `json:"projectId"` + Arg1 string `json:"address"` + Arg2 *string `json:"name"` + Arg3 *bool `json:"active"` + }{projectId, address, name, active} out := struct { - Ret0 []*GasSponsorUsage `json:"gasSponsorUsage"` + Ret0 bool `json:"status"` + Ret1 *GasSponsor `json:"gasSponsor"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[25], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[26], in, &out) 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) } } - return out.Ret0, err + return out.Ret0, out.Ret1, err } -func (c *relayerClient) NextGasTankBalanceAdjustmentNonce(ctx context.Context, id uint64) (uint64, error) { +func (c *relayerClient) UpdateGasSponsor(ctx context.Context, projectId uint64, id uint64, name *string, active *bool) (bool, *GasSponsor, error) { in := struct { - Arg0 uint64 `json:"id"` - }{id} + Arg0 uint64 `json:"projectId"` + Arg1 uint64 `json:"id"` + Arg2 *string `json:"name"` + Arg3 *bool `json:"active"` + }{projectId, id, name, active} out := struct { - Ret0 uint64 `json:"nonce"` + Ret0 bool `json:"status"` + Ret1 *GasSponsor `json:"gasSponsor"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[26], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[27], in, &out) 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) + } + } + + return out.Ret0, out.Ret1, err +} + +func (c *relayerClient) RemoveGasSponsor(ctx context.Context, projectId uint64, id uint64) (bool, error) { + in := struct { + Arg0 uint64 `json:"projectId"` + Arg1 uint64 `json:"id"` + }{projectId, id} + out := struct { + Ret0 bool `json:"status"` + }{} + + resp, err := doHTTPRequest(ctx, c.client, c.urls[28], in, &out) + if resp != nil { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = ErrWebrpcRequestFailed.WithCausef("failed to close response body: %w", cerr) } } return out.Ret0, err } -func (c *relayerClient) AdjustGasTankBalance(ctx context.Context, id uint64, nonce uint64, amount float64) (bool, *GasTankBalanceAdjustment, error) { +func (c *relayerClient) AddressGasSponsors(ctx context.Context, address string, page *Page) (*Page, []*GasSponsor, error) { in := struct { - Arg0 uint64 `json:"id"` - Arg1 uint64 `json:"nonce"` - Arg2 float64 `json:"amount"` - }{id, nonce, amount} + Arg0 string `json:"address"` + Arg1 *Page `json:"page"` + }{address, page} out := struct { - Ret0 bool `json:"status"` - Ret1 *GasTankBalanceAdjustment `json:"adjustment"` + Ret0 *Page `json:"page"` + Ret1 []*GasSponsor `json:"gasSponsors"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[27], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[29], in, &out) 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) } } return out.Ret0, out.Ret1, err } -func (c *relayerClient) GetGasTankBalanceAdjustment(ctx context.Context, id uint64, nonce uint64) (*GasTankBalanceAdjustment, error) { +func (c *relayerClient) GetProjectBalance(ctx context.Context, projectId uint64) (float64, error) { in := struct { - Arg0 uint64 `json:"id"` - Arg1 uint64 `json:"nonce"` - }{id, nonce} + Arg0 uint64 `json:"projectId"` + }{projectId} out := struct { - Ret0 *GasTankBalanceAdjustment `json:"adjustment"` + Ret0 float64 `json:"balance"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[28], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[30], in, &out) 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) } } return out.Ret0, err } -func (c *relayerClient) ListGasTankBalanceAdjustments(ctx context.Context, id uint64, page *Page) (*Page, []*GasTankBalanceAdjustment, error) { +func (c *relayerClient) AdjustProjectBalance(ctx context.Context, projectId uint64, amount float64, identifier string) (float64, error) { in := struct { - Arg0 uint64 `json:"id"` - Arg1 *Page `json:"page"` - }{id, page} + Arg0 uint64 `json:"projectId"` + Arg1 float64 `json:"amount"` + Arg2 string `json:"identifier"` + }{projectId, amount, identifier} out := struct { - Ret0 *Page `json:"page"` - Ret1 []*GasTankBalanceAdjustment `json:"adjustments"` + Ret0 float64 `json:"balance"` }{} - resp, err := doHTTPRequest(ctx, c.client, c.urls[29], in, &out) + resp, err := doHTTPRequest(ctx, c.client, c.urls[31], in, &out) 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) } } - return out.Ret0, out.Ret1, err + return out.Ret0, err } // HTTPClient is the interface used by generated clients to send HTTP requests. @@ -1317,6 +1589,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] { @@ -1331,15 +1604,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) @@ -1350,12 +1623,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) @@ -1366,12 +1639,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) } } @@ -1408,6 +1681,12 @@ func HTTPRequestHeaders(ctx context.Context) (http.Header, bool) { // Helpers // +type method struct { + Name string + Service string + Annotations map[string]string +} + type contextKey struct { name string } @@ -1440,6 +1719,20 @@ func RequestFromContext(ctx context.Context) *http.Request { return r } +func MethodCtx(ctx context.Context) (method, bool) { + req := RequestFromContext(ctx) + if req == nil { + return method{}, false + } + + m, ok := methods[req.URL.Path] + if !ok { + return method{}, false + } + + return m, true +} + // // Errors // @@ -1513,14 +1806,29 @@ 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} - ErrMethodNotFound = WebRPCError{Code: 1003, Name: "MethodNotFound", Message: "Method not found", HTTPStatus: 404} - 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: 2001, 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} - ErrInsufficientFee = WebRPCError{Code: 3004, Name: "InsufficientFee", Message: "Insufficient fee", HTTPStatus: 402} + 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: 2001, 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} + ErrInsufficientFee = WebRPCError{Code: 3004, Name: "InsufficientFee", Message: "Insufficient fee", HTTPStatus: 402} ) diff --git a/relayer/rpc_relayer.go b/relayer/rpc_relayer.go index 1e881154..2203a257 100644 --- a/relayer/rpc_relayer.go +++ b/relayer/rpc_relayer.go @@ -185,7 +185,7 @@ func (r *RpcRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransa // TODO: check contents of Contract and input, if empty, lets not even bother asking the server.. - ok, metaTxnID, err := r.Service.SendMetaTxn(ctx, call, txQuote) + ok, metaTxnID, err := r.Service.SendMetaTxn(ctx, call, txQuote, nil) if err != nil { return sequence.MetaTxnID(metaTxnID), nil, nil, err }