Skip to content

Commit bd4d4cc

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

11 files changed

+221
-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

+12-8
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ func (h *Handler) GaslessEstimate(ctx context.Context, req *oas.GaslessEstimateR
5454
if err != nil {
5555
return nil, toError(http.StatusBadRequest, err)
5656
}
57+
fmt.Printf("estimate protocol name: %v\n", signParams.ProtocolName)
5758
o := &oas.SignRawParams{
5859
RelayAddress: signParams.RelayAddress,
5960
Commission: signParams.Commission,
6061
From: walletAddress.ToRaw(),
6162
ValidUntil: time.Now().UTC().Add(4 * time.Minute).Unix(),
63+
ProtocolName: signParams.ProtocolName,
6264
}
6365
o.Messages = make([]oas.SignRawMessage, 0, len(signParams.Messages))
6466
for _, msg := range signParams.Messages {
@@ -77,23 +79,25 @@ func (h *Handler) GaslessEstimate(ctx context.Context, req *oas.GaslessEstimateR
7779
return o, nil
7880
}
7981

80-
func (h *Handler) GaslessSend(ctx context.Context, req *oas.GaslessSendReq) error {
82+
func (h *Handler) GaslessSend(ctx context.Context, req *oas.GaslessSendReq) (*oas.GaslessTx, error) {
8183
if h.gasless == nil {
82-
return toError(http.StatusNotImplemented, fmt.Errorf("not implemented"))
84+
return nil, toError(http.StatusNotImplemented, fmt.Errorf("not implemented"))
8385
}
8486
msg, err := decodeMessage(req.Boc)
8587
if err != nil {
86-
return toError(http.StatusBadRequest, err)
88+
return nil, toError(http.StatusBadRequest, err)
8789
}
8890
pubkey, err := hex.DecodeString(req.WalletPublicKey)
8991
if err != nil {
90-
return toError(http.StatusBadRequest, err)
92+
return nil, toError(http.StatusBadRequest, err)
9193
}
9294
if len(pubkey) != ed25519.PublicKeySize {
93-
return toError(http.StatusBadRequest, fmt.Errorf("invalid public key"))
95+
return nil, toError(http.StatusBadRequest, fmt.Errorf("invalid public key"))
9496
}
95-
if err := h.gasless.Send(ctx, pubkey, msg.payload); err != nil {
96-
return toError(http.StatusInternalServerError, err)
97+
results, err := h.gasless.Send(ctx, pubkey, msg.payload)
98+
if err != nil {
99+
return nil, toError(http.StatusInternalServerError, err)
97100
}
98-
return nil
101+
fmt.Printf("results.protocol_name: %v\n", results.ProtocolName)
102+
return &oas.GaslessTx{ProtocolName: results.ProtocolName}, nil
99103
}

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)