Skip to content

Commit

Permalink
fix: Ensuring filtering works for ASA and Asset txns
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmoore committed Dec 10, 2023
1 parent 71f40ea commit 5ade91f
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/code/interfaces/types_subscription.TransactionFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ___
`Optional` **maxAmount**: `number`

Filter to transactions where the amount being transferred is less than
or equal to the given maximum (microAlgos or decimal units of an ASA).
or equal to the given maximum (microAlgos or decimal units of an ASA if type: axfer).

#### Defined in

Expand All @@ -143,7 +143,7 @@ ___
`Optional` **minAmount**: `number`

Filter to transactions where the amount being transferred is greater
than or equal to the given minimum (microAlgos or decimal units of an ASA).
than or equal to the given minimum (microAlgos or decimal units of an ASA if type: axfer).

#### Defined in

Expand Down
4 changes: 2 additions & 2 deletions docs/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export interface TransactionFilter {
/** Filter to transactions that are creating an asset. */
assetCreate?: boolean
/** Filter to transactions where the amount being transferred is greater
* than or equal to the given minimum (microAlgos or decimal units of an ASA). */
* than or equal to the given minimum (microAlgos or decimal units of an ASA if type: axfer). */
minAmount?: number
/** Filter to transactions where the amount being transferred is less than
* or equal to the given maximum (microAlgos or decimal units of an ASA). */
* or equal to the given maximum (microAlgos or decimal units of an ASA if type: axfer). */
maxAmount?: number
/** Filter to app transactions that have the given ARC-0004 method selector for
* the given method signature as the first app argument. */
Expand Down
4 changes: 2 additions & 2 deletions src/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function indexerPreFilter(
filter = filter.txType(subscription.type.toString())
}
if (subscription.notePrefix) {
filter = filter.notePrefix(subscription.notePrefix)
filter = filter.notePrefix(Buffer.from(subscription.notePrefix).toString('base64'))
}
if (subscription.appId) {
filter = filter.applicationID(subscription.appId)
Expand Down Expand Up @@ -210,7 +210,7 @@ function transactionFilter(
result &&= !!t.from && encodeAddress(t.from.publicKey) === subscription.sender
}
if (subscription.receiver) {
result &&= !!t.to && encodeAddress(t.to.publicKey) === subscription.sender
result &&= !!t.to && encodeAddress(t.to.publicKey) === subscription.receiver
}
if (subscription.type) {
result &&= t.type === subscription.type
Expand Down
8 changes: 5 additions & 3 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ export function getIndexerTransactionFromAlgodTransaction(
'default-frozen': transaction.assetDefaultFrozen,
'metadata-hash': transaction.assetMetadataHash,
name: transaction.assetName,
'name-b64': encoder.encode(Buffer.from(transaction.assetName).toString('base64')),
'name-b64': transaction.assetName ? encoder.encode(Buffer.from(transaction.assetName).toString('base64')) : undefined,
'unit-name': transaction.assetUnitName,
'unit-name-b64': encoder.encode(Buffer.from(transaction.assetUnitName).toString('base64')),
'unit-name-b64': transaction.assetUnitName
? encoder.encode(Buffer.from(transaction.assetUnitName).toString('base64'))
: undefined,
url: transaction.assetURL,
'url-b64': encoder.encode(Buffer.from(transaction.assetURL).toString('base64')),
'url-b64': transaction.assetURL ? encoder.encode(Buffer.from(transaction.assetURL).toString('base64')) : undefined,
manager: transaction.assetManager ? algosdk.encodeAddress(transaction.assetManager.publicKey) : undefined,
reserve: transaction.assetReserve ? algosdk.encodeAddress(transaction.assetReserve.publicKey) : undefined,
clawback: transaction.assetClawback ? algosdk.encodeAddress(transaction.assetClawback.publicKey) : undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/types/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export interface TransactionFilter {
/** Filter to transactions that are creating an asset. */
assetCreate?: boolean
/** Filter to transactions where the amount being transferred is greater
* than or equal to the given minimum (microAlgos or decimal units of an ASA). */
* than or equal to the given minimum (microAlgos or decimal units of an ASA if type: axfer). */
minAmount?: number
/** Filter to transactions where the amount being transferred is less than
* or equal to the given maximum (microAlgos or decimal units of an ASA). */
* or equal to the given maximum (microAlgos or decimal units of an ASA if type: axfer). */
maxAmount?: number
/** Filter to app transactions that have the given ARC-0004 method selector for
* the given method signature as the first app argument. */
Expand Down
Loading

0 comments on commit 5ade91f

Please sign in to comment.