Skip to content

Commit

Permalink
Fix paging next,prev and fix rebase miss
Browse files Browse the repository at this point in the history
  • Loading branch information
anarcher committed Nov 21, 2018
1 parent 3cf9e45 commit 92634ee
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/block/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func LoadBlockOperationsInsideIterator(

return (func() (BlockOperation, bool, []byte) {
item, hasNext := iterFunc()
if !hasNext {
if !hasNext && (item.Key == nil || item.Value == nil) {
return BlockOperation{}, false, item.Key
}

Expand Down
2 changes: 1 addition & 1 deletion lib/block/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func LoadBlockTransactionsInsideIterator(

return (func() (BlockTransaction, bool, []byte) {
item, hasNext := iterFunc()
if !hasNext {
if !hasNext && (item.Key == nil || item.Value == nil) {
return BlockTransaction{}, false, item.Key
}

Expand Down
4 changes: 3 additions & 1 deletion lib/node/runner/api/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (api NetworkHandlerAPI) GetOperationsByAccountHandler(w http.ResponseWriter
}
for {
t, hasNext, _ := iterFunc()
if t.BlockOrder() != nil {
order = t.BlockOrder()
}
if !hasNext {
break
}
Expand All @@ -76,7 +79,6 @@ func (api NetworkHandlerAPI) GetOperationsByAccountHandler(w http.ResponseWriter
r := resource.NewOperation(&t)
r.Block = blk
txs = append(txs, r)
order = t.BlockOrder()
}
closeFunc()
return txs
Expand Down
8 changes: 6 additions & 2 deletions lib/node/runner/api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ func (api NetworkHandlerAPI) GetTransactionsHandler(w http.ResponseWriter, r *ht
iterFunc, closeFunc := block.GetBlockTransactions(api.storage, options)
for {
t, hasNext, _ := iterFunc()
if t.BlockOrder() != nil {
order = t.BlockOrder()
}
if !hasNext {
break
}
order = t.BlockOrder()
txs = append(txs, resource.NewTransaction(&t))
}
closeFunc()
Expand Down Expand Up @@ -127,10 +129,12 @@ func (api NetworkHandlerAPI) GetTransactionsByAccountHandler(w http.ResponseWrit
iterFunc, closeFunc := block.GetBlockTransactionsByAccount(api.storage, address, options)
for {
t, hasNext, _ := iterFunc()
if t.BlockOrder() != nil {
order = t.BlockOrder()
}
if !hasNext {
break
}
order = t.BlockOrder()
txs = append(txs, resource.NewTransaction(&t))
}
closeFunc()
Expand Down
1 change: 0 additions & 1 deletion lib/node/runner/api/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ func TestGetTransactionsHandlerPage(t *testing.T) {

{
records, _ := requestFunction(nextLink)
println(len(records))
require.Equal(t, len(btList[5:]), len(records), "length is not the same")

for i, r := range records {
Expand Down
5 changes: 3 additions & 2 deletions lib/node/runner/api/tx_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ func (api NetworkHandlerAPI) getOperationsByTxHash(txHash string, blk *block.Blo
iterFunc, closeFunc := block.GetBlockOperationsByTxHash(api.storage, txHash, options)
for {
o, hasNext, _ := iterFunc()
if o.BlockOrder() != nil {
order = o.BlockOrder()
}
if !hasNext {
break
}
rs := resource.NewOperation(&o)
rs.Block = blk
txs = append(txs, rs)
order = o.BlockOrder()
txs = append(txs, resource.NewOperation(&o))
}
closeFunc()
return
Expand Down

0 comments on commit 92634ee

Please sign in to comment.