|
| 1 | +package paymaster |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/NethermindEth/juno/core/felt" |
| 7 | + "github.com/NethermindEth/starknet.go/typedData" |
| 8 | +) |
| 9 | + |
| 10 | +// ExecuteTransaction sends the signed typed data to the paymaster service for execution |
| 11 | +// |
| 12 | +// Parameters: |
| 13 | +// - ctx: The context.Context object for controlling the function call |
| 14 | +// - request: The signed typed data of the transaction to be executed by the paymaster service |
| 15 | +// |
| 16 | +// Returns: |
| 17 | +// - *ExecuteTransactionResponse: The hash of the transaction broadcasted by the paymaster and |
| 18 | +// the tracking ID corresponding to the user `execute` request |
| 19 | +// - error: An error if any error occurs |
| 20 | +func (p *Paymaster) ExecuteTransaction(ctx context.Context, request *ExecuteTransactionRequest) (*ExecuteTransactionResponse, error) { |
| 21 | + var response ExecuteTransactionResponse |
| 22 | + if err := p.c.CallContextWithSliceArgs(ctx, &response, "paymaster_executeTransaction", request); err != nil { |
| 23 | + return nil, err |
| 24 | + } |
| 25 | + |
| 26 | + return &response, nil |
| 27 | +} |
| 28 | + |
| 29 | +// ExecuteTransactionRequest is the request to execute a transaction via the paymaster (transaction + parameters). |
| 30 | +type ExecuteTransactionRequest struct { |
| 31 | + // Typed data build by calling paymaster_buildTransaction signed by the |
| 32 | + // user to be executed by the paymaster service |
| 33 | + Transaction ExecutableUserTransaction `json:"transaction"` |
| 34 | + // Execution parameters to be used when executing the transaction |
| 35 | + Parameters UserParameters `json:"parameters"` |
| 36 | +} |
| 37 | + |
| 38 | +// ExecutableUserTransaction is a user transaction ready for execution (deploy, invoke, or both). |
| 39 | +type ExecutableUserTransaction struct { |
| 40 | + // The type of the transaction to be executed by the paymaster |
| 41 | + Type UserTxnType `json:"type"` |
| 42 | + // The deployment data for the transaction, used for `deploy` and `deploy_and_invoke` transaction types. |
| 43 | + // Should be `nil` for `invoke` transaction types. |
| 44 | + Deployment *AccDeploymentData `json:"deployment,omitempty"` |
| 45 | + // Invoke data signed by the user to be executed by the paymaster service, used for`invoke` and |
| 46 | + // `deploy_and_invoke` transaction types. |
| 47 | + // Should be `nil` for `deploy` transaction types. |
| 48 | + Invoke *ExecutableUserInvoke `json:"invoke,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// ExecutableUserInvoke is a signed typed data of an invoke transaction ready to be executed by the paymaster service. |
| 52 | +type ExecutableUserInvoke struct { |
| 53 | + // The address of the user account |
| 54 | + UserAddress *felt.Felt `json:"user_address"` |
| 55 | + // Typed data returned by the endpoint paymaster_buildTransaction |
| 56 | + TypedData typedData.TypedData `json:"typed_data"` |
| 57 | + // Signature of the associated Typed Data |
| 58 | + Signature []*felt.Felt `json:"signature"` |
| 59 | +} |
| 60 | + |
| 61 | +// ExecuteTransactionResponse is the response from executing a transaction (tracking ID and transaction hash). |
| 62 | +type ExecuteTransactionResponse struct { |
| 63 | + // A unique identifier used to track an execution request of a user. Its purpose is to track |
| 64 | + // possibly different transactions sent by the paymaster and which are associated with a same |
| 65 | + // user request. Such cases can happen during congestion, where a fee or tip bump may be needed |
| 66 | + // in order for a transaction to enter a block |
| 67 | + TrackingId *felt.Felt `json:"tracking_id"` |
| 68 | + TransactionHash *felt.Felt `json:"transaction_hash"` |
| 69 | +} |
0 commit comments