Skip to content

Commit

Permalink
feat: added getWalletActiveChains(). (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Jul 12, 2023
1 parent 46edeee commit 7a646d1
Show file tree
Hide file tree
Showing 19 changed files with 433 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/dull-jars-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
'moralis': patch
---

Added a new endpoint method to the EVM API module: `Moralis.EvmApi.wallets.getWalletActiveChains`.
5 changes: 3 additions & 2 deletions packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"operationParameters": [
{
"names": ["chain"],
"names": ["chain", "chains"],
"className": "EvmChain",
"import": "../../dataTypes"
},
Expand All @@ -74,7 +74,8 @@
"getTopERC20TokensByPriceMovers",
"getTopNFTCollectionsByMarketCap",
"getHottestNFTCollectionsByTradingVolume",
"reviewContracts"
"reviewContracts",
"getWalletActiveChains"
]
}
}
Expand Down
17 changes: 17 additions & 0 deletions packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { EvmMarketDataHottestNFTCollectionByTradingVolumeItem, EvmMarketDataHott
import { ReviewContractsOperation, ReviewContractsOperationRequest, ReviewContractsOperationRequestJSON } from '../operations/ReviewContractsOperation';
import { EvmReviewContracts, EvmReviewContractsJSON } from '../types/EvmReviewContracts';
import { EvmContractsReviewDto, EvmContractsReviewDtoInput, EvmContractsReviewDtoJSON } from '../types/EvmContractsReviewDto';
import { GetWalletActiveChainsOperation, GetWalletActiveChainsOperationRequest, GetWalletActiveChainsOperationRequestJSON } from '../operations/GetWalletActiveChainsOperation';
import { EvmWalletActiveChains, EvmWalletActiveChainsJSON } from '../types/EvmWalletActiveChains';

export interface OperationV3<Request, RequestJSON, Response, ResponseJSON, Body, BodyJSON> {
operationId: string;
Expand Down Expand Up @@ -176,4 +178,19 @@ export abstract class AbstractClient {
EvmContractsReviewDtoJSON
>(ReviewContractsOperation),
};
public readonly wallets = {
/**
* @description Get the active chains for a wallet address.
* @param request Request with parameters.
* @param {Object} request.address Wallet address
* @param {Object[]} [request.chains] The chains to query (optional)
* @returns {Object} Response for the request.
*/
getWalletActiveChains: this.createEndpoint<
GetWalletActiveChainsOperationRequest,
GetWalletActiveChainsOperationRequestJSON,
EvmWalletActiveChains,
EvmWalletActiveChainsJSON
>(GetWalletActiveChainsOperation),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { EvmAddress, EvmAddressInput, EvmAddressJSON, EvmChain, EvmChainInput, EvmChainJSON } from '../../dataTypes';
import { EvmWalletActiveChains, EvmWalletActiveChainsJSON } from '../types/EvmWalletActiveChains';

// request parameters:
// - address ($ref: #/paths/~1wallets~1{address}~1chains/get/parameters/0/schema)
// - chains ($ref: #/components/schemas/chainList)

export interface GetWalletActiveChainsOperationRequest {
/**
* @description Wallet address
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description The chains to query
*/
readonly chains?: EvmChainInput[] | EvmChain[];
}

export interface GetWalletActiveChainsOperationRequestJSON {
readonly address: EvmAddressJSON;
readonly chains?: EvmChainJSON[];
}

export type GetWalletActiveChainsOperationResponse = EvmWalletActiveChains;
export type GetWalletActiveChainsOperationResponseJSON = EvmWalletActiveChainsJSON;

export const GetWalletActiveChainsOperation = {
operationId: "getWalletActiveChains",
groupName: "wallets",
httpMethod: "get",
routePattern: "/wallets/{address}/chains",
parameterNames: ["address","chains"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmWalletActiveChainsJSON): EvmWalletActiveChains {
return EvmWalletActiveChains.fromJSON(json);
},

serializeRequest(request: GetWalletActiveChainsOperationRequest): GetWalletActiveChainsOperationRequestJSON {
const address = EvmAddress.create(request.address);
const chains = request.chains ? request.chains.map((item) => EvmChain.create(item)) : undefined;
return {
address: address.toJSON(),
chains: chains ? chains.map((item) => item.toJSON()) : undefined,
};
},

}
1 change: 1 addition & 0 deletions packages/common/evmUtils/src/generated/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from './GetTopERC20TokensByPriceMoversOperation';
export * from './GetTopNFTCollectionsByMarketCapOperation';
export * from './GetHottestNFTCollectionsByTradingVolumeOperation';
export * from './ReviewContractsOperation';
export * from './GetWalletActiveChainsOperation';
export * from './operations';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GetTopERC20TokensByPriceMoversOperation } from './GetTopERC20TokensByPr
import { GetTopNFTCollectionsByMarketCapOperation } from './GetTopNFTCollectionsByMarketCapOperation';
import { GetHottestNFTCollectionsByTradingVolumeOperation } from './GetHottestNFTCollectionsByTradingVolumeOperation';
import { ReviewContractsOperation } from './ReviewContractsOperation';
import { GetWalletActiveChainsOperation } from './GetWalletActiveChainsOperation';

export const operations = [
GetNFTTradesOperation,
Expand All @@ -18,4 +19,5 @@ export const operations = [
GetTopNFTCollectionsByMarketCapOperation,
GetHottestNFTCollectionsByTradingVolumeOperation,
ReviewContractsOperation,
GetWalletActiveChainsOperation,
];
22 changes: 22 additions & 0 deletions packages/common/evmUtils/src/generated/types/EvmErc20Transfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { BigNumber, BigNumberInput, BigNumberJSON } from '@moralisweb3/common-core';
import { EvmErc20TransferFromWalletLabel, EvmErc20TransferFromWalletLabelValue, EvmErc20TransferFromWalletLabelInput, EvmErc20TransferFromWalletLabelJSON } from '../types/EvmErc20TransferFromWalletLabel';
import { EvmErc20TransferToWalletLabel, EvmErc20TransferToWalletLabelValue, EvmErc20TransferToWalletLabelInput, EvmErc20TransferToWalletLabelJSON } from '../types/EvmErc20TransferToWalletLabel';

// $ref: #/components/schemas/erc20Transfer
// type: erc20Transfer
Expand All @@ -16,7 +18,9 @@ import { BigNumber, BigNumberInput, BigNumberJSON } from '@moralisweb3/common-co
// - block_number ($ref: #/components/schemas/erc20Transfer/properties/block_number)
// - block_hash ($ref: #/components/schemas/erc20Transfer/properties/block_hash)
// - from_wallet ($ref: #/components/schemas/erc20Transfer/properties/from_wallet)
// - from_wallet_label ($ref: #/components/schemas/erc20Transfer/properties/from_wallet_label)
// - to_wallet ($ref: #/components/schemas/erc20Transfer/properties/to_wallet)
// - to_wallet_label ($ref: #/components/schemas/erc20Transfer/properties/to_wallet_label)
// - value ($ref: #/components/schemas/erc20Transfer/properties/value)
// - value_decimal ($ref: #/components/schemas/erc20Transfer/properties/value_decimal)
// - possible_spam ($ref: #/components/schemas/erc20Transfer/properties/possible_spam)
Expand All @@ -34,7 +38,9 @@ export interface EvmErc20TransferJSON {
readonly block_number: BigNumberJSON;
readonly block_hash: string;
readonly from_wallet: EvmAddressJSON;
readonly from_wallet_label?: EvmErc20TransferFromWalletLabelJSON;
readonly to_wallet: EvmAddressJSON;
readonly to_wallet_label?: EvmErc20TransferToWalletLabelJSON;
readonly value: string;
readonly value_decimal: string;
readonly possible_spam: boolean;
Expand All @@ -53,7 +59,9 @@ export interface EvmErc20TransferInput {
readonly blockNumber: BigNumberInput | BigNumber;
readonly blockHash: string;
readonly fromWallet: EvmAddressInput | EvmAddress;
readonly fromWalletLabel?: EvmErc20TransferFromWalletLabelInput | EvmErc20TransferFromWalletLabelValue;
readonly toWallet: EvmAddressInput | EvmAddress;
readonly toWalletLabel?: EvmErc20TransferToWalletLabelInput | EvmErc20TransferToWalletLabelValue;
readonly value: string;
readonly valueDecimal: string;
readonly possibleSpam: boolean;
Expand Down Expand Up @@ -81,7 +89,9 @@ export class EvmErc20Transfer {
blockNumber: BigNumber.fromJSON(json.block_number),
blockHash: json.block_hash,
fromWallet: EvmAddress.fromJSON(json.from_wallet),
fromWalletLabel: json.from_wallet_label ? EvmErc20TransferFromWalletLabel.fromJSON(json.from_wallet_label) : undefined,
toWallet: EvmAddress.fromJSON(json.to_wallet),
toWalletLabel: json.to_wallet_label ? EvmErc20TransferToWalletLabel.fromJSON(json.to_wallet_label) : undefined,
value: json.value,
valueDecimal: json.value_decimal,
possibleSpam: json.possible_spam,
Expand Down Expand Up @@ -116,10 +126,18 @@ export class EvmErc20Transfer {
* @description The address of the contract
*/
public readonly fromWallet: EvmAddress;
/**
* @description The label of the from wallet
*/
public readonly fromWalletLabel?: EvmErc20TransferFromWalletLabelValue;
/**
* @description The address of the contract
*/
public readonly toWallet: EvmAddress;
/**
* @description The label of the to wallet
*/
public readonly toWalletLabel?: EvmErc20TransferToWalletLabelValue;
/**
* @description The value of the transfer
*/
Expand All @@ -146,7 +164,9 @@ export class EvmErc20Transfer {
this.blockNumber = BigNumber.create(input.blockNumber);
this.blockHash = input.blockHash;
this.fromWallet = EvmAddress.create(input.fromWallet);
this.fromWalletLabel = input.fromWalletLabel ? EvmErc20TransferFromWalletLabel.create(input.fromWalletLabel) : undefined;
this.toWallet = EvmAddress.create(input.toWallet);
this.toWalletLabel = input.toWalletLabel ? EvmErc20TransferToWalletLabel.create(input.toWalletLabel) : undefined;
this.value = input.value;
this.valueDecimal = input.valueDecimal;
this.possibleSpam = input.possibleSpam;
Expand All @@ -166,7 +186,9 @@ export class EvmErc20Transfer {
block_number: this.blockNumber.toJSON(),
block_hash: this.blockHash,
from_wallet: this.fromWallet.toJSON(),
from_wallet_label: this.fromWalletLabel ? EvmErc20TransferFromWalletLabel.toJSON(this.fromWalletLabel) : undefined,
to_wallet: this.toWallet.toJSON(),
to_wallet_label: this.toWalletLabel ? EvmErc20TransferToWalletLabel.toJSON(this.toWalletLabel) : undefined,
value: this.value,
value_decimal: this.valueDecimal,
possible_spam: this.possibleSpam,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// $ref: #/components/schemas/erc20Transfer/properties/from_wallet_label
// typeName: erc20Transfer_from_wallet_label
// unionType: oneOf

export type EvmErc20TransferFromWalletLabelJSON = string | null;
export type EvmErc20TransferFromWalletLabelInput = string | null;
export type EvmErc20TransferFromWalletLabelValue = string | null;

export abstract class EvmErc20TransferFromWalletLabel {
public static create(input: EvmErc20TransferFromWalletLabelInput): EvmErc20TransferFromWalletLabelValue {
return input;
}

public static fromJSON(json: EvmErc20TransferFromWalletLabelJSON): EvmErc20TransferFromWalletLabelValue {
return json;
}

public static toJSON(value: EvmErc20TransferFromWalletLabelValue): EvmErc20TransferFromWalletLabelJSON {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// $ref: #/components/schemas/erc20Transfer/properties/to_wallet_label
// typeName: erc20Transfer_to_wallet_label
// unionType: oneOf

export type EvmErc20TransferToWalletLabelJSON = string | null;
export type EvmErc20TransferToWalletLabelInput = string | null;
export type EvmErc20TransferToWalletLabelValue = string | null;

export abstract class EvmErc20TransferToWalletLabel {
public static create(input: EvmErc20TransferToWalletLabelInput): EvmErc20TransferToWalletLabelValue {
return input;
}

public static fromJSON(json: EvmErc20TransferToWalletLabelJSON): EvmErc20TransferToWalletLabelValue {
return json;
}

public static toJSON(value: EvmErc20TransferToWalletLabelValue): EvmErc20TransferToWalletLabelJSON {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { EvmErc20Transfer, EvmErc20TransferInput, EvmErc20TransferJSON } from '.

export interface EvmErc20TransfersResponseJSON {
readonly cursor?: string;
readonly result?: EvmErc20TransferJSON[];
readonly result: EvmErc20TransferJSON[];
}

export interface EvmErc20TransfersResponseInput {
readonly cursor?: string;
readonly result?: EvmErc20TransferInput[] | EvmErc20Transfer[];
readonly result: EvmErc20TransferInput[] | EvmErc20Transfer[];
}

export class EvmErc20TransfersResponse {
Expand All @@ -27,7 +27,7 @@ export class EvmErc20TransfersResponse {
public static fromJSON(json: EvmErc20TransfersResponseJSON): EvmErc20TransfersResponse {
const input: EvmErc20TransfersResponseInput = {
cursor: json.cursor,
result: json.result ? json.result.map((item) => EvmErc20Transfer.fromJSON(item)) : undefined,
result: json.result.map((item) => EvmErc20Transfer.fromJSON(item)),
};
return EvmErc20TransfersResponse.create(input);
}
Expand All @@ -36,17 +36,17 @@ export class EvmErc20TransfersResponse {
* @description The cursor to get to the next page
*/
public readonly cursor?: string;
public readonly result?: EvmErc20Transfer[];
public readonly result: EvmErc20Transfer[];

private constructor(input: EvmErc20TransfersResponseInput) {
this.cursor = input.cursor;
this.result = input.result ? input.result.map((item) => EvmErc20Transfer.create(item)) : undefined;
this.result = input.result.map((item) => EvmErc20Transfer.create(item));
}

public toJSON(): EvmErc20TransfersResponseJSON {
return {
cursor: this.cursor,
result: this.result ? this.result.map((item) => item.toJSON()) : undefined,
result: this.result.map((item) => item.toJSON()),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export interface EvmTradeCollectionJSON {
readonly page?: number;
readonly page_size?: number;
readonly cursor?: string;
readonly result?: EvmTradeJSON[];
readonly result: EvmTradeJSON[];
}

export interface EvmTradeCollectionInput {
readonly total?: number;
readonly page?: number;
readonly pageSize?: number;
readonly cursor?: string;
readonly result?: EvmTradeInput[] | EvmTrade[];
readonly result: EvmTradeInput[] | EvmTrade[];
}

export class EvmTradeCollection {
Expand All @@ -39,7 +39,7 @@ export class EvmTradeCollection {
page: json.page,
pageSize: json.page_size,
cursor: json.cursor,
result: json.result ? json.result.map((item) => EvmTrade.fromJSON(item)) : undefined,
result: json.result.map((item) => EvmTrade.fromJSON(item)),
};
return EvmTradeCollection.create(input);
}
Expand All @@ -60,14 +60,14 @@ export class EvmTradeCollection {
* @description The cursor to get to the next page
*/
public readonly cursor?: string;
public readonly result?: EvmTrade[];
public readonly result: EvmTrade[];

private constructor(input: EvmTradeCollectionInput) {
this.total = input.total;
this.page = input.page;
this.pageSize = input.pageSize;
this.cursor = input.cursor;
this.result = input.result ? input.result.map((item) => EvmTrade.create(item)) : undefined;
this.result = input.result.map((item) => EvmTrade.create(item));
}

public toJSON(): EvmTradeCollectionJSON {
Expand All @@ -76,7 +76,7 @@ export class EvmTradeCollection {
page: this.page,
page_size: this.pageSize,
cursor: this.cursor,
result: this.result ? this.result.map((item) => item.toJSON()) : undefined,
result: this.result.map((item) => item.toJSON()),
}
}
}
Loading

1 comment on commit 7a646d1

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 96%
96.93% (95/98) 66.66% (6/9) 95.31% (61/64)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 65%
65.63% (1604/2444) 26.87% (261/971) 45.35% (439/968)
sol-api Coverage: 100%
100% (40/40) 66.66% (6/9) 100% (15/15)
common-sol-utils Coverage: 69%
69.04% (203/294) 51.42% (18/35) 55.67% (54/97)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 91%
90.54% (603/666) 72.34% (68/94) 90.97% (131/144)

Please sign in to comment.