-
Notifications
You must be signed in to change notification settings - Fork 519
/exp/lighthorizon: new endpoints for tx and ops paged listing by account id #4453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3982ea7
#4333: wip on tx/ops by account id
sreuland dcc8953
#4033: new endpoints for tx and ops by account id
sreuland ae5f81d
#4433: more verbose error message for missing ledger
sreuland 8f370af
#4433: updated the api docs
sreuland 09ebf0a
#4433: removed static check warnings
sreuland fc233f8
#4433: added interfaces for transactxion and account data access
sreuland 6aff024
#4433: refactor domain model for operations/transactions interface
sreuland ec950a8
Merge remote-tracking branch 'upstream/lighthorizon' into lite_search…
sreuland 427611d
Merge remote-tracking branch 'upstream/lighthorizon' into lite_search…
sreuland ad2b90a
#4433: fixes to incorporate after latest merge of metrics
sreuland be847d1
#4433: fixed race condition during index flush
sreuland f5051d8
Merge remote-tracking branch 'upstream/lighthorizon' into lite_search…
sreuland 5c9e551
#4433: removed unnecessary /operations /transactions endpoints
sreuland 6de7faa
#4433: refactored service tx index traversal to be less duplicate code
sreuland 99ab856
Merge remote-tracking branch 'upstream/lighthorizon' into lite_search…
sreuland 91fcd88
#4433: pr feedback, refactor index search interface to be on ledger s…
sreuland 5ffcb32
#4433: pr feedback, make zero-based operations index the standard on …
sreuland a6b87ec
#4433: pr feedback, parameterize the index name
sreuland fa45ee2
#4433: pr feedback, cleanup up method docs
sreuland 53fde55
#4433: pr feedback, perf optimize on index checkpoint reads
sreuland 483434b
#4433: fixed static check error
sreuland ff5b145
#4433: fixed go fmt warning
sreuland 223626e
Merge remote-tracking branch 'upstream/lighthorizon' into lite_search…
sreuland 62370cf
#4433: used CheckpointManager for some of checkpoint math
sreuland 90cd1f1
#4433: fixed index next checkpoint counter values
sreuland 882408f
#4433: remove debugging code
sreuland 4647710
#4433: fixed unit test failure
sreuland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package actions | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/stellar/go/support/log" | ||
|
||
"github.com/stellar/go/exp/lighthorizon/adapters" | ||
"github.com/stellar/go/exp/lighthorizon/services" | ||
hProtocol "github.com/stellar/go/protocols/horizon" | ||
"github.com/stellar/go/protocols/horizon/operations" | ||
"github.com/stellar/go/support/render/hal" | ||
"github.com/stellar/go/toid" | ||
) | ||
|
||
const ( | ||
urlAccountId = "account_id" | ||
) | ||
|
||
func accountRequestParams(w http.ResponseWriter, r *http.Request) (string, pagination) { | ||
var accountId string | ||
var accountErr bool | ||
|
||
if accountId, accountErr = getURLParam(r, urlAccountId); !accountErr { | ||
sendErrorResponse(w, http.StatusBadRequest, "") | ||
return "", pagination{} | ||
} | ||
|
||
paginate, err := paging(r) | ||
if err != nil { | ||
sendErrorResponse(w, http.StatusBadRequest, string(invalidPagingParameters)) | ||
return "", pagination{} | ||
} | ||
|
||
if paginate.Cursor < 1 { | ||
paginate.Cursor = toid.New(1, 1, 1).ToInt64() | ||
} | ||
|
||
if paginate.Limit == 0 { | ||
paginate.Limit = 10 | ||
sreuland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return accountId, paginate | ||
} | ||
|
||
func NewTXByAccountHandler(lightHorizon services.LightHorizon) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
var accountId string | ||
var paginate pagination | ||
|
||
if accountId, paginate = accountRequestParams(w, r); accountId == "" { | ||
return | ||
} | ||
|
||
page := hal.Page{ | ||
Cursor: strconv.FormatInt(paginate.Cursor, 10), | ||
Order: string(paginate.Order), | ||
Limit: uint64(paginate.Limit), | ||
} | ||
page.Init() | ||
page.FullURL = r.URL | ||
|
||
txns, err := lightHorizon.Transactions.GetTransactionsByAccount(ctx, paginate.Cursor, paginate.Limit, accountId) | ||
if err != nil { | ||
log.Error(err) | ||
sendErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
for _, txn := range txns { | ||
var response hProtocol.Transaction | ||
response, err = adapters.PopulateTransaction(r, &txn) | ||
if err != nil { | ||
log.Error(err) | ||
sendErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
page.Add(response) | ||
} | ||
|
||
page.PopulateLinks() | ||
sendPageResponse(w, page) | ||
} | ||
} | ||
|
||
func NewOpsByAccountHandler(lightHorizon services.LightHorizon) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
var accountId string | ||
var paginate pagination | ||
|
||
if accountId, paginate = accountRequestParams(w, r); accountId == "" { | ||
return | ||
} | ||
|
||
page := hal.Page{ | ||
Cursor: strconv.FormatInt(paginate.Cursor, 10), | ||
Order: string(paginate.Order), | ||
Limit: uint64(paginate.Limit), | ||
} | ||
page.Init() | ||
page.FullURL = r.URL | ||
|
||
ops, err := lightHorizon.Operations.GetOperationsByAccount(ctx, paginate.Cursor, paginate.Limit, accountId) | ||
if err != nil { | ||
log.Error(err) | ||
sendErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
for _, op := range ops { | ||
var response operations.Operation | ||
response, err = adapters.PopulateOperation(r, &op) | ||
if err != nil { | ||
log.Error(err) | ||
sendErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
page.Add(response) | ||
} | ||
|
||
page.PopulateLinks() | ||
sendPageResponse(w, page) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.