How to filter transaction using message?

I am using message as one way to differentiate type of transaction, for example I used “sales”, “transfer”, etc., so it is easier for me to filter the transaction history by type.

Using the SDK provided, I can do the paging through QueryParams:

new QueryParams(pageSize, transactionId, ordered)

The problem is, for example if I select 10 records from TransferTransaction, but only 5 of it is ‘sales’, and I am expecting 10 ‘sales’ records.

Is there any good way to do it?

so you are expecting 5 records of type ‘Sale’ from the 10 transactions?

I’d do something like this:

Look up the account using AccountHttp ->
Get txes from that account ->
Filter by TransactionType.TRANSFER ->
For each transfer tx, look in it’s message.payload and determine if the contents are valid ->
Map them to a custom type (Sale)

You have to make sure you mark tx correctly as a ‘sale’, then check for it exactly how you put it in the message
.

Example, all the transaction is TransactionType.TRANSFER:

pageSize is set to 10

  1. sales
  2. sales
  3. sales
  4. transfer
  5. sales
  6. sales
  7. transfer
  8. transfer
  9. transfer
  10. transfer

So, I get the above result from blockchain, then I remove transaction with message transfer, so I only get 5 sales.

Yes, so using an Observable chain you can do this. If sale transactions have a specific kind of message saying that it’s a sale, like Sale: <...contents> then search for that and return it. Otherwise, do not return that transaction.

Again, maybe something like this could help?

But the problem is the expected result is 10, because after 10 transfer transaction, there are another few sales 'transaction.

have you tried setting pageSize to a higher number? 100, perhaps?

Will try to use higher number, to to find out is there any other better alternative, instead of using message to filter the transaction type.

Try the higher page size. It will help with your problem