Skip to content
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
6 changes: 3 additions & 3 deletions src/networkProviders/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";
import { Address } from "./primitives";

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

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

static fromHttpResponse(responsePart: any): Guardian {
Expand Down
6 changes: 3 additions & 3 deletions src/networkProviders/apiNetworkProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import { ErrContractQuery, ErrNetworkProvider } from "../errors";
import { numberToPaddedHex } from "../utils.codec";
import { AccountOnNetwork, GuardianData } from "./accounts";
import { defaultAxiosConfig, defaultPagination } from "./config";
import { BaseUserAgent } from "./constants";
Expand All @@ -12,7 +13,6 @@ import { NetworkProviderConfig } from "./networkProviderConfig";
import { NetworkStake } from "./networkStake";
import { NetworkStatus } from "./networkStatus";
import { PairOnNetwork } from "./pairs";
import { Nonce } from "./primitives";
import { ProxyNetworkProvider } from "./proxyNetworkProvider";
import { DefinitionOfFungibleTokenOnNetwork, DefinitionOfTokenCollectionOnNetwork } from "./tokenDefinitions";
import { FungibleTokenOfAccountOnNetwork, NonFungibleTokenOfAccountOnNetwork } from "./tokens";
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ApiNetworkProvider implements INetworkProvider {
collection: string,
nonce: number,
): Promise<NonFungibleTokenOfAccountOnNetwork> {
const nonceAsHex = new Nonce(nonce).hex();
const nonceAsHex = numberToPaddedHex(nonce);
const response = await this.doGetGeneric(`accounts/${address.bech32()}/nfts/${collection}-${nonceAsHex}`);
const tokenData = NonFungibleTokenOfAccountOnNetwork.fromApiHttpResponse(response);
return tokenData;
Expand Down Expand Up @@ -181,7 +181,7 @@ export class ApiNetworkProvider implements INetworkProvider {
}

async getNonFungibleToken(collection: string, nonce: number): Promise<NonFungibleTokenOfAccountOnNetwork> {
const nonceAsHex = new Nonce(nonce).hex();
const nonceAsHex = numberToPaddedHex(nonce);
const response = await this.doGetGeneric(`nfts/${collection}-${nonceAsHex}`);
const token = NonFungibleTokenOfAccountOnNetwork.fromApiHttpResponse(response);
return token;
Expand Down
6 changes: 3 additions & 3 deletions src/networkProviders/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from "bignumber.js";
import { Address } from "./primitives";
import { Address } from "../address";

export const MaxUint64AsBigNumber = new BigNumber("18446744073709551615");
export const EsdtContractAddress = new Address("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u");
export const BaseUserAgent = "multiversx-sdk"
export const UnknownClientName = "unknown"
export const BaseUserAgent = "multiversx-sdk";
export const UnknownClientName = "unknown";
10 changes: 5 additions & 5 deletions src/networkProviders/contractResults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from "../address";
import { IAddress } from "./interface";
import { TransactionLogs } from "./transactionLogs";
import { Address } from "./primitives";

export class ContractResults {
readonly items: ContractResultItem[];
Expand All @@ -14,12 +14,12 @@ export class ContractResults {
}

static fromProxyHttpResponse(results: any[]): ContractResults {
let items = results.map(item => ContractResultItem.fromProxyHttpResponse(item));
let items = results.map((item) => ContractResultItem.fromProxyHttpResponse(item));
return new ContractResults(items);
}

static fromApiHttpResponse(results: any[]): ContractResults {
let items = results.map(item => ContractResultItem.fromApiHttpResponse(item));
let items = results.map((item) => ContractResultItem.fromApiHttpResponse(item));
return new ContractResults(items);
}
}
Expand All @@ -28,8 +28,8 @@ export class ContractResultItem {
hash: string = "";
nonce: number = 0;
value: string = "";
receiver: IAddress = new Address("");
sender: IAddress = new Address("");
receiver: IAddress = Address.empty();
sender: IAddress = Address.empty();
data: string = "";
previousHash: string = "";
originalHash: string = "";
Expand Down
6 changes: 3 additions & 3 deletions src/networkProviders/pairs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Address} from "./primitives";
import {IAddress} from "./interface";
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";

export class PairOnNetwork {
address: IAddress = new Address("");
address: IAddress = Address.empty();
id: string = "";
symbol: string = "";
name: string = "";
Expand Down
17 changes: 0 additions & 17 deletions src/networkProviders/primitives.spec.ts

This file was deleted.

66 changes: 0 additions & 66 deletions src/networkProviders/primitives.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/networkProviders/providers.dev.net.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AxiosHeaders } from "axios";
import { assert } from "chai";
import { Address } from "../address";
import { MockQuery } from "../testutils/dummyQuery";
import { ApiNetworkProvider } from "./apiNetworkProvider";
import { INetworkProvider, ITransactionNext } from "./interface";
import { Address } from "./primitives";
import { ProxyNetworkProvider } from "./proxyNetworkProvider";
import { NonFungibleTokenOfAccountOnNetwork } from "./tokens";
import { TransactionEventData } from "./transactionEvents";
import { TransactionOnNetwork } from "./transactions";
import { MockQuery } from "../testutils/dummyQuery";

describe("test network providers on devnet: Proxy and API", function () {
let alice = new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
Expand Down
19 changes: 11 additions & 8 deletions src/networkProviders/tokenDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import BigNumber from "bignumber.js";
import { Address } from "../address";
import { IAddress } from "./interface";
import { Address } from "./primitives";

export class DefinitionOfFungibleTokenOnNetwork {
identifier: string = "";
name: string = "";
ticker: string = "";
owner: IAddress = new Address("");
owner: IAddress = Address.empty();
decimals: number = 0;
supply: BigNumber = new BigNumber(0);
isPaused: boolean = false;
Expand Down Expand Up @@ -55,7 +55,7 @@ export class DefinitionOfFungibleTokenOnNetwork {
result.identifier = identifier;
result.name = tokenName.toString();
result.ticker = identifier;
result.owner = Address.fromPubkey(owner);
result.owner = new Address(owner);
result.decimals = properties.NumDecimals.toNumber();
result.supply = new BigNumber(supply.toString()).shiftedBy(-result.decimals);
result.isPaused = properties.IsPaused;
Expand All @@ -76,7 +76,7 @@ export class DefinitionOfTokenCollectionOnNetwork {
type: string = "";
name: string = "";
ticker: string = "";
owner: IAddress = new Address("");
owner: IAddress = Address.empty();
decimals: number = 0;
canPause: boolean = false;
canFreeze: boolean = false;
Expand Down Expand Up @@ -120,7 +120,7 @@ export class DefinitionOfTokenCollectionOnNetwork {
result.type = tokenType.toString();
result.name = tokenName.toString();
result.ticker = collection;
result.owner = Address.fromPubkey(owner);
result.owner = new Address(owner);
result.decimals = properties.NumDecimals.toNumber() ?? 0;
result.canPause = properties.CanPause || false;
result.canFreeze = properties.CanFreeze || false;
Expand Down Expand Up @@ -150,8 +150,11 @@ function parseTokenProperties(propertiesBuffers: Buffer[]): Record<string, any>
// This only handles booleans and numbers.
function parseValueOfTokenProperty(value: string): any {
switch (value) {
case "true": return true;
case "false": return false;
default: return new BigNumber(value);
case "true":
return true;
case "false":
return false;
default:
return new BigNumber(value);
}
}
7 changes: 4 additions & 3 deletions src/networkProviders/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumber } from "bignumber.js";
import { Address, Nonce } from "./primitives";
import { Address } from "../address";
import { numberToPaddedHex } from "../utils.codec";
import { IAddress } from "./interface";

export class FungibleTokenOfAccountOnNetwork {
Expand All @@ -26,7 +27,7 @@ export class NonFungibleTokenOfAccountOnNetwork {
nonce: number = 0;
type: string = "";
name: string = "";
creator: IAddress = new Address("");
creator: IAddress = Address.empty();
supply: BigNumber = new BigNumber(0);
decimals: number = 0;
royalties: BigNumber = new BigNumber(0);
Expand All @@ -49,7 +50,7 @@ export class NonFungibleTokenOfAccountOnNetwork {

static fromProxyHttpResponseByNonce(payload: any): NonFungibleTokenOfAccountOnNetwork {
let result = NonFungibleTokenOfAccountOnNetwork.fromHttpResponse(payload);
let nonceAsHex = new Nonce(result.nonce).hex();
let nonceAsHex = numberToPaddedHex(result.nonce);

result.identifier = `${payload.tokenIdentifier}-${nonceAsHex}`;
result.collection = payload.tokenIdentifier || "";
Expand Down
18 changes: 9 additions & 9 deletions src/networkProviders/transactionEvents.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address } from "../address";
import { IAddress } from "./interface";
import { Address } from "./primitives";

export class TransactionEvent {
address: IAddress = new Address("");
address: IAddress = Address.empty();
identifier: string = "";
topics: TransactionEventTopic[] = [];

Expand All @@ -18,16 +18,16 @@ export class TransactionEvent {
}

static fromHttpResponse(responsePart: {
address: string,
identifier: string,
topics: string[],
data: string,
additionalData?: string[]
address: string;
identifier: string;
topics: string[];
data: string;
additionalData?: string[];
}): TransactionEvent {
let result = new TransactionEvent();
result.address = new Address(responsePart.address);
result.identifier = responsePart.identifier || "";
result.topics = (responsePart.topics || []).map(topic => new TransactionEventTopic(topic));
result.topics = (responsePart.topics || []).map((topic) => new TransactionEventTopic(topic));

result.dataPayload = TransactionEventData.fromBase64(responsePart.data);
result.additionalData = (responsePart.additionalData || []).map(TransactionEventData.fromBase64);
Expand All @@ -37,7 +37,7 @@ export class TransactionEvent {
}

findFirstOrNoneTopic(predicate: (topic: TransactionEventTopic) => boolean): TransactionEventTopic | undefined {
return this.topics.filter(topic => predicate(topic))[0];
return this.topics.filter((topic) => predicate(topic))[0];
}

getLastTopic(): TransactionEventTopic {
Expand Down
4 changes: 2 additions & 2 deletions src/networkProviders/transactionLogs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address } from "../address";
import { ErrUnexpectedCondition } from "./../errors";
import { IAddress } from "./interface";
import { Address } from "./primitives";
import { TransactionEvent } from "./transactionEvents";

export class TransactionLogs {
address: IAddress = new Address("");
address: IAddress = Address.empty();
events: TransactionEvent[] = [];

constructor(init?: Partial<TransactionLogs>) {
Expand Down
12 changes: 6 additions & 6 deletions src/networkProviders/transactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Address } from "../address";
import { IAddress } from "./interface";
import { Address } from "./primitives";

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

static fromHttpResponse(response: {
value: string,
sender: string,
data: string,
txHash: string
value: string;
sender: string;
data: string;
txHash: string;
}): TransactionReceipt {
let receipt = new TransactionReceipt();

Expand Down
Loading
Loading