Skip to content

Commit f8856c6

Browse files
/gasless/estimate and /gasless/send to return protocol name
1 parent 92984a8 commit f8856c6

11 files changed

+219
-33
lines changed

api/openapi.json

+23-1
Original file line numberDiff line numberDiff line change
@@ -3467,6 +3467,17 @@
34673467
],
34683468
"type": "object"
34693469
},
3470+
"GaslessTx": {
3471+
"properties": {
3472+
"protocol_name": {
3473+
"type": "string"
3474+
}
3475+
},
3476+
"required": [
3477+
"protocol_name"
3478+
],
3479+
"type": "object"
3480+
},
34703481
"ImagePreview": {
34713482
"properties": {
34723483
"resolution": {
@@ -5299,6 +5310,9 @@
52995310
},
53005311
"type": "array"
53015312
},
5313+
"protocol_name": {
5314+
"type": "string"
5315+
},
53025316
"relay_address": {
53035317
"example": "0:da6b1b6663a0e4d18cc8574ccd9db5296e367dd9324706f3bbd9eb1cd2caf0bf",
53045318
"format": "address",
@@ -5315,7 +5329,8 @@
53155329
"relay_address",
53165330
"commission",
53175331
"from",
5318-
"valid_until"
5332+
"valid_until",
5333+
"protocol_name"
53195334
],
53205335
"type": "object"
53215336
},
@@ -8641,6 +8656,13 @@
86418656
},
86428657
"responses": {
86438658
"200": {
8659+
"content": {
8660+
"application/json": {
8661+
"schema": {
8662+
"$ref": "#/components/schemas/GaslessTx"
8663+
}
8664+
}
8665+
},
86448666
"description": "the message has been sent"
86458667
},
86468668
"default": {

api/openapi.yml

+14
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,10 @@ paths:
21262126
responses:
21272127
'200':
21282128
description: the message has been sent
2129+
content:
2130+
application/json:
2131+
schema:
2132+
$ref: '#/components/schemas/GaslessTx'
21292133
'default':
21302134
$ref: '#/components/responses/Error'
21312135
/v2/pubkeys/{public_key}/wallets:
@@ -4806,6 +4810,13 @@ components:
48064810
type: string
48074811
format: cell
48084812
description: "Raw once-cell BoC encoded in hex."
4813+
GaslessTx:
4814+
type: object
4815+
required:
4816+
- protocol_name
4817+
properties:
4818+
protocol_name:
4819+
type: string
48094820
SignRawParams:
48104821
type: object
48114822
required:
@@ -4814,7 +4825,10 @@ components:
48144825
- commission
48154826
- from
48164827
- valid_until
4828+
- protocol_name
48174829
properties:
4830+
protocol_name:
4831+
type: string
48184832
relay_address:
48194833
type: string
48204834
format: address

pkg/api/gasless_handlers.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (h *Handler) GaslessEstimate(ctx context.Context, req *oas.GaslessEstimateR
5959
Commission: signParams.Commission,
6060
From: walletAddress.ToRaw(),
6161
ValidUntil: time.Now().UTC().Add(4 * time.Minute).Unix(),
62+
ProtocolName: signParams.ProtocolName,
6263
}
6364
o.Messages = make([]oas.SignRawMessage, 0, len(signParams.Messages))
6465
for _, msg := range signParams.Messages {
@@ -77,23 +78,24 @@ func (h *Handler) GaslessEstimate(ctx context.Context, req *oas.GaslessEstimateR
7778
return o, nil
7879
}
7980

80-
func (h *Handler) GaslessSend(ctx context.Context, req *oas.GaslessSendReq) error {
81+
func (h *Handler) GaslessSend(ctx context.Context, req *oas.GaslessSendReq) (*oas.GaslessTx, error) {
8182
if h.gasless == nil {
82-
return toError(http.StatusNotImplemented, fmt.Errorf("not implemented"))
83+
return nil, toError(http.StatusNotImplemented, fmt.Errorf("not implemented"))
8384
}
8485
msg, err := decodeMessage(req.Boc)
8586
if err != nil {
86-
return toError(http.StatusBadRequest, err)
87+
return nil, toError(http.StatusBadRequest, err)
8788
}
8889
pubkey, err := hex.DecodeString(req.WalletPublicKey)
8990
if err != nil {
90-
return toError(http.StatusBadRequest, err)
91+
return nil, toError(http.StatusBadRequest, err)
9192
}
9293
if len(pubkey) != ed25519.PublicKeySize {
93-
return toError(http.StatusBadRequest, fmt.Errorf("invalid public key"))
94+
return nil, toError(http.StatusBadRequest, fmt.Errorf("invalid public key"))
9495
}
95-
if err := h.gasless.Send(ctx, pubkey, msg.payload); err != nil {
96-
return toError(http.StatusInternalServerError, err)
96+
results, err := h.gasless.Send(ctx, pubkey, msg.payload)
97+
if err != nil {
98+
return nil, toError(http.StatusInternalServerError, err)
9799
}
98-
return nil
100+
return &oas.GaslessTx{ProtocolName: results.ProtocolName}, nil
99101
}

pkg/api/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ type addressBook interface {
174174
type Gasless interface {
175175
Config(ctx context.Context) (gasless.Config, error)
176176
Estimate(ctx context.Context, masterID ton.AccountID, walletAddress ton.AccountID, walletPubkey []byte, messages []string) (gasless.SignRawParams, error)
177-
Send(ctx context.Context, walletPublicKey ed25519.PublicKey, payload []byte) error
177+
Send(ctx context.Context, walletPublicKey ed25519.PublicKey, payload []byte) (*gasless.TxSendingResults, error)
178178
}
179179

180180
type ratesSource interface {

pkg/gasless/models.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ type SignRawParams struct {
1616
RelayAddress string
1717
Commission string
1818
Messages []Message
19+
ProtocolName string
20+
}
21+
22+
type TxSendingResults struct {
23+
ProtocolName string
1924
}

pkg/oas/oas_handlers_gen.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_json_gen.go

+125-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)