-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement function calls and blockDate
- Loading branch information
Showing
7 changed files
with
173 additions
and
56 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ExecutionStatus, ReceiptStatusFilter } from "./types/core/types"; | ||
|
||
function isMatchingReceiverSingle(receiverId: string, wildcardFilter: string) { | ||
if (wildcardFilter === '*') { | ||
return true; | ||
} | ||
const regExp = new RegExp(wildcardFilter | ||
.replace(/\*/g, '[\\w\\d]+') | ||
.replace(/./g, '\.') | ||
); | ||
return regExp.test(receiverId); | ||
} | ||
|
||
export function isMatchingReceiver(receiverId: string, contractFilter: string): boolean { | ||
const filters = contractFilter.split(',').map(f => f.trim()); | ||
return filters.some(f => isMatchingReceiverSingle(receiverId, f)); | ||
} | ||
|
||
export function isMatchingReceiptStatus(receiptStatus: ExecutionStatus, statusFilter: ReceiptStatusFilter): boolean { | ||
switch (statusFilter) { | ||
case "all": return true; | ||
case "onlySuccessful": | ||
return receiptStatus.hasOwnProperty('SuccessValue') | ||
|| receiptStatus.hasOwnProperty('SuccessReceiptId'); | ||
case "onlyFailed": | ||
return receiptStatus.hasOwnProperty('Failure'); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getBlock } from "./helpers"; | ||
|
||
describe("Block", () => { | ||
describe("functionCalls", () => { | ||
it("gets successful function calls", async () => { | ||
let block = await getBlock(105793821); | ||
const functionCalls = block.functionCalls(); | ||
console.log(JSON.stringify(functionCalls, null, 2)); | ||
|
||
}); | ||
}); | ||
}); |
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,10 @@ | ||
import { readFile } from "fs/promises"; | ||
import { Block } from "../src"; | ||
|
||
export async function getBlock(blockHeight: number) { | ||
const streamerMessageBuffer = await readFile( | ||
`${__dirname}/../../../blocks/${blockHeight}.json` | ||
); | ||
const streamerMessage = JSON.parse(streamerMessageBuffer.toString()); | ||
return Block.fromStreamerMessage(streamerMessage); | ||
} |