Skip to content

Commit

Permalink
Merge pull request #488 from multiversx/feat/unify
Browse files Browse the repository at this point in the history
Add Network provider sdk into sdk-core js
  • Loading branch information
danielailie authored Oct 2, 2024
2 parents dbe49e2 + ef3db11 commit 04b3b4b
Show file tree
Hide file tree
Showing 43 changed files with 2,565 additions and 86 deletions.
70 changes: 21 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "13.6.3",
"version": "13.7.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"author": "MultiversX",
"homepage": "https://multiversx.com",
Expand Down Expand Up @@ -44,14 +44,12 @@
"keccak": "3.0.2"
},
"devDependencies": {
"@multiversx/sdk-network-providers": "2.6.0",
"@multiversx/sdk-wallet": "4.5.1",
"@types/assert": "1.4.6",
"@types/chai": "4.2.11",
"@types/mocha": "9.1.0",
"@types/node": "13.13.2",
"assert": "2.0.0",
"axios": "^1.7.4",
"browserify": "17.0.0",
"chai": "4.2.0",
"mocha": "9.2.2",
Expand All @@ -66,6 +64,7 @@
},
"peerDependencies": {
"bignumber.js": "^9.0.1",
"protobufjs": "^7.2.6"
"protobufjs": "^7.2.6",
"axios": "^1.7.4"
}
}
6 changes: 3 additions & 3 deletions src/converters/transactionsConverters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
ContractResultItem,
ContractResults,
TransactionEventData,
TransactionEvent as TransactionEventOnNetwork,
TransactionEventOnNetwork,
TransactionEventTopic,
TransactionLogs as TransactionLogsOnNetwork,
TransactionLogsOnNetwork,
TransactionOnNetwork,
} from "@multiversx/sdk-network-providers";
} from "../networkProviders";
import { assert } from "chai";
import { Address } from "../address";
import { Transaction } from "../transaction";
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export * from "./transactionWatcher";
export * from "./transactionsFactories";
export * from "./transactionsOutcomeParsers";
export * from "./utils";
export * from "./networkProviders";
80 changes: 80 additions & 0 deletions src/networkProviders/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import BigNumber from "bignumber.js";
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("");
nonce: number = 0;
balance: BigNumber = new BigNumber(0);
code: string = "";
userName: string = "";

constructor(init?: Partial<AccountOnNetwork>) {
Object.assign(this, init);
}

static fromHttpResponse(payload: any): AccountOnNetwork {
let result = new AccountOnNetwork();

result.address = new Address(payload["address"] || "");
result.nonce = Number(payload["nonce"] || 0);
result.balance = new BigNumber(payload["balance"] || 0);
result.code = payload["code"] || "";
result.userName = payload["username"] || "";

return result;
}
}

export class GuardianData {
guarded: boolean = false;
activeGuardian?: Guardian;
pendingGuardian?: Guardian;

constructor(init?: Partial<GuardianData>) {
Object.assign(this, init);
}

static fromHttpResponse(response: any): GuardianData {
const result = new GuardianData();

result.guarded = response["guarded"] || false;

if (response["activeGuardian"]) {
result.activeGuardian = Guardian.fromHttpResponse(response["activeGuardian"]);
}

if (response["pendingGuardian"]) {
result.pendingGuardian = Guardian.fromHttpResponse(response["pendingGuardian"]);
}

return result;
}

getCurrentGuardianAddress(): IAddress | undefined {
if (!this.guarded) {
return undefined;
}

return this.activeGuardian?.address;
}
}

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

static fromHttpResponse(responsePart: any): Guardian {
const result = new Guardian();

result.activationEpoch = Number(responsePart["activationEpoch"] || 0);
result.address = new Address(responsePart["address"] || "");
result.serviceUID = responsePart["serviceUID"] || "";

return result;
}
}
Loading

0 comments on commit 04b3b4b

Please sign in to comment.