Skip to content

Commit

Permalink
Merge pull request #19 from ericsharma/methodSignatures-filter
Browse files Browse the repository at this point in the history
feat: Added methodSignatures filter
  • Loading branch information
robdmoore authored Mar 13, 2024
2 parents 252c6f0 + 6ffec8e commit df21fa3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ function indexerPostFilter(subscription: TransactionFilter): (t: TransactionResu
!!t['application-transaction']['application-args'] &&
t['application-transaction']['application-args'][0] === getMethodSelectorBase64(subscription.methodSignature)
}
if (subscription.methodSignatures) {
subscription.methodSignatures.filter(
(method) =>
!!t['application-transaction'] &&
!!t['application-transaction']['application-args'] &&
t['application-transaction']['application-args'][0] === getMethodSelectorBase64(method),
).length > 0
? (result &&= true)
: (result &&= false)
}
if (subscription.appCallArgumentsMatch) {
result &&=
!!t['application-transaction'] &&
Expand Down Expand Up @@ -287,6 +297,13 @@ function transactionFilter(
if (subscription.methodSignature) {
result &&= !!t.appArgs && Buffer.from(t.appArgs[0] ?? []).toString('base64') === getMethodSelectorBase64(subscription.methodSignature)
}
if (subscription.methodSignatures) {
subscription.methodSignatures.filter(
(method) => !!t.appArgs && Buffer.from(t.appArgs[0] ?? []).toString('base64') === getMethodSelectorBase64(method),
).length > 0
? (result &&= true)
: (result &&= false)
}
if (subscription.appCallArgumentsMatch) {
result &&= subscription.appCallArgumentsMatch(t.appArgs)
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export interface TransactionFilter {
/** Filter to app transactions that have the given ARC-0004 method selector for
* the given method signature as the first app argument. */
methodSignature?: string
/** Filter to app transactions that match one of the given ARC-0004 method selectors as the first app argument. */
methodSignatures?: string[]
/** Filter to app transactions that meet the given app arguments predicate. */
appCallArgumentsMatch?: (appCallArguments?: Uint8Array[]) => boolean
}
Expand Down
23 changes: 23 additions & 0 deletions tests/scenarios/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,29 @@ describe('Subscribing using various filters', () => {
)
})

test('Works for method signatures', async () => {
const { testAccount, algod } = localnet.context
const app1 = await app({ create: true })
const txns = await algokit.sendGroupOfTransactions(
{
transactions: [
app1.app.callAbi({ value: 'test' }, { sender: testAccount, sendParams: { skipSending: true } }),
app1.app.optIn.optIn({}, { sender: testAccount, sendParams: { skipSending: true } }),
],
signer: testAccount,
},
algod,
)

await subscribeAndVerifyFilter(
{
sender: testAccount.addr,
methodSignatures: ['opt_in()void', 'madeUpMethod()void'],
},
extractFromGroupResult(txns, 1),
)
})

test('Works for app args', async () => {
const { testAccount, algod } = localnet.context
const app1 = await app({ create: true })
Expand Down

0 comments on commit df21fa3

Please sign in to comment.