From d6435a4cce3aac5b081c7e0ebfe64c563de958f3 Mon Sep 17 00:00:00 2001 From: Bryan Potter Date: Fri, 18 Oct 2024 11:24:48 -0400 Subject: [PATCH] codegen from templates --- server/api_account.go | 10 ++++ server/api_block.go | 15 +++++- server/api_construction.go | 105 ++++++++++++++++++++++++++++++++++--- server/api_mempool.go | 15 +++++- server/api_network.go | 20 +++++++ server/api_search.go | 5 +- 6 files changed, 160 insertions(+), 10 deletions(-) diff --git a/server/api_account.go b/server/api_account.go index a98d4565..6d3d9783 100644 --- a/server/api_account.go +++ b/server/api_account.go @@ -105,6 +105,16 @@ func (c *AccountAPIController) AccountBalance(w http.ResponseWriter, r *http.Req EncodeJSONResponse(result, http.StatusOK, w) } +func (c *AccountAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // AccountCoins - Get an Account's Unspent Coins func (c *AccountAPIController) AccountCoins(w http.ResponseWriter, r *http.Request) { accountCoinsRequest := &types.AccountCoinsRequest{} diff --git a/server/api_block.go b/server/api_block.go index 07f5a7be..9321db45 100644 --- a/server/api_block.go +++ b/server/api_block.go @@ -105,6 +105,16 @@ func (c *BlockAPIController) Block(w http.ResponseWriter, r *http.Request) { EncodeJSONResponse(result, http.StatusOK, w) } +func (c *BlockAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // BlockTransaction - Get a Block Transaction func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Request) { blockTransactionRequest := &types.BlockTransactionRequest{} @@ -125,7 +135,10 @@ func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Req return } - result, serviceErr := c.service.BlockTransaction(c.ContextFromRequest(r), blockTransactionRequest) + result, serviceErr := c.service.BlockTransaction( + c.ContextFromRequest(r), + blockTransactionRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) diff --git a/server/api_construction.go b/server/api_construction.go index 47cb1c05..a071bdc8 100644 --- a/server/api_construction.go +++ b/server/api_construction.go @@ -131,7 +131,10 @@ func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r return } - result, serviceErr := c.service.ConstructionCombine(c.ContextFromRequest(r), constructionCombineRequest) + result, serviceErr := c.service.ConstructionCombine( + c.ContextFromRequest(r), + constructionCombineRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -141,6 +144,16 @@ func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionDerive - Derive an AccountIdentifier from a PublicKey func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r *http.Request) { constructionDeriveRequest := &types.ConstructionDeriveRequest{} @@ -161,7 +174,10 @@ func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r return } - result, serviceErr := c.service.ConstructionDerive(c.ContextFromRequest(r), constructionDeriveRequest) + result, serviceErr := c.service.ConstructionDerive( + c.ContextFromRequest(r), + constructionDeriveRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -171,6 +187,16 @@ func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionHash - Get the Hash of a Signed Transaction func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *http.Request) { constructionHashRequest := &types.ConstructionHashRequest{} @@ -191,7 +217,10 @@ func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *h return } - result, serviceErr := c.service.ConstructionHash(c.ContextFromRequest(r), constructionHashRequest) + result, serviceErr := c.service.ConstructionHash( + c.ContextFromRequest(r), + constructionHashRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -201,6 +230,16 @@ func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *h EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionMetadata - Get Metadata for Transaction Construction func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, r *http.Request) { constructionMetadataRequest := &types.ConstructionMetadataRequest{} @@ -221,7 +260,10 @@ func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, return } - result, serviceErr := c.service.ConstructionMetadata(c.ContextFromRequest(r), constructionMetadataRequest) + result, serviceErr := c.service.ConstructionMetadata( + c.ContextFromRequest(r), + constructionMetadataRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -231,6 +273,16 @@ func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionParse - Parse a Transaction func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *http.Request) { constructionParseRequest := &types.ConstructionParseRequest{} @@ -251,7 +303,10 @@ func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r * return } - result, serviceErr := c.service.ConstructionParse(c.ContextFromRequest(r), constructionParseRequest) + result, serviceErr := c.service.ConstructionParse( + c.ContextFromRequest(r), + constructionParseRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -261,6 +316,16 @@ func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r * EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionPayloads - Generate an Unsigned Transaction and Signing Payloads func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, r *http.Request) { constructionPayloadsRequest := &types.ConstructionPayloadsRequest{} @@ -281,7 +346,10 @@ func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, return } - result, serviceErr := c.service.ConstructionPayloads(c.ContextFromRequest(r), constructionPayloadsRequest) + result, serviceErr := c.service.ConstructionPayloads( + c.ContextFromRequest(r), + constructionPayloadsRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) @@ -291,6 +359,16 @@ func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionPreprocess - Create a Request to Fetch Metadata func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter, r *http.Request) { constructionPreprocessRequest := &types.ConstructionPreprocessRequest{} @@ -324,6 +402,16 @@ func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter EncodeJSONResponse(result, http.StatusOK, w) } +func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // ConstructionSubmit - Submit a Signed Transaction func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r *http.Request) { constructionSubmitRequest := &types.ConstructionSubmitRequest{} @@ -344,7 +432,10 @@ func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r return } - result, serviceErr := c.service.ConstructionSubmit(c.ContextFromRequest(r), constructionSubmitRequest) + result, serviceErr := c.service.ConstructionSubmit( + c.ContextFromRequest(r), + constructionSubmitRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) diff --git a/server/api_mempool.go b/server/api_mempool.go index db66ead0..beb40167 100644 --- a/server/api_mempool.go +++ b/server/api_mempool.go @@ -105,6 +105,16 @@ func (c *MempoolAPIController) Mempool(w http.ResponseWriter, r *http.Request) { EncodeJSONResponse(result, http.StatusOK, w) } +func (c *MempoolAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // MempoolTransaction - Get a Mempool Transaction func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http.Request) { mempoolTransactionRequest := &types.MempoolTransactionRequest{} @@ -125,7 +135,10 @@ func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http return } - result, serviceErr := c.service.MempoolTransaction(c.ContextFromRequest(r), mempoolTransactionRequest) + result, serviceErr := c.service.MempoolTransaction( + c.ContextFromRequest(r), + mempoolTransactionRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) diff --git a/server/api_network.go b/server/api_network.go index 323c8aa9..91c39e11 100644 --- a/server/api_network.go +++ b/server/api_network.go @@ -111,6 +111,16 @@ func (c *NetworkAPIController) NetworkList(w http.ResponseWriter, r *http.Reques EncodeJSONResponse(result, http.StatusOK, w) } +func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // NetworkOptions - Get Network Options func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Request) { networkRequest := &types.NetworkRequest{} @@ -141,6 +151,16 @@ func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Req EncodeJSONResponse(result, http.StatusOK, w) } +func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context { + ctx := r.Context() + + if c.contextFromRequest != nil { + ctx = c.contextFromRequest(r) + } + + return ctx +} + // NetworkStatus - Get Network Status func (c *NetworkAPIController) NetworkStatus(w http.ResponseWriter, r *http.Request) { networkRequest := &types.NetworkRequest{} diff --git a/server/api_search.go b/server/api_search.go index 5f91abde..70ea7e54 100644 --- a/server/api_search.go +++ b/server/api_search.go @@ -89,7 +89,10 @@ func (c *SearchAPIController) SearchTransactions(w http.ResponseWriter, r *http. return } - result, serviceErr := c.service.SearchTransactions(c.contextFromRequest(r), searchTransactionsRequest) + result, serviceErr := c.service.SearchTransactions( + c.ContextFromRequest(r), + searchTransactionsRequest, + ) if serviceErr != nil { EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w)