Skip to content

Commit 18d8eee

Browse files
committed
chore: add to v1 endpoints
1 parent 1cab802 commit 18d8eee

21 files changed

+143
-23
lines changed

internal/api/v1/controllers_accounts_add_metadata.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ func addAccountMetadata(w http.ResponseWriter, r *http.Request) {
3535
return
3636
}
3737

38-
_, _, err = l.SaveAccountMetadata(r.Context(), getCommandParameters(r, ledger.SaveAccountMetadata{
38+
_, idempotencyHit, err := l.SaveAccountMetadata(r.Context(), getCommandParameters(r, ledger.SaveAccountMetadata{
3939
Address: address,
4040
Metadata: m,
4141
}))
4242
if err != nil {
4343
common.HandleCommonWriteErrors(w, r, err)
4444
return
4545
}
46+
if idempotencyHit {
47+
w.Header().Set("Idempotency-Hit", "true")
48+
}
4649

4750
api.NoContent(w)
4851
}

internal/api/v1/controllers_accounts_delete_metadata.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ func deleteAccountMetadata(w http.ResponseWriter, r *http.Request) {
1919
return
2020
}
2121

22-
if _, _, err := common.LedgerFromContext(r.Context()).
22+
_, idempotencyHit, err := common.LedgerFromContext(r.Context()).
2323
DeleteAccountMetadata(
2424
r.Context(),
2525
getCommandParameters(r, ledger.DeleteAccountMetadata{
2626
Address: address,
2727
Key: chi.URLParam(r, "key"),
2828
}),
29-
); err != nil {
29+
)
30+
if err != nil {
3031
common.HandleCommonWriteErrors(w, r, err)
3132
return
3233
}
3334

35+
if idempotencyHit {
36+
w.Header().Set("Idempotency-Hit", "true")
37+
}
38+
3439
api.NoContent(w)
3540
}

internal/api/v1/controllers_transactions_add_metadata.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ func addTransactionMetadata(w http.ResponseWriter, r *http.Request) {
3030
return
3131
}
3232

33-
if _, _, err := l.SaveTransactionMetadata(r.Context(), getCommandParameters(r, ledgercontroller.SaveTransactionMetadata{
33+
_, idempotencyHit, err := l.SaveTransactionMetadata(r.Context(), getCommandParameters(r, ledgercontroller.SaveTransactionMetadata{
3434
TransactionID: txID,
3535
Metadata: m,
36-
})); err != nil {
36+
}))
37+
if err != nil {
3738
switch {
3839
case errors.Is(err, ledgercontroller.ErrNotFound):
3940
api.NotFound(w, err)
@@ -42,6 +43,9 @@ func addTransactionMetadata(w http.ResponseWriter, r *http.Request) {
4243
}
4344
return
4445
}
46+
if idempotencyHit {
47+
w.Header().Set("Idempotency-Hit", "true")
48+
}
4549

4650
api.NoContent(w)
4751
}

internal/api/v1/controllers_transactions_create.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func createTransaction(w http.ResponseWriter, r *http.Request) {
8484
Metadata: payload.Metadata,
8585
}
8686

87-
_, res, _, err := l.CreateTransaction(r.Context(), getCommandParameters(r, ledgercontroller.CreateTransaction{
87+
_, res, idempotencyHit, err := l.CreateTransaction(r.Context(), getCommandParameters(r, ledgercontroller.CreateTransaction{
8888
RunScript: ledgercontroller.TxToScriptData(txData, false),
8989
}))
9090
if err != nil {
@@ -105,6 +105,11 @@ func createTransaction(w http.ResponseWriter, r *http.Request) {
105105
}
106106
return
107107
}
108+
109+
if idempotencyHit {
110+
w.Header().Set("Idempotency-Hit", "true")
111+
}
112+
108113
api.Ok(w, []any{mapTransactionToV1(res.Transaction)})
109114
return
110115
}
@@ -115,7 +120,7 @@ func createTransaction(w http.ResponseWriter, r *http.Request) {
115120
return
116121
}
117122

118-
_, res, _, err := l.CreateTransaction(r.Context(), getCommandParameters(r, ledgercontroller.CreateTransaction{
123+
_, res, idempotencyHit, err := l.CreateTransaction(r.Context(), getCommandParameters(r, ledgercontroller.CreateTransaction{
119124
RunScript: ledgercontroller.RunScript{
120125
Script: *script,
121126
Timestamp: payload.Timestamp,
@@ -140,6 +145,9 @@ func createTransaction(w http.ResponseWriter, r *http.Request) {
140145
}
141146
return
142147
}
148+
if idempotencyHit {
149+
w.Header().Set("Idempotency-Hit", "true")
150+
}
143151

144152
api.Ok(w, []any{mapTransactionToV1(res.Transaction)})
145153
}

internal/api/v1/controllers_transactions_delete_metadata.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ func deleteTransactionMetadata(w http.ResponseWriter, r *http.Request) {
2424

2525
metadataKey := chi.URLParam(r, "key")
2626

27-
if _, _, err := l.DeleteTransactionMetadata(r.Context(), getCommandParameters(r, ledgercontroller.DeleteTransactionMetadata{
27+
_, idempotencyHit, err := l.DeleteTransactionMetadata(r.Context(), getCommandParameters(r, ledgercontroller.DeleteTransactionMetadata{
2828
TransactionID: transactionID,
2929
Key: metadataKey,
30-
})); err != nil {
30+
}))
31+
if err != nil {
3132
common.HandleCommonWriteErrors(w, r, err)
3233
return
3334
}
35+
if idempotencyHit {
36+
w.Header().Set("Idempotency-Hit", "true")
37+
}
3438

3539
api.NoContent(w)
3640
}

internal/api/v1/controllers_transactions_revert.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func revertTransaction(w http.ResponseWriter, r *http.Request) {
2222
return
2323
}
2424

25-
_, ret, _, err := l.RevertTransaction(
25+
_, ret, idempotencyHit, err := l.RevertTransaction(
2626
r.Context(),
2727
getCommandParameters(r, ledgercontroller.RevertTransaction{
2828
Force: api.QueryParamBool(r, "disableChecks"),
@@ -43,6 +43,9 @@ func revertTransaction(w http.ResponseWriter, r *http.Request) {
4343
}
4444
return
4545
}
46+
if idempotencyHit {
47+
w.Header().Set("Idempotency-Hit", "true")
48+
}
4649

4750
api.Created(w, mapTransactionToV1(ret.RevertTransaction))
4851
}

openapi.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ paths:
345345
responses:
346346
'204':
347347
description: No Content
348+
headers:
349+
Idempotency-Hit:
350+
description: Indicates that the request was processed using an idempotency key that was already used
351+
schema:
352+
type: string
353+
example: "true"
348354
content: {}
349355
default:
350356
description: Error
@@ -828,6 +834,12 @@ paths:
828834
responses:
829835
'200':
830836
description: OK
837+
headers:
838+
Idempotency-Hit:
839+
description: Indicates that the request was processed using an idempotency key that was already used
840+
schema:
841+
type: string
842+
example: "true"
831843
content:
832844
application/json:
833845
schema:
@@ -913,6 +925,12 @@ paths:
913925
responses:
914926
'204':
915927
description: No Content
928+
headers:
929+
Idempotency-Hit:
930+
description: Indicates that the request was processed using an idempotency key that was already used
931+
schema:
932+
type: string
933+
example: "true"
916934
content: {}
917935
default:
918936
description: Error
@@ -955,6 +973,12 @@ paths:
955973
responses:
956974
'201':
957975
description: OK
976+
headers:
977+
Idempotency-Hit:
978+
description: Indicates that the request was processed using an idempotency key that was already used
979+
schema:
980+
type: string
981+
example: "true"
958982
content:
959983
application/json:
960984
schema:

openapi/v1.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ paths:
350350
responses:
351351
'204':
352352
description: No Content
353+
headers:
354+
Idempotency-Hit:
355+
description: Indicates that the request was processed using an idempotency key that was already used
356+
schema:
357+
type: string
358+
example: "true"
353359
content: {}
354360
default:
355361
description: Error
@@ -845,6 +851,12 @@ paths:
845851
responses:
846852
'200':
847853
description: OK
854+
headers:
855+
Idempotency-Hit:
856+
description: Indicates that the request was processed using an idempotency key that was already used
857+
schema:
858+
type: string
859+
example: "true"
848860
content:
849861
application/json:
850862
schema:
@@ -930,6 +942,12 @@ paths:
930942
responses:
931943
'204':
932944
description: No Content
945+
headers:
946+
Idempotency-Hit:
947+
description: Indicates that the request was processed using an idempotency key that was already used
948+
schema:
949+
type: string
950+
example: "true"
933951
content: {}
934952
default:
935953
description: Error
@@ -972,6 +990,12 @@ paths:
972990
responses:
973991
'201':
974992
description: OK
993+
headers:
994+
Idempotency-Hit:
995+
description: Indicates that the request was processed using an idempotency key that was already used
996+
schema:
997+
type: string
998+
example: "true"
975999
content:
9761000
application/json:
9771001
schema:

pkg/client/.speakeasy/gen.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lockVersion: 2.0.0
22
id: a9ac79e1-e429-4ee3-96c4-ec973f19bec3
33
management:
4-
docChecksum: 443460c483ca1c26febf7c523516f71c
4+
docChecksum: 2db68e4b7fed19e48b68ddd438d97099
55
docVersion: v2
66
speakeasyVersion: 1.563.0
77
generationVersion: 2.629.1

pkg/client/.speakeasy/logs/naming.log

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ GetAccountResponse (HttpMeta: HTTPMetadata, AccountResponse: AccountResponse)
3232
AccountWithVolumesAndBalances (address: string, type: string, metadata: map ...)
3333
Volume (input: bigint, output: bigint, balance: bigint)
3434
AddMetadataToAccountRequest (ledger: string, address: string, RequestBody: map)
35-
AddMetadataToAccountResponse (HttpMeta: HTTPMetadata)
35+
AddMetadataToAccountResponse (HttpMeta: HTTPMetadata, Headers: map)
3636
GetMappingRequest (ledger: string)
3737
GetMappingResponse (HttpMeta: HTTPMetadata, MappingResponse: MappingResponse)
3838
MappingResponse (data: Mapping)
@@ -61,15 +61,15 @@ ListTransactionsResponse (HttpMeta: HTTPMetadata, TransactionsCursorResponse: Tr
6161
CreateTransactionRequest (ledger: string, preview: boolean, PostTransaction: PostTransaction)
6262
PostTransaction (timestamp: date-time, postings: array, script: class ...)
6363
PostTransactionScript (plain: string, vars: map)
64-
CreateTransactionResponse (HttpMeta: HTTPMetadata, TransactionsResponse: TransactionsResponse)
64+
CreateTransactionResponse (HttpMeta: HTTPMetadata, TransactionsResponse: TransactionsResponse, Headers: map)
6565
TransactionsResponse (data: array)
6666
GetTransactionRequest (ledger: string, txid: bigint)
6767
GetTransactionResponse (HttpMeta: HTTPMetadata, TransactionResponse: TransactionResponse)
6868
TransactionResponse (data: Transaction)
6969
AddMetadataOnTransactionRequest (ledger: string, txid: bigint, RequestBody: map)
70-
AddMetadataOnTransactionResponse (HttpMeta: HTTPMetadata)
70+
AddMetadataOnTransactionResponse (HttpMeta: HTTPMetadata, Headers: map)
7171
RevertTransactionRequest (ledger: string, txid: bigint, disableChecks: boolean)
72-
RevertTransactionResponse (HttpMeta: HTTPMetadata, TransactionResponse: TransactionResponse)
72+
RevertTransactionResponse (HttpMeta: HTTPMetadata, TransactionResponse: TransactionResponse, Headers: map)
7373
CreateTransactionsRequest (ledger: string, Transactions: Transactions)
7474
Transactions (transactions: array)
7575
TransactionData (postings: array, reference: string, metadata: map ...)

0 commit comments

Comments
 (0)