-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support search by zero address. #771
Changes from all commits
2a2d9cb
2d47eb8
c563e99
f7c7f68
0c6c56a
5406b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |||
"fmt" | ||||
"net/http" | ||||
"strconv" | ||||
"strings" | ||||
|
||||
"github.com/algorand/go-algorand/data/basics" | ||||
"github.com/labstack/echo/v4" | ||||
|
@@ -52,6 +53,46 @@ const defaultAssetsLimit = 100 | |||
const maxBalancesLimit = 10000 | ||||
const defaultBalancesLimit = 1000 | ||||
|
||||
////////////////////// | ||||
// Helper functions // | ||||
////////////////////// | ||||
|
||||
func validateTransactionFilter(filter *idb.TransactionFilter) error { | ||||
var errorArr = make([]string, 0) | ||||
|
||||
// Round + min/max round | ||||
if filter.Round != nil && (filter.MaxRound != 0 || filter.MinRound != 0) { | ||||
errorArr = append(errorArr, errInvalidRoundAndMinMax) | ||||
} | ||||
|
||||
// If min/max are mixed up | ||||
if filter.Round == nil && filter.MinRound != 0 && filter.MaxRound != 0 && filter.MinRound > filter.MaxRound { | ||||
errorArr = append(errorArr, errInvalidRoundMinMax) | ||||
} | ||||
|
||||
{ | ||||
var address basics.Address | ||||
copy(address[:], filter.Address) | ||||
if address.IsZero() { | ||||
if filter.AddressRole&idb.AddressRoleCloseRemainderTo != 0 { | ||||
errorArr = append(errorArr, errZeroAddressCloseRemainderToRole) | ||||
} | ||||
if filter.AddressRole&idb.AddressRoleAssetSender != 0 { | ||||
errorArr = append(errorArr, errZeroAddressAssetSenderRole) | ||||
} | ||||
if filter.AddressRole&idb.AddressRoleAssetCloseTo != 0 { | ||||
errorArr = append(errorArr, errZeroAddressAssetCloseToRole) | ||||
} | ||||
} | ||||
} | ||||
|
||||
if len(errorArr) > 0 { | ||||
return errors.New("invalid input: " + strings.Join(errorArr, ", ")) | ||||
} | ||||
|
||||
return nil | ||||
} | ||||
|
||||
//////////////////////////// | ||||
// Handler implementation // | ||||
//////////////////////////// | ||||
|
@@ -274,13 +315,18 @@ func (si *ServerImplementation) LookupApplicationLogsByID(ctx echo.Context, appl | |||
MinRound: params.MinRound, | ||||
MaxRound: params.MaxRound, | ||||
Address: params.SenderAddress, | ||||
AddressRole: strPtr(addrRoleSender), | ||||
} | ||||
|
||||
filter, err := transactionParamsToTransactionFilter(searchParams) | ||||
if err != nil { | ||||
return badRequest(ctx, err.Error()) | ||||
} | ||||
filter.AddressRole = idb.AddressRoleSender | ||||
|
||||
err = validateTransactionFilter(&filter) | ||||
if err != nil { | ||||
return badRequest(ctx, err.Error()) | ||||
} | ||||
|
||||
// Fetch the transactions | ||||
txns, next, round, err := si.fetchTransactions(ctx.Request().Context(), filter) | ||||
|
@@ -457,6 +503,11 @@ func (si *ServerImplementation) LookupTransaction(ctx echo.Context, txid string) | |||
return badRequest(ctx, err.Error()) | ||||
} | ||||
|
||||
err = validateTransactionFilter(&filter) | ||||
if err != nil { | ||||
return badRequest(ctx, err.Error()) | ||||
} | ||||
|
||||
// Fetch the transactions | ||||
txns, _, round, err := si.fetchTransactions(ctx.Request().Context(), filter) | ||||
if err != nil { | ||||
|
@@ -487,6 +538,11 @@ func (si *ServerImplementation) SearchForTransactions(ctx echo.Context, params g | |||
return badRequest(ctx, err.Error()) | ||||
} | ||||
|
||||
err = validateTransactionFilter(&filter) | ||||
if err != nil { | ||||
return badRequest(ctx, err.Error()) | ||||
} | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize that this doesn't happen in practice, but all of the other parameter checking happens in The fact that the app log search violates this constraint is pretty weird, but do you think it's a problem to generate an error here? The zero address probably shouldn't be making application calls. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the current code is ok, especially given that no one in their right mind will use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also validates the input, there's a test in
Could you also add the error message to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the error message to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is incorrect that Line 277 in 830e1ba
idb.AddressRoleSender | idb.AddressRoleAssetSender , so I set filter.AddressRole directly and run validation that used to be in transactionParamsToTransactionFilter() after.
|
||||
// Fetch the transactions | ||||
txns, next, round, err := si.fetchTransactions(ctx.Request().Context(), filter) | ||||
if err != nil { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍