-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from PiVortex/main
Add indexer
- Loading branch information
Showing
8 changed files
with
94 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
**/dist/ | ||
**/.parcel-cache | ||
**/.next | ||
**/.env.local | ||
|
||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const AuctionContract = "auction-example.testnet"; | ||
export const AUCTION_CONTRACT = "auction-example.testnet"; // Replace with your contract name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default async function handler(req, res) { | ||
try { | ||
if (!process.env.API_KEY) { | ||
return res.status(500).json({ error: "API key not provided" }); | ||
} | ||
// Get all bid transactions | ||
const { contractId, ftId } = req.query; | ||
const bidsRes = await fetch(`https://api-testnet.nearblocks.io/v1/account/${contractId}/txns?from=${ftId}&method=ft_on_transfer&page=1&per_page=25&order=desc`, { | ||
headers: { | ||
'Accept': '*/*', | ||
'Authorization': `Bearer ${process.env.API_KEY}` // Use your API key here | ||
} | ||
}); | ||
|
||
const bidsJson = await bidsRes.json(); | ||
|
||
const txns = bidsJson.txns; | ||
let pastBids = []; | ||
|
||
// Loop through all bids and add valid bids to the pastBids array until 5 are found | ||
for (let i = 0; i < txns.length; i++) { | ||
const txn = txns[i]; | ||
|
||
if (txn.receipt_outcome.status) { | ||
let args = txn.actions[0].args; | ||
let parsedArgs = JSON.parse(args); | ||
let amount = Number(parsedArgs.amount); | ||
let account = parsedArgs.sender_id; | ||
|
||
if (pastBids.length < 5) { | ||
pastBids.push([account, amount]); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Respond with the past bids | ||
return res.status(200).json({ pastBids }); | ||
} catch (error) { | ||
return res.status(500).json({ error: "Failed to fetch past bids" }); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters