Skip to content

Commit 10c93ed

Browse files
authored
Merge pull request #504 from multiversx/TOOL-264-bring-sdk-wallet-into-sdk-core-remove-duplicated-code
Remove primitives file
2 parents 6cd9f47 + e0c7db1 commit 10c93ed

16 files changed

+77
-145
lines changed

src/networkProviders/accounts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import BigNumber from "bignumber.js";
2+
import { Address } from "../address";
23
import { IAddress } from "./interface";
3-
import { Address } from "./primitives";
44

55
/**
66
* A plain view of an account, as queried from the Network.
77
*/
88
export class AccountOnNetwork {
9-
address: IAddress = new Address("");
9+
address: IAddress = Address.empty();
1010
nonce: number = 0;
1111
balance: BigNumber = new BigNumber(0);
1212
code: string = "";
@@ -65,7 +65,7 @@ export class GuardianData {
6565

6666
class Guardian {
6767
activationEpoch: number = 0;
68-
address: IAddress = new Address("");
68+
address: IAddress = Address.empty();
6969
serviceUID: string = "";
7070

7171
static fromHttpResponse(responsePart: any): Guardian {

src/networkProviders/apiNetworkProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from "axios";
22
import { ErrContractQuery, ErrNetworkProvider } from "../errors";
3+
import { numberToPaddedHex } from "../utils.codec";
34
import { AccountOnNetwork, GuardianData } from "./accounts";
45
import { defaultAxiosConfig, defaultPagination } from "./config";
56
import { BaseUserAgent } from "./constants";
@@ -12,7 +13,6 @@ import { NetworkProviderConfig } from "./networkProviderConfig";
1213
import { NetworkStake } from "./networkStake";
1314
import { NetworkStatus } from "./networkStatus";
1415
import { PairOnNetwork } from "./pairs";
15-
import { Nonce } from "./primitives";
1616
import { ProxyNetworkProvider } from "./proxyNetworkProvider";
1717
import { DefinitionOfFungibleTokenOnNetwork, DefinitionOfTokenCollectionOnNetwork } from "./tokenDefinitions";
1818
import { FungibleTokenOfAccountOnNetwork, NonFungibleTokenOfAccountOnNetwork } from "./tokens";
@@ -115,7 +115,7 @@ export class ApiNetworkProvider implements INetworkProvider {
115115
collection: string,
116116
nonce: number,
117117
): Promise<NonFungibleTokenOfAccountOnNetwork> {
118-
const nonceAsHex = new Nonce(nonce).hex();
118+
const nonceAsHex = numberToPaddedHex(nonce);
119119
const response = await this.doGetGeneric(`accounts/${address.bech32()}/nfts/${collection}-${nonceAsHex}`);
120120
const tokenData = NonFungibleTokenOfAccountOnNetwork.fromApiHttpResponse(response);
121121
return tokenData;
@@ -181,7 +181,7 @@ export class ApiNetworkProvider implements INetworkProvider {
181181
}
182182

183183
async getNonFungibleToken(collection: string, nonce: number): Promise<NonFungibleTokenOfAccountOnNetwork> {
184-
const nonceAsHex = new Nonce(nonce).hex();
184+
const nonceAsHex = numberToPaddedHex(nonce);
185185
const response = await this.doGetGeneric(`nfts/${collection}-${nonceAsHex}`);
186186
const token = NonFungibleTokenOfAccountOnNetwork.fromApiHttpResponse(response);
187187
return token;

src/networkProviders/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BigNumber from "bignumber.js";
2-
import { Address } from "./primitives";
2+
import { Address } from "../address";
33

44
export const MaxUint64AsBigNumber = new BigNumber("18446744073709551615");
55
export const EsdtContractAddress = new Address("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u");
6-
export const BaseUserAgent = "multiversx-sdk"
7-
export const UnknownClientName = "unknown"
6+
export const BaseUserAgent = "multiversx-sdk";
7+
export const UnknownClientName = "unknown";

src/networkProviders/contractResults.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Address } from "../address";
12
import { IAddress } from "./interface";
23
import { TransactionLogs } from "./transactionLogs";
3-
import { Address } from "./primitives";
44

55
export class ContractResults {
66
readonly items: ContractResultItem[];
@@ -14,12 +14,12 @@ export class ContractResults {
1414
}
1515

1616
static fromProxyHttpResponse(results: any[]): ContractResults {
17-
let items = results.map(item => ContractResultItem.fromProxyHttpResponse(item));
17+
let items = results.map((item) => ContractResultItem.fromProxyHttpResponse(item));
1818
return new ContractResults(items);
1919
}
2020

2121
static fromApiHttpResponse(results: any[]): ContractResults {
22-
let items = results.map(item => ContractResultItem.fromApiHttpResponse(item));
22+
let items = results.map((item) => ContractResultItem.fromApiHttpResponse(item));
2323
return new ContractResults(items);
2424
}
2525
}
@@ -28,8 +28,8 @@ export class ContractResultItem {
2828
hash: string = "";
2929
nonce: number = 0;
3030
value: string = "";
31-
receiver: IAddress = new Address("");
32-
sender: IAddress = new Address("");
31+
receiver: IAddress = Address.empty();
32+
sender: IAddress = Address.empty();
3333
data: string = "";
3434
previousHash: string = "";
3535
originalHash: string = "";

src/networkProviders/pairs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Address} from "./primitives";
2-
import {IAddress} from "./interface";
31
import BigNumber from "bignumber.js";
2+
import { Address } from "../address";
3+
import { IAddress } from "./interface";
44

55
export class PairOnNetwork {
6-
address: IAddress = new Address("");
6+
address: IAddress = Address.empty();
77
id: string = "";
88
symbol: string = "";
99
name: string = "";

src/networkProviders/primitives.spec.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/networkProviders/primitives.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/networkProviders/providers.dev.net.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AxiosHeaders } from "axios";
22
import { assert } from "chai";
3+
import { Address } from "../address";
4+
import { MockQuery } from "../testutils/dummyQuery";
35
import { ApiNetworkProvider } from "./apiNetworkProvider";
46
import { INetworkProvider, ITransactionNext } from "./interface";
5-
import { Address } from "./primitives";
67
import { ProxyNetworkProvider } from "./proxyNetworkProvider";
78
import { NonFungibleTokenOfAccountOnNetwork } from "./tokens";
89
import { TransactionEventData } from "./transactionEvents";
910
import { TransactionOnNetwork } from "./transactions";
10-
import { MockQuery } from "../testutils/dummyQuery";
1111

1212
describe("test network providers on devnet: Proxy and API", function () {
1313
let alice = new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");

src/networkProviders/tokenDefinitions.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import BigNumber from "bignumber.js";
2+
import { Address } from "../address";
23
import { IAddress } from "./interface";
3-
import { Address } from "./primitives";
44

55
export class DefinitionOfFungibleTokenOnNetwork {
66
identifier: string = "";
77
name: string = "";
88
ticker: string = "";
9-
owner: IAddress = new Address("");
9+
owner: IAddress = Address.empty();
1010
decimals: number = 0;
1111
supply: BigNumber = new BigNumber(0);
1212
isPaused: boolean = false;
@@ -55,7 +55,7 @@ export class DefinitionOfFungibleTokenOnNetwork {
5555
result.identifier = identifier;
5656
result.name = tokenName.toString();
5757
result.ticker = identifier;
58-
result.owner = Address.fromPubkey(owner);
58+
result.owner = new Address(owner);
5959
result.decimals = properties.NumDecimals.toNumber();
6060
result.supply = new BigNumber(supply.toString()).shiftedBy(-result.decimals);
6161
result.isPaused = properties.IsPaused;
@@ -76,7 +76,7 @@ export class DefinitionOfTokenCollectionOnNetwork {
7676
type: string = "";
7777
name: string = "";
7878
ticker: string = "";
79-
owner: IAddress = new Address("");
79+
owner: IAddress = Address.empty();
8080
decimals: number = 0;
8181
canPause: boolean = false;
8282
canFreeze: boolean = false;
@@ -120,7 +120,7 @@ export class DefinitionOfTokenCollectionOnNetwork {
120120
result.type = tokenType.toString();
121121
result.name = tokenName.toString();
122122
result.ticker = collection;
123-
result.owner = Address.fromPubkey(owner);
123+
result.owner = new Address(owner);
124124
result.decimals = properties.NumDecimals.toNumber() ?? 0;
125125
result.canPause = properties.CanPause || false;
126126
result.canFreeze = properties.CanFreeze || false;
@@ -150,8 +150,11 @@ function parseTokenProperties(propertiesBuffers: Buffer[]): Record<string, any>
150150
// This only handles booleans and numbers.
151151
function parseValueOfTokenProperty(value: string): any {
152152
switch (value) {
153-
case "true": return true;
154-
case "false": return false;
155-
default: return new BigNumber(value);
153+
case "true":
154+
return true;
155+
case "false":
156+
return false;
157+
default:
158+
return new BigNumber(value);
156159
}
157160
}

src/networkProviders/tokens.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BigNumber } from "bignumber.js";
2-
import { Address, Nonce } from "./primitives";
2+
import { Address } from "../address";
3+
import { numberToPaddedHex } from "../utils.codec";
34
import { IAddress } from "./interface";
45

56
export class FungibleTokenOfAccountOnNetwork {
@@ -26,7 +27,7 @@ export class NonFungibleTokenOfAccountOnNetwork {
2627
nonce: number = 0;
2728
type: string = "";
2829
name: string = "";
29-
creator: IAddress = new Address("");
30+
creator: IAddress = Address.empty();
3031
supply: BigNumber = new BigNumber(0);
3132
decimals: number = 0;
3233
royalties: BigNumber = new BigNumber(0);
@@ -49,7 +50,7 @@ export class NonFungibleTokenOfAccountOnNetwork {
4950

5051
static fromProxyHttpResponseByNonce(payload: any): NonFungibleTokenOfAccountOnNetwork {
5152
let result = NonFungibleTokenOfAccountOnNetwork.fromHttpResponse(payload);
52-
let nonceAsHex = new Nonce(result.nonce).hex();
53+
let nonceAsHex = numberToPaddedHex(result.nonce);
5354

5455
result.identifier = `${payload.tokenIdentifier}-${nonceAsHex}`;
5556
result.collection = payload.tokenIdentifier || "";

0 commit comments

Comments
 (0)