Skip to content

Commit

Permalink
feat: add multiple addresses (#715)
Browse files Browse the repository at this point in the history
* feat: add multiple addresses
* fix: update api types
* fix: update demo
  • Loading branch information
ErnoW authored Sep 30, 2022
1 parent bfea2ba commit f3cd2b5
Show file tree
Hide file tree
Showing 30 changed files with 243 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-bikes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moralisweb3/streams': patch
---

Update types according to api changes: remove `address` and `tokenAddress`, add includeContractLogs, includeInternalTxs and allAddresses flags, and mape `topic0` an array
5 changes: 5 additions & 0 deletions .changeset/tall-nails-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moralisweb3/streams': patch
---

Allow multiple addresses for Moralis.Streams.addAddress
6 changes: 0 additions & 6 deletions demos/moralis-stream/src/stream/streamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ interface StreamOptions {

const DESCRIPTION = 'some description';
const TAG = 'transactions';
const ADDRESS = '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7';
const CHAINIDS = ['0x3', '0x4'];
const TYPE = 'wallet';

export async function addStream(options: StreamOptions) {
const { network, webhookUrl } = options;
Expand All @@ -18,9 +16,7 @@ export async function addStream(options: StreamOptions) {
webhookUrl,
chains: CHAINIDS,
tag: TAG,
type: TYPE,
description: DESCRIPTION,
address: ADDRESS,
includeNativeTxs: true,
});

Expand Down Expand Up @@ -53,9 +49,7 @@ export async function updateStream(id: string, options: StreamOptions) {
webhookUrl,
chains: CHAINIDS,
tag: TAG,
type: TYPE,
description: DESCRIPTION,
address: ADDRESS,
includeNativeTxs: true,
});

Expand Down
7 changes: 7 additions & 0 deletions packages/integration/mockRequests/streamApi/addAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const AddAddressResponse: Record<string, { data: any; status: number }> = {
},
status: 200,
},
MULTIPLE_ADDRESSES: {
data: {
streamId: 'MULTIPLE_ADDRESSES',
address: ['0x295522b61890c3672d12efbff4358a6411ce996f', '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],
},
status: 200,
},
INVALID_ADDRESS: {
data: {
message: 'Invalid Address: some-address',
Expand Down
22 changes: 12 additions & 10 deletions packages/integration/mockRequests/streamApi/createStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { STREAM_API_ROOT, MOCK_API_KEY } from '../config';

export const mockCreateStreamOutput: Record<string, unknown> = {
webhookUrl: 'https://webhook.site/c76c6361-960d-4600-8498-9fecba8abb5f',
description: 'string',
tag: 'string',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
filter: {},
abi: {},
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
chainIds: ['0x3'],
type: 'wallet',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
description: 'test stream',
tag: 'test',
topic0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
allAddresses: false,
includeNativeTxs: false,
includeContractLogs: false,
includeInternalTxs: false,
abi: null,
filter: null,
chainIds: ['0x3', '0x4'],
status: 'active',
statusMessage: 'Stream is active',
};

export const mockCreateStream = rest.put(`${STREAM_API_ROOT}/streams/evm`, (req, res, ctx) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/integration/mockRequests/streamApi/deleteStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export const mockDeleteStreamOutput: Record<string, unknown> = {
webhookUrl: 'https://webhook.site/c76c6361-960d-4600-8498-9fecba8abb5f',
description: 'string',
tag: 'string',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
topic0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
filter: {},
abi: {},
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
chainIds: ['0x3'],
type: 'wallet',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
allAddresses: false,
includeNativeTxs: false,
includeContractLogs: false,
includeInternalTxs: false,
};

export const mockDeleteStream = rest.delete(`${STREAM_API_ROOT}/streams/evm/:id`, (req, res, ctx) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/integration/mockRequests/streamApi/getStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export const mockGetStreamsOutput = {
webhookUrl: 'https://webhook.site/c76c6361-960d-4600-8498-9fecba8abb5f',
description: 'string',
tag: 'string',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
topic0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
filter: {},
abi: {},
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
chainIds: ['0x3'],
type: 'wallet',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
allAddresses: false,
includeNativeTxs: false,
includeContractLogs: false,
includeInternalTxs: false,
},
],
cursor: 'string',
Expand Down
23 changes: 13 additions & 10 deletions packages/integration/mockRequests/streamApi/updateStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { rest } from 'msw';
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config';

export const mockUpdateStreamOutput: Record<string, unknown> = {
id: 'VALID_REQUEST',
webhookUrl: 'https://webhook.site/c76c6361-960d-4600-8498-9fecba8abb5f',
description: 'string',
tag: 'string',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
filter: {},
abi: {},
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
chainIds: ['0x3'],
type: 'wallet',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
description: 'test stream',
tag: 'test',
topic0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
allAddresses: false,
includeNativeTxs: false,
includeContractLogs: false,
includeInternalTxs: false,
abi: null,
filter: null,
chainIds: ['0x3', '0x4'],
status: 'active',
statusMessage: 'Stream is active',
};

export const mockUpdateStream = rest.post(`${STREAM_API_ROOT}/streams/evm/:id`, (req, res, ctx) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/integration/test/streamApi/addAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('addAddress', () => {
expect(result.result.streamId).toEqual('VALID_RESPONSE');
});

it('should create multiple addresses succesfully ', async () => {
const result = await StreamApi.addAddress({
network: 'evm',
address: ['0x295522b61890c3672d12efbff4358a6411ce996f', '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],
id: 'MULTIPLE_ADDRESSES',
});

expect(result).toBeDefined();
expect(result.toJSON().address).toStrictEqual([
'0x295522b61890c3672d12efbff4358a6411ce996f',
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
]);
expect(result.result.streamId).toEqual('MULTIPLE_ADDRESSES');
});

it('should throw a 400 Error on invalid address ', async () => {
expect(
StreamApi.addAddress({
Expand Down
9 changes: 1 addition & 8 deletions packages/integration/test/streamApi/createStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,24 @@ describe('Create stream', () => {
it('should create a stream ', async () => {
const result = await StreamApi.add({
chains: ['0x3'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
network: 'evm',
});

expect(result).toBeDefined();
expect(result).toEqual(expect.objectContaining({}));
expect(result.result.chainIds).toContain('0x3');
expect(result.result.type).toEqual('wallet');
});

it('should not create stream', async () => {
const failedResult = await StreamApi.add({
chains: ['0x3'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
network: 'evm',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
})
.then()
.catch((err: any) => {
Expand All @@ -48,10 +43,8 @@ describe('Create stream', () => {
expect(
StreamApi.add({
chains: ['invalid_chain'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
network: 'evm',
}),
Expand Down
1 change: 0 additions & 1 deletion packages/integration/test/streamApi/deleteStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ describe('Delete stream', () => {
expect(result).toBeDefined();
expect(result).toEqual(expect.objectContaining({}));
expect(result.result.chainIds).toContain('0x3');
expect(result.result.type).toEqual('wallet');
});
});
1 change: 0 additions & 1 deletion packages/integration/test/streamApi/getStreams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ describe('Get stream', () => {
expect(result.result).toBeDefined();
expect(result.pagination.total).toEqual(20);
expect(result.result[0].chainIds).toContain('0x3');
expect(result.result[0].type).toEqual('wallet');
});
});
9 changes: 1 addition & 8 deletions packages/integration/test/streamApi/updateStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ describe('Update stream', () => {
it('should update a stream ', async () => {
const result = await StreamApi.update({
chains: ['0x3'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
id: 'VALID_REQUEST',
network: 'evm',
});

expect(result).toBeDefined();
expect(result).toEqual(expect.objectContaining({}));
expect(result.result.chainIds).toContain('0x3');
expect(result.result.type).toEqual('wallet');
});

it('should not update stream', async () => {
const failedResult = await StreamApi.update({
chains: ['0x3'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
network: 'evm',
Expand All @@ -50,10 +45,8 @@ describe('Update stream', () => {
expect(
StreamApi.update({
chains: ['invalid_chain'],
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7',
tag: 'test',
description: 'test',
type: 'wallet',
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b',
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
network: 'evm',
Expand Down
1 change: 1 addition & 0 deletions packages/streams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"gen:api-types": "openapi-typescript https://api.moralis-streams.com/api-docs/swagger.json --output src/generated/types.ts",
"gen:api-types-beta": "openapi-typescript https://streams-api-stage.aws-prod-streams-master-1.moralis.io/api-docs/swagger.json --output src/generated/types.ts",
"build": "tsc",
"dev": "tsc --watch"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/streams/src/MoralisStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getHistory } from './resolvers/history/getHistory';
import { replayHistory } from './resolvers/history/replayHistory';
import { makeGetAddresses } from './methods/getAddresses';
import { makeDeleteAddress } from './methods/deleteAddress';
import { makeGetStreamById } from './methods/getById';

export const BASE_URL = 'https://api.moralis-streams.com';

Expand Down Expand Up @@ -41,6 +42,7 @@ export class MoralisStreams extends ApiModule {
public readonly update = makeUpdateStream(this.endpoints);
public readonly delete = makeDeleteStream(this.endpoints);
public readonly getAll = makeGetStreams(this.endpoints);
public readonly getById = makeGetStreamById(this.endpoints);
public readonly updateStatus = makeUpdateStreamStatus(this.endpoints);

public readonly addAddress = makeAddAddress(this.endpoints);
Expand Down
Loading

0 comments on commit f3cd2b5

Please sign in to comment.