Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IAddress Interface and update to use Address #546

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/networkProviders/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";

/**
* A plain view of an account, as queried from the Network.
*/
export class AccountOnNetwork {
address: IAddress = Address.empty();
address: Address = Address.empty();
nonce: number = 0;
balance: BigNumber = new BigNumber(0);
code: string = "";
Expand Down Expand Up @@ -54,7 +53,7 @@ export class GuardianData {
return result;
}

getCurrentGuardianAddress(): IAddress | undefined {
getCurrentGuardianAddress(): Address | undefined {
if (!this.guarded) {
return undefined;
}
Expand All @@ -65,7 +64,7 @@ export class GuardianData {

class Guardian {
activationEpoch: number = 0;
address: IAddress = Address.empty();
address: Address = Address.empty();
serviceUID: string = "";

static fromHttpResponse(responsePart: any): Guardian {
Expand Down
15 changes: 8 additions & 7 deletions src/networkProviders/apiNetworkProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "../address";
import { ErrContractQuery, ErrNetworkProvider } from "../errors";
import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery";
import { Transaction } from "../transaction";
Expand All @@ -9,7 +10,7 @@ import { AccountOnNetwork, GuardianData } from "./accounts";
import { defaultAxiosConfig, defaultPagination } from "./config";
import { BaseUserAgent } from "./constants";
import { ContractQueryRequest } from "./contractQueryRequest";
import { IAddress, INetworkProvider, IPagination } from "./interface";
import { INetworkProvider, IPagination } from "./interface";
import { NetworkConfig } from "./networkConfig";
import { NetworkGeneralStatistics } from "./networkGeneralStatistics";
import { NetworkProviderConfig } from "./networkProviderConfig";
Expand Down Expand Up @@ -64,18 +65,18 @@ export class ApiNetworkProvider implements INetworkProvider {
return stats;
}

async getAccount(address: IAddress): Promise<AccountOnNetwork> {
async getAccount(address: Address): Promise<AccountOnNetwork> {
const response = await this.doGetGeneric(`accounts/${address.bech32()}`);
const account = AccountOnNetwork.fromHttpResponse(response);
return account;
}

async getGuardianData(address: IAddress): Promise<GuardianData> {
async getGuardianData(address: Address): Promise<GuardianData> {
return await this.backingProxyNetworkProvider.getGuardianData(address);
}

async getFungibleTokensOfAccount(
address: IAddress,
address: Address,
pagination?: IPagination,
): Promise<FungibleTokenOfAccountOnNetwork[]> {
pagination = pagination || defaultPagination;
Expand All @@ -90,7 +91,7 @@ export class ApiNetworkProvider implements INetworkProvider {
}

async getNonFungibleTokensOfAccount(
address: IAddress,
address: Address,
pagination?: IPagination,
): Promise<NonFungibleTokenOfAccountOnNetwork[]> {
pagination = pagination || defaultPagination;
Expand All @@ -105,7 +106,7 @@ export class ApiNetworkProvider implements INetworkProvider {
}

async getFungibleTokenOfAccount(
address: IAddress,
address: Address,
tokenIdentifier: string,
): Promise<FungibleTokenOfAccountOnNetwork> {
const response = await this.doGetGeneric(`accounts/${address.bech32()}/tokens/${tokenIdentifier}`);
Expand All @@ -114,7 +115,7 @@ export class ApiNetworkProvider implements INetworkProvider {
}

async getNonFungibleTokenOfAccount(
address: IAddress,
address: Address,
collection: string,
nonce: number,
): Promise<NonFungibleTokenOfAccountOnNetwork> {
Expand Down
19 changes: 8 additions & 11 deletions src/networkProviders/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "../address";
import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery";
import { Transaction } from "../transaction";
import { TransactionOnNetwork } from "../transactionOnNetwork";
Expand Down Expand Up @@ -37,31 +38,31 @@ export interface INetworkProvider {
/**
* Fetches the state of an account.
*/
getAccount(address: IAddress): Promise<AccountOnNetwork>;
getAccount(address: Address): Promise<AccountOnNetwork>;

/**
* Fetches data about the fungible tokens held by an account.
*/
getFungibleTokensOfAccount(address: IAddress, pagination?: IPagination): Promise<FungibleTokenOfAccountOnNetwork[]>;
getFungibleTokensOfAccount(address: Address, pagination?: IPagination): Promise<FungibleTokenOfAccountOnNetwork[]>;

/**
* Fetches data about the non-fungible tokens held by account.
*/
getNonFungibleTokensOfAccount(
address: IAddress,
address: Address,
pagination?: IPagination,
): Promise<NonFungibleTokenOfAccountOnNetwork[]>;

/**
* Fetches data about a specific fungible token held by an account.
*/
getFungibleTokenOfAccount(address: IAddress, tokenIdentifier: string): Promise<FungibleTokenOfAccountOnNetwork>;
getFungibleTokenOfAccount(address: Address, tokenIdentifier: string): Promise<FungibleTokenOfAccountOnNetwork>;

/**
* Fetches data about a specific non-fungible token (instance) held by an account.
*/
getNonFungibleTokenOfAccount(
address: IAddress,
address: Address,
collection: string,
nonce: number,
): Promise<NonFungibleTokenOfAccountOnNetwork>;
Expand Down Expand Up @@ -124,8 +125,8 @@ export interface INetworkProvider {
}

export interface IContractQuery {
address: IAddress;
caller?: IAddress;
address: Address;
caller?: Address;
func: { toString(): string };
value?: { toString(): string };
getEncodedArguments(): string[];
Expand All @@ -135,7 +136,3 @@ export interface IPagination {
from: number;
size: number;
}

export interface IAddress {
bech32(): string;
}
3 changes: 1 addition & 2 deletions src/networkProviders/pairs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";

export class PairOnNetwork {
address: IAddress = Address.empty();
address: Address = Address.empty();
id: string = "";
symbol: string = "";
name: string = "";
Expand Down
14 changes: 7 additions & 7 deletions src/networkProviders/proxyNetworkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AccountOnNetwork, GuardianData } from "./accounts";
import { defaultAxiosConfig } from "./config";
import { BaseUserAgent } from "./constants";
import { ContractQueryRequest } from "./contractQueryRequest";
import { IAddress, INetworkProvider, IPagination } from "./interface";
import { INetworkProvider, IPagination } from "./interface";
import { NetworkConfig } from "./networkConfig";
import { NetworkGeneralStatistics } from "./networkGeneralStatistics";
import { NetworkProviderConfig } from "./networkProviderConfig";
Expand Down Expand Up @@ -58,20 +58,20 @@ export class ProxyNetworkProvider implements INetworkProvider {
throw new Error("Method not implemented.");
}

async getAccount(address: IAddress): Promise<AccountOnNetwork> {
async getAccount(address: Address): Promise<AccountOnNetwork> {
const response = await this.doGetGeneric(`address/${address.bech32()}`);
const account = AccountOnNetwork.fromHttpResponse(response.account);
return account;
}

async getGuardianData(address: IAddress): Promise<GuardianData> {
async getGuardianData(address: Address): Promise<GuardianData> {
const response = await this.doGetGeneric(`address/${address.bech32()}/guardian-data`);
const accountGuardian = GuardianData.fromHttpResponse(response.guardianData);
return accountGuardian;
}

async getFungibleTokensOfAccount(
address: IAddress,
address: Address,
_pagination?: IPagination,
): Promise<FungibleTokenOfAccountOnNetwork[]> {
const url = `address/${address.bech32()}/esdt`;
Expand All @@ -87,7 +87,7 @@ export class ProxyNetworkProvider implements INetworkProvider {
}

async getNonFungibleTokensOfAccount(
address: IAddress,
address: Address,
_pagination?: IPagination,
): Promise<NonFungibleTokenOfAccountOnNetwork[]> {
const url = `address/${address.bech32()}/esdt`;
Expand All @@ -105,7 +105,7 @@ export class ProxyNetworkProvider implements INetworkProvider {
}

async getFungibleTokenOfAccount(
address: IAddress,
address: Address,
tokenIdentifier: string,
): Promise<FungibleTokenOfAccountOnNetwork> {
const response = await this.doGetGeneric(`address/${address.bech32()}/esdt/${tokenIdentifier}`);
Expand All @@ -114,7 +114,7 @@ export class ProxyNetworkProvider implements INetworkProvider {
}

async getNonFungibleTokenOfAccount(
address: IAddress,
address: Address,
collection: string,
nonce: number,
): Promise<NonFungibleTokenOfAccountOnNetwork> {
Expand Down
5 changes: 2 additions & 3 deletions src/networkProviders/tokenDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";

export class DefinitionOfFungibleTokenOnNetwork {
identifier: string = "";
name: string = "";
ticker: string = "";
owner: IAddress = Address.empty();
owner: Address = Address.empty();
decimals: number = 0;
supply: BigNumber = new BigNumber(0);
isPaused: boolean = false;
Expand Down Expand Up @@ -76,7 +75,7 @@ export class DefinitionOfTokenCollectionOnNetwork {
type: string = "";
name: string = "";
ticker: string = "";
owner: IAddress = Address.empty();
owner: Address = Address.empty();
decimals: number = 0;
canPause: boolean = false;
canFreeze: boolean = false;
Expand Down
3 changes: 1 addition & 2 deletions src/networkProviders/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigNumber } from "bignumber.js";
import { Address } from "../address";
import { numberToPaddedHex } from "../utils.codec";
import { IAddress } from "./interface";

export class FungibleTokenOfAccountOnNetwork {
identifier: string = "";
Expand All @@ -27,7 +26,7 @@ export class NonFungibleTokenOfAccountOnNetwork {
nonce: number = 0;
type: string = "";
name: string = "";
creator: IAddress = Address.empty();
creator: Address = Address.empty();
supply: BigNumber = new BigNumber(0);
decimals: number = 0;
royalties: BigNumber = new BigNumber(0);
Expand Down
3 changes: 1 addition & 2 deletions src/networkProviders/transactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Address } from "../address";
import { IAddress } from "./interface";

export class TransactionReceipt {
value: string = "";
sender: IAddress = Address.empty();
sender: Address = Address.empty();
data: string = "";
hash: string = "";

Expand Down
10 changes: 5 additions & 5 deletions src/testutils/mockNetworkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NetworkStatus,
NonFungibleTokenOfAccountOnNetwork,
} from "../networkProviders";
import { IAddress, INetworkProvider, IPagination } from "../networkProviders/interface";
import { INetworkProvider, IPagination } from "../networkProviders/interface";
import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery";
import { Transaction, TransactionHash } from "../transaction";
import { TransactionOnNetwork } from "../transactionOnNetwork";
Expand Down Expand Up @@ -66,22 +66,22 @@ export class MockNetworkProvider implements INetworkProvider {
throw new Error("Method not implemented.");
}
getFungibleTokensOfAccount(
_address: IAddress,
_address: Address,
_pagination?: IPagination,
): Promise<FungibleTokenOfAccountOnNetwork[]> {
throw new Error("Method not implemented.");
}
getNonFungibleTokensOfAccount(
_address: IAddress,
_address: Address,
_pagination?: IPagination,
): Promise<NonFungibleTokenOfAccountOnNetwork[]> {
throw new Error("Method not implemented.");
}
getFungibleTokenOfAccount(_address: IAddress, _tokenIdentifier: string): Promise<FungibleTokenOfAccountOnNetwork> {
getFungibleTokenOfAccount(_address: Address, _tokenIdentifier: string): Promise<FungibleTokenOfAccountOnNetwork> {
throw new Error("Method not implemented.");
}
getNonFungibleTokenOfAccount(
_address: IAddress,
_address: Address,
_collection: string,
_nonce: number,
): Promise<NonFungibleTokenOfAccountOnNetwork> {
Expand Down
Loading