@massalabs/wallet-provider 1.5.1 → 1.5.2-dev.20231220152928
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/massaStation/MassaStationAccount.d.ts +2 -2
- package/dist/cmd/massaStation/MassaStationAccount.d.ts.map +1 -1
- package/dist/cmd/massaStation/MassaStationAccount.js +9 -5
- package/dist/cmd/massaStation/MassaStationAccount.js.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.d.ts +2 -2
- package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.js +9 -5
- package/dist/esm/massaStation/MassaStationAccount.js.map +1 -1
- package/package.json +2 -1
|
@@ -98,8 +98,8 @@ export declare class MassaStationAccount implements IAccount {
|
|
|
98
98
|
* Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.
|
|
99
99
|
*
|
|
100
100
|
*/
|
|
101
|
-
callSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args,
|
|
101
|
+
callSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args, coins: bigint, fee?: bigint, maxGas?: bigint, nonPersistentExecution?: boolean): Promise<ITransactionDetails | IContractReadOperationResponse>;
|
|
102
102
|
getNodeUrlFromMassaStation(): Promise<string>;
|
|
103
|
-
nonPersistentCallSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args,
|
|
103
|
+
nonPersistentCallSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args, maxGas?: bigint): Promise<IContractReadOperationResponse>;
|
|
104
104
|
}
|
|
105
105
|
//# sourceMappingURL=MassaStationAccount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,uBAAuB,EACvB,eAAe,EAEf,mBAAmB,EACpB,MAAM,IAAI,CAAC;AACZ,OAAO,EA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d,gBAAgB,EAAE,MAAM,EACxB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC;IAuB/B;;;;;;;;;;;;;;;;;;;OAmBG;IACU,MAAM,CACjB,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,UAAU,GAAG,IAAI,EAC5B,KAAK,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,sBAAsB,UAAQ,GAC7B,OAAO,CAAC,mBAAmB,GAAG,8BAA8B,CAAC;IA2CnD,0BAA0B,IAAI,OAAO,CAAC,MAAM,CAAC;IAoB7C,mBAAmB,CAC9B,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,UAAU,GAAG,IAAI,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,8BAA8B,CAAC;CAgE3C"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MassaStationAccount = void 0;
|
|
4
4
|
const RequestHandler_1 = require("./RequestHandler");
|
|
5
5
|
const MassaStationProvider_1 = require("./MassaStationProvider");
|
|
6
|
+
const web3_utils_1 = require("@massalabs/web3-utils");
|
|
6
7
|
const argsToBase64_1 = require("../utils/argsToBase64");
|
|
7
8
|
const bs58check_1 = require("bs58check");
|
|
8
9
|
/**
|
|
@@ -205,9 +206,9 @@ class MassaStationAccount {
|
|
|
205
206
|
* Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.
|
|
206
207
|
*
|
|
207
208
|
*/
|
|
208
|
-
async callSC(contractAddress, functionName, parameter,
|
|
209
|
+
async callSC(contractAddress, functionName, parameter, coins, fee, maxGas, nonPersistentExecution = false) {
|
|
209
210
|
if (nonPersistentExecution) {
|
|
210
|
-
return this.nonPersistentCallSC(contractAddress, functionName, parameter,
|
|
211
|
+
return this.nonPersistentCallSC(contractAddress, functionName, parameter, maxGas);
|
|
211
212
|
}
|
|
212
213
|
// convert parameter to base64
|
|
213
214
|
let args = '';
|
|
@@ -224,7 +225,10 @@ class MassaStationAccount {
|
|
|
224
225
|
name: functionName,
|
|
225
226
|
at: contractAddress,
|
|
226
227
|
args: args,
|
|
227
|
-
coins: Number(
|
|
228
|
+
coins: Number(coins),
|
|
229
|
+
fee: fee ? fee.toString() : '0',
|
|
230
|
+
// If maxGas is not provided, estimation will be done by MS
|
|
231
|
+
maxGas: maxGas ? maxGas.toString() : '',
|
|
228
232
|
async: true,
|
|
229
233
|
};
|
|
230
234
|
try {
|
|
@@ -257,7 +261,7 @@ class MassaStationAccount {
|
|
|
257
261
|
}
|
|
258
262
|
return node;
|
|
259
263
|
}
|
|
260
|
-
async nonPersistentCallSC(contractAddress, functionName, parameter,
|
|
264
|
+
async nonPersistentCallSC(contractAddress, functionName, parameter, maxGas) {
|
|
261
265
|
const node = await this.getNodeUrlFromMassaStation();
|
|
262
266
|
// Gas amount check
|
|
263
267
|
if (maxGas > MAX_READ_BLOCK_GAS) {
|
|
@@ -276,7 +280,7 @@ class MassaStationAccount {
|
|
|
276
280
|
}
|
|
277
281
|
// setup the request body
|
|
278
282
|
const data = {
|
|
279
|
-
max_gas: Number(maxGas),
|
|
283
|
+
max_gas: maxGas ? Number(maxGas) : web3_utils_1.MAX_GAS_CALL,
|
|
280
284
|
target_address: contractAddress,
|
|
281
285
|
target_function: functionName,
|
|
282
286
|
parameter: argumentArray,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":";;;AAOA,qDAAgF;AAChF,iEAGgC;AAOhC,wDAAyE;AAEzE,yCAAmD;AAGnD;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;AA6BjD;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAK9B;;;;;;;;;;;;OAYG;IACH,YA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AC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF;AA5WD,kDA4WC","sourcesContent":["import {\n IAccountBalanceResponse,\n IAccountDetails,\n IAccountSignResponse,\n ITransactionDetails,\n} from '..';\nimport { IAccount } from '../account/IAccount';\nimport { JsonRpcResponseData, getRequest, postRequest } from './RequestHandler';\nimport {\n MASSA_STATION_URL,\n MASSA_STATION_ACCOUNTS_URL,\n} from './MassaStationProvider';\nimport {\n Args,\n IContractReadOperationData,\n IContractReadOperationResponse,\n} from '@massalabs/web3-utils';\n\nimport { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';\nimport { IAccountSignOutput } from '../account/AccountSign';\nimport { encode as base58Encode } from 'bs58check';\nimport { ExecuteFunctionBody } from './types';\n\n/**\n * The maximum allowed gas for a read operation\n */\nconst MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's sign\n * operation `/signOperation` url.\n */\ninterface ISignOperation {\n operation: string;\n batch?: boolean;\n correlationId?: string;\n}\n\n/**\n * This interface represents the the individual wallet's final and pending balances returned by MassaStation\n */\ninterface IBalance {\n final: string;\n pending: string;\n}\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\ninterface IAddressesBalances {\n addressesAttributes: {\n [key: string]: { balance: IBalance };\n };\n}\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n\n /**\n * This constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n *\n * @param address - The address of the account.\n * @param name - The name of the account.\n * @param providerName - The name of the provider.\n * @returns An instance of the Account class.\n *\n * @remarks\n * - The Account constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n * - The IAccountDetails object contains the account's address and name.\n * - The providerName string identifies the provider that is used to interact with the blockchain.\n */\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name;\n this._providerName = providerName;\n }\n\n /**\n * @returns The address of the account.\n */\n public address(): string {\n return this._address;\n }\n\n /**\n * @returns The name of the account.\n */\n public name(): string {\n return this._name;\n }\n\n /**\n * @returns The name of the provider.\n */\n public providerName(): string {\n return this._providerName;\n }\n\n /**\n * This method aims to retrieve the account's balance.\n *\n * @returns A promise that resolves to an object of type IAccountBalanceResponse. It contains the account's balance.\n */\n public async balance(): Promise<IAccountBalanceResponse> {\n let signOpResponse: JsonRpcResponseData<IAddressesBalances> = null;\n try {\n signOpResponse = await getRequest<IAddressesBalances>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this._address}`,\n );\n } catch (ex) {\n console.error(`MassaStation account balance error`);\n throw ex;\n }\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n const balance: IBalance =\n signOpResponse.result.addressesAttributes[this._address].balance;\n return {\n finalBalance: balance.final,\n candidateBalance: balance.pending,\n };\n }\n\n /**\n * This method aims to sign a message.\n *\n * @param data - The message to be signed.\n * @returns An IAccountSignResponse object. It contains the signature of the message.\n */\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n let signOpResponse: JsonRpcResponseData<IAccountSignResponse> = null;\n\n try {\n signOpResponse = await postRequest<IAccountSignResponse>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/sign`,\n {\n operation: Buffer.from(data).toString('base64'),\n batch: false,\n } as ISignOperation,\n );\n } catch (ex) {\n console.error(`MassaStation account signing error`);\n throw ex;\n }\n\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n\n const signature = base58Encode(\n Buffer.from(signOpResponse.result.signature, 'base64'),\n );\n\n return {\n publicKey: signOpResponse.result.publicKey,\n base58Encoded: signature,\n };\n }\n\n /**\n * This method aims to buy rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be bought.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async buyRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let buyRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'buy',\n };\n try {\n buyRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while buying rolls: ${ex}`);\n throw ex;\n }\n if (buyRollsOpResponse.isError || buyRollsOpResponse.error) {\n throw buyRollsOpResponse.error;\n }\n return buyRollsOpResponse.result;\n }\n\n /**\n * This method aims to sell rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be sold.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async sellRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sellRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'sell',\n };\n try {\n sellRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while selling rolls: ${ex}`);\n throw ex;\n }\n if (sellRollsOpResponse.isError || sellRollsOpResponse.error) {\n throw sellRollsOpResponse.error;\n }\n return sellRollsOpResponse.result;\n }\n\n /**\n * This method aims to transfer MAS on behalf of the sender to a recipient.\n *\n * @param amount - The amount of MAS (in the smallest unit) to be transferred.\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sendTxOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/transfer`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: recipientAddress,\n };\n\n try {\n sendTxOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(\n `MassaStation account: error while sending transaction: ${ex}`,\n );\n throw ex;\n }\n if (sendTxOpResponse.isError || sendTxOpResponse.error) {\n throw sendTxOpResponse.error;\n }\n return sendTxOpResponse.result;\n }\n\n /**\n * This method aims to interact with a smart contract deployed on the MASSA blockchain.\n *\n * @remarks\n * If dryRun.dryRun is true, the method will dry run the smart contract call and return an\n * IContractReadOperationResponse object which contains all the information about the dry run\n * (state changes, gas used, etc.)\n *\n * @param contractAddress - The address of the smart contract.\n * @param functionName - The name of the function to be called.\n * @param parameter - The parameters as an Args object to be passed to the function.\n * @param amount - The amount of MASSA coins to be sent to the contract (in the smallest unit).\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @param maxGas - The maximum amount of gas to be used for the transaction execution.\n * @param nonPersistentExecution - The dryRun object to be passed to the function.\n *\n * @returns if 'nonPersistentExecution' is true, it returns an IContractReadOperationResponse object.\n * Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.\n *\n */\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n amount,\n fee,\n maxGas,\n );\n }\n // convert parameter to base64\n let args = '';\n if (parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(parameter);\n } else {\n args = argsToBase64(parameter);\n }\n let CallSCOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_URL}cmd/executeFunction`;\n const body: ExecuteFunctionBody = {\n nickname: this._name,\n name: functionName,\n at: contractAddress,\n args: args,\n coins: Number(amount),\n async: true,\n };\n try {\n CallSCOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.log(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n throw ex;\n }\n if (CallSCOpResponse.isError || CallSCOpResponse.error) {\n throw CallSCOpResponse.error;\n }\n return CallSCOpResponse.result;\n }\n\n public async getNodeUrlFromMassaStation(): Promise<string> {\n // get the node url from MassaStation\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n let node = '';\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n node = nodes.url;\n } catch (ex) {\n throw new Error(`MassaStation nodes retrieval error: ${ex}`);\n }\n return node;\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n ): Promise<IContractReadOperationResponse> {\n const node = await this.getNodeUrlFromMassaStation();\n // Gas amount check\n if (maxGas > MAX_READ_BLOCK_GAS) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_READ_BLOCK_GAS.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: Number(maxGas),\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n node,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":";;;AAOA,qDAAgF;AAChF,iEAGgC;AAChC,sDAK+B;AAE/B,wDAAyE;AAEzE,yCAAmD;AAGnD;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;AA6BjD;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAK9B;;;;;;;;;;;;OAYG;IACH,YAAmB,EAAE,OAAO,EAAE,IAAI,EAAmB,EAAE,YAAoB;QACzE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,cAAc,GAA4C,IAAI,CAAC;QACnE,IAAI;YACF,cAAc,GAAG,MAAM,IAAA,2BAAU,EAC/B,GAAG,wCAAiB,gDAAgD,IAAI,CAAC,QAAQ,E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AE,EAAE,CAAC;aACN;SACF,CAAC;QACF,wBAAwB;QACxB,IAAI,iBAAiB,GAAsC,EAAE,CAAC;QAC9D,IAAI;YACF,IAAI,IAAI,GAAG,MAAM,IAAA,4BAAW,EAC1B,IAAI,EACJ,IAAI,CACL,CAAC;YACF,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;aAC1B;YACD,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;SACjC;QAAC,OAAO,EAAE,EAAE;YACX,MAAM,IAAI,KAAK,CACb,sEAAsE,EAAE,EAAE,CAC3E,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO;YACL,WAAW,EAAE,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YACrE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF;AA3WD,kDA2WC","sourcesContent":["import {\n IAccountBalanceResponse,\n IAccountDetails,\n IAccountSignResponse,\n ITransactionDetails,\n} from '..';\nimport { IAccount } from '../account/IAccount';\nimport { JsonRpcResponseData, getRequest, postRequest } from './RequestHandler';\nimport {\n MASSA_STATION_URL,\n MASSA_STATION_ACCOUNTS_URL,\n} from './MassaStationProvider';\nimport {\n Args,\n IContractReadOperationData,\n IContractReadOperationResponse,\n MAX_GAS_CALL,\n} from '@massalabs/web3-utils';\n\nimport { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';\nimport { IAccountSignOutput } from '../account/AccountSign';\nimport { encode as base58Encode } from 'bs58check';\nimport { ExecuteFunctionBody } from './types';\n\n/**\n * The maximum allowed gas for a read operation\n */\nconst MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's sign\n * operation `/signOperation` url.\n */\ninterface ISignOperation {\n operation: string;\n batch?: boolean;\n correlationId?: string;\n}\n\n/**\n * This interface represents the the individual wallet's final and pending balances returned by MassaStation\n */\ninterface IBalance {\n final: string;\n pending: string;\n}\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\ninterface IAddressesBalances {\n addressesAttributes: {\n [key: string]: { balance: IBalance };\n };\n}\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n\n /**\n * This constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n *\n * @param address - The address of the account.\n * @param name - The name of the account.\n * @param providerName - The name of the provider.\n * @returns An instance of the Account class.\n *\n * @remarks\n * - The Account constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n * - The IAccountDetails object contains the account's address and name.\n * - The providerName string identifies the provider that is used to interact with the blockchain.\n */\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name;\n this._providerName = providerName;\n }\n\n /**\n * @returns The address of the account.\n */\n public address(): string {\n return this._address;\n }\n\n /**\n * @returns The name of the account.\n */\n public name(): string {\n return this._name;\n }\n\n /**\n * @returns The name of the provider.\n */\n public providerName(): string {\n return this._providerName;\n }\n\n /**\n * This method aims to retrieve the account's balance.\n *\n * @returns A promise that resolves to an object of type IAccountBalanceResponse. It contains the account's balance.\n */\n public async balance(): Promise<IAccountBalanceResponse> {\n let signOpResponse: JsonRpcResponseData<IAddressesBalances> = null;\n try {\n signOpResponse = await getRequest<IAddressesBalances>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this._address}`,\n );\n } catch (ex) {\n console.error(`MassaStation account balance error`);\n throw ex;\n }\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n const balance: IBalance =\n signOpResponse.result.addressesAttributes[this._address].balance;\n return {\n finalBalance: balance.final,\n candidateBalance: balance.pending,\n };\n }\n\n /**\n * This method aims to sign a message.\n *\n * @param data - The message to be signed.\n * @returns An IAccountSignResponse object. It contains the signature of the message.\n */\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n let signOpResponse: JsonRpcResponseData<IAccountSignResponse> = null;\n\n try {\n signOpResponse = await postRequest<IAccountSignResponse>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/sign`,\n {\n operation: Buffer.from(data).toString('base64'),\n batch: false,\n } as ISignOperation,\n );\n } catch (ex) {\n console.error(`MassaStation account signing error`);\n throw ex;\n }\n\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n\n const signature = base58Encode(\n Buffer.from(signOpResponse.result.signature, 'base64'),\n );\n\n return {\n publicKey: signOpResponse.result.publicKey,\n base58Encoded: signature,\n };\n }\n\n /**\n * This method aims to buy rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be bought.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async buyRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let buyRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'buy',\n };\n try {\n buyRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while buying rolls: ${ex}`);\n throw ex;\n }\n if (buyRollsOpResponse.isError || buyRollsOpResponse.error) {\n throw buyRollsOpResponse.error;\n }\n return buyRollsOpResponse.result;\n }\n\n /**\n * This method aims to sell rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be sold.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async sellRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sellRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'sell',\n };\n try {\n sellRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while selling rolls: ${ex}`);\n throw ex;\n }\n if (sellRollsOpResponse.isError || sellRollsOpResponse.error) {\n throw sellRollsOpResponse.error;\n }\n return sellRollsOpResponse.result;\n }\n\n /**\n * This method aims to transfer MAS on behalf of the sender to a recipient.\n *\n * @param amount - The amount of MAS (in the smallest unit) to be transferred.\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sendTxOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/transfer`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: recipientAddress,\n };\n\n try {\n sendTxOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(\n `MassaStation account: error while sending transaction: ${ex}`,\n );\n throw ex;\n }\n if (sendTxOpResponse.isError || sendTxOpResponse.error) {\n throw sendTxOpResponse.error;\n }\n return sendTxOpResponse.result;\n }\n\n /**\n * This method aims to interact with a smart contract deployed on the MASSA blockchain.\n *\n * @remarks\n * If dryRun.dryRun is true, the method will dry run the smart contract call and return an\n * IContractReadOperationResponse object which contains all the information about the dry run\n * (state changes, gas used, etc.)\n *\n * @param contractAddress - The address of the smart contract.\n * @param functionName - The name of the function to be called.\n * @param parameter - The parameters as an Args object to be passed to the function.\n * @param amount - The amount of MASSA coins to be sent to the contract (in the smallest unit).\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @param maxGas - The maximum amount of gas to be used for the transaction execution.\n * @param nonPersistentExecution - The dryRun object to be passed to the function.\n *\n * @returns if 'nonPersistentExecution' is true, it returns an IContractReadOperationResponse object.\n * Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.\n *\n */\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n coins: bigint,\n fee?: bigint,\n maxGas?: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n maxGas,\n );\n }\n // convert parameter to base64\n let args = '';\n if (parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(parameter);\n } else {\n args = argsToBase64(parameter);\n }\n let CallSCOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_URL}cmd/executeFunction`;\n const body: ExecuteFunctionBody = {\n nickname: this._name,\n name: functionName,\n at: contractAddress,\n args: args,\n coins: Number(coins),\n fee: fee ? fee.toString() : '0',\n // If maxGas is not provided, estimation will be done by MS\n maxGas: maxGas ? maxGas.toString() : '',\n async: true,\n };\n try {\n CallSCOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.log(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n throw ex;\n }\n if (CallSCOpResponse.isError || CallSCOpResponse.error) {\n throw CallSCOpResponse.error;\n }\n return CallSCOpResponse.result;\n }\n\n public async getNodeUrlFromMassaStation(): Promise<string> {\n // get the node url from MassaStation\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n let node = '';\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n node = nodes.url;\n } catch (ex) {\n throw new Error(`MassaStation nodes retrieval error: ${ex}`);\n }\n return node;\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n maxGas?: bigint,\n ): Promise<IContractReadOperationResponse> {\n const node = await this.getNodeUrlFromMassaStation();\n // Gas amount check\n if (maxGas > MAX_READ_BLOCK_GAS) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_READ_BLOCK_GAS.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: maxGas ? Number(maxGas) : MAX_GAS_CALL,\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n node,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n"]}
|
|
@@ -98,8 +98,8 @@ export declare class MassaStationAccount implements IAccount {
|
|
|
98
98
|
* Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.
|
|
99
99
|
*
|
|
100
100
|
*/
|
|
101
|
-
callSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args,
|
|
101
|
+
callSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args, coins: bigint, fee?: bigint, maxGas?: bigint, nonPersistentExecution?: boolean): Promise<ITransactionDetails | IContractReadOperationResponse>;
|
|
102
102
|
getNodeUrlFromMassaStation(): Promise<string>;
|
|
103
|
-
nonPersistentCallSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args,
|
|
103
|
+
nonPersistentCallSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args, maxGas?: bigint): Promise<IContractReadOperationResponse>;
|
|
104
104
|
}
|
|
105
105
|
//# sourceMappingURL=MassaStationAccount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,uBAAuB,EACvB,eAAe,EAEf,mBAAmB,EACpB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EACL,IAAI,EAEJ,8BAA8B,
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,uBAAuB,EACvB,eAAe,EAEf,mBAAmB,EACpB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EACL,IAAI,EAEJ,8BAA8B,EAE/B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,kBAAk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C,MAAM,CAAC;IAoB7C,mBAAmB,CAC9B,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,UAAU,GAAG,IAAI,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,8BAA8B,CAAC;CAgE3C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getRequest, postRequest } from './RequestHandler';
|
|
2
2
|
import { MASSA_STATION_URL, MASSA_STATION_ACCOUNTS_URL, } from './MassaStationProvider';
|
|
3
|
+
import { MAX_GAS_CALL, } from '@massalabs/web3-utils';
|
|
3
4
|
import { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';
|
|
4
5
|
import { encode as base58Encode } from 'bs58check';
|
|
5
6
|
/**
|
|
@@ -205,9 +206,9 @@ export class MassaStationAccount {
|
|
|
205
206
|
* Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.
|
|
206
207
|
*
|
|
207
208
|
*/
|
|
208
|
-
async callSC(contractAddress, functionName, parameter,
|
|
209
|
+
async callSC(contractAddress, functionName, parameter, coins, fee, maxGas, nonPersistentExecution = false) {
|
|
209
210
|
if (nonPersistentExecution) {
|
|
210
|
-
return this.nonPersistentCallSC(contractAddress, functionName, parameter,
|
|
211
|
+
return this.nonPersistentCallSC(contractAddress, functionName, parameter, maxGas);
|
|
211
212
|
}
|
|
212
213
|
// convert parameter to base64
|
|
213
214
|
let args = '';
|
|
@@ -224,7 +225,10 @@ export class MassaStationAccount {
|
|
|
224
225
|
name: functionName,
|
|
225
226
|
at: contractAddress,
|
|
226
227
|
args: args,
|
|
227
|
-
coins: Number(
|
|
228
|
+
coins: Number(coins),
|
|
229
|
+
fee: fee ? fee.toString() : '0',
|
|
230
|
+
// If maxGas is not provided, estimation will be done by MS
|
|
231
|
+
maxGas: maxGas ? maxGas.toString() : '',
|
|
228
232
|
async: true,
|
|
229
233
|
};
|
|
230
234
|
try {
|
|
@@ -257,7 +261,7 @@ export class MassaStationAccount {
|
|
|
257
261
|
}
|
|
258
262
|
return node;
|
|
259
263
|
}
|
|
260
|
-
async nonPersistentCallSC(contractAddress, functionName, parameter,
|
|
264
|
+
async nonPersistentCallSC(contractAddress, functionName, parameter, maxGas) {
|
|
261
265
|
const node = await this.getNodeUrlFromMassaStation();
|
|
262
266
|
// Gas amount check
|
|
263
267
|
if (maxGas > MAX_READ_BLOCK_GAS) {
|
|
@@ -276,7 +280,7 @@ export class MassaStationAccount {
|
|
|
276
280
|
}
|
|
277
281
|
// setup the request body
|
|
278
282
|
const data = {
|
|
279
|
-
max_gas: Number(maxGas),
|
|
283
|
+
max_gas: maxGas ? Number(maxGas) : MAX_GAS_CALL,
|
|
280
284
|
target_address: contractAddress,
|
|
281
285
|
target_function: functionName,
|
|
282
286
|
parameter: argumentArray,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AAGnD;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AA6BjD;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACtB,aAAa,CAAS;IACtB,QAAQ,CAAS;IACjB,KAAK,CAAS;IAEtB;;;;;;;;;;;;OAYG;IACH,YAAmB,EAAE,OAAO,EAAE,IAAI,EAAmB,EAAE,YAAoB;QACzE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,aA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AAC;QACF,MAAM,IAAI,GAAG;YACX;gBACE,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,wBAAwB;gBAChC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;gBAChB,EAAE,EAAE,CAAC;aACN;SACF,CAAC;QACF,wBAAwB;QACxB,IAAI,iBAAiB,GAAsC,EAAE,CAAC;QAC9D,IAAI;YACF,IAAI,IAAI,GAAG,MAAM,WAAW,CAC1B,IAAI,EACJ,IAAI,CACL,CAAC;YACF,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;aAC1B;YACD,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;SACjC;QAAC,OAAO,EAAE,EAAE;YACX,MAAM,IAAI,KAAK,CACb,sEAAsE,EAAE,EAAE,CAC3E,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO;YACL,WAAW,EAAE,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YACrE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n IAccountBalanceResponse,\n IAccountDetails,\n IAccountSignResponse,\n ITransactionDetails,\n} from '..';\nimport { IAccount } from '../account/IAccount';\nimport { JsonRpcResponseData, getRequest, postRequest } from './RequestHandler';\nimport {\n MASSA_STATION_URL,\n MASSA_STATION_ACCOUNTS_URL,\n} from './MassaStationProvider';\nimport {\n Args,\n IContractReadOperationData,\n IContractReadOperationResponse,\n} from '@massalabs/web3-utils';\n\nimport { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';\nimport { IAccountSignOutput } from '../account/AccountSign';\nimport { encode as base58Encode } from 'bs58check';\nimport { ExecuteFunctionBody } from './types';\n\n/**\n * The maximum allowed gas for a read operation\n */\nconst MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's sign\n * operation `/signOperation` url.\n */\ninterface ISignOperation {\n operation: string;\n batch?: boolean;\n correlationId?: string;\n}\n\n/**\n * This interface represents the the individual wallet's final and pending balances returned by MassaStation\n */\ninterface IBalance {\n final: string;\n pending: string;\n}\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\ninterface IAddressesBalances {\n addressesAttributes: {\n [key: string]: { balance: IBalance };\n };\n}\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n\n /**\n * This constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n *\n * @param address - The address of the account.\n * @param name - The name of the account.\n * @param providerName - The name of the provider.\n * @returns An instance of the Account class.\n *\n * @remarks\n * - The Account constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n * - The IAccountDetails object contains the account's address and name.\n * - The providerName string identifies the provider that is used to interact with the blockchain.\n */\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name;\n this._providerName = providerName;\n }\n\n /**\n * @returns The address of the account.\n */\n public address(): string {\n return this._address;\n }\n\n /**\n * @returns The name of the account.\n */\n public name(): string {\n return this._name;\n }\n\n /**\n * @returns The name of the provider.\n */\n public providerName(): string {\n return this._providerName;\n }\n\n /**\n * This method aims to retrieve the account's balance.\n *\n * @returns A promise that resolves to an object of type IAccountBalanceResponse. It contains the account's balance.\n */\n public async balance(): Promise<IAccountBalanceResponse> {\n let signOpResponse: JsonRpcResponseData<IAddressesBalances> = null;\n try {\n signOpResponse = await getRequest<IAddressesBalances>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this._address}`,\n );\n } catch (ex) {\n console.error(`MassaStation account balance error`);\n throw ex;\n }\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n const balance: IBalance =\n signOpResponse.result.addressesAttributes[this._address].balance;\n return {\n finalBalance: balance.final,\n candidateBalance: balance.pending,\n };\n }\n\n /**\n * This method aims to sign a message.\n *\n * @param data - The message to be signed.\n * @returns An IAccountSignResponse object. It contains the signature of the message.\n */\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n let signOpResponse: JsonRpcResponseData<IAccountSignResponse> = null;\n\n try {\n signOpResponse = await postRequest<IAccountSignResponse>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/sign`,\n {\n operation: Buffer.from(data).toString('base64'),\n batch: false,\n } as ISignOperation,\n );\n } catch (ex) {\n console.error(`MassaStation account signing error`);\n throw ex;\n }\n\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n\n const signature = base58Encode(\n Buffer.from(signOpResponse.result.signature, 'base64'),\n );\n\n return {\n publicKey: signOpResponse.result.publicKey,\n base58Encoded: signature,\n };\n }\n\n /**\n * This method aims to buy rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be bought.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async buyRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let buyRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'buy',\n };\n try {\n buyRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while buying rolls: ${ex}`);\n throw ex;\n }\n if (buyRollsOpResponse.isError || buyRollsOpResponse.error) {\n throw buyRollsOpResponse.error;\n }\n return buyRollsOpResponse.result;\n }\n\n /**\n * This method aims to sell rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be sold.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async sellRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sellRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'sell',\n };\n try {\n sellRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while selling rolls: ${ex}`);\n throw ex;\n }\n if (sellRollsOpResponse.isError || sellRollsOpResponse.error) {\n throw sellRollsOpResponse.error;\n }\n return sellRollsOpResponse.result;\n }\n\n /**\n * This method aims to transfer MAS on behalf of the sender to a recipient.\n *\n * @param amount - The amount of MAS (in the smallest unit) to be transferred.\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sendTxOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/transfer`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: recipientAddress,\n };\n\n try {\n sendTxOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(\n `MassaStation account: error while sending transaction: ${ex}`,\n );\n throw ex;\n }\n if (sendTxOpResponse.isError || sendTxOpResponse.error) {\n throw sendTxOpResponse.error;\n }\n return sendTxOpResponse.result;\n }\n\n /**\n * This method aims to interact with a smart contract deployed on the MASSA blockchain.\n *\n * @remarks\n * If dryRun.dryRun is true, the method will dry run the smart contract call and return an\n * IContractReadOperationResponse object which contains all the information about the dry run\n * (state changes, gas used, etc.)\n *\n * @param contractAddress - The address of the smart contract.\n * @param functionName - The name of the function to be called.\n * @param parameter - The parameters as an Args object to be passed to the function.\n * @param amount - The amount of MASSA coins to be sent to the contract (in the smallest unit).\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @param maxGas - The maximum amount of gas to be used for the transaction execution.\n * @param nonPersistentExecution - The dryRun object to be passed to the function.\n *\n * @returns if 'nonPersistentExecution' is true, it returns an IContractReadOperationResponse object.\n * Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.\n *\n */\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n amount,\n fee,\n maxGas,\n );\n }\n // convert parameter to base64\n let args = '';\n if (parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(parameter);\n } else {\n args = argsToBase64(parameter);\n }\n let CallSCOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_URL}cmd/executeFunction`;\n const body: ExecuteFunctionBody = {\n nickname: this._name,\n name: functionName,\n at: contractAddress,\n args: args,\n coins: Number(amount),\n async: true,\n };\n try {\n CallSCOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.log(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n throw ex;\n }\n if (CallSCOpResponse.isError || CallSCOpResponse.error) {\n throw CallSCOpResponse.error;\n }\n return CallSCOpResponse.result;\n }\n\n public async getNodeUrlFromMassaStation(): Promise<string> {\n // get the node url from MassaStation\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n let node = '';\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n node = nodes.url;\n } catch (ex) {\n throw new Error(`MassaStation nodes retrieval error: ${ex}`);\n }\n return node;\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n ): Promise<IContractReadOperationResponse> {\n const node = await this.getNodeUrlFromMassaStation();\n // Gas amount check\n if (maxGas > MAX_READ_BLOCK_GAS) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_READ_BLOCK_GAS.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: Number(maxGas),\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n node,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAIL,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AAGnD;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AA6BjD;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACtB,aAAa,CAAS;IACtB,QAAQ,CAAS;IACjB,KAAK,CAAS;IAEtB;;;;;;;;;;;;OAYG;IACH,YAAmB,EAAE,OAAO,EAAE,IAAI,EAAmB,EAAE,YAAoB;QACzE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,cAAc,GAA4C,IAAI,CAAC;QACnE,IAAI;YACF,cAAc,GAAG,MAAM,UAAU,CAC/B,GAAG,i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C;QACF,wBAAwB;QACxB,IAAI,iBAAiB,GAAsC,EAAE,CAAC;QAC9D,IAAI;YACF,IAAI,IAAI,GAAG,MAAM,WAAW,CAC1B,IAAI,EACJ,IAAI,CACL,CAAC;YACF,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;aAC1B;YACD,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;SACjC;QAAC,OAAO,EAAE,EAAE;YACX,MAAM,IAAI,KAAK,CACb,sEAAsE,EAAE,EAAE,CAC3E,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAC;SACH;QACD,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO;YACL,WAAW,EAAE,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YACrE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n IAccountBalanceResponse,\n IAccountDetails,\n IAccountSignResponse,\n ITransactionDetails,\n} from '..';\nimport { IAccount } from '../account/IAccount';\nimport { JsonRpcResponseData, getRequest, postRequest } from './RequestHandler';\nimport {\n MASSA_STATION_URL,\n MASSA_STATION_ACCOUNTS_URL,\n} from './MassaStationProvider';\nimport {\n Args,\n IContractReadOperationData,\n IContractReadOperationResponse,\n MAX_GAS_CALL,\n} from '@massalabs/web3-utils';\n\nimport { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';\nimport { IAccountSignOutput } from '../account/AccountSign';\nimport { encode as base58Encode } from 'bs58check';\nimport { ExecuteFunctionBody } from './types';\n\n/**\n * The maximum allowed gas for a read operation\n */\nconst MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's sign\n * operation `/signOperation` url.\n */\ninterface ISignOperation {\n operation: string;\n batch?: boolean;\n correlationId?: string;\n}\n\n/**\n * This interface represents the the individual wallet's final and pending balances returned by MassaStation\n */\ninterface IBalance {\n final: string;\n pending: string;\n}\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\ninterface IAddressesBalances {\n addressesAttributes: {\n [key: string]: { balance: IBalance };\n };\n}\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n\n /**\n * This constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n *\n * @param address - The address of the account.\n * @param name - The name of the account.\n * @param providerName - The name of the provider.\n * @returns An instance of the Account class.\n *\n * @remarks\n * - The Account constructor takes an object of type IAccountDetails and a providerName string as its arguments.\n * - The IAccountDetails object contains the account's address and name.\n * - The providerName string identifies the provider that is used to interact with the blockchain.\n */\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name;\n this._providerName = providerName;\n }\n\n /**\n * @returns The address of the account.\n */\n public address(): string {\n return this._address;\n }\n\n /**\n * @returns The name of the account.\n */\n public name(): string {\n return this._name;\n }\n\n /**\n * @returns The name of the provider.\n */\n public providerName(): string {\n return this._providerName;\n }\n\n /**\n * This method aims to retrieve the account's balance.\n *\n * @returns A promise that resolves to an object of type IAccountBalanceResponse. It contains the account's balance.\n */\n public async balance(): Promise<IAccountBalanceResponse> {\n let signOpResponse: JsonRpcResponseData<IAddressesBalances> = null;\n try {\n signOpResponse = await getRequest<IAddressesBalances>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this._address}`,\n );\n } catch (ex) {\n console.error(`MassaStation account balance error`);\n throw ex;\n }\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n const balance: IBalance =\n signOpResponse.result.addressesAttributes[this._address].balance;\n return {\n finalBalance: balance.final,\n candidateBalance: balance.pending,\n };\n }\n\n /**\n * This method aims to sign a message.\n *\n * @param data - The message to be signed.\n * @returns An IAccountSignResponse object. It contains the signature of the message.\n */\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n let signOpResponse: JsonRpcResponseData<IAccountSignResponse> = null;\n\n try {\n signOpResponse = await postRequest<IAccountSignResponse>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/sign`,\n {\n operation: Buffer.from(data).toString('base64'),\n batch: false,\n } as ISignOperation,\n );\n } catch (ex) {\n console.error(`MassaStation account signing error`);\n throw ex;\n }\n\n if (signOpResponse.isError || signOpResponse.error) {\n throw signOpResponse.error;\n }\n\n const signature = base58Encode(\n Buffer.from(signOpResponse.result.signature, 'base64'),\n );\n\n return {\n publicKey: signOpResponse.result.publicKey,\n base58Encoded: signature,\n };\n }\n\n /**\n * This method aims to buy rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be bought.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async buyRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let buyRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'buy',\n };\n try {\n buyRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while buying rolls: ${ex}`);\n throw ex;\n }\n if (buyRollsOpResponse.isError || buyRollsOpResponse.error) {\n throw buyRollsOpResponse.error;\n }\n return buyRollsOpResponse.result;\n }\n\n /**\n * This method aims to sell rolls on behalf of the sender.\n *\n * @param amount - The amount of rolls to be sold.\n * @param fee - The fee to be paid for the transaction execution by the node.\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n public async sellRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sellRollsOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/rolls`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: 'sell',\n };\n try {\n sellRollsOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(`MassaStation account: error while selling rolls: ${ex}`);\n throw ex;\n }\n if (sellRollsOpResponse.isError || sellRollsOpResponse.error) {\n throw sellRollsOpResponse.error;\n }\n return sellRollsOpResponse.result;\n }\n\n /**\n * This method aims to transfer MAS on behalf of the sender to a recipient.\n *\n * @param amount - The amount of MAS (in the smallest unit) to be transferred.\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @returns An ITransactionDetails object. It contains the operationId on the network.\n */\n async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n let sendTxOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_ACCOUNTS_URL}/${this._name}/transfer`;\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: recipientAddress,\n };\n\n try {\n sendTxOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.error(\n `MassaStation account: error while sending transaction: ${ex}`,\n );\n throw ex;\n }\n if (sendTxOpResponse.isError || sendTxOpResponse.error) {\n throw sendTxOpResponse.error;\n }\n return sendTxOpResponse.result;\n }\n\n /**\n * This method aims to interact with a smart contract deployed on the MASSA blockchain.\n *\n * @remarks\n * If dryRun.dryRun is true, the method will dry run the smart contract call and return an\n * IContractReadOperationResponse object which contains all the information about the dry run\n * (state changes, gas used, etc.)\n *\n * @param contractAddress - The address of the smart contract.\n * @param functionName - The name of the function to be called.\n * @param parameter - The parameters as an Args object to be passed to the function.\n * @param amount - The amount of MASSA coins to be sent to the contract (in the smallest unit).\n * @param fee - The fee to be paid for the transaction execution (in the smallest unit).\n * @param maxGas - The maximum amount of gas to be used for the transaction execution.\n * @param nonPersistentExecution - The dryRun object to be passed to the function.\n *\n * @returns if 'nonPersistentExecution' is true, it returns an IContractReadOperationResponse object.\n * Otherwise, it returns an ITransactionDetails object which contains the operationId on the network.\n *\n */\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n coins: bigint,\n fee?: bigint,\n maxGas?: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n maxGas,\n );\n }\n // convert parameter to base64\n let args = '';\n if (parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(parameter);\n } else {\n args = argsToBase64(parameter);\n }\n let CallSCOpResponse: JsonRpcResponseData<ITransactionDetails> = null;\n const url = `${MASSA_STATION_URL}cmd/executeFunction`;\n const body: ExecuteFunctionBody = {\n nickname: this._name,\n name: functionName,\n at: contractAddress,\n args: args,\n coins: Number(coins),\n fee: fee ? fee.toString() : '0',\n // If maxGas is not provided, estimation will be done by MS\n maxGas: maxGas ? maxGas.toString() : '',\n async: true,\n };\n try {\n CallSCOpResponse = await postRequest<ITransactionDetails>(url, body);\n } catch (ex) {\n console.log(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n throw ex;\n }\n if (CallSCOpResponse.isError || CallSCOpResponse.error) {\n throw CallSCOpResponse.error;\n }\n return CallSCOpResponse.result;\n }\n\n public async getNodeUrlFromMassaStation(): Promise<string> {\n // get the node url from MassaStation\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n let node = '';\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n node = nodes.url;\n } catch (ex) {\n throw new Error(`MassaStation nodes retrieval error: ${ex}`);\n }\n return node;\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n maxGas?: bigint,\n ): Promise<IContractReadOperationResponse> {\n const node = await this.getNodeUrlFromMassaStation();\n // Gas amount check\n if (maxGas > MAX_READ_BLOCK_GAS) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_READ_BLOCK_GAS.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: maxGas ? Number(maxGas) : MAX_GAS_CALL,\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n node,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@massalabs/wallet-provider",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2-dev.20231220152928",
|
|
4
4
|
"description": "massa's wallet provider",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@hicaru/bearby.js": "^0.5.0",
|
|
56
|
+
"@massalabs/massa-web3": "^2.2.7",
|
|
56
57
|
"@massalabs/web3-utils": "^1.4.1",
|
|
57
58
|
"axios": "^0.26.1",
|
|
58
59
|
"bignumber.js": "^9.1.1",
|