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