Skip to content

Commit

Permalink
codegen from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
potterbm-cb committed Oct 18, 2024
1 parent 1f319d6 commit d6435a4
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 10 deletions.
10 changes: 10 additions & 0 deletions server/api_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 108 in server/api_account.go

View workflow job for this annotation

GitHub Actions / Build

AccountAPIController.ContextFromRequest redeclared in this block

Check failure on line 108 in server/api_account.go

View workflow job for this annotation

GitHub Actions / Lint

method AccountAPIController.ContextFromRequest already declared at server/api_account.go:68:32 (typecheck)

Check failure on line 108 in server/api_account.go

View workflow job for this annotation

GitHub Actions / Test

AccountAPIController.ContextFromRequest redeclared in this block
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{}
Expand Down
15 changes: 14 additions & 1 deletion server/api_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 108 in server/api_block.go

View workflow job for this annotation

GitHub Actions / Build

BlockAPIController.ContextFromRequest redeclared in this block

Check failure on line 108 in server/api_block.go

View workflow job for this annotation

GitHub Actions / Lint

method BlockAPIController.ContextFromRequest already declared at server/api_block.go:68:30 (typecheck)

Check failure on line 108 in server/api_block.go

View workflow job for this annotation

GitHub Actions / Test

BlockAPIController.ContextFromRequest redeclared in this block
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{}
Expand All @@ -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)

Expand Down
105 changes: 98 additions & 7 deletions server/api_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {

Check failure on line 147 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Build

ConstructionAPIController.ContextFromRequest redeclared in this block

Check failure on line 147 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Lint

method ConstructionAPIController.ContextFromRequest already declared at server/api_construction.go:104:37 (typecheck)

Check failure on line 147 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Test

ConstructionAPIController.ContextFromRequest redeclared in this block
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{}
Expand All @@ -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)

Expand All @@ -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 {

Check failure on line 190 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Build

ConstructionAPIController.ContextFromRequest redeclared in this block

Check failure on line 190 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Lint

method ConstructionAPIController.ContextFromRequest already declared at server/api_construction.go:104:37 (typecheck)

Check failure on line 190 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Test

ConstructionAPIController.ContextFromRequest redeclared in this block
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{}
Expand All @@ -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)

Expand All @@ -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 {

Check failure on line 233 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Build

ConstructionAPIController.ContextFromRequest redeclared in this block

Check failure on line 233 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Lint

method ConstructionAPIController.ContextFromRequest already declared at server/api_construction.go:104:37 (typecheck)

Check failure on line 233 in server/api_construction.go

View workflow job for this annotation

GitHub Actions / Test

ConstructionAPIController.ContextFromRequest redeclared in this block
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{}
Expand All @@ -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)

Expand All @@ -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{}
Expand All @@ -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)

Expand All @@ -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{}
Expand All @@ -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)

Expand All @@ -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{}
Expand Down Expand Up @@ -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{}
Expand All @@ -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)

Expand Down
15 changes: 14 additions & 1 deletion server/api_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 108 in server/api_mempool.go

View workflow job for this annotation

GitHub Actions / Lint

method MempoolAPIController.ContextFromRequest already declared at server/api_mempool.go:68:32 (typecheck)
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{}
Expand All @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions server/api_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 114 in server/api_network.go

View workflow job for this annotation

GitHub Actions / Lint

method NetworkAPIController.ContextFromRequest already declared at server/api_network.go:74:32 (typecheck)
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{}
Expand Down Expand Up @@ -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 {

Check failure on line 154 in server/api_network.go

View workflow job for this annotation

GitHub Actions / Lint

method NetworkAPIController.ContextFromRequest already declared at server/api_network.go:74:32 (typecheck)
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{}
Expand Down
5 changes: 4 additions & 1 deletion server/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d6435a4

Please sign in to comment.