Skip to content

Commit

Permalink
New paginated approach for reading the orders from blockchain (#563)
Browse files Browse the repository at this point in the history
As the current approach for reading the orders would not work anymore for the mainnet network, due to too many orders, I implemented the paginated approach.

testplan:

npx truffle exec  scripts/stablex/get_auction_elements.js --network mainnet  
and observe all >660 orders
  • Loading branch information
josojo authored Feb 24, 2020
1 parent 8f711b5 commit c194f71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scripts/stablex/get_auction_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const argv = require("yargs")
.option("tokens", {
describe: "Filter only orders between the given tokens",
})
.option("pageSize", {
default: 100,
describe: "The page size for the function getOrdersPaginated",
})
.version(false).argv

const { decodeOrdersBN } = require("../../src/encoding")
const { getOrdersPaginated } = require("./utilities")

const COLORS = {
NONE: "\x1b[0m",
Expand Down Expand Up @@ -85,8 +89,7 @@ const printOrder = function(order, currentBatchId) {
module.exports = async callback => {
try {
const instance = await BatchExchange.deployed()
const auctionElementsEncoded = await instance.getEncodedOrders.call()
let auctionElementsDecoded = decodeOrdersBN(auctionElementsEncoded)
let auctionElementsDecoded = await getOrdersPaginated(instance, argv.pageSize)

const batchId = (await instance.getCurrentBatchId()).toNumber()
if (!argv.expired) {
Expand Down
17 changes: 17 additions & 0 deletions scripts/stablex/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,25 @@ const closeAuction = async (instance, web3Provider = web3) => {
await waitForNSeconds(time_remaining + 1, web3Provider)
}

const getOrdersPaginated = async (instance, pageSize) => {
const { decodeOrdersBN } = require("../../src/encoding")
let orders = []
let currentUser = "0x0000000000000000000000000000000000000000"
let currentOffSet = 0
let lastPageSize = pageSize
while (lastPageSize == pageSize) {
const page = decodeOrdersBN(await instance.getEncodedUsersPaginated(currentUser, currentOffSet, pageSize))
orders = orders.concat(page)
currentUser = page[page.length - 1].user
currentOffSet = orders.filter(order => order.user == currentUser).length
lastPageSize = page.length
}
return orders
}

module.exports = {
addTokens,
closeAuction,
token_list_url,
getOrdersPaginated,
}

0 comments on commit c194f71

Please sign in to comment.