Skip to content

Commit

Permalink
ALL-3136 - Fix CONTRACT_ADDRESS_LOG_EVENT data in getAll() (#997)
Browse files Browse the repository at this point in the history
* ALL-3136 - Fix CONTRACT_ADDRESS_LOG_EVENT data in getAll()

* ALL-3136 - Fix CONTRACT_ADDRESS_LOG_EVENT data in getAll() - CR

* ALL-3136 - Fix CONTRACT_ADDRESS_LOG_EVENT data in getAll() - CR 2

* ALL-3136 - Fix CONTRACT_ADDRESS_LOG_EVENT data in getAll() - CR 3
  • Loading branch information
Smrecz authored Oct 20, 2023
1 parent 623fdcc commit 9706f40
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## [4.1.13] - 2023.10.20
### Changed
- Fixed CONTRACT_ADDRESS_LOG_EVENT data in getAll() Notification method

## [4.1.12] - 2023.10.19
### Added
- Fixed response parsing for calls where the body is not defined e.g. DELETE endpoints

## [4.1.11] - 2023.10.19
### Added
- Added RPC support for the CELO network. Users can now make RPC calls to these network using the `Network.CELO` network.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "4.1.12",
"version": "4.1.13",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
2 changes: 1 addition & 1 deletion src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const EVM_LOAD_BALANCER_NETWORKS = [
Network.ETHEREUM_CLASSIC,
Network.AVALANCHE_C,
Network.CELO,
Network.CELO_ALFAJORES
Network.CELO_ALFAJORES,
]

export const TRON_LOAD_BALANCER_NETWORKS = [Network.TRON]
Expand Down
2 changes: 1 addition & 1 deletion src/e2e/rpc/evm/evm.rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const testNetworks = [
expected: { chainId: 421613 },
apiKey: process.env.V3_API_KEY_TESTNET,
},
{ network: Network.HORIZEN_EON, expected: { chainId: 7332 } },
//{ network: Network.HORIZEN_EON, expected: { chainId: 7332 } },
{ network: Network.HORIZEN_EON_GOBI, expected: { chainId: 1663 } },
{ network: Network.CHILIZ, expected: { chainId: 88888 } },
{ network: Network.BINANCE_SMART_CHAIN, expected: { chainId: 56 } },
Expand Down
2 changes: 1 addition & 1 deletion src/service/extensions/tatumsdk.extensions.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export abstract class TatumSdkExtension {
}
export type ExtensionConstructor = new (
tatumSdkContainer: ITatumSdkContainer,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
) => TatumSdkExtension

Expand Down
6 changes: 3 additions & 3 deletions src/service/extensions/tatumsdk.wallet.providers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export abstract class TatumSdkWalletProvider<T, P> extends TatumSdkExtension {

export type WalletProviderConstructor = new (
tatumSdkContainer: ITatumSdkContainer,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => TatumSdkWalletProvider<any, any>
) => // eslint-disable-next-line @typescript-eslint/no-explicit-any
TatumSdkWalletProvider<any, any>

export type WalletProviderWithConfig = {
type: WalletProviderConstructor
Expand Down
19 changes: 19 additions & 0 deletions src/service/notification/notification.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export interface NotificationSubscription {
* Address to monitor, valid for some of the types only.
*/
address?: string
/**
* Contract Address to monitor, valid for some of the types only.
*/
contractAddress?: string
/**
* topic[0] event to be tracked.
*/
event?: string
}

export interface ContractBasedNotificationDetail {
Expand Down Expand Up @@ -115,6 +123,17 @@ export interface AddressEventNotificationApi {
}
}

export interface ContractAddressLogEventNotificationApi {
id: string
type: NotificationType.CONTRACT_ADDRESS_LOG_EVENT
attr: {
chain: AddressEventNotificationChain
contractAddress: string
event: string
url: string
}
}

export interface GetAllExecutedWebhooksQuery {
/**
* The number of items to return per page. Defaults to 10.
Expand Down
41 changes: 32 additions & 9 deletions src/service/notification/notification.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Container, Service } from 'typedi'
import { TatumConnector } from '../../connector/tatum.connector'
import { TatumConnector } from '../../connector'
import { ErrorUtils, ResponseDto, Utils } from '../../util'
import {
AddressEventNotificationApi,
ContractAddressLogEventNotificationApi,
GetAllExecutedWebhooksQuery,
GetAllSubscriptionsQuery,
NotificationSubscription,
NotificationType,
Webhook,
} from './notification.dto'
import { Subscribe } from './subscribe'
Expand Down Expand Up @@ -33,21 +35,42 @@ export class Notification {
*/
async getAll(body?: GetAllSubscriptionsQuery): Promise<ResponseDto<NotificationSubscription[]>> {
return ErrorUtils.tryFail(async () => {
const subscriptions = await this.connector.get<AddressEventNotificationApi[]>({
const subscriptions = await this.connector.get<
[AddressEventNotificationApi | ContractAddressLogEventNotificationApi]
>({
path: 'subscription',
params: {
pageSize: body?.pageSize?.toString() ?? '10',
...(body?.offset && { offset: body.offset.toString() }),
...(body?.address && { address: body.address }),
},
})
return subscriptions.map((notification) => ({
id: notification.id,
network: Utils.mapNotificationChainToNetwork(notification.attr.chain),
address: notification.attr.address,
url: notification.attr.url,
type: notification.type,
}))

return subscriptions.map((notification) => {
const result: Partial<NotificationSubscription> = {
id: notification.id,
network: Utils.mapNotificationChainToNetwork(notification.attr.chain),
url: notification.attr.url,
type: notification.type,
}

if (notification.type === NotificationType.CONTRACT_ADDRESS_LOG_EVENT) {
return {
...result,
contractAddress: notification.attr.contractAddress,
event: notification.attr.event,
} as NotificationSubscription
}

if(notification.attr.address) {
return {
...result,
address: notification.attr.address,
} as NotificationSubscription
}

return result as NotificationSubscription
})
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/walletProvider/wallet.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class WalletProvider {
* @param type - Wallet Provider type imported to the SDK instance
*/
use<T, P, E extends TatumSdkWalletProvider<T, P>>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type: new (tatumSdkContainer: ITatumSdkContainer, ...args: any[]) => E,
): E {
return Container.of(this.id).get(type)
Expand Down

0 comments on commit 9706f40

Please sign in to comment.