Skip to content

Commit 1164214

Browse files
committed
feat: implement ExecuteTransaction functionality in paymaster
- Added ExecuteTransaction method to handle the execution of signed transactions via the paymaster service. - Introduced ExecuteTransactionRequest and ExecuteTransactionResponse types for structured transaction execution requests and responses.
1 parent b2673fb commit 1164214

File tree

4 files changed

+71
-47
lines changed

4 files changed

+71
-47
lines changed

paymaster/build_txn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ type UserTransaction struct {
5151
// The type of the transaction to be executed by the paymaster
5252
Type UserTxnType `json:"type"`
5353
// The deployment data for the transaction, used for `deploy` and `deploy_and_invoke` transaction types.
54-
// Should be omitted for `invoke` transaction types.
54+
// Should be `nil` for `invoke` transaction types.
5555
Deployment *AccDeploymentData `json:"deployment,omitempty"`
5656
// The invoke data for the transaction, used for `invoke` and `deploy_and_invoke` transaction types.
57-
// Should be omitted for `deploy` transaction types.
57+
// Should be `nil` for `deploy` transaction types.
5858
Invoke *UserInvoke `json:"invoke,omitempty"`
5959
}
6060

paymaster/execute_txn.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

paymaster/paymaster.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,6 @@ func (p *Paymaster) TrackingIdToLatestHash(ctx context.Context, trackingId *felt
122122
return response, nil
123123
}
124124

125-
// ExecuteTransaction executes a signed transaction via the paymaster service.
126-
// Returns an ExecuteTransactionResponse with tracking ID and transaction hash.
127-
//
128-
// Parameters:
129-
// - ctx: The context.Context object for controlling the function call
130-
// - request: The ExecuteTransactionRequest containing the transaction and parameters
131-
//
132-
// Returns:
133-
// - *ExecuteTransactionResponse: The response containing tracking ID and transaction hash
134-
// - error: An error if the execution fails
135-
func (p *Paymaster) ExecuteTransaction(ctx context.Context, request *ExecuteTransactionRequest) (*ExecuteTransactionResponse, error) {
136-
var response ExecuteTransactionResponse
137-
if err := p.c.CallContextWithSliceArgs(ctx, &response, "paymaster_executeTransaction", request); err != nil {
138-
return nil, err
139-
}
140-
141-
return &response, nil
142-
}
143-
144125
// Constants for the SNIP-X specification
145126
const (
146127
// OUTSIDE_EXECUTION_TYPED_DATA_V1 represents the typed data structure for version 1

paymaster/types_paymaster.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,29 +210,3 @@ type TrackingIdResponse struct {
210210
// The status of the transaction associated with the ID
211211
Status TxnStatus `json:"status"`
212212
}
213-
214-
// ExecutableUserInvoke is an invoke transaction ready for execution (user address, typed data, signature).
215-
type ExecutableUserInvoke struct {
216-
UserAddress *felt.Felt `json:"user_address"`
217-
TypedData interface{} `json:"typed_data"`
218-
Signature []*felt.Felt `json:"signature"`
219-
}
220-
221-
// ExecutableUserTransaction is a user transaction ready for execution (deploy, invoke, or both).
222-
type ExecutableUserTransaction struct {
223-
Type string `json:"type"` // "deploy", "invoke", "deploy_and_invoke"
224-
Deploy interface{} `json:"deployment,omitempty"`
225-
Invoke ExecutableUserInvoke `json:"invoke,omitempty"`
226-
}
227-
228-
// ExecuteTransactionRequest is the request to execute a transaction via the paymaster (transaction + parameters).
229-
type ExecuteTransactionRequest struct {
230-
Transaction ExecutableUserTransaction `json:"transaction"`
231-
Parameters UserParameters `json:"parameters"`
232-
}
233-
234-
// ExecuteTransactionResponse is the response from executing a transaction (tracking ID and transaction hash).
235-
type ExecuteTransactionResponse struct {
236-
TrackingId *felt.Felt `json:"tracking_id"`
237-
TransactionHash *felt.Felt `json:"transaction_hash"`
238-
}

0 commit comments

Comments
 (0)