|
| 1 | +package entrypoint |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "github.com/ethereum/go-ethereum/accounts/abi" |
| 8 | + "github.com/ethereum/go-ethereum/common/hexutil" |
| 9 | + "github.com/stackup-wallet/stackup-bundler/pkg/userop" |
| 10 | +) |
| 11 | + |
| 12 | +var ( |
| 13 | + bytes32, _ = abi.NewType("bytes32", "", nil) |
| 14 | + uint256, _ = abi.NewType("uint256", "", nil) |
| 15 | + bytes, _ = abi.NewType("bytes", "", nil) |
| 16 | + validatePaymasterUserOpMethod = abi.NewMethod( |
| 17 | + "validatePaymasterUserOp", |
| 18 | + "validatePaymasterUserOp", |
| 19 | + abi.Function, |
| 20 | + "", |
| 21 | + false, |
| 22 | + false, |
| 23 | + abi.Arguments{ |
| 24 | + {Name: "userOp", Type: userop.UserOpType}, |
| 25 | + {Name: "userOpHash", Type: bytes32}, |
| 26 | + {Name: "maxCost", Type: uint256}, |
| 27 | + }, |
| 28 | + abi.Arguments{ |
| 29 | + {Name: "context", Type: bytes}, |
| 30 | + {Name: "deadline", Type: uint256}, |
| 31 | + }, |
| 32 | + ) |
| 33 | + validatePaymasterUserOpSelector = hexutil.Encode(validatePaymasterUserOpMethod.ID) |
| 34 | +) |
| 35 | + |
| 36 | +type validatePaymasterUserOpOutput struct { |
| 37 | + Context []byte |
| 38 | +} |
| 39 | + |
| 40 | +func decodeValidatePaymasterUserOpOutput(ret any) (*validatePaymasterUserOpOutput, error) { |
| 41 | + hex, ok := ret.(string) |
| 42 | + if !ok { |
| 43 | + return nil, errors.New("validatePaymasterUserOp: cannot assert type: hex is not of type string") |
| 44 | + } |
| 45 | + data, err := hexutil.Decode(hex) |
| 46 | + if err != nil { |
| 47 | + return nil, fmt.Errorf("validatePaymasterUserOp: %s", err) |
| 48 | + } |
| 49 | + |
| 50 | + args, err := validatePaymasterUserOpMethod.Outputs.Unpack(data) |
| 51 | + if err != nil { |
| 52 | + return nil, fmt.Errorf("validatePaymasterUserOp: %s", err) |
| 53 | + } |
| 54 | + if len(args) != 2 { |
| 55 | + return nil, fmt.Errorf( |
| 56 | + "validatePaymasterUserOp: invalid args length: expected 2, got %d", |
| 57 | + len(args), |
| 58 | + ) |
| 59 | + } |
| 60 | + |
| 61 | + ctx, ok := args[0].([]byte) |
| 62 | + if !ok { |
| 63 | + return nil, errors.New("validatePaymasterUserOp: cannot assert type: hex is not of type string") |
| 64 | + } |
| 65 | + |
| 66 | + return &validatePaymasterUserOpOutput{ |
| 67 | + Context: ctx, |
| 68 | + }, nil |
| 69 | +} |
0 commit comments