func (a *API) listAddresses(ctx context.Context, ins struct {
AccountID string `json:"account_id"`
AccountAlias string `json:"account_alias"`
+ From uint `json:"from"`
+ Count uint `json:"count"`
}) Response {
accountID := ins.AccountID
var target *account.Account
// sort AddressResp by KeyIndex
sort.Sort(SortByIndex(addresses))
- return NewSuccessResponse(addresses)
+ start, end := getPageRange(len(addresses), ins.From, ins.Count)
+ return NewSuccessResponse(addresses[start:end])
}
type minigAddressResp struct {
--- /dev/null
+package api
+
+// Get the start and end of the page.
+func getPageRange(size int, from uint, count uint) (uint, uint) {
+ total := uint(size)
+ if from == 0 && count == 0 {
+ return 0, total
+ }
+ start := from
+ end := from + count
+ if start > total {start = total}
+ if end > total {end = total}
+ return start, end
+}
\ No newline at end of file
AccountID string `json:"account_id"`
Detail bool `json:"detail"`
Unconfirmed bool `json:"unconfirmed"`
+ From uint `json:"from"`
+ Count uint `json:"count"`
}) Response {
transactions := []*query.AnnotatedTx{}
var err error
if filter.Detail == false {
txSummary := a.wallet.GetTransactionsSummary(transactions)
- return NewSuccessResponse(txSummary)
+ start, end := getPageRange(len(txSummary), filter.From, filter.Count)
+ return NewSuccessResponse(txSummary[start:end])
}
- return NewSuccessResponse(transactions)
+ start, end := getPageRange(len(transactions), filter.From, filter.Count)
+ return NewSuccessResponse(transactions[start:end])
}
// POST /get-unconfirmed-transaction
ID string `json:"id"`
Unconfirmed bool `json:"unconfirmed"`
SmartContract bool `json:"smart_contract"`
+ From uint `json:"from"`
+ Count uint `json:"count"`
}) Response {
accountUTXOs := a.wallet.GetAccountUtxos(filter.ID, filter.Unconfirmed, filter.SmartContract)
Change: utxo.Change,
}}, UTXOs...)
}
-
- return NewSuccessResponse(UTXOs)
+ start, end := getPageRange(len(UTXOs), filter.From, filter.Count)
+ return NewSuccessResponse(UTXOs[start:end])
}
// return gasRate