Skip to content

Commit d6435a4

Browse files
committed
codegen from templates
1 parent 1f319d6 commit d6435a4

6 files changed

+160
-10
lines changed

server/api_account.go

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ func (c *AccountAPIController) AccountBalance(w http.ResponseWriter, r *http.Req
105105
EncodeJSONResponse(result, http.StatusOK, w)
106106
}
107107

108+
func (c *AccountAPIController) ContextFromRequest(r *http.Request) context.Context {
109+
ctx := r.Context()
110+
111+
if c.contextFromRequest != nil {
112+
ctx = c.contextFromRequest(r)
113+
}
114+
115+
return ctx
116+
}
117+
108118
// AccountCoins - Get an Account's Unspent Coins
109119
func (c *AccountAPIController) AccountCoins(w http.ResponseWriter, r *http.Request) {
110120
accountCoinsRequest := &types.AccountCoinsRequest{}

server/api_block.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ func (c *BlockAPIController) Block(w http.ResponseWriter, r *http.Request) {
105105
EncodeJSONResponse(result, http.StatusOK, w)
106106
}
107107

108+
func (c *BlockAPIController) ContextFromRequest(r *http.Request) context.Context {
109+
ctx := r.Context()
110+
111+
if c.contextFromRequest != nil {
112+
ctx = c.contextFromRequest(r)
113+
}
114+
115+
return ctx
116+
}
117+
108118
// BlockTransaction - Get a Block Transaction
109119
func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Request) {
110120
blockTransactionRequest := &types.BlockTransactionRequest{}
@@ -125,7 +135,10 @@ func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Req
125135
return
126136
}
127137

128-
result, serviceErr := c.service.BlockTransaction(c.ContextFromRequest(r), blockTransactionRequest)
138+
result, serviceErr := c.service.BlockTransaction(
139+
c.ContextFromRequest(r),
140+
blockTransactionRequest,
141+
)
129142
if serviceErr != nil {
130143
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
131144

server/api_construction.go

+98-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r
131131
return
132132
}
133133

134-
result, serviceErr := c.service.ConstructionCombine(c.ContextFromRequest(r), constructionCombineRequest)
134+
result, serviceErr := c.service.ConstructionCombine(
135+
c.ContextFromRequest(r),
136+
constructionCombineRequest,
137+
)
135138
if serviceErr != nil {
136139
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
137140

@@ -141,6 +144,16 @@ func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r
141144
EncodeJSONResponse(result, http.StatusOK, w)
142145
}
143146

147+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
148+
ctx := r.Context()
149+
150+
if c.contextFromRequest != nil {
151+
ctx = c.contextFromRequest(r)
152+
}
153+
154+
return ctx
155+
}
156+
144157
// ConstructionDerive - Derive an AccountIdentifier from a PublicKey
145158
func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r *http.Request) {
146159
constructionDeriveRequest := &types.ConstructionDeriveRequest{}
@@ -161,7 +174,10 @@ func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r
161174
return
162175
}
163176

164-
result, serviceErr := c.service.ConstructionDerive(c.ContextFromRequest(r), constructionDeriveRequest)
177+
result, serviceErr := c.service.ConstructionDerive(
178+
c.ContextFromRequest(r),
179+
constructionDeriveRequest,
180+
)
165181
if serviceErr != nil {
166182
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
167183

@@ -171,6 +187,16 @@ func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r
171187
EncodeJSONResponse(result, http.StatusOK, w)
172188
}
173189

190+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
191+
ctx := r.Context()
192+
193+
if c.contextFromRequest != nil {
194+
ctx = c.contextFromRequest(r)
195+
}
196+
197+
return ctx
198+
}
199+
174200
// ConstructionHash - Get the Hash of a Signed Transaction
175201
func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *http.Request) {
176202
constructionHashRequest := &types.ConstructionHashRequest{}
@@ -191,7 +217,10 @@ func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *h
191217
return
192218
}
193219

194-
result, serviceErr := c.service.ConstructionHash(c.ContextFromRequest(r), constructionHashRequest)
220+
result, serviceErr := c.service.ConstructionHash(
221+
c.ContextFromRequest(r),
222+
constructionHashRequest,
223+
)
195224
if serviceErr != nil {
196225
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
197226

@@ -201,6 +230,16 @@ func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *h
201230
EncodeJSONResponse(result, http.StatusOK, w)
202231
}
203232

233+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
234+
ctx := r.Context()
235+
236+
if c.contextFromRequest != nil {
237+
ctx = c.contextFromRequest(r)
238+
}
239+
240+
return ctx
241+
}
242+
204243
// ConstructionMetadata - Get Metadata for Transaction Construction
205244
func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, r *http.Request) {
206245
constructionMetadataRequest := &types.ConstructionMetadataRequest{}
@@ -221,7 +260,10 @@ func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter,
221260
return
222261
}
223262

224-
result, serviceErr := c.service.ConstructionMetadata(c.ContextFromRequest(r), constructionMetadataRequest)
263+
result, serviceErr := c.service.ConstructionMetadata(
264+
c.ContextFromRequest(r),
265+
constructionMetadataRequest,
266+
)
225267
if serviceErr != nil {
226268
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
227269

@@ -231,6 +273,16 @@ func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter,
231273
EncodeJSONResponse(result, http.StatusOK, w)
232274
}
233275

276+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
277+
ctx := r.Context()
278+
279+
if c.contextFromRequest != nil {
280+
ctx = c.contextFromRequest(r)
281+
}
282+
283+
return ctx
284+
}
285+
234286
// ConstructionParse - Parse a Transaction
235287
func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *http.Request) {
236288
constructionParseRequest := &types.ConstructionParseRequest{}
@@ -251,7 +303,10 @@ func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *
251303
return
252304
}
253305

254-
result, serviceErr := c.service.ConstructionParse(c.ContextFromRequest(r), constructionParseRequest)
306+
result, serviceErr := c.service.ConstructionParse(
307+
c.ContextFromRequest(r),
308+
constructionParseRequest,
309+
)
255310
if serviceErr != nil {
256311
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
257312

@@ -261,6 +316,16 @@ func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *
261316
EncodeJSONResponse(result, http.StatusOK, w)
262317
}
263318

319+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
320+
ctx := r.Context()
321+
322+
if c.contextFromRequest != nil {
323+
ctx = c.contextFromRequest(r)
324+
}
325+
326+
return ctx
327+
}
328+
264329
// ConstructionPayloads - Generate an Unsigned Transaction and Signing Payloads
265330
func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, r *http.Request) {
266331
constructionPayloadsRequest := &types.ConstructionPayloadsRequest{}
@@ -281,7 +346,10 @@ func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter,
281346
return
282347
}
283348

284-
result, serviceErr := c.service.ConstructionPayloads(c.ContextFromRequest(r), constructionPayloadsRequest)
349+
result, serviceErr := c.service.ConstructionPayloads(
350+
c.ContextFromRequest(r),
351+
constructionPayloadsRequest,
352+
)
285353
if serviceErr != nil {
286354
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
287355

@@ -291,6 +359,16 @@ func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter,
291359
EncodeJSONResponse(result, http.StatusOK, w)
292360
}
293361

362+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
363+
ctx := r.Context()
364+
365+
if c.contextFromRequest != nil {
366+
ctx = c.contextFromRequest(r)
367+
}
368+
369+
return ctx
370+
}
371+
294372
// ConstructionPreprocess - Create a Request to Fetch Metadata
295373
func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter, r *http.Request) {
296374
constructionPreprocessRequest := &types.ConstructionPreprocessRequest{}
@@ -324,6 +402,16 @@ func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter
324402
EncodeJSONResponse(result, http.StatusOK, w)
325403
}
326404

405+
func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
406+
ctx := r.Context()
407+
408+
if c.contextFromRequest != nil {
409+
ctx = c.contextFromRequest(r)
410+
}
411+
412+
return ctx
413+
}
414+
327415
// ConstructionSubmit - Submit a Signed Transaction
328416
func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r *http.Request) {
329417
constructionSubmitRequest := &types.ConstructionSubmitRequest{}
@@ -344,7 +432,10 @@ func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r
344432
return
345433
}
346434

347-
result, serviceErr := c.service.ConstructionSubmit(c.ContextFromRequest(r), constructionSubmitRequest)
435+
result, serviceErr := c.service.ConstructionSubmit(
436+
c.ContextFromRequest(r),
437+
constructionSubmitRequest,
438+
)
348439
if serviceErr != nil {
349440
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
350441

server/api_mempool.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ func (c *MempoolAPIController) Mempool(w http.ResponseWriter, r *http.Request) {
105105
EncodeJSONResponse(result, http.StatusOK, w)
106106
}
107107

108+
func (c *MempoolAPIController) ContextFromRequest(r *http.Request) context.Context {
109+
ctx := r.Context()
110+
111+
if c.contextFromRequest != nil {
112+
ctx = c.contextFromRequest(r)
113+
}
114+
115+
return ctx
116+
}
117+
108118
// MempoolTransaction - Get a Mempool Transaction
109119
func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http.Request) {
110120
mempoolTransactionRequest := &types.MempoolTransactionRequest{}
@@ -125,7 +135,10 @@ func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http
125135
return
126136
}
127137

128-
result, serviceErr := c.service.MempoolTransaction(c.ContextFromRequest(r), mempoolTransactionRequest)
138+
result, serviceErr := c.service.MempoolTransaction(
139+
c.ContextFromRequest(r),
140+
mempoolTransactionRequest,
141+
)
129142
if serviceErr != nil {
130143
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
131144

server/api_network.go

+20
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ func (c *NetworkAPIController) NetworkList(w http.ResponseWriter, r *http.Reques
111111
EncodeJSONResponse(result, http.StatusOK, w)
112112
}
113113

114+
func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context {
115+
ctx := r.Context()
116+
117+
if c.contextFromRequest != nil {
118+
ctx = c.contextFromRequest(r)
119+
}
120+
121+
return ctx
122+
}
123+
114124
// NetworkOptions - Get Network Options
115125
func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Request) {
116126
networkRequest := &types.NetworkRequest{}
@@ -141,6 +151,16 @@ func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Req
141151
EncodeJSONResponse(result, http.StatusOK, w)
142152
}
143153

154+
func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context {
155+
ctx := r.Context()
156+
157+
if c.contextFromRequest != nil {
158+
ctx = c.contextFromRequest(r)
159+
}
160+
161+
return ctx
162+
}
163+
144164
// NetworkStatus - Get Network Status
145165
func (c *NetworkAPIController) NetworkStatus(w http.ResponseWriter, r *http.Request) {
146166
networkRequest := &types.NetworkRequest{}

server/api_search.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func (c *SearchAPIController) SearchTransactions(w http.ResponseWriter, r *http.
8989
return
9090
}
9191

92-
result, serviceErr := c.service.SearchTransactions(c.contextFromRequest(r), searchTransactionsRequest)
92+
result, serviceErr := c.service.SearchTransactions(
93+
c.ContextFromRequest(r),
94+
searchTransactionsRequest,
95+
)
9396
if serviceErr != nil {
9497
EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)
9598

0 commit comments

Comments
 (0)