Skip to content

Commit

Permalink
feat: add getTransactionsVerbose method and operations
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoAmura committed Nov 30, 2022
1 parent 1310a8b commit b53e444
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/client/evmApi/src/generated/ClientEvmApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// CAUTION: This file is automatically generated. Do not edit it manually!

import { endpointWeightsOperation, EndpointWeightsRequest, EndpointWeightsResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, web3ApiVersionOperation, Web3ApiVersionRequest, Web3ApiVersionResponseAdapter, getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTradesOperation, GetNFTTradesRequest, GetNFTTradesResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, searchNFTsOperation, SearchNFTsRequest, SearchNFTsResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter } from '@moralisweb3/common-evm-utils';
import { endpointWeightsOperation, EndpointWeightsRequest, EndpointWeightsResponseAdapter, runContractFunctionOperation, RunContractFunctionRequest, RunContractFunctionResponseAdapter, web3ApiVersionOperation, Web3ApiVersionRequest, Web3ApiVersionResponseAdapter, getBlockOperation, GetBlockRequest, GetBlockResponseAdapter, getDateToBlockOperation, GetDateToBlockRequest, GetDateToBlockResponseAdapter, getContractEventsOperation, GetContractEventsRequest, GetContractEventsResponseAdapter, getContractLogsOperation, GetContractLogsRequest, GetContractLogsResponseAdapter, getContractNFTsOperation, GetContractNFTsRequest, GetContractNFTsResponseAdapter, getNFTContractMetadataOperation, GetNFTContractMetadataRequest, GetNFTContractMetadataResponseAdapter, getNFTContractTransfersOperation, GetNFTContractTransfersRequest, GetNFTContractTransfersResponseAdapter, getNFTLowestPriceOperation, GetNFTLowestPriceRequest, GetNFTLowestPriceResponseAdapter, getNFTMetadataOperation, GetNFTMetadataRequest, GetNFTMetadataResponseAdapter, getNFTOwnersOperation, GetNFTOwnersRequest, GetNFTOwnersResponseAdapter, getNFTTokenIdOwnersOperation, GetNFTTokenIdOwnersRequest, GetNFTTokenIdOwnersResponseAdapter, getNFTTradesOperation, GetNFTTradesRequest, GetNFTTradesResponseAdapter, getNFTTransfersByBlockOperation, GetNFTTransfersByBlockRequest, GetNFTTransfersByBlockResponseAdapter, getNFTTransfersFromToBlockOperation, GetNFTTransfersFromToBlockRequest, GetNFTTransfersFromToBlockResponseAdapter, getNFTTransfersOperation, GetNFTTransfersRequest, GetNFTTransfersResponseAdapter, getWalletNFTCollectionsOperation, GetWalletNFTCollectionsRequest, GetWalletNFTCollectionsResponseAdapter, getWalletNFTsOperation, GetWalletNFTsRequest, GetWalletNFTsResponseAdapter, getWalletNFTTransfersOperation, GetWalletNFTTransfersRequest, GetWalletNFTTransfersResponseAdapter, reSyncMetadataOperation, ReSyncMetadataRequest, ReSyncMetadataResponseAdapter, searchNFTsOperation, SearchNFTsRequest, SearchNFTsResponseAdapter, syncNFTContractOperation, SyncNFTContractRequest, SyncNFTContractResponseAdapter, getNativeBalanceOperation, GetNativeBalanceRequest, GetNativeBalanceResponseAdapter, getPairAddressOperation, GetPairAddressRequest, GetPairAddressResponseAdapter, getPairReservesOperation, GetPairReservesRequest, GetPairReservesResponseAdapter, getTokenAllowanceOperation, GetTokenAllowanceRequest, GetTokenAllowanceResponseAdapter, getTokenMetadataBySymbolOperation, GetTokenMetadataBySymbolRequest, GetTokenMetadataBySymbolResponseAdapter, getTokenMetadataOperation, GetTokenMetadataRequest, GetTokenMetadataResponseAdapter, getTokenPriceOperation, GetTokenPriceRequest, GetTokenPriceResponseAdapter, getTokenTransfersOperation, GetTokenTransfersRequest, GetTokenTransfersResponseAdapter, getWalletTokenBalancesOperation, GetWalletTokenBalancesRequest, GetWalletTokenBalancesResponseAdapter, getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest, GetWalletTokenTransfersResponseAdapter, getTransactionOperation, GetTransactionRequest, GetTransactionResponseAdapter, getWalletTransactionsOperation, GetWalletTransactionsRequest, GetWalletTransactionsResponseAdapter, getWalletTransactionsVerboseOperation, GetWalletTransactionsVerboseRequest, GetWalletTransactionsVerboseResponseAdapter, resolveAddressOperation, ResolveAddressRequest, ResolveAddressResponseAdapter, resolveDomainOperation, ResolveDomainRequest, ResolveDomainResponseAdapter, uploadFolderOperation, UploadFolderRequest, UploadFolderResponseAdapter } from '@moralisweb3/common-evm-utils';
import { ClientRequestHandler } from '@moralisweb3/client-api-utils';

export class ClientEvmApi {
Expand Down Expand Up @@ -146,6 +146,9 @@ export class ClientEvmApi {
getWalletTransactions: (request: GetWalletTransactionsRequest): Promise<GetWalletTransactionsResponseAdapter> => {
return this.requestHandler.handlePaginated(request, getWalletTransactionsOperation);
},
getWalletTransactionsVerbose: (request: GetWalletTransactionsVerboseRequest): Promise<GetWalletTransactionsVerboseResponseAdapter> => {
return this.requestHandler.handlePaginated(request, getWalletTransactionsVerboseOperation);
},

};

Expand Down
97 changes: 91 additions & 6 deletions packages/common/evmUtils/src/operations/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface paths {
/**
* Resync the metadata for an NFT
* * The metadata flag will request the NFT's metadata from an already existing token_uri
* * The URI (default) flag will fetch the latest token_uri from the given NFT contract address. In sync mode the metadata will also be fetched
* * The uri (default) flag will fetch the latest token_uri from the given NFT contract address. In sync mode the metadata will also be fetched
* * The sync mode will make the endpoint synchronous so it will wait for the task to be completed before responding
* * The async mode (default) will make the endpoint asynchronous so we will wait for the task to be completed before responding
*/
Expand Down Expand Up @@ -136,6 +136,10 @@ export interface paths {
/** Get native transactions ordered by block number in descending order. */
get: operations["getWalletTransactions"];
};
"/{address}/verbose": {
/** Get native transactions and logs ordered by block number in descending order. */
get: operations["getWalletTransactionsVerbose"];
};
"/transaction/{transaction_hash}": {
/** Get the contents of a transaction by the given transaction hash. */
get: operations["getTransaction"];
Expand All @@ -153,11 +157,11 @@ export interface paths {
get: operations["getContractLogs"];
};
"/{address}/events": {
/** Get events for a contract ordered by block number in descending order. */
/** Get events for a contract ordered by block number in descending order. [Try it with Swagger](https://deep-index.moralis.io/api-docs-2.1/#/Events/getContractEvents). */
post: operations["getContractEvents"];
};
"/{address}/function": {
/** Run a given function of a contract ABI and retrieve readonly data. */
/** Run a given function of a contract ABI and retrieve readonly data. [Try it with Swagger](https://deep-index.moralis.io/api-docs-2.1/#/Utils/runContractFunction). */
post: operations["runContractFunction"];
};
"/web3/version": {
Expand Down Expand Up @@ -502,6 +506,21 @@ export interface components {
* @example 1577836811
*/
timestamp: number;
/**
* @description The timestamp of the block
* @example 2022-01-03T22:59:39.000Z
*/
block_timestamp?: number;
/**
* @description The block hash
* @example 0x9b559aef7ea858608c2e554246fe4a24287e7aeeb976848df2b9a2531f4b9171
*/
block_hash?: string;
/**
* @description The block hash of the parent block
* @example 0x011d1fc45839de975cc55d758943f9f1d204f80a90eb631f3bf064b80d53e045
*/
parent_hash?: string;
};
RunContractDto: {
/**
Expand Down Expand Up @@ -533,6 +552,19 @@ export interface components {
page_size?: number;
result?: components["schemas"]["transaction"][];
};
transactionCollectionVerbose: {
/**
* @description The current page of the result
* @example 2
*/
page?: number;
/**
* @description The number of results per page
* @example 100
*/
page_size?: number;
result?: components["schemas"]["blockTransaction"][];
};
transaction: {
/**
* @description The hash of the transaction
Expand Down Expand Up @@ -760,6 +792,8 @@ export interface components {
| "0xa869"
| "fantom"
| "0xfa"
| "palm"
| "0x2a15c308d"
| "cronos"
| "0x19"
| "cronos testnet"
Expand Down Expand Up @@ -2071,7 +2105,7 @@ export interface operations {
/**
* Resync the metadata for an NFT
* * The metadata flag will request the NFT's metadata from an already existing token_uri
* * The URI (default) flag will fetch the latest token_uri from the given NFT contract address. In sync mode the metadata will also be fetched
* * The uri (default) flag will fetch the latest token_uri from the given NFT contract address. In sync mode the metadata will also be fetched
* * The sync mode will make the endpoint synchronous so it will wait for the task to be completed before responding
* * The async mode (default) will make the endpoint asynchronous so we will wait for the task to be completed before responding
*/
Expand Down Expand Up @@ -2507,6 +2541,57 @@ export interface operations {
};
};
};
/** Get native transactions and logs ordered by block number in descending order. */
getWalletTransactionsVerbose: {
parameters: {
query: {
/** The chain to query */
chain?: components["schemas"]["chainList"];
/** The subdomain of the Moralis server to use (only use when selecting local devchain as chain) */
subdomain?: string;
/**
* The minimum block number from which to get the transactions
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
from_block?: number;
/**
* The maximum block number from which to get the transactions.
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used.
*/
to_block?: number;
/**
* The start date from which to get the transactions (any format that is accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
from_date?: string;
/**
* Get the transactions up to this date (any format that is accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used.
*/
to_date?: string;
/** The cursor returned in the previous response (used for getting the next page). */
cursor?: string;
/** The desired page size of the result. */
limit?: number;
};
path: {
/** The address of the wallet */
address: string;
};
};
responses: {
/** Returns a collection of native transactions. */
200: {
content: {
"application/json": components["schemas"]["transactionCollectionVerbose"];
};
};
};
};
/** Get the contents of a transaction by the given transaction hash. */
getTransaction: {
parameters: {
Expand Down Expand Up @@ -2641,7 +2726,7 @@ export interface operations {
};
};
};
/** Get events for a contract ordered by block number in descending order. */
/** Get events for a contract ordered by block number in descending order. [Try it with Swagger](https://deep-index.moralis.io/api-docs-2.1/#/Events/getContractEvents). */
getContractEvents: {
parameters: {
query: {
Expand Down Expand Up @@ -2719,7 +2804,7 @@ export interface operations {
};
};
};
/** Run a given function of a contract ABI and retrieve readonly data. */
/** Run a given function of a contract ABI and retrieve readonly data. [Try it with Swagger](https://deep-index.moralis.io/api-docs-2.1/#/Utils/runContractFunction). */
runContractFunction: {
parameters: {
query: {
Expand Down
7 changes: 6 additions & 1 deletion packages/common/evmUtils/src/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import {
getWalletTokenBalancesOperation,
} from './token';
import { getWalletTokenTransfersOperation } from './token/getWalletTokenTransfersOperation';
import { getTransactionOperation, getWalletTransactionsOperation } from './transaction';
import {
getTransactionOperation,
getWalletTransactionsOperation,
getWalletTransactionsVerboseOperation,
} from './transaction';
import { endpointWeightsOperation, web3ApiVersionOperation } from './utils';
import { runContractFunctionOperation } from './utils/runContractFunctionOperation';

Expand Down Expand Up @@ -68,6 +72,7 @@ export const operations = [
getWalletTokenBalancesOperation,
getWalletTokenTransfersOperation,
getWalletTransactionsOperation,
getWalletTransactionsVerboseOperation,
resolveAddressOperation,
resolveDomainOperation,
reSyncMetadataOperation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import MoralisCore from '@moralisweb3/common-core';
import { EvmAddress, EvmChain } from '../../dataTypes';
import {
getWalletTransactionsVerboseOperation,
GetWalletTransactionsVerboseRequest,
} from './getWalletTransactionsVerboseOperation';

describe('getWalletVerboseTransactionsOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359';
const chain = '0x10';
const fromDate = '2021-01-01T00:00:00.000Z';
const toDate = '2021-01-01T00:00:00.000Z';

const request: Required<GetWalletTransactionsVerboseRequest> = {
address: EvmAddress.create(address, core),
chain: EvmChain.create(chain, core),
fromBlock: 10,
toBlock: 20,
fromDate: new Date(fromDate),
toDate: new Date(toDate),
subdomain: 'test.com',
cursor: 'CURSOR1',
limit: 333,
};

const serializedRequest = getWalletTransactionsVerboseOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.fromBlock).toBe(request.fromBlock);
expect(serializedRequest.toBlock).toBe(request.toBlock);
expect(serializedRequest.fromDate).toBe(request.fromDate);
expect(serializedRequest.toDate).toBe(request.toDate);
expect(serializedRequest.subdomain).toBe(request.subdomain);
expect(serializedRequest.cursor).toBe(request.cursor);
expect(serializedRequest.limit).toBe(request.limit);

const deserializedRequest = getWalletTransactionsVerboseOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as EvmAddress).checksum).toBe(address);
expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.fromBlock).toBe(request.fromBlock);
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect(deserializedRequest.fromDate).toBe(request.fromDate);
expect(deserializedRequest.toDate).toBe(request.toDate);
expect(deserializedRequest.subdomain).toBe(request.subdomain);
expect(deserializedRequest.cursor).toBe(request.cursor);
expect(deserializedRequest.limit).toBe(request.limit);
});
});
Loading

0 comments on commit b53e444

Please sign in to comment.