From 5ec7c02d4caf33627fededb691480f4099ed00ff Mon Sep 17 00:00:00 2001 From: andreyvEze Date: Fri, 6 Aug 2021 00:36:45 +0300 Subject: [PATCH 1/2] Change baseUrl be unique per FIOSDK instance --- lib/FIOSDK.js | 77 ++++++++++---------- lib/transactions/Transactions.js | 9 ++- lib/transactions/queries/Query.js | 3 +- lib/transactions/signed/SignedTransaction.js | 3 +- src/FIOSDK.ts | 77 ++++++++++---------- src/transactions/Transactions.ts | 10 +-- src/transactions/queries/Query.ts | 3 +- src/transactions/signed/SignedTransaction.ts | 3 +- 8 files changed, 96 insertions(+), 89 deletions(-) diff --git a/lib/FIOSDK.js b/lib/FIOSDK.js index eaa29eb9..1ca8aa83 100644 --- a/lib/FIOSDK.js +++ b/lib/FIOSDK.js @@ -42,12 +42,13 @@ class FIOSDK { * @param technologyProviderId Default FIO Address of the wallet which generates transactions. */ constructor(privateKey, publicKey, baseUrl, fetchjson, registerMockUrl = '', technologyProviderId = '', returnPreparedTrx = false) { + this.baseUrl = ''; /** * Defines whether SignedTransaction would execute or return prepared transaction */ this.returnPreparedTrx = false; this.transactions = new Transactions_1.Transactions(); - Transactions_1.Transactions.baseUrl = baseUrl; + this.baseUrl = baseUrl; Transactions_1.Transactions.FioProvider = fiojs_1.Fio; Transactions_1.Transactions.fetchJson = fetchjson; this.registerMockUrl = registerMockUrl; @@ -271,7 +272,7 @@ class FIOSDK { */ registerFioAddress(fioAddress, maxFee, technologyProviderId = null) { const registerFioAddress = new SignedTransactions.RegisterFioAddress(fioAddress, null, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a Fio Address on behalf of the owner FIO Public key parameter. Owner FIO Public key owns the FIO address @@ -283,7 +284,7 @@ class FIOSDK { */ registerOwnerFioAddress(fioAddress, ownerPublicKey, maxFee, technologyProviderId = null) { const registerFioAddress = new SignedTransactions.RegisterFioAddress(fioAddress, ownerPublicKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a FIO Domain on the FIO blockchain. @@ -294,7 +295,7 @@ class FIOSDK { */ registerFioDomain(fioDomain, maxFee, technologyProviderId = null) { const registerFioDomain = new SignedTransactions.RegisterFioDomain(fioDomain, null, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a FIO Domain on behalf of the owner FIO Public key parameter. Owner FIO Public key owns the FIO domain. @@ -306,7 +307,7 @@ class FIOSDK { */ registerOwnerFioDomain(fioDomain, ownerPublicKey, maxFee, technologyProviderId = null) { const registerFioDomain = new SignedTransactions.RegisterFioDomain(fioDomain, ownerPublicKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Burns a FIO Address on the FIO blockchain. @@ -317,7 +318,7 @@ class FIOSDK { */ burnFioAddress(fioAddress, maxFee, technologyProviderId = null) { const burnFioAddress = new SignedTransactions.BurnFioAddress(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return burnFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return burnFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Transfers a FIO Domain on the FIO blockchain. @@ -329,7 +330,7 @@ class FIOSDK { */ transferFioDomain(fioDomain, newOwnerKey, maxFee, technologyProviderId = null) { const transferFioDomain = new SignedTransactions.TransferFioDomain(fioDomain, newOwnerKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Transfers a FIO Address on the FIO blockchain. @@ -341,7 +342,7 @@ class FIOSDK { */ transferFioAddress(fioAddress, newOwnerKey, maxFee, technologyProviderId = null) { const transferFioAddress = new SignedTransactions.TransferFioAddress(fioAddress, newOwnerKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Adds bundles of transactions to FIO Address. @@ -353,7 +354,7 @@ class FIOSDK { */ addBundledTransactions(fioAddress, bundleSets, maxFee, technologyProviderId = null) { const addBundledTransactions = new SignedTransactions.AddBundledTransactions(fioAddress, bundleSets, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addBundledTransactions.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return addBundledTransactions.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Renew a FIO Address on the FIO blockchain. @@ -364,7 +365,7 @@ class FIOSDK { */ renewFioAddress(fioAddress, maxFee, technologyProviderId = null) { const renewFioAddress = new SignedTransactions.RenewFioAddress(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return renewFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return renewFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Renew a FIO Domain on the FIO blockchain. @@ -375,7 +376,7 @@ class FIOSDK { */ renewFioDomain(fioDomain, maxFee, technologyProviderId = null) { const renewFioDomain = new SignedTransactions.RenewFioDomain(fioDomain, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return renewFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return renewFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a public address of the specific blockchain type to be added to the FIO Address. @@ -393,7 +394,7 @@ class FIOSDK { token_code: tokenCode, public_address: publicAddress }], maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addPublicAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call cancels the specified fio funds request.. @@ -404,7 +405,7 @@ class FIOSDK { */ cancelFundsRequest(fioRequestId, maxFee, technologyProviderId = null) { const cancelFundsRequest = new SignedTransactions.CancelFundsRequest(fioRequestId, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return cancelFundsRequest.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return cancelFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a any number of public addresses matching the blockchain code, the token code and the public address to be removed from the FIO Address. @@ -416,7 +417,7 @@ class FIOSDK { */ removePublicAddresses(fioAddress, publicAddresses, maxFee, technologyProviderId = null) { const removePublicAddresses = new SignedTransactions.RemovePublicAddresses(fioAddress, publicAddresses, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return removePublicAddresses.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return removePublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a user to transfer locked tokens to the specified fio public key @@ -430,7 +431,7 @@ class FIOSDK { */ transferLockedTokens(payeePublicKey, canVote, periods, amount, maxFee, technologyProviderId = null) { const transferLockedTokens = new SignedTransactions.TransferLockedTokens(payeePublicKey, canVote, periods, amount, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferLockedTokens.execute(this.privateKey, this.publicKey); + return transferLockedTokens.execute(this.baseUrl, this.privateKey, this.publicKey); } /** * This call allows a user to remove all addresses from the specified FIO Address, all addresses except the FIO address will be removed. @@ -441,7 +442,7 @@ class FIOSDK { */ removeAllPublicAddresses(fioAddress, maxFee, technologyProviderId = null) { const removeAllPublicAddresses = new SignedTransactions.RemoveAllPublicAddresses(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return removeAllPublicAddresses.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return removeAllPublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a public addresses of the specific blockchain type to be added to the FIO Address. @@ -453,7 +454,7 @@ class FIOSDK { */ addPublicAddresses(fioAddress, publicAddresses, maxFee, technologyProviderId = null) { const addPublicAddress = new SignedTransactions.AddPublicAddress(fioAddress, publicAddresses, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addPublicAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * By default all FIO Domains are non-public, meaning only the owner can register FIO Addresses on that domain. Setting them to public allows anyone to register a FIO Address on that domain. @@ -465,7 +466,7 @@ class FIOSDK { */ setFioDomainVisibility(fioDomain, isPublic, maxFee, technologyProviderId = null) { const SetFioDomainVisibility = new SignedTransactions.SetFioDomainVisibility(fioDomain, isPublic, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return SetFioDomainVisibility.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return SetFioDomainVisibility.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * @@ -499,7 +500,7 @@ class FIOSDK { payeeKey.public_address = payeeFioPublicKey; } const recordObtData = new SignedTransactions.RecordObtData(fioRequestId, payerFioAddress, payeeFioAddress, payerTokenPublicAddress, payeeTokenPublicAddress, amount, chainCode, tokenCode, obtId, maxFee, status, this.getTechnologyProviderId(technologyProviderId), payeeKey.public_address, memo, hash, offLineUrl); - return recordObtData.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return recordObtData.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); }); } /** @@ -511,7 +512,7 @@ class FIOSDK { */ getObtData(limit, offset, tokenCode) { const getObtDataRequest = new queries.GetObtData(this.publicKey, limit, offset, tokenCode); - return getObtDataRequest.execute(this.publicKey, this.privateKey); + return getObtDataRequest.execute(this.baseUrl, this.publicKey, this.privateKey); } /** * Reject funds request. @@ -522,7 +523,7 @@ class FIOSDK { */ rejectFundsRequest(fioRequestId, maxFee, technologyProviderId = null) { const rejectFundsRequest = new SignedTransactions.RejectFundsRequest(fioRequestId, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return rejectFundsRequest.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return rejectFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Create a new funds request on the FIO chain. @@ -550,7 +551,7 @@ class FIOSDK { payerKey.public_address = payerFioPublicKey; } const requestNewFunds = new SignedTransactions.RequestNewFunds(payerFioAddress, payerKey.public_address, payeeFioAddress, this.getTechnologyProviderId(technologyProviderId), maxFee, payeeTokenPublicAddress, amount, chainCode, tokenCode, memo, hash, offlineUrl); - return requestNewFunds.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return requestNewFunds.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); }); } /** @@ -560,7 +561,7 @@ class FIOSDK { */ getLocks(fioPublicKey) { const getLocks = new queries.GetLocks(fioPublicKey); - return getLocks.execute(this.publicKey); + return getLocks.execute(this.baseUrl, this.publicKey); } /* * Retrieves info on account for this actor @@ -569,7 +570,7 @@ class FIOSDK { */ getAccount(actor) { const getAccount = new queries.GetAccount(actor); - return getAccount.execute(this.publicKey); + return getAccount.execute(this.baseUrl, this.publicKey); } /** * Checks if a FIO Address or FIO Domain is available for registration. @@ -578,7 +579,7 @@ class FIOSDK { */ isAvailable(fioName) { const availabilityCheck = new queries.AvailabilityCheck(fioName); - return availabilityCheck.execute(this.publicKey); + return availabilityCheck.execute(this.baseUrl, this.publicKey); } /** * Retrieves balance of FIO tokens @@ -587,7 +588,7 @@ class FIOSDK { */ getFioBalance(fioPublicKey) { const getFioBalance = new queries.GetFioBalance(fioPublicKey); - return getFioBalance.execute(this.publicKey); + return getFioBalance.execute(this.baseUrl, this.publicKey); } /** * Returns FIO Addresses and FIO Domains owned by this public key. @@ -596,7 +597,7 @@ class FIOSDK { */ getFioNames(fioPublicKey) { const getNames = new queries.GetNames(fioPublicKey); - return getNames.execute(this.publicKey); + return getNames.execute(this.baseUrl, this.publicKey); } /** * Returns FIO Addresses owned by this public key. @@ -607,7 +608,7 @@ class FIOSDK { */ getFioAddresses(fioPublicKey, limit, offset) { const getNames = new queries.GetAddresses(fioPublicKey, limit, offset); - return getNames.execute(this.publicKey); + return getNames.execute(this.baseUrl, this.publicKey); } /** * Returns FIO domains owned by this public key. @@ -618,7 +619,7 @@ class FIOSDK { */ getFioDomains(fioPublicKey, limit, offset) { const getNames = new queries.GetDomains(fioPublicKey, limit, offset); - return getNames.execute(this.publicKey); + return getNames.execute(this.baseUrl, this.publicKey); } /** * Polls for any pending requests sent to public key associated with the FIO SDK instance. @@ -628,7 +629,7 @@ class FIOSDK { */ getPendingFioRequests(limit, offset) { const pendingFioRequests = new queries.PendingFioRequests(this.publicKey, limit, offset); - return pendingFioRequests.execute(this.publicKey, this.privateKey); + return pendingFioRequests.execute(this.baseUrl, this.publicKey, this.privateKey); } /** * Polls for any sent requests sent by public key associated with the FIO SDK instance. @@ -638,7 +639,7 @@ class FIOSDK { */ getSentFioRequests(limit, offset) { const sentFioRequest = new queries.SentFioRequests(this.publicKey, limit, offset); - return sentFioRequest.execute(this.publicKey, this.privateKey); + return sentFioRequest.execute(this.baseUrl, this.publicKey, this.privateKey); } /** * Polls for any cancelled requests sent by public key associated with the FIO SDK instance. @@ -648,7 +649,7 @@ class FIOSDK { */ getCancelledFioRequests(limit, offset) { const cancelledFioRequest = new queries.CancelledFioRequests(this.publicKey, limit, offset); - return cancelledFioRequest.execute(this.publicKey, this.privateKey); + return cancelledFioRequest.execute(this.baseUrl, this.publicKey, this.privateKey); } /** * Returns a token public address for specified token code and FIO Address. @@ -659,7 +660,7 @@ class FIOSDK { */ getPublicAddress(fioAddress, chainCode, tokenCode) { const publicAddressLookUp = new queries.GetPublicAddress(fioAddress, chainCode, tokenCode); - return publicAddressLookUp.execute(this.publicKey); + return publicAddressLookUp.execute(this.baseUrl, this.publicKey); } /** * Returns all public addresses for specified FIO Address. @@ -670,7 +671,7 @@ class FIOSDK { */ getPublicAddresses(fioAddress, limit, offset) { const publicAddressesLookUp = new queries.GetPublicAddresses(fioAddress, limit, offset); - return publicAddressesLookUp.execute(this.publicKey); + return publicAddressesLookUp.execute(this.baseUrl, this.publicKey); } /** * Returns the FIO token public address for specified FIO Address. @@ -692,7 +693,7 @@ class FIOSDK { */ transferTokens(payeeFioPublicKey, amount, maxFee, technologyProviderId = null) { const transferTokens = new SignedTransactions.TransferTokens(payeeFioPublicKey, amount, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferTokens.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferTokens.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Compute and return fee amount for specific call and specific user @@ -718,7 +719,7 @@ class FIOSDK { */ getFee(endPoint, fioAddress = '') { const fioFee = new queries.GetFee(endPoint, fioAddress); - return fioFee.execute(this.publicKey); + return fioFee.execute(this.baseUrl, this.publicKey); } /** * Compute and return fee amount for specific call and specific user @@ -832,7 +833,7 @@ class FIOSDK { pushTransaction(account, action, data) { data.tpid = this.getTechnologyProviderId(data.tpid); const pushTransaction = new SignedTransactions.PushTransaction(action, account, data); - return pushTransaction.execute(this.privateKey, this.publicKey, this.returnPreparedTrx); + return pushTransaction.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * @ignore @@ -956,7 +957,7 @@ class FIOSDK { */ getAbi(accountName) { const abi = new queries.GetAbi(accountName); - return abi.execute(this.publicKey); + return abi.execute(this.baseUrl, this.publicKey); } } exports.FIOSDK = FIOSDK; diff --git a/lib/transactions/Transactions.js b/lib/transactions/Transactions.js index cf9b05b9..37799347 100644 --- a/lib/transactions/Transactions.js +++ b/lib/transactions/Transactions.js @@ -18,6 +18,7 @@ const textEncoder = new text_encoding_1.TextEncoder(); const textDecoder = new text_encoding_1.TextDecoder(); class Transactions { constructor() { + this.baseUrl = ''; this.publicKey = ''; this.privateKey = ''; this.serilizeEndpoint = 'chain/serialize_json'; @@ -37,7 +38,7 @@ class Transactions { 'Content-Type': 'application/json', }, }; - const res = yield Transactions.fetchJson(Transactions.baseUrl + 'chain/get_info', options); + const res = yield Transactions.fetchJson(this.baseUrl + 'chain/get_info', options); return yield res.json(); }); } @@ -49,7 +50,7 @@ class Transactions { if (chain.last_irreversible_block_num == undefined) { throw new Error('chain.last_irreversible_block_num undefined'); } - const res = yield Transactions.fetchJson(Transactions.baseUrl + 'chain/get_block', { + const res = yield Transactions.fetchJson(this.baseUrl + 'chain/get_block', { method: 'POST', headers: { 'Accept': 'application/json', @@ -127,9 +128,9 @@ class Transactions { }; } try { - const res = yield Transactions.fetchJson(Transactions.baseUrl + endPoint, options); + const res = yield Transactions.fetchJson(this.baseUrl + endPoint, options); if (!res.ok) { - const error = new Error(`Error ${res.status} while fetching ${Transactions.baseUrl + endPoint}`); + const error = new Error(`Error ${res.status} while fetching ${this.baseUrl + endPoint}`); try { error.json = yield res.json(); } diff --git a/lib/transactions/queries/Query.js b/lib/transactions/queries/Query.js index 4311fdc5..a2c8cbde 100644 --- a/lib/transactions/queries/Query.js +++ b/lib/transactions/queries/Query.js @@ -18,10 +18,11 @@ class Query extends Transactions_1.Transactions { } decrypt(result) { } - execute(publicKey, privateKey = '') { + execute(baseUrl, publicKey, privateKey = '') { return __awaiter(this, void 0, void 0, function* () { this.publicKey = publicKey; this.privateKey = privateKey; + this.baseUrl = baseUrl; if (!this.isEncrypted) { return this.executeCall(this.getEndPoint(), JSON.stringify(this.getData())); } diff --git a/lib/transactions/signed/SignedTransaction.js b/lib/transactions/signed/SignedTransaction.js index 31f6296e..a9eb4ea8 100644 --- a/lib/transactions/signed/SignedTransaction.js +++ b/lib/transactions/signed/SignedTransaction.js @@ -15,10 +15,11 @@ const RawAction_1 = require("../../entities/RawAction"); const RawTransaction_1 = require("../../entities/RawTransaction"); const Transactions_1 = require("../Transactions"); class SignedTransaction extends Transactions_1.Transactions { - execute(privateKey, publicKey, dryRun = false) { + execute(baseUrl, privateKey, publicKey, dryRun = false) { return __awaiter(this, void 0, void 0, function* () { this.privateKey = privateKey; this.publicKey = publicKey; + this.baseUrl = baseUrl; const rawTransaction = new RawTransaction_1.RawTransaction(); const rawaction = new RawAction_1.RawAction(); rawaction.account = this.getAccount(); diff --git a/src/FIOSDK.ts b/src/FIOSDK.ts index cd1fad9b..ec44cfcc 100644 --- a/src/FIOSDK.ts +++ b/src/FIOSDK.ts @@ -54,6 +54,7 @@ const { Ecc } = require('@fioprotocol/fiojs') type FetchJson = (uri: string, opts?: object) => Promise export class FIOSDK { + private baseUrl: string = '' /** * @ignore */ @@ -302,7 +303,7 @@ export class FIOSDK { returnPreparedTrx: boolean = false, ) { this.transactions = new Transactions() - Transactions.baseUrl = baseUrl + this.baseUrl = baseUrl Transactions.FioProvider = Fio Transactions.fetchJson = fetchjson this.registerMockUrl = registerMockUrl @@ -375,7 +376,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -398,7 +399,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -419,7 +420,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -442,7 +443,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -462,7 +463,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return burnFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return burnFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -485,7 +486,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -508,7 +509,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -531,7 +532,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addBundledTransactions.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return addBundledTransactions.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -551,7 +552,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return renewFioAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return renewFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -571,7 +572,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return renewFioDomain.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return renewFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -602,7 +603,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addPublicAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -622,7 +623,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return cancelFundsRequest.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return cancelFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } @@ -646,7 +647,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return removePublicAddresses.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return removePublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -675,7 +676,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferLockedTokens.execute(this.privateKey, this.publicKey) + return transferLockedTokens.execute(this.baseUrl, this.privateKey, this.publicKey) } @@ -697,7 +698,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return removeAllPublicAddresses.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return removeAllPublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } @@ -721,7 +722,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addPublicAddress.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -744,7 +745,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return SetFioDomainVisibility.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return SetFioDomainVisibility.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -811,7 +812,7 @@ export class FIOSDK { hash, offLineUrl, ) - return recordObtData.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return recordObtData.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -823,7 +824,7 @@ export class FIOSDK { */ public getObtData(limit?: number, offset?: number, tokenCode?: string): Promise { const getObtDataRequest = new queries.GetObtData(this.publicKey, limit, offset, tokenCode) - return getObtDataRequest.execute(this.publicKey, this.privateKey) + return getObtDataRequest.execute(this.baseUrl, this.publicKey, this.privateKey) } /** @@ -843,7 +844,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return rejectFundsRequest.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return rejectFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -896,7 +897,7 @@ export class FIOSDK { hash, offlineUrl, ) - return requestNewFunds.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return requestNewFunds.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -906,7 +907,7 @@ export class FIOSDK { */ public getLocks(fioPublicKey: string): Promise { const getLocks = new queries.GetLocks(fioPublicKey) - return getLocks.execute(this.publicKey) + return getLocks.execute(this.baseUrl, this.publicKey) } /* @@ -916,7 +917,7 @@ export class FIOSDK { */ public getAccount(actor: string): Promise { const getAccount = new queries.GetAccount(actor) - return getAccount.execute(this.publicKey) + return getAccount.execute(this.baseUrl, this.publicKey) } /** @@ -926,7 +927,7 @@ export class FIOSDK { */ public isAvailable(fioName: string): Promise { const availabilityCheck = new queries.AvailabilityCheck(fioName) - return availabilityCheck.execute(this.publicKey) + return availabilityCheck.execute(this.baseUrl, this.publicKey) } /** @@ -936,7 +937,7 @@ export class FIOSDK { */ public getFioBalance(fioPublicKey?: string): Promise { const getFioBalance = new queries.GetFioBalance(fioPublicKey) - return getFioBalance.execute(this.publicKey) + return getFioBalance.execute(this.baseUrl, this.publicKey) } /** @@ -946,7 +947,7 @@ export class FIOSDK { */ public getFioNames(fioPublicKey: string): Promise { const getNames = new queries.GetNames(fioPublicKey) - return getNames.execute(this.publicKey) + return getNames.execute(this.baseUrl, this.publicKey) } /** @@ -958,7 +959,7 @@ export class FIOSDK { */ public getFioAddresses(fioPublicKey: string, limit?: number, offset?: number): Promise { const getNames = new queries.GetAddresses(fioPublicKey, limit, offset) - return getNames.execute(this.publicKey) + return getNames.execute(this.baseUrl, this.publicKey) } /** @@ -970,7 +971,7 @@ export class FIOSDK { */ public getFioDomains(fioPublicKey: string, limit?: number, offset?: number): Promise { const getNames = new queries.GetDomains(fioPublicKey, limit, offset) - return getNames.execute(this.publicKey) + return getNames.execute(this.baseUrl, this.publicKey) } /** @@ -981,7 +982,7 @@ export class FIOSDK { */ public getPendingFioRequests(limit?: number, offset?: number): Promise { const pendingFioRequests = new queries.PendingFioRequests(this.publicKey, limit, offset) - return pendingFioRequests.execute(this.publicKey, this.privateKey) + return pendingFioRequests.execute(this.baseUrl, this.publicKey, this.privateKey) } /** @@ -992,7 +993,7 @@ export class FIOSDK { */ public getSentFioRequests(limit?: number, offset?: number): Promise { const sentFioRequest = new queries.SentFioRequests(this.publicKey, limit, offset) - return sentFioRequest.execute(this.publicKey, this.privateKey) + return sentFioRequest.execute(this.baseUrl, this.publicKey, this.privateKey) } /** @@ -1003,7 +1004,7 @@ export class FIOSDK { */ public getCancelledFioRequests(limit?: number, offset?: number): Promise { const cancelledFioRequest = new queries.CancelledFioRequests(this.publicKey, limit, offset) - return cancelledFioRequest.execute(this.publicKey, this.privateKey) + return cancelledFioRequest.execute(this.baseUrl, this.publicKey, this.privateKey) } /** @@ -1023,7 +1024,7 @@ export class FIOSDK { chainCode, tokenCode, ) - return publicAddressLookUp.execute(this.publicKey) + return publicAddressLookUp.execute(this.baseUrl, this.publicKey) } /** @@ -1043,7 +1044,7 @@ export class FIOSDK { limit, offset, ) - return publicAddressesLookUp.execute(this.publicKey) + return publicAddressesLookUp.execute(this.baseUrl, this.publicKey) } /** @@ -1077,7 +1078,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferTokens.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferTokens.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -1106,7 +1107,7 @@ export class FIOSDK { */ public getFee(endPoint: EndPoint, fioAddress: string = ''): Promise { const fioFee = new queries.GetFee(endPoint, fioAddress) - return fioFee.execute(this.publicKey) + return fioFee.execute(this.baseUrl, this.publicKey) } /** @@ -1242,7 +1243,7 @@ export class FIOSDK { account, data, ) - return pushTransaction.execute(this.privateKey, this.publicKey, this.returnPreparedTrx) + return pushTransaction.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -1492,6 +1493,6 @@ export class FIOSDK { */ private getAbi(accountName: string): Promise { const abi = new queries.GetAbi(accountName) - return abi.execute(this.publicKey) + return abi.execute(this.baseUrl, this.publicKey) } } diff --git a/src/transactions/Transactions.ts b/src/transactions/Transactions.ts index f4ec1183..7a1e4b80 100644 --- a/src/transactions/Transactions.ts +++ b/src/transactions/Transactions.ts @@ -10,13 +10,13 @@ const textEncoder: TextEncoder = new TextEncoder() const textDecoder: TextDecoder = new TextDecoder() export class Transactions { - public static baseUrl: string public static abiMap: Map = new Map() public static FioProvider: { prepareTransaction(param: any): Promise; accountHash(pubkey: string): string } + public baseUrl: string = '' public static fetchJson: FetchJson public publicKey: string = '' public privateKey: string = '' @@ -38,7 +38,7 @@ export class Transactions { 'Content-Type': 'application/json', }, } - const res = await Transactions.fetchJson(Transactions.baseUrl + 'chain/get_info', options) + const res = await Transactions.fetchJson(this.baseUrl + 'chain/get_info', options) return await res.json() } @@ -49,7 +49,7 @@ export class Transactions { if (chain.last_irreversible_block_num == undefined) { throw new Error('chain.last_irreversible_block_num undefined') } - const res = await Transactions.fetchJson(Transactions.baseUrl + 'chain/get_block', { + const res = await Transactions.fetchJson(this.baseUrl + 'chain/get_block', { method: 'POST', headers: { 'Accept': 'application/json', @@ -122,9 +122,9 @@ export class Transactions { } } try { - const res = await Transactions.fetchJson(Transactions.baseUrl + endPoint, options) + const res = await Transactions.fetchJson(this.baseUrl + endPoint, options) if (!res.ok) { - const error: Error & { json?: Object, errorCode?: string, requestParams?: { endPoint: string, body: string, fetchOptions?: any } } = new Error(`Error ${res.status} while fetching ${Transactions.baseUrl + endPoint}`) + const error: Error & { json?: Object, errorCode?: string, requestParams?: { endPoint: string, body: string, fetchOptions?: any } } = new Error(`Error ${res.status} while fetching ${this.baseUrl + endPoint}`) try { error.json = await res.json() } catch (e) { diff --git a/src/transactions/queries/Query.ts b/src/transactions/queries/Query.ts index d01cf8ca..1db83968 100644 --- a/src/transactions/queries/Query.ts +++ b/src/transactions/queries/Query.ts @@ -10,9 +10,10 @@ export abstract class Query extends Transactions { isEncrypted = false - async execute(publicKey: string, privateKey: string = ''): Promise { + async execute(baseUrl: string, publicKey: string, privateKey: string = ''): Promise { this.publicKey = publicKey this.privateKey = privateKey + this.baseUrl = baseUrl if (!this.isEncrypted) { return this.executeCall(this.getEndPoint(), JSON.stringify(this.getData())) } else { diff --git a/src/transactions/signed/SignedTransaction.ts b/src/transactions/signed/SignedTransaction.ts index ce5c1961..df52a7d2 100644 --- a/src/transactions/signed/SignedTransaction.ts +++ b/src/transactions/signed/SignedTransaction.ts @@ -10,9 +10,10 @@ export abstract class SignedTransaction extends Transactions { public abstract getData(): any - public async execute(privateKey: string, publicKey: string, dryRun = false): Promise { + public async execute(baseUrl: string, privateKey: string, publicKey: string, dryRun = false): Promise { this.privateKey = privateKey this.publicKey = publicKey + this.baseUrl = baseUrl const rawTransaction = new RawTransaction() const rawaction = new RawAction() From 35c72a5fb36175daf125e0f5dc54ae7959d9010d Mon Sep 17 00:00:00 2001 From: andreyvEze Date: Fri, 6 Aug 2021 00:50:17 +0300 Subject: [PATCH 2/2] Make abiMap unique per FIOSDK instance --- lib/FIOSDK.js | 47 ++++++++++---------- lib/transactions/Transactions.js | 6 +-- lib/transactions/signed/SignedTransaction.js | 3 +- src/FIOSDK.ts | 47 ++++++++++---------- src/transactions/Transactions.ts | 6 +-- src/transactions/signed/SignedTransaction.ts | 4 +- 6 files changed, 59 insertions(+), 54 deletions(-) diff --git a/lib/FIOSDK.js b/lib/FIOSDK.js index 1ca8aa83..e96239e3 100644 --- a/lib/FIOSDK.js +++ b/lib/FIOSDK.js @@ -43,6 +43,7 @@ class FIOSDK { */ constructor(privateKey, publicKey, baseUrl, fetchjson, registerMockUrl = '', technologyProviderId = '', returnPreparedTrx = false) { this.baseUrl = ''; + this.abiMap = new Map(); /** * Defines whether SignedTransaction would execute or return prepared transaction */ @@ -59,7 +60,7 @@ class FIOSDK { for (const accountName of constants_1.Constants.rawAbiAccountName) { this.getAbi(accountName) .then((response) => { - Transactions_1.Transactions.abiMap.set(response.account_name, response); + this.abiMap.set(response.account_name, response); }) .catch((error) => { throw error; @@ -272,7 +273,7 @@ class FIOSDK { */ registerFioAddress(fioAddress, maxFee, technologyProviderId = null) { const registerFioAddress = new SignedTransactions.RegisterFioAddress(fioAddress, null, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a Fio Address on behalf of the owner FIO Public key parameter. Owner FIO Public key owns the FIO address @@ -284,7 +285,7 @@ class FIOSDK { */ registerOwnerFioAddress(fioAddress, ownerPublicKey, maxFee, technologyProviderId = null) { const registerFioAddress = new SignedTransactions.RegisterFioAddress(fioAddress, ownerPublicKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a FIO Domain on the FIO blockchain. @@ -295,7 +296,7 @@ class FIOSDK { */ registerFioDomain(fioDomain, maxFee, technologyProviderId = null) { const registerFioDomain = new SignedTransactions.RegisterFioDomain(fioDomain, null, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Registers a FIO Domain on behalf of the owner FIO Public key parameter. Owner FIO Public key owns the FIO domain. @@ -307,7 +308,7 @@ class FIOSDK { */ registerOwnerFioDomain(fioDomain, ownerPublicKey, maxFee, technologyProviderId = null) { const registerFioDomain = new SignedTransactions.RegisterFioDomain(fioDomain, ownerPublicKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return registerFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Burns a FIO Address on the FIO blockchain. @@ -318,7 +319,7 @@ class FIOSDK { */ burnFioAddress(fioAddress, maxFee, technologyProviderId = null) { const burnFioAddress = new SignedTransactions.BurnFioAddress(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return burnFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return burnFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Transfers a FIO Domain on the FIO blockchain. @@ -330,7 +331,7 @@ class FIOSDK { */ transferFioDomain(fioDomain, newOwnerKey, maxFee, technologyProviderId = null) { const transferFioDomain = new SignedTransactions.TransferFioDomain(fioDomain, newOwnerKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Transfers a FIO Address on the FIO blockchain. @@ -342,7 +343,7 @@ class FIOSDK { */ transferFioAddress(fioAddress, newOwnerKey, maxFee, technologyProviderId = null) { const transferFioAddress = new SignedTransactions.TransferFioAddress(fioAddress, newOwnerKey, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Adds bundles of transactions to FIO Address. @@ -354,7 +355,7 @@ class FIOSDK { */ addBundledTransactions(fioAddress, bundleSets, maxFee, technologyProviderId = null) { const addBundledTransactions = new SignedTransactions.AddBundledTransactions(fioAddress, bundleSets, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addBundledTransactions.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return addBundledTransactions.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Renew a FIO Address on the FIO blockchain. @@ -365,7 +366,7 @@ class FIOSDK { */ renewFioAddress(fioAddress, maxFee, technologyProviderId = null) { const renewFioAddress = new SignedTransactions.RenewFioAddress(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return renewFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return renewFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Renew a FIO Domain on the FIO blockchain. @@ -376,7 +377,7 @@ class FIOSDK { */ renewFioDomain(fioDomain, maxFee, technologyProviderId = null) { const renewFioDomain = new SignedTransactions.RenewFioDomain(fioDomain, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return renewFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return renewFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a public address of the specific blockchain type to be added to the FIO Address. @@ -394,7 +395,7 @@ class FIOSDK { token_code: tokenCode, public_address: publicAddress }], maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return addPublicAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call cancels the specified fio funds request.. @@ -405,7 +406,7 @@ class FIOSDK { */ cancelFundsRequest(fioRequestId, maxFee, technologyProviderId = null) { const cancelFundsRequest = new SignedTransactions.CancelFundsRequest(fioRequestId, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return cancelFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return cancelFundsRequest.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a any number of public addresses matching the blockchain code, the token code and the public address to be removed from the FIO Address. @@ -417,7 +418,7 @@ class FIOSDK { */ removePublicAddresses(fioAddress, publicAddresses, maxFee, technologyProviderId = null) { const removePublicAddresses = new SignedTransactions.RemovePublicAddresses(fioAddress, publicAddresses, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return removePublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return removePublicAddresses.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a user to transfer locked tokens to the specified fio public key @@ -431,7 +432,7 @@ class FIOSDK { */ transferLockedTokens(payeePublicKey, canVote, periods, amount, maxFee, technologyProviderId = null) { const transferLockedTokens = new SignedTransactions.TransferLockedTokens(payeePublicKey, canVote, periods, amount, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferLockedTokens.execute(this.baseUrl, this.privateKey, this.publicKey); + return transferLockedTokens.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey); } /** * This call allows a user to remove all addresses from the specified FIO Address, all addresses except the FIO address will be removed. @@ -442,7 +443,7 @@ class FIOSDK { */ removeAllPublicAddresses(fioAddress, maxFee, technologyProviderId = null) { const removeAllPublicAddresses = new SignedTransactions.RemoveAllPublicAddresses(fioAddress, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return removeAllPublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return removeAllPublicAddresses.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * This call allows a public addresses of the specific blockchain type to be added to the FIO Address. @@ -454,7 +455,7 @@ class FIOSDK { */ addPublicAddresses(fioAddress, publicAddresses, maxFee, technologyProviderId = null) { const addPublicAddress = new SignedTransactions.AddPublicAddress(fioAddress, publicAddresses, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return addPublicAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * By default all FIO Domains are non-public, meaning only the owner can register FIO Addresses on that domain. Setting them to public allows anyone to register a FIO Address on that domain. @@ -466,7 +467,7 @@ class FIOSDK { */ setFioDomainVisibility(fioDomain, isPublic, maxFee, technologyProviderId = null) { const SetFioDomainVisibility = new SignedTransactions.SetFioDomainVisibility(fioDomain, isPublic, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return SetFioDomainVisibility.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return SetFioDomainVisibility.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * @@ -500,7 +501,7 @@ class FIOSDK { payeeKey.public_address = payeeFioPublicKey; } const recordObtData = new SignedTransactions.RecordObtData(fioRequestId, payerFioAddress, payeeFioAddress, payerTokenPublicAddress, payeeTokenPublicAddress, amount, chainCode, tokenCode, obtId, maxFee, status, this.getTechnologyProviderId(technologyProviderId), payeeKey.public_address, memo, hash, offLineUrl); - return recordObtData.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return recordObtData.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); }); } /** @@ -523,7 +524,7 @@ class FIOSDK { */ rejectFundsRequest(fioRequestId, maxFee, technologyProviderId = null) { const rejectFundsRequest = new SignedTransactions.RejectFundsRequest(fioRequestId, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return rejectFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return rejectFundsRequest.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Create a new funds request on the FIO chain. @@ -551,7 +552,7 @@ class FIOSDK { payerKey.public_address = payerFioPublicKey; } const requestNewFunds = new SignedTransactions.RequestNewFunds(payerFioAddress, payerKey.public_address, payeeFioAddress, this.getTechnologyProviderId(technologyProviderId), maxFee, payeeTokenPublicAddress, amount, chainCode, tokenCode, memo, hash, offlineUrl); - return requestNewFunds.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return requestNewFunds.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); }); } /** @@ -693,7 +694,7 @@ class FIOSDK { */ transferTokens(payeeFioPublicKey, amount, maxFee, technologyProviderId = null) { const transferTokens = new SignedTransactions.TransferTokens(payeeFioPublicKey, amount, maxFee, this.getTechnologyProviderId(technologyProviderId)); - return transferTokens.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return transferTokens.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * Compute and return fee amount for specific call and specific user @@ -833,7 +834,7 @@ class FIOSDK { pushTransaction(account, action, data) { data.tpid = this.getTechnologyProviderId(data.tpid); const pushTransaction = new SignedTransactions.PushTransaction(action, account, data); - return pushTransaction.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx); + return pushTransaction.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx); } /** * @ignore diff --git a/lib/transactions/Transactions.js b/lib/transactions/Transactions.js index 37799347..8b8b5a05 100644 --- a/lib/transactions/Transactions.js +++ b/lib/transactions/Transactions.js @@ -18,6 +18,7 @@ const textEncoder = new text_encoding_1.TextEncoder(); const textDecoder = new text_encoding_1.TextDecoder(); class Transactions { constructor() { + this.abiMap = new Map(); this.baseUrl = ''; this.publicKey = ''; this.privateKey = ''; @@ -94,13 +95,13 @@ class Transactions { transaction.expiration = expirationStr.substr(0, expirationStr.length - 1); if (dryRun) { return Transactions.FioProvider.prepareTransaction({ - transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: Transactions.abiMap, + transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: this.abiMap, textDecoder: new text_encoding_1.TextDecoder(), textEncoder: new text_encoding_1.TextEncoder(), }); } else { const signedTransaction = yield Transactions.FioProvider.prepareTransaction({ - transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: Transactions.abiMap, + transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: this.abiMap, textDecoder: new text_encoding_1.TextDecoder(), textEncoder: new text_encoding_1.TextEncoder(), }); return this.executeCall(endpoint, JSON.stringify(signedTransaction)); @@ -167,4 +168,3 @@ class Transactions { } } exports.Transactions = Transactions; -Transactions.abiMap = new Map(); diff --git a/lib/transactions/signed/SignedTransaction.js b/lib/transactions/signed/SignedTransaction.js index a9eb4ea8..f982e421 100644 --- a/lib/transactions/signed/SignedTransaction.js +++ b/lib/transactions/signed/SignedTransaction.js @@ -15,11 +15,12 @@ const RawAction_1 = require("../../entities/RawAction"); const RawTransaction_1 = require("../../entities/RawTransaction"); const Transactions_1 = require("../Transactions"); class SignedTransaction extends Transactions_1.Transactions { - execute(baseUrl, privateKey, publicKey, dryRun = false) { + execute(baseUrl, abiMap, privateKey, publicKey, dryRun = false) { return __awaiter(this, void 0, void 0, function* () { this.privateKey = privateKey; this.publicKey = publicKey; this.baseUrl = baseUrl; + this.abiMap = abiMap; const rawTransaction = new RawTransaction_1.RawTransaction(); const rawaction = new RawAction_1.RawAction(); rawaction.account = this.getAccount(); diff --git a/src/FIOSDK.ts b/src/FIOSDK.ts index ec44cfcc..6ab07edf 100644 --- a/src/FIOSDK.ts +++ b/src/FIOSDK.ts @@ -55,6 +55,7 @@ type FetchJson = (uri: string, opts?: object) => Promise export class FIOSDK { private baseUrl: string = '' + private abiMap: Map = new Map() /** * @ignore */ @@ -315,7 +316,7 @@ export class FIOSDK { for (const accountName of Constants.rawAbiAccountName) { this.getAbi(accountName) .then((response) => { - Transactions.abiMap.set(response.account_name, response) + this.abiMap.set(response.account_name, response) }) .catch((error) => { throw error @@ -376,7 +377,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -399,7 +400,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -420,7 +421,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -443,7 +444,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return registerFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return registerFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -463,7 +464,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return burnFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return burnFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -486,7 +487,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -509,7 +510,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -532,7 +533,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addBundledTransactions.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return addBundledTransactions.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -552,7 +553,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return renewFioAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return renewFioAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -572,7 +573,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return renewFioDomain.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return renewFioDomain.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -603,7 +604,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return addPublicAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -623,7 +624,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return cancelFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return cancelFundsRequest.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } @@ -647,7 +648,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return removePublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return removePublicAddresses.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -676,7 +677,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferLockedTokens.execute(this.baseUrl, this.privateKey, this.publicKey) + return transferLockedTokens.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey) } @@ -698,7 +699,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return removeAllPublicAddresses.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return removeAllPublicAddresses.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } @@ -722,7 +723,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return addPublicAddress.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return addPublicAddress.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -745,7 +746,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return SetFioDomainVisibility.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return SetFioDomainVisibility.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -812,7 +813,7 @@ export class FIOSDK { hash, offLineUrl, ) - return recordObtData.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return recordObtData.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -844,7 +845,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return rejectFundsRequest.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return rejectFundsRequest.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -897,7 +898,7 @@ export class FIOSDK { hash, offlineUrl, ) - return requestNewFunds.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return requestNewFunds.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -1078,7 +1079,7 @@ export class FIOSDK { maxFee, this.getTechnologyProviderId(technologyProviderId), ) - return transferTokens.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return transferTokens.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** @@ -1243,7 +1244,7 @@ export class FIOSDK { account, data, ) - return pushTransaction.execute(this.baseUrl, this.privateKey, this.publicKey, this.returnPreparedTrx) + return pushTransaction.execute(this.baseUrl, this.abiMap, this.privateKey, this.publicKey, this.returnPreparedTrx) } /** diff --git a/src/transactions/Transactions.ts b/src/transactions/Transactions.ts index 7a1e4b80..63a8eeeb 100644 --- a/src/transactions/Transactions.ts +++ b/src/transactions/Transactions.ts @@ -10,12 +10,12 @@ const textEncoder: TextEncoder = new TextEncoder() const textDecoder: TextDecoder = new TextDecoder() export class Transactions { - public static abiMap: Map = new Map() public static FioProvider: { prepareTransaction(param: any): Promise; accountHash(pubkey: string): string } + public abiMap: Map = new Map() public baseUrl: string = '' public static fetchJson: FetchJson public publicKey: string = '' @@ -90,12 +90,12 @@ export class Transactions { transaction.expiration = expirationStr.substr(0, expirationStr.length - 1) if (dryRun) { return Transactions.FioProvider.prepareTransaction({ - transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: Transactions.abiMap, + transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: this.abiMap, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), }) } else { const signedTransaction = await Transactions.FioProvider.prepareTransaction({ - transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: Transactions.abiMap, + transaction, chainId: chain.chain_id, privateKeys: privky, abiMap: this.abiMap, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), }) return this.executeCall(endpoint, JSON.stringify(signedTransaction)) diff --git a/src/transactions/signed/SignedTransaction.ts b/src/transactions/signed/SignedTransaction.ts index df52a7d2..0ca67685 100644 --- a/src/transactions/signed/SignedTransaction.ts +++ b/src/transactions/signed/SignedTransaction.ts @@ -2,6 +2,7 @@ import { Autorization } from '../../entities/Autorization' import { RawAction } from '../../entities/RawAction' import { RawTransaction } from '../../entities/RawTransaction' import { Transactions } from '../Transactions' +import { AbiResponse } from "../../entities/AbiResponse"; export abstract class SignedTransaction extends Transactions { public abstract ENDPOINT: string @@ -10,10 +11,11 @@ export abstract class SignedTransaction extends Transactions { public abstract getData(): any - public async execute(baseUrl: string, privateKey: string, publicKey: string, dryRun = false): Promise { + public async execute(baseUrl: string, abiMap: Map, privateKey: string, publicKey: string, dryRun = false): Promise { this.privateKey = privateKey this.publicKey = publicKey this.baseUrl = baseUrl + this.abiMap = abiMap const rawTransaction = new RawTransaction() const rawaction = new RawAction()