@massalabs/wallet-provider 3.2.1-dev.20250520085601 → 3.2.1-dev.20250523120050
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/esm/bearbyWallet/BearbyAccount.d.ts +2 -1
- package/dist/esm/bearbyWallet/BearbyAccount.d.ts.map +1 -1
- package/dist/esm/bearbyWallet/BearbyAccount.js +24 -4
- package/dist/esm/bearbyWallet/BearbyAccount.js.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.d.ts +5 -3
- package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.js +75 -18
- package/dist/esm/massaStation/MassaStationAccount.js.map +1 -1
- package/dist/esm/massaStation/types.d.ts +17 -1
- package/dist/esm/massaStation/types.d.ts.map +1 -1
- package/dist/esm/massaStation/types.js.map +1 -1
- package/dist/esm/massaStation/utils/network.d.ts +2 -2
- package/dist/esm/massaStation/utils/network.d.ts.map +1 -1
- package/dist/esm/massaStation/utils/network.js +5 -15
- package/dist/esm/massaStation/utils/network.js.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.d.ts +2 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.d.ts.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.js +19 -24
- package/dist/esm/metamaskSnap/MetamaskAccount.js.map +1 -1
- package/dist/esm/metamaskSnap/utils/network.d.ts +2 -2
- package/dist/esm/metamaskSnap/utils/network.d.ts.map +1 -1
- package/dist/esm/metamaskSnap/utils/network.js +2 -2
- package/dist/esm/metamaskSnap/utils/network.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, CallSCParams, DeploySCParams, EventFilter, Network, NodeStatusInfo, Operation, OperationOptions, OperationStatus, Provider, ReadSCData, ReadSCParams, SignedData, SmartContract, rpcTypes, ExecuteScParams } from '@massalabs/massa-web3';
|
|
1
|
+
import { Address, CallSCParams, DeploySCParams, EventFilter, Network, NodeStatusInfo, Operation, OperationOptions, OperationStatus, Provider, ReadSCData, ReadSCParams, SignedData, SmartContract, rpcTypes, ExecuteScParams, ExecuteSCReadOnlyParams, ExecuteSCReadOnlyResult } from '@massalabs/massa-web3';
|
|
2
2
|
export declare class BearbyAccount implements Provider {
|
|
3
3
|
address: string;
|
|
4
4
|
constructor(address: string);
|
|
@@ -20,6 +20,7 @@ export declare class BearbyAccount implements Provider {
|
|
|
20
20
|
readSC(params: ReadSCParams): Promise<ReadSCData>;
|
|
21
21
|
deploySC(params: DeploySCParams): Promise<SmartContract>;
|
|
22
22
|
executeSC(params: ExecuteScParams): Promise<Operation>;
|
|
23
|
+
executeSCReadOnly(params: ExecuteSCReadOnlyParams): Promise<ExecuteSCReadOnlyResult>;
|
|
23
24
|
getOperationStatus(opId: string): Promise<OperationStatus>;
|
|
24
25
|
getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents>;
|
|
25
26
|
getNodeStatus(): Promise<NodeStatusInfo>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyAccount.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AASA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,EAIX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EAIb,QAAQ,EAER,eAAe,
|
|
1
|
+
{"version":3,"file":"BearbyAccount.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AASA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,EAIX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EAIb,QAAQ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B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC;IAWtB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAmC1D,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IA6B9D,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC;IAQxC,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,UAAU,GAAG,MAAyB,EAC9C,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;IA0BX,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,EAC7B,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;CAkBzB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { web3, } from '@hicaru/bearby.js';
|
|
2
2
|
import { errorHandler } from '../errors/utils/errorHandler';
|
|
3
3
|
import { operationType } from '../utils/constants';
|
|
4
|
-
import { DEPLOYER_BYTECODE, formatNodeStatusObject, Mas, MAX_GAS_CALL, Operation, OperationStatus, SmartContract, StorageCost, strToBytes, bytesToStr, JsonRpcPublicProvider, } from '@massalabs/massa-web3';
|
|
4
|
+
import { DEPLOYER_BYTECODE, formatNodeStatusObject, Mas, MAX_GAS_CALL, Operation, OperationStatus, SmartContract, StorageCost, strToBytes, bytesToStr, JsonRpcPublicProvider, populateDatastore, } from '@massalabs/massa-web3';
|
|
5
5
|
import { networkInfos } from './utils/network';
|
|
6
6
|
import { WalletName } from '../wallet';
|
|
7
7
|
import isEqual from 'lodash.isequal';
|
|
@@ -204,24 +204,35 @@ export class BearbyAccount {
|
|
|
204
204
|
const coins = params.coins ?? 0n;
|
|
205
205
|
const maxCoins = params.maxCoins ??
|
|
206
206
|
StorageCost.smartContractDeploy(params.byteCode.length) + coins;
|
|
207
|
+
const args = params.parameter ?? new Uint8Array();
|
|
208
|
+
const parameters = args instanceof Uint8Array ? args : args.serialize();
|
|
207
209
|
let maxGas = params.maxGas;
|
|
208
210
|
if (!maxGas) {
|
|
209
211
|
const client = await this.getClient();
|
|
212
|
+
const datastore = populateDatastore([
|
|
213
|
+
{
|
|
214
|
+
data: params.byteCode,
|
|
215
|
+
args: parameters,
|
|
216
|
+
coins,
|
|
217
|
+
},
|
|
218
|
+
]);
|
|
210
219
|
maxGas = await client.executeSCGasEstimation({
|
|
211
220
|
...params,
|
|
221
|
+
byteCode: DEPLOYER_BYTECODE,
|
|
222
|
+
datastore,
|
|
212
223
|
caller: this.address,
|
|
213
224
|
});
|
|
214
225
|
}
|
|
215
|
-
const
|
|
216
|
-
...params,
|
|
226
|
+
const bearbyParams = {
|
|
217
227
|
maxCoins,
|
|
218
228
|
maxGas,
|
|
219
229
|
coins,
|
|
220
230
|
fee,
|
|
221
231
|
contractDataBase64: uint8ArrayToBase64(params.byteCode),
|
|
222
232
|
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
|
|
233
|
+
unsafeParameters: parameters,
|
|
223
234
|
};
|
|
224
|
-
const operationId = await web3.contract.deploy(
|
|
235
|
+
const operationId = await web3.contract.deploy(bearbyParams);
|
|
225
236
|
const operation = new Operation(this, operationId);
|
|
226
237
|
const deployedAddress = await operation.getDeployedAddress(params.waitFinalExecution);
|
|
227
238
|
return new SmartContract(this, deployedAddress);
|
|
@@ -251,6 +262,15 @@ export class BearbyAccount {
|
|
|
251
262
|
const operationId = await web3.contract.executeBytecode(args);
|
|
252
263
|
return new Operation(this, operationId);
|
|
253
264
|
}
|
|
265
|
+
async executeSCReadOnly(params) {
|
|
266
|
+
try {
|
|
267
|
+
const client = await this.getClient();
|
|
268
|
+
return client.executeSCReadOnly(params);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
throw new Error(`Error during readonly smart contract bytecode execution: ${error}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
254
274
|
async getOperationStatus(opId) {
|
|
255
275
|
try {
|
|
256
276
|
const res = await web3.massa.getOperations(opId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,GAIL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAGL,iBAAiB,EAGjB,sBAAsB,EACtB,GAAG,EACH,YAAY,EAGZ,SAAS,EAET,eAAe,EAKf,aAAa,EACb,WAAW,EACX,UAAU,EACV,UAAU,EAEV,qBAAqB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,IAAI,UAAiC,CAAC;AAEtC,MAAM,OAAO,aAAa;IACE;IAA1B,YAA0B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAE7C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,2BAA2B;IAC3B,UAAU;IACV,mCAAmC;IACnC,mBAAmB;IACnB,oDAAoD;IACpD,MAAM;IACN,IAAI;IAEI,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,OAAO,GAAG,MAAM,YAAY,EAAE,CAAC;YACrC,UAAU,GAAG,CACX,OAAO,CAAC,IAAI,KAAK,SAAS;gBACxB,CAAC,CAAC,qBAAqB,CA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AAC;gBAC3D,GAAG;gBACH,OAAO;aACR,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC,CAAC;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,SAAS,GAAG,KAAK;gBACrB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;gBACxD,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,gDAAgD,KAAK,CAAC,OAAO,EAAE,CAChE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["import {\n EventFilterParam,\n web3,\n DatastoreEntryInputParam,\n JsonRPCResponse,\n ExecuteBytecodeParams,\n} from '@hicaru/bearby.js';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DEPLOYER_BYTECODE,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n StorageCost,\n strToBytes,\n bytesToStr,\n rpcTypes,\n JsonRpcPublicProvider,\n ExecuteScParams,\n} from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport isEqual from 'lodash.isequal';\nimport { uint8ArrayToBase64 } from '../utils/base64';\n\nlet jsonClient: JsonRpcPublicProvider;\n\nexport class BearbyAccount implements Provider {\n public constructor(public address: string) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Bearby;\n }\n\n // public async connect() {\n // try {\n // await web3.wallet.connect();\n // } catch (ex) {\n // console.log('Bearby connection error: ', ex);\n // }\n // }\n\n private async getClient(): Promise<JsonRpcPublicProvider> {\n if (!jsonClient) {\n const network = await networkInfos();\n jsonClient = (\n network.name === 'mainnet'\n ? JsonRpcPublicProvider.mainnet()\n : JsonRpcPublicProvider.buildnet()\n ) as JsonRpcPublicProvider;\n }\n return jsonClient;\n }\n\n public async balance(final = false): Promise<bigint> {\n // // TODO: check if we need to connect every time\n // await this.connect();\n\n try {\n const res = await web3.massa.getAddresses(this.address);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n const { final_balance, candidate_balance } = res.result[0];\n\n return Mas.fromString(final ? final_balance : candidate_balance);\n } catch (error) {\n const errorMessage = `An unexpected error occurred while fetching the account balance: ${error.message}.`;\n\n throw new Error(errorMessage);\n }\n }\n\n public async balanceOf(\n addresses: string[],\n final?: boolean,\n ): Promise<{ address: string; balance: bigint }[]> {\n const res = await web3.massa.getAddresses(...addresses);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n return res.result.map((addressInfo) => {\n const { final_balance, candidate_balance } = addressInfo;\n return {\n address: addressInfo.address,\n balance: Mas.fromString(final ? final_balance : candidate_balance),\n };\n });\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async sign(data: Uint8Array | string): Promise<SignedData> {\n // await this.connect();\n\n if (data instanceof Uint8Array) {\n data = bytesToStr(data);\n }\n\n try {\n const signature = await web3.wallet.signMessage(data);\n\n return {\n publicKey: signature.publicKey,\n signature: signature.signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.buyRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.BuyRolls, error);\n }\n }\n\n public async sellRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.sellRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SellRolls, error);\n }\n }\n\n public async transfer(\n to: Address | string,\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n\n try {\n const operationId = await web3.massa.payment(\n amount.toString(),\n to.toString(),\n );\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const { minimalFee } = await this.networkInfos();\n return minimalFee;\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // await this.connect();\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params.fee ?? (await this.minimalFee());\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.getGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n try {\n const operationId = await web3.contract.call({\n // TODO: add bigint support in bearby.js\n maxGas: Number(maxGas),\n coins: Number(params.coins || 0),\n fee: Number(fee),\n targetAddress: params.target,\n functionName: params.func,\n unsafeParameters,\n });\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}.`,\n );\n }\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n\n try {\n // const res = await web3.contract.readSmartContract({\n // // TODO: add bigint support in bearby.js\n // maxGas: Number(params.maxGas),\n // coins: Number(params.coins),\n // fee: Number(fee),\n // targetAddress: params.target,\n // targetFunction: params.func,\n // // TODO: add unsafeParameters to bearby.js\n // // https://github.com/bearby-wallet/bearby-web3/pull/18\n // parameter: unsafeParameters as any,\n // });\n\n // console.log('bearby readSC res', res[0]);\n // const data = res[0].result[0];\n\n // return {\n // value: data.result.Ok ? Uint8Array.from(data.result.Ok): new Uint8Array(),\n // info: {\n // error: data.result.Error,\n // events: data.output_events.map((event: SCEvent) => ({\n // data: event.data,\n // context: event.context,\n // })),\n // gasCost: data.gas_cost,\n // },\n // };\n\n // Temp implementation to remove when bearby.js is fixed\n const client = await this.getClient();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter: unsafeParameters,\n };\n return client.readSC(readOnlyParams);\n } catch (error) {\n throw new Error(\n `An error occurred while reading the smart contract: ${error.message}`,\n );\n }\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const fee = Number(params.fee ?? (await this.minimalFee()));\n const coins = params.coins ?? 0n;\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContractDeploy(params.byteCode.length) + coins;\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.executeSCGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n const args = {\n ...params,\n maxCoins,\n maxGas,\n coins,\n fee,\n contractDataBase64: uint8ArrayToBase64(params.byteCode),\n deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),\n };\n\n const operationId = await web3.contract.deploy(args);\n\n const operation = new Operation(this, operationId);\n\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n console.error('Error deploying smart contract:', error);\n throw new Error(`Failed to deploy smart contract: ${error.message}`);\n }\n }\n\n public async executeSC(params: ExecuteScParams): Promise<Operation> {\n const fee = params.fee ?? (await this.minimalFee());\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.executeSCGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n const args: ExecuteBytecodeParams = {\n maxCoins: params.maxCoins ?? 0n,\n maxGas,\n fee,\n bytecodeBase64: uint8ArrayToBase64(params.byteCode),\n datastore: params.datastore ?? new Map<Uint8Array, Uint8Array>(),\n };\n\n const operationId = await web3.contract.executeBytecode(args);\n\n return new Operation(this, operationId);\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n try {\n const res = await web3.massa.getOperations(opId);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getOperations error');\n }\n const op = res.result[0];\n if (op.op_exec_status === null) {\n if (op.is_operation_final === null) {\n return OperationStatus.NotFound;\n }\n throw new Error('unexpected status');\n }\n\n if (op.in_pool) {\n return OperationStatus.PendingInclusion;\n }\n\n if (!op.is_operation_final) {\n return op.op_exec_status\n ? OperationStatus.SpeculativeSuccess\n : OperationStatus.SpeculativeError;\n }\n\n return op.op_exec_status\n ? OperationStatus.Success\n : OperationStatus.Error;\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const formattedFilter: EventFilterParam = {\n start: filter.start,\n end: filter.end,\n emitter_address: filter.smartContractAddress,\n original_caller_address: filter.callerAddress,\n original_operation_id: filter.operationId,\n is_final: filter.isFinal,\n is_error: filter.isError,\n };\n\n try {\n /* \n Currently getFilteredSCOutputEvent is supposed to return a JsonRPCResponseFilteredSCOutputEvent object.\n But in practice it's returning an array of JsonRPCResponse<rpcTypes.OutputEvents> objects.\n */\n const res = (await web3.contract.getFilteredSCOutputEvent(\n formattedFilter,\n )) as JsonRPCResponse<rpcTypes.OutputEvents>[];\n\n if (res?.[0]?.error) throw res[0].error;\n return res?.[0]?.result ?? [];\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const status = await web3.massa.getNodesStatus();\n if (status.error || !status.result) {\n throw new Error(status.error?.message || 'Bearby getNodeStatus error');\n }\n return formatNodeStatusObject(status.result);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const res = await web3.massa.getAddresses(address);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getStorageKeys error');\n }\n\n const addressInfo = res.result[0];\n const keys = final\n ? addressInfo.final_datastore_keys\n : addressInfo.candidate_datastore_keys;\n\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n\n return keys\n .filter(\n (key) =>\n !filter.length ||\n isEqual(\n Uint8Array.from(key.slice(0, filterBytes.length)),\n filterBytes,\n ),\n )\n .map((d) => Uint8Array.from(d));\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n try {\n const input: DatastoreEntryInputParam[] = keys.map((key) => ({\n key,\n address,\n }));\n const data = await web3.contract.getDatastoreEntries(...input);\n const resultArray = data[0]['result'];\n const dataArray = final\n ? resultArray.map((d) => Uint8Array.from(d.final_value))\n : resultArray.map((d) => Uint8Array.from(d.candidate_value));\n return dataArray;\n } catch (error) {\n throw new Error(\n `An error occurred while reading the storage: ${error.message}`,\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,GAIL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,Y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,MAAM,CAAC,MAAM;YACd,OAAO,CACL,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,EACjD,WAAW,CACZ,CACJ;aACA,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,IAAI;YACF,MAAM,KAAK,GAA+B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC3D,GAAG;gBACH,OAAO;aACR,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC,CAAC;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,SAAS,GAAG,KAAK;gBACrB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;gBACxD,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,gDAAgD,KAAK,CAAC,OAAO,EAAE,CAChE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["import {\n EventFilterParam,\n web3,\n DatastoreEntryInputParam,\n JsonRPCResponse,\n ExecuteBytecodeParams,\n} from '@hicaru/bearby.js';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DEPLOYER_BYTECODE,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n StorageCost,\n strToBytes,\n bytesToStr,\n rpcTypes,\n JsonRpcPublicProvider,\n ExecuteScParams,\n populateDatastore,\n ExecuteSCReadOnlyParams,\n ExecuteSCReadOnlyResult,\n} from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport isEqual from 'lodash.isequal';\nimport { uint8ArrayToBase64 } from '../utils/base64';\n\nlet jsonClient: JsonRpcPublicProvider;\n\nexport class BearbyAccount implements Provider {\n public constructor(public address: string) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Bearby;\n }\n\n // public async connect() {\n // try {\n // await web3.wallet.connect();\n // } catch (ex) {\n // console.log('Bearby connection error: ', ex);\n // }\n // }\n\n private async getClient(): Promise<JsonRpcPublicProvider> {\n if (!jsonClient) {\n const network = await networkInfos();\n jsonClient = (\n network.name === 'mainnet'\n ? JsonRpcPublicProvider.mainnet()\n : JsonRpcPublicProvider.buildnet()\n ) as JsonRpcPublicProvider;\n }\n return jsonClient;\n }\n\n public async balance(final = false): Promise<bigint> {\n // // TODO: check if we need to connect every time\n // await this.connect();\n\n try {\n const res = await web3.massa.getAddresses(this.address);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n const { final_balance, candidate_balance } = res.result[0];\n\n return Mas.fromString(final ? final_balance : candidate_balance);\n } catch (error) {\n const errorMessage = `An unexpected error occurred while fetching the account balance: ${error.message}.`;\n\n throw new Error(errorMessage);\n }\n }\n\n public async balanceOf(\n addresses: string[],\n final?: boolean,\n ): Promise<{ address: string; balance: bigint }[]> {\n const res = await web3.massa.getAddresses(...addresses);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n return res.result.map((addressInfo) => {\n const { final_balance, candidate_balance } = addressInfo;\n return {\n address: addressInfo.address,\n balance: Mas.fromString(final ? final_balance : candidate_balance),\n };\n });\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async sign(data: Uint8Array | string): Promise<SignedData> {\n // await this.connect();\n\n if (data instanceof Uint8Array) {\n data = bytesToStr(data);\n }\n\n try {\n const signature = await web3.wallet.signMessage(data);\n\n return {\n publicKey: signature.publicKey,\n signature: signature.signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.buyRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.BuyRolls, error);\n }\n }\n\n public async sellRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.sellRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SellRolls, error);\n }\n }\n\n public async transfer(\n to: Address | string,\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n\n try {\n const operationId = await web3.massa.payment(\n amount.toString(),\n to.toString(),\n );\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const { minimalFee } = await this.networkInfos();\n return minimalFee;\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // await this.connect();\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params.fee ?? (await this.minimalFee());\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.getGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n try {\n const operationId = await web3.contract.call({\n // TODO: add bigint support in bearby.js\n maxGas: Number(maxGas),\n coins: Number(params.coins || 0),\n fee: Number(fee),\n targetAddress: params.target,\n functionName: params.func,\n unsafeParameters,\n });\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}.`,\n );\n }\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n\n try {\n // const res = await web3.contract.readSmartContract({\n // // TODO: add bigint support in bearby.js\n // maxGas: Number(params.maxGas),\n // coins: Number(params.coins),\n // fee: Number(fee),\n // targetAddress: params.target,\n // targetFunction: params.func,\n // // TODO: add unsafeParameters to bearby.js\n // // https://github.com/bearby-wallet/bearby-web3/pull/18\n // parameter: unsafeParameters as any,\n // });\n\n // console.log('bearby readSC res', res[0]);\n // const data = res[0].result[0];\n\n // return {\n // value: data.result.Ok ? Uint8Array.from(data.result.Ok): new Uint8Array(),\n // info: {\n // error: data.result.Error,\n // events: data.output_events.map((event: SCEvent) => ({\n // data: event.data,\n // context: event.context,\n // })),\n // gasCost: data.gas_cost,\n // },\n // };\n\n // Temp implementation to remove when bearby.js is fixed\n const client = await this.getClient();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter: unsafeParameters,\n };\n return client.readSC(readOnlyParams);\n } catch (error) {\n throw new Error(\n `An error occurred while reading the smart contract: ${error.message}`,\n );\n }\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const fee = Number(params.fee ?? (await this.minimalFee()));\n const coins = params.coins ?? 0n;\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContractDeploy(params.byteCode.length) + coins;\n\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n\n const datastore = populateDatastore([\n {\n data: params.byteCode,\n args: parameters,\n coins,\n },\n ]);\n\n maxGas = await client.executeSCGasEstimation({\n ...params,\n byteCode: DEPLOYER_BYTECODE,\n datastore,\n caller: this.address,\n });\n }\n\n const bearbyParams = {\n maxCoins,\n maxGas,\n coins,\n fee,\n contractDataBase64: uint8ArrayToBase64(params.byteCode),\n deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),\n unsafeParameters: parameters,\n };\n\n const operationId = await web3.contract.deploy(bearbyParams);\n\n const operation = new Operation(this, operationId);\n\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n console.error('Error deploying smart contract:', error);\n throw new Error(`Failed to deploy smart contract: ${error.message}`);\n }\n }\n\n public async executeSC(params: ExecuteScParams): Promise<Operation> {\n const fee = params.fee ?? (await this.minimalFee());\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.executeSCGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n const args: ExecuteBytecodeParams = {\n maxCoins: params.maxCoins ?? 0n,\n maxGas,\n fee,\n bytecodeBase64: uint8ArrayToBase64(params.byteCode),\n datastore: params.datastore ?? new Map<Uint8Array, Uint8Array>(),\n };\n\n const operationId = await web3.contract.executeBytecode(args);\n\n return new Operation(this, operationId);\n }\n\n async executeSCReadOnly(\n params: ExecuteSCReadOnlyParams,\n ): Promise<ExecuteSCReadOnlyResult> {\n try {\n const client = await this.getClient();\n return client.executeSCReadOnly(params);\n } catch (error) {\n throw new Error(\n `Error during readonly smart contract bytecode execution: ${error}`,\n );\n }\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n try {\n const res = await web3.massa.getOperations(opId);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getOperations error');\n }\n const op = res.result[0];\n if (op.op_exec_status === null) {\n if (op.is_operation_final === null) {\n return OperationStatus.NotFound;\n }\n throw new Error('unexpected status');\n }\n\n if (op.in_pool) {\n return OperationStatus.PendingInclusion;\n }\n\n if (!op.is_operation_final) {\n return op.op_exec_status\n ? OperationStatus.SpeculativeSuccess\n : OperationStatus.SpeculativeError;\n }\n\n return op.op_exec_status\n ? OperationStatus.Success\n : OperationStatus.Error;\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const formattedFilter: EventFilterParam = {\n start: filter.start,\n end: filter.end,\n emitter_address: filter.smartContractAddress,\n original_caller_address: filter.callerAddress,\n original_operation_id: filter.operationId,\n is_final: filter.isFinal,\n is_error: filter.isError,\n };\n\n try {\n /* \n Currently getFilteredSCOutputEvent is supposed to return a JsonRPCResponseFilteredSCOutputEvent object.\n But in practice it's returning an array of JsonRPCResponse<rpcTypes.OutputEvents> objects.\n */\n const res = (await web3.contract.getFilteredSCOutputEvent(\n formattedFilter,\n )) as JsonRPCResponse<rpcTypes.OutputEvents>[];\n\n if (res?.[0]?.error) throw res[0].error;\n return res?.[0]?.result ?? [];\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const status = await web3.massa.getNodesStatus();\n if (status.error || !status.result) {\n throw new Error(status.error?.message || 'Bearby getNodeStatus error');\n }\n return formatNodeStatusObject(status.result);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const res = await web3.massa.getAddresses(address);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getStorageKeys error');\n }\n\n const addressInfo = res.result[0];\n const keys = final\n ? addressInfo.final_datastore_keys\n : addressInfo.candidate_datastore_keys;\n\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n\n return keys\n .filter(\n (key) =>\n !filter.length ||\n isEqual(\n Uint8Array.from(key.slice(0, filterBytes.length)),\n filterBytes,\n ),\n )\n .map((d) => Uint8Array.from(d));\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n try {\n const input: DatastoreEntryInputParam[] = keys.map((key) => ({\n key,\n address,\n }));\n const data = await web3.contract.getDatastoreEntries(...input);\n const resultArray = data[0]['result'];\n const dataArray = final\n ? resultArray.map((d) => Uint8Array.from(d.final_value))\n : resultArray.map((d) => Uint8Array.from(d.candidate_value));\n return dataArray;\n } catch (error) {\n throw new Error(\n `An error occurred while reading the storage: ${error.message}`,\n );\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MSDeploySCParams, MSExecuteScParams } from './types';
|
|
2
|
+
import { Address, CallSCParams, EventFilter, Network, NodeStatusInfo, Operation, OperationOptions, OperationStatus, Provider, ReadSCData, ReadSCParams, SignedData, SignOptions, SmartContract, rpcTypes, ExecuteSCReadOnlyResult, ExecuteSCReadOnlyParams } from '@massalabs/massa-web3';
|
|
2
3
|
/**
|
|
3
4
|
* This module contains the MassaStationAccount class. It is responsible for representing an account in
|
|
4
5
|
* the MassaStation wallet.
|
|
@@ -27,8 +28,9 @@ export declare class MassaStationAccount implements Provider {
|
|
|
27
28
|
callSC(params: CallSCParams): Promise<Operation>;
|
|
28
29
|
networkInfos(): Promise<Network>;
|
|
29
30
|
readSC(params: ReadSCParams): Promise<ReadSCData>;
|
|
30
|
-
deploySC(params:
|
|
31
|
-
executeSC(): Promise<Operation>;
|
|
31
|
+
deploySC(params: MSDeploySCParams): Promise<SmartContract>;
|
|
32
|
+
executeSC(params: MSExecuteScParams): Promise<Operation>;
|
|
33
|
+
executeSCReadOnly(params: ExecuteSCReadOnlyParams): Promise<ExecuteSCReadOnlyResult>;
|
|
32
34
|
getOperationStatus(opId: string): Promise<OperationStatus>;
|
|
33
35
|
getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents>;
|
|
34
36
|
getNodeStatus(): Promise<NodeStatusInfo>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAOA,OAAO,EAOL,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EAGX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,aAAa,EACb,QAAQ,EAKR,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAK/B;;;;;;;GAOG;AACH,qBAAa,mBAAoB,YAAW,QAAQ;IAIzC,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,MAAM;IAJ5B,OAAO,CAAC,aAAa,CAA0B;gBAGtC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM;IAG5B,IAAI,YAAY,IAAI,MAAM,CAEzB;IAEY,OAAO,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAU9C,SAAS,CACb,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,UAAQ,GACZ,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,O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,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,EAC7B,KAAK,UAAO,GACX,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC;CAKlC"}
|
|
@@ -3,7 +3,7 @@ import { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';
|
|
|
3
3
|
import { argsToBase64, base64ToByteArray, uint8ArrayToBase64, } from '../utils/base64';
|
|
4
4
|
import { errorHandler } from '../errors/utils/errorHandler';
|
|
5
5
|
import { operationType } from '../utils/constants';
|
|
6
|
-
import {
|
|
6
|
+
import { Mas, MAX_GAS_CALL, Operation, SmartContract, StorageCost, formatMas, DEPLOYER_BYTECODE, populateDatastore, } from '@massalabs/massa-web3';
|
|
7
7
|
import { getClient, networkInfos } from './utils/network';
|
|
8
8
|
import { WalletName } from '../wallet';
|
|
9
9
|
import bs58check from 'bs58check';
|
|
@@ -67,7 +67,8 @@ export class MassaStationAccount {
|
|
|
67
67
|
}
|
|
68
68
|
async minimalFee() {
|
|
69
69
|
const client = await getClient();
|
|
70
|
-
|
|
70
|
+
const { minimalFee } = await client.networkInfos();
|
|
71
|
+
return minimalFee;
|
|
71
72
|
}
|
|
72
73
|
async rollOperation(type, amount, opts) {
|
|
73
74
|
let fee = opts?.fee ?? (await this.minimalFee());
|
|
@@ -158,7 +159,7 @@ export class MassaStationAccount {
|
|
|
158
159
|
parameter: args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),
|
|
159
160
|
};
|
|
160
161
|
// This implementation is wrong. We should use massaStation instead of targeting the node directly.
|
|
161
|
-
return client.
|
|
162
|
+
return client.readSC(readOnlyParams);
|
|
162
163
|
}
|
|
163
164
|
async deploySC(params) {
|
|
164
165
|
try {
|
|
@@ -167,15 +168,35 @@ export class MassaStationAccount {
|
|
|
167
168
|
const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic
|
|
168
169
|
const maxCoins = params.maxCoins ??
|
|
169
170
|
StorageCost.smartContractDeploy(params.byteCode.length) + coins;
|
|
170
|
-
const fee = params.fee
|
|
171
|
+
const fee = params.fee ?? (await this.minimalFee());
|
|
172
|
+
let maxGas = params.maxGas;
|
|
173
|
+
if (!maxGas) {
|
|
174
|
+
const client = await getClient();
|
|
175
|
+
const datastore = populateDatastore([
|
|
176
|
+
{
|
|
177
|
+
data: params.byteCode,
|
|
178
|
+
args: parameters,
|
|
179
|
+
coins,
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
maxGas = await client.executeSCGasEstimation({
|
|
183
|
+
...params,
|
|
184
|
+
byteCode: DEPLOYER_BYTECODE,
|
|
185
|
+
datastore,
|
|
186
|
+
caller: this.address,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const description = params.description ??
|
|
190
|
+
`${formatMas(coins)} MAS coins allocated to new smart contract`;
|
|
171
191
|
const body = {
|
|
172
192
|
nickname: this.accountName,
|
|
173
193
|
smartContract: uint8ArrayToBase64(params.byteCode),
|
|
174
|
-
maxCoins: maxCoins.toString(),
|
|
175
194
|
coins: coins.toString(),
|
|
176
|
-
fee: fee.toString(),
|
|
177
195
|
parameters: uint8ArrayToBase64(parameters),
|
|
178
|
-
|
|
196
|
+
maxCoins: maxCoins.toString(),
|
|
197
|
+
fee: fee.toString(),
|
|
198
|
+
maxGas: maxGas.toString(),
|
|
199
|
+
description,
|
|
179
200
|
};
|
|
180
201
|
const { result } = await postRequest(`${MASSA_STATION_URL}cmd/deploySC`, body);
|
|
181
202
|
const operationId = result?.operationId;
|
|
@@ -189,8 +210,50 @@ export class MassaStationAccount {
|
|
|
189
210
|
throw new Error(`Error during smart contract deployment: ${error}`);
|
|
190
211
|
}
|
|
191
212
|
}
|
|
192
|
-
executeSC() {
|
|
193
|
-
|
|
213
|
+
async executeSC(params) {
|
|
214
|
+
try {
|
|
215
|
+
const fee = params.fee ?? (await this.minimalFee());
|
|
216
|
+
const maxCoins = params.maxCoins ?? 0n;
|
|
217
|
+
let maxGas = params.maxGas;
|
|
218
|
+
if (!maxGas) {
|
|
219
|
+
const client = await getClient();
|
|
220
|
+
maxGas = await client.executeSCGasEstimation({
|
|
221
|
+
...params,
|
|
222
|
+
caller: this.address,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const datastore = [];
|
|
226
|
+
if (params.datastore) {
|
|
227
|
+
for (const [key, value] of params.datastore.entries()) {
|
|
228
|
+
datastore.push([uint8ArrayToBase64(key), uint8ArrayToBase64(value)]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const body = {
|
|
232
|
+
nickname: this.accountName,
|
|
233
|
+
bytecode: uint8ArrayToBase64(params.byteCode),
|
|
234
|
+
datastore,
|
|
235
|
+
maxCoins: maxCoins.toString(),
|
|
236
|
+
fee: fee.toString(),
|
|
237
|
+
description: params.description ?? '',
|
|
238
|
+
};
|
|
239
|
+
const { result } = await postRequest(`${MASSA_STATION_URL}cmd/executeSC`, body);
|
|
240
|
+
const operationId = result?.operationId;
|
|
241
|
+
if (!operationId)
|
|
242
|
+
throw new Error('Operation ID not found');
|
|
243
|
+
return new Operation(this, operationId);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
throw new Error(`Error during smart contract bytecode execution: ${error}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async executeSCReadOnly(params) {
|
|
250
|
+
try {
|
|
251
|
+
const client = await getClient();
|
|
252
|
+
return client.executeSCReadOnly(params);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
throw new Error(`Error during readonly smart contract bytecode execution: ${error}`);
|
|
256
|
+
}
|
|
194
257
|
}
|
|
195
258
|
async getOperationStatus(opId) {
|
|
196
259
|
const client = await getClient();
|
|
@@ -204,23 +267,17 @@ export class MassaStationAccount {
|
|
|
204
267
|
}
|
|
205
268
|
async getNodeStatus() {
|
|
206
269
|
const client = await getClient();
|
|
207
|
-
|
|
208
|
-
return formatNodeStatusObject(status);
|
|
270
|
+
return client.getNodeStatus();
|
|
209
271
|
}
|
|
210
272
|
async getStorageKeys(address, filter = new Uint8Array(), final = true) {
|
|
211
273
|
// This implementation is wrong. We should use massaStation instead of targeting the node directly.
|
|
212
274
|
const client = await getClient();
|
|
213
|
-
|
|
214
|
-
return client.getDataStoreKeys(address, filterBytes, final);
|
|
275
|
+
return client.getStorageKeys(address, filter, final);
|
|
215
276
|
}
|
|
216
277
|
async readStorage(address, keys, final = true) {
|
|
217
278
|
// This implementation is wrong. We should use massaStation instead of targeting the node directly.
|
|
218
279
|
const client = await getClient();
|
|
219
|
-
|
|
220
|
-
key,
|
|
221
|
-
address,
|
|
222
|
-
}));
|
|
223
|
-
return client.getDatastoreEntries(entries, final);
|
|
280
|
+
return client.readStorage(address, keys, final);
|
|
224
281
|
}
|
|
225
282
|
}
|
|
226
283
|
//# sourceMappingURL=MassaStationAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAML,sBAAsB,EACtB,GAAG,EACH,YAAY,EAGZ,SAAS,EAQT,aAAa,EACb,UAAU,EAEV,WAAW,EACX,SAAS,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,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AmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnD,GAAG;YACH,OAAO;SACR,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n strToBytes,\n rpcTypes,\n StorageCost,\n formatMas,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\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 Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n const balances = result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n return addresses.map((address) => {\n const balance = result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n try {\n const { result } = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(result.signature),\n );\n\n return {\n publicKey: result.publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n return client.getMinimalFee();\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(type, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter) {\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler('callSmartContract', error);\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.executeReadOnlyCall(readOnlyParams);\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContractDeploy(params.byteCode.length) + coins;\n const fee = params.fee || (await this.minimalFee());\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n maxCoins: maxCoins.toString(), // SmartContract deployment costs\n coins: coins.toString(),\n fee: fee.toString(),\n parameters: uint8ArrayToBase64(parameters),\n description: `${formatMas(\n coins,\n )} $MAS coins allocated to datastore + ${formatMas(\n fee,\n )} $MAS fee for operation`,\n };\n\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<(Uint8Array | null)[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAIL,GAAG,EACH,YAAY,EAGZ,SAAS,EAQT,aAAa,EAEb,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IAIrB;IACA;IAJD,aAAa,GAAG,UAAU,CAAC,WAAW,C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AAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,MAAmB;QACxC,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,mGAAmG;QACnG,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,aAAa;QACxB,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,OAAe,EACf,SAA8B,IAAI,UAAU,EAAE,EAC9C,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n ExecuteSCBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSDeploySCParams,\n MSExecuteScParams,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n EventFilter,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n rpcTypes,\n StorageCost,\n formatMas,\n DEPLOYER_BYTECODE,\n populateDatastore,\n ExecuteSCReadOnlyResult,\n ExecuteSCReadOnlyParams,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\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 Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n const balances = result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n return addresses.map((address) => {\n const balance = result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n try {\n const { result } = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(result.signature),\n );\n\n return {\n publicKey: result.publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n const { minimalFee } = await client.networkInfos();\n return minimalFee;\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(type, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter) {\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler('callSmartContract', error);\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.readSC(readOnlyParams);\n }\n\n public async deploySC(params: MSDeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContractDeploy(params.byteCode.length) + coins;\n const fee = params.fee ?? (await this.minimalFee());\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await getClient();\n const datastore = populateDatastore([\n {\n data: params.byteCode,\n args: parameters,\n coins,\n },\n ]);\n\n maxGas = await client.executeSCGasEstimation({\n ...params,\n byteCode: DEPLOYER_BYTECODE,\n datastore,\n caller: this.address,\n });\n }\n\n const description =\n params.description ??\n `${formatMas(coins)} MAS coins allocated to new smart contract`;\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n coins: coins.toString(),\n parameters: uint8ArrayToBase64(parameters),\n maxCoins: maxCoins.toString(),\n fee: fee.toString(),\n maxGas: maxGas.toString(),\n description,\n };\n\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n async executeSC(params: MSExecuteScParams): Promise<Operation> {\n try {\n const fee = params.fee ?? (await this.minimalFee());\n const maxCoins = params.maxCoins ?? 0n;\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await getClient();\n maxGas = await client.executeSCGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n const datastore: [string, string][] = [];\n if (params.datastore) {\n for (const [key, value] of params.datastore.entries()) {\n datastore.push([uint8ArrayToBase64(key), uint8ArrayToBase64(value)]);\n }\n }\n\n const body: ExecuteSCBody = {\n nickname: this.accountName,\n bytecode: uint8ArrayToBase64(params.byteCode),\n datastore,\n maxCoins: maxCoins.toString(),\n fee: fee.toString(),\n description: params.description ?? '',\n };\n\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeSC`,\n body,\n );\n\n const operationId = result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n return new Operation(this, operationId);\n } catch (error) {\n throw new Error(\n `Error during smart contract bytecode execution: ${error}`,\n );\n }\n }\n\n async executeSCReadOnly(\n params: ExecuteSCReadOnlyParams,\n ): Promise<ExecuteSCReadOnlyResult> {\n try {\n const client = await getClient();\n return client.executeSCReadOnly(params);\n } catch (error) {\n throw new Error(\n `Error during readonly smart contract bytecode execution: ${error}`,\n );\n }\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n return client.getNodeStatus();\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n return client.getStorageKeys(address, filter, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<(Uint8Array | null)[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n return client.readStorage(address, keys, final);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NetworkName } from '@massalabs/massa-web3';
|
|
1
|
+
import { DeploySCParams, ExecuteScParams, NetworkName } from '@massalabs/massa-web3';
|
|
2
2
|
export type ExecuteFunctionBody = {
|
|
3
3
|
nickname: string;
|
|
4
4
|
name: string;
|
|
@@ -17,6 +17,16 @@ export type DeploySCFunctionBody = {
|
|
|
17
17
|
parameters: string;
|
|
18
18
|
fee: string;
|
|
19
19
|
description: string;
|
|
20
|
+
maxGas?: string;
|
|
21
|
+
};
|
|
22
|
+
export type ExecuteSCBody = {
|
|
23
|
+
nickname: string;
|
|
24
|
+
bytecode: string;
|
|
25
|
+
datastore: [string, string][];
|
|
26
|
+
maxCoins: string;
|
|
27
|
+
fee: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
maxGas?: string;
|
|
20
30
|
};
|
|
21
31
|
export type PluginInfo = {
|
|
22
32
|
author: string;
|
|
@@ -106,4 +116,10 @@ export interface SignRule {
|
|
|
106
116
|
export type AddUpdateSignRuleResponse = {
|
|
107
117
|
id: string;
|
|
108
118
|
};
|
|
119
|
+
export type MSDeploySCParams = DeploySCParams & {
|
|
120
|
+
description?: string;
|
|
121
|
+
};
|
|
122
|
+
export type MSExecuteScParams = ExecuteScParams & {
|
|
123
|
+
description?: string;
|
|
124
|
+
};
|
|
109
125
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE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CAAC;KACH,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC;KAC9B,CAAC;CACH;AAED,oBAAY,QAAQ;IAClB,qBAAqB,4BAA4B;IACjD,QAAQ,cAAc;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAN,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACnC,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHW,yBAAyB,KAAzB,yBAAyB,QAGpC;AAkED,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,6DAAiD,CAAA;IACjD,kCAAsB,CAAA;AACxB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB","sourcesContent":["import {\n DeploySCParams,\n ExecuteScParams,\n NetworkName,\n} from '@massalabs/massa-web3';\n\nexport type ExecuteFunctionBody = {\n nickname: string;\n name: string;\n at: string;\n args?: string;\n fee?: string;\n maxGas?: string;\n coins?: number; // number type keeped for backward compatibility\n async?: boolean;\n};\n\nexport type DeploySCFunctionBody = {\n nickname: string;\n smartContract: string;\n maxCoins: string;\n coins: string;\n parameters: string;\n fee: string;\n description: string;\n maxGas?: string;\n};\n\nexport type ExecuteSCBody = {\n nickname: string;\n bytecode: string;\n datastore: [string, string][];\n maxCoins: string;\n fee: string;\n description?: string;\n maxGas?: string;\n};\n\nexport type PluginInfo = {\n author: string;\n description: string;\n home: string;\n name: string;\n status: string;\n version: string;\n};\n\nexport type PluginManagerBody = PluginInfo[];\n\nexport type MSNetworksResp = {\n chainId: number | string;\n network: NetworkName;\n url: string;\n};\n\nexport enum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\nexport type MSAccountsResp = MSAccount[];\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport type MSAccount = {\n address: string;\n nickname: string;\n keyPair: {\n nonce: string;\n privateKey: string;\n publicKey: string;\n salt: string;\n };\n status: MassaStationAccountStatus;\n};\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\nexport type MSBalancesResp = {\n addressesAttributes: {\n [key: string]: {\n balance: {\n pending: string;\n final: string;\n };\n };\n };\n};\n\n/**\n * Payload for a sign message request.\n */\nexport type MSAccountSignPayload = {\n description: string;\n message: string;\n DisplayData: boolean;\n};\n\n/**\n * Response from the content script after a signing operation.\n */\nexport type MSAccountSignResp = {\n /** Public key of the account */\n publicKey: string;\n /** Signed message data */\n signature: string;\n};\n\nexport type MSSendOperationResp = {\n operationId: string;\n};\n\nexport interface AccountConfig {\n signRules: SignRule[];\n}\n\nexport interface Config {\n accounts: {\n [key: string]: AccountConfig;\n };\n}\n\nexport enum RuleType {\n DisablePasswordPrompt = 'DISABLE_PASSWORD_PROMPT',\n AutoSign = 'AUTO_SIGN',\n}\n\nexport interface SignRule {\n id?: string;\n ruleType: RuleType;\n name?: string;\n contract: string;\n enabled: boolean;\n}\n\nexport type AddUpdateSignRuleResponse = {\n id: string;\n};\n\nexport type MSDeploySCParams = DeploySCParams & {\n description?: string;\n};\n\nexport type MSExecuteScParams = ExecuteScParams & {\n description?: string;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcPublicProvider, Network } from '@massalabs/massa-web3';
|
|
2
2
|
export declare function networkInfos(): Promise<Network>;
|
|
3
|
-
export declare function getClient(): Promise<
|
|
3
|
+
export declare function getClient(): Promise<JsonRpcPublicProvider>;
|
|
4
4
|
//# sourceMappingURL=network.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,OAAO,EAER,MAAM,uBAAuB,CAAC;AAW/B,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAkBrD;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAMhE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcPublicProvider, PublicApiUrl, } from '@massalabs/massa-web3';
|
|
2
2
|
import { MASSA_STATION_URL } from '../MassaStationWallet';
|
|
3
3
|
import { getRequest } from '../RequestHandler';
|
|
4
4
|
import { isStandalone } from './standalone';
|
|
@@ -9,26 +9,16 @@ let rpcUrl;
|
|
|
9
9
|
export async function networkInfos() {
|
|
10
10
|
if (isStandalone()) {
|
|
11
11
|
rpcUrl = PublicApiUrl.Buildnet;
|
|
12
|
-
client =
|
|
13
|
-
return
|
|
14
|
-
name: NetworkName.Buildnet,
|
|
15
|
-
url: rpcUrl,
|
|
16
|
-
chainId: CHAIN_ID.Buildnet,
|
|
17
|
-
minimalFee: await client.getMinimalFee(),
|
|
18
|
-
};
|
|
12
|
+
client = JsonRpcPublicProvider.fromRPCUrl(rpcUrl);
|
|
13
|
+
return client.networkInfos();
|
|
19
14
|
}
|
|
20
15
|
const { result } = await getRequest(`${MASSA_STATION_URL}massa/node`);
|
|
21
16
|
const url = result.url;
|
|
22
17
|
if (!client || rpcUrl !== url) {
|
|
23
|
-
client =
|
|
18
|
+
client = JsonRpcPublicProvider.fromRPCUrl(url);
|
|
24
19
|
rpcUrl = url;
|
|
25
20
|
}
|
|
26
|
-
return
|
|
27
|
-
name: result.network,
|
|
28
|
-
url,
|
|
29
|
-
chainId: BigInt(result.chainId),
|
|
30
|
-
minimalFee: await client.getMinimalFee(),
|
|
31
|
-
};
|
|
21
|
+
return client.networkInfos();
|
|
32
22
|
}
|
|
33
23
|
export async function getClient() {
|
|
34
24
|
if (!client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAErB,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,+CAA+C;AAC/C,IAAI,MAA6B,CAAC;AAClC,0CAA0C;AAC1C,IAAI,MAAc,CAAC;AAEnB,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,YAAY,EAAE,EAAE;QAClB,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC;QAC/B,MAAM,GAAG,qBAAqB,CAAC,UAAU,CAAC,MAAM,CAA0B,CAAC;QAC3E,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;KAC9B;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CACjC,GAAG,iBAAiB,YAAY,CACjC,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IACvB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE;QAC7B,MAAM,GAAG,qBAAqB,CAAC,UAAU,CAAC,GAAG,CAA0B,CAAC;QACxE,MAAM,GAAG,GAAG,CAAC;KACd;IAED,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,CAAC,MAAM,EAAE;QACX,yBAAyB;QACzB,MAAM,YAAY,EAAE,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n JsonRpcPublicProvider,\n Network,\n PublicApiUrl,\n} from '@massalabs/massa-web3';\nimport { MSNetworksResp } from '../types';\nimport { MASSA_STATION_URL } from '../MassaStationWallet';\nimport { getRequest } from '../RequestHandler';\nimport { isStandalone } from './standalone';\n\n// Use client singleton to benefit from caching\nlet client: JsonRpcPublicProvider;\n// Use rpcUrl to check if node has changed\nlet rpcUrl: string;\n\nexport async function networkInfos(): Promise<Network> {\n if (isStandalone()) {\n rpcUrl = PublicApiUrl.Buildnet;\n client = JsonRpcPublicProvider.fromRPCUrl(rpcUrl) as JsonRpcPublicProvider;\n return client.networkInfos();\n }\n\n const { result } = await getRequest<MSNetworksResp>(\n `${MASSA_STATION_URL}massa/node`,\n );\n\n const url = result.url;\n if (!client || rpcUrl !== url) {\n client = JsonRpcPublicProvider.fromRPCUrl(url) as JsonRpcPublicProvider;\n rpcUrl = url;\n }\n\n return client.networkInfos();\n}\n\nexport async function getClient(): Promise<JsonRpcPublicProvider> {\n if (!client) {\n // this initialize client\n await networkInfos();\n }\n return client;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MetaMaskInpageProvider } from '@metamask/providers';
|
|
2
|
-
import { Address, CallSCParams, DeploySCParams, EventFilter, Network, NodeStatusInfo, Operation, OperationOptions, OperationStatus, Provider, ReadSCData, ReadSCParams, SignedData, SmartContract, rpcTypes, ExecuteScParams } from '@massalabs/massa-web3';
|
|
2
|
+
import { Address, CallSCParams, DeploySCParams, EventFilter, Network, NodeStatusInfo, Operation, OperationOptions, OperationStatus, Provider, ReadSCData, ReadSCParams, SignedData, SmartContract, rpcTypes, ExecuteScParams, ExecuteSCReadOnlyParams, ExecuteSCReadOnlyResult } from '@massalabs/massa-web3';
|
|
3
3
|
export declare class MetamaskAccount implements Provider {
|
|
4
4
|
readonly address: string;
|
|
5
5
|
private readonly provider;
|
|
@@ -26,5 +26,6 @@ export declare class MetamaskAccount implements Provider {
|
|
|
26
26
|
getStorageKeys(address: string, filter?: Uint8Array | string, final?: boolean): Promise<Uint8Array[]>;
|
|
27
27
|
readStorage(address: string, keys: Uint8Array[] | string[], final?: boolean): Promise<(Uint8Array | null)[]>;
|
|
28
28
|
executeSC(params: ExecuteScParams): Promise<Operation>;
|
|
29
|
+
executeSCReadOnly(params: ExecuteSCReadOnlyParams): Promise<ExecuteSCReadOnlyResult>;
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=MetamaskAccount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetamaskAccount.d.ts","sourceRoot":"","sources":["../../../src/metamaskSnap/MetamaskAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,YAAY,
|
|
1
|
+
{"version":3,"file":"MetamaskAccount.d.ts","sourceRoot":"","sources":["../../../src/metamaskSnap/MetamaskAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,YAAY,EACZ,cAAc,EACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EACb,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAwB/B,qBAAa,eAAgB,YAAW,QAAQ;aAE5B,OAAO,EAAE,MAAM;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADT,OAAO,EAAE,MAAM,EACd,QAAQ,EAAE,sBAAsB;IAGnD,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAEK,OAAO,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAOvC,SAAS,CACb,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,UAAQ,GACZ,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAK5C,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;YAgB9C,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
1
|
+
import { Operation, SmartContract, } from '@massalabs/massa-web3';
|
|
2
2
|
import { WalletName } from '../wallet';
|
|
3
3
|
import { errorHandler } from '../errors/utils/errorHandler';
|
|
4
4
|
import { operationType } from '../utils/constants';
|
|
@@ -25,13 +25,7 @@ export class MetamaskAccount {
|
|
|
25
25
|
}
|
|
26
26
|
async balanceOf(addresses, final = false) {
|
|
27
27
|
const client = await getClient(this.provider);
|
|
28
|
-
|
|
29
|
-
return addressesInfo.map((addressInfo) => ({
|
|
30
|
-
address: addressInfo.address,
|
|
31
|
-
balance: final
|
|
32
|
-
? Mas.fromString(addressInfo.final_balance)
|
|
33
|
-
: Mas.fromString(addressInfo.candidate_balance),
|
|
34
|
-
}));
|
|
28
|
+
return client.balanceOf(addresses, final);
|
|
35
29
|
}
|
|
36
30
|
async networkInfos() {
|
|
37
31
|
return networkInfos(this.provider);
|
|
@@ -119,19 +113,13 @@ export class MetamaskAccount {
|
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
async readSC(params) {
|
|
122
|
-
if (params.maxGas && params.maxGas > MAX_GAS_CALL) {
|
|
123
|
-
throw new Error(`Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}`);
|
|
124
|
-
}
|
|
125
116
|
try {
|
|
126
|
-
const args = params.parameter ?? new Uint8Array();
|
|
127
|
-
const parameter = args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());
|
|
128
117
|
const client = await getClient(this.provider);
|
|
129
118
|
const readOnlyParams = {
|
|
130
119
|
...params,
|
|
131
120
|
caller: params.caller ?? this.address,
|
|
132
|
-
parameter,
|
|
133
121
|
};
|
|
134
|
-
return client.
|
|
122
|
+
return client.readSC(readOnlyParams);
|
|
135
123
|
}
|
|
136
124
|
catch (error) {
|
|
137
125
|
throw new Error(`Smart contract read failed: ${error.message}`);
|
|
@@ -179,21 +167,15 @@ export class MetamaskAccount {
|
|
|
179
167
|
}
|
|
180
168
|
async getNodeStatus() {
|
|
181
169
|
const client = await getClient(this.provider);
|
|
182
|
-
|
|
183
|
-
return formatNodeStatusObject(status);
|
|
170
|
+
return client.getNodeStatus();
|
|
184
171
|
}
|
|
185
172
|
async getStorageKeys(address, filter = new Uint8Array(), final = true) {
|
|
186
173
|
const client = await getClient(this.provider);
|
|
187
|
-
|
|
188
|
-
return client.getDataStoreKeys(address, filterBytes, final);
|
|
174
|
+
return client.getStorageKeys(address, filter, final);
|
|
189
175
|
}
|
|
190
176
|
async readStorage(address, keys, final = true) {
|
|
191
177
|
const client = await getClient(this.provider);
|
|
192
|
-
|
|
193
|
-
key,
|
|
194
|
-
address,
|
|
195
|
-
}));
|
|
196
|
-
return client.getDatastoreEntries(entries, final);
|
|
178
|
+
return client.readStorage(address, keys, final);
|
|
197
179
|
}
|
|
198
180
|
async executeSC(params) {
|
|
199
181
|
try {
|
|
@@ -222,5 +204,18 @@ export class MetamaskAccount {
|
|
|
222
204
|
throw errorHandler(operationType.ExecuteSC, error);
|
|
223
205
|
}
|
|
224
206
|
}
|
|
207
|
+
async executeSCReadOnly(params) {
|
|
208
|
+
try {
|
|
209
|
+
const readOnlyParams = {
|
|
210
|
+
...params,
|
|
211
|
+
caller: params.caller ?? this.address,
|
|
212
|
+
};
|
|
213
|
+
const client = await getClient(this.provider);
|
|
214
|
+
return client.executeSCReadOnly(readOnlyParams);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new Error(`Error during readonly smart contract bytecode execution: ${error}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
225
220
|
}
|
|
226
221
|
//# sourceMappingURL=MetamaskAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetamaskAccount.js","sourceRoot":"","sources":["../../../src/metamaskSnap/MetamaskAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAML,sBAAsB,EACtB,YAAY,EAGZ,SAAS,EAOT,aAAa,EACb,UAAU,EAEV,GAAG,GAEJ,MAAM,uBAAuB,CAAC;AAC/B,OAA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C,QAAQ,EAAE,CAAC;aACjD;YACD,IAAI,MAAM,CAAC,GAAG,EAAE;gBACd,aAAa,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;aAC3C;YACD,IAAI,MAAM,CAAC,QAAQ,EAAE;gBACnB,aAAa,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;aACrD;YAED,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YACtE,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;SACzC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,YAAY,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SACpD;IACH,CAAC;CACF","sourcesContent":["import { MetaMaskInpageProvider } from '@metamask/providers';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n strToBytes,\n rpcTypes,\n Mas,\n ExecuteScParams,\n} from '@massalabs/massa-web3';\nimport { WalletName } from '../wallet';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport { networkInfos, getClient } from './utils/network';\nimport {\n buyRolls,\n callSC,\n deploySC,\n executeSC,\n getBalance,\n sellRolls,\n signMessage,\n transfer,\n} from './services';\nimport type {\n BuyRollsParams,\n SellRollsParams,\n TransferParams,\n CallSCParams as MMCallSCParams,\n DeploySCParams as MMDeploySCParams,\n ExecuteSCParams as MMExecuteSCParams,\n} from '@massalabs/metamask-snap';\n\nexport class MetamaskAccount implements Provider {\n constructor(\n public readonly address: string,\n private readonly provider: MetaMaskInpageProvider,\n ) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Metamask;\n }\n\n async balance(final = false): Promise<bigint> {\n const { finalBalance, candidateBalance } = await getBalance(this.provider, {\n address: this.address,\n });\n return BigInt(final ? finalBalance : candidateBalance);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const client = await getClient(this.provider);\n const addressesInfo = await client.getMultipleAddressInfo(addresses);\n\n return addressesInfo.map((addressInfo) => ({\n address: addressInfo.address,\n balance: final\n ? Mas.fromString(addressInfo.final_balance)\n : Mas.fromString(addressInfo.candidate_balance),\n }));\n }\n\n async networkInfos(): Promise<Network> {\n return networkInfos(this.provider);\n }\n\n async sign(inData: Uint8Array | string): Promise<SignedData> {\n try {\n const data = typeof inData === 'string' ? inData : Array.from(inData);\n const { publicKey, signature } = await signMessage(this.provider, {\n data,\n });\n\n return {\n publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async handleRollOperation(\n operation: 'buy' | 'sell',\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n try {\n const params: BuyRollsParams | SellRollsParams = {\n amount: amount.toString(),\n };\n if (opts?.fee) {\n params.fee = opts?.fee.toString();\n }\n\n const { operationId } = await (operation === 'buy'\n ? buyRolls(this.provider, params)\n : sellRolls(this.provider, params));\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(\n operation === 'buy' ? operationType.BuyRolls : operationType.SellRolls,\n error,\n );\n }\n }\n\n async buyRolls(amount: bigint, opts?: OperationOptions): Promise<Operation> {\n return this.handleRollOperation('buy', amount, opts);\n }\n\n async sellRolls(amount: bigint, opts?: OperationOptions): Promise<Operation> {\n return this.handleRollOperation('sell', amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n try {\n const params: TransferParams = {\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n if (opts?.fee) {\n params.fee = opts?.fee.toString();\n }\n const { operationId } = await transfer(this.provider, params);\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n async callSC(params: CallSCParams): Promise<Operation> {\n try {\n const callSCparams: MMCallSCParams = {\n functionName: params.func,\n at: params.target,\n };\n if (params.parameter) {\n callSCparams.args =\n params.parameter instanceof Uint8Array\n ? Array.from(params.parameter)\n : Array.from(params.parameter.serialize());\n }\n if (params.coins) {\n callSCparams.coins = params.coins.toString();\n }\n if (params.maxGas) {\n callSCparams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n callSCparams.fee = params.fee.toString();\n }\n\n const { operationId } = await callSC(this.provider, callSCparams);\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n async readSC(params: ReadSCParams): Promise<ReadSCData> {\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}`,\n );\n }\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameter =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const client = await getClient(this.provider);\n const readOnlyParams = {\n ...params,\n caller: params.caller ?? this.address,\n parameter,\n };\n return client.executeReadOnlyCall(readOnlyParams);\n } catch (error) {\n throw new Error(`Smart contract read failed: ${error.message}`);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const deployParams: MMDeploySCParams = {\n bytecode: Array.from(params.byteCode),\n };\n if (params.parameter) {\n deployParams.args = Array.from(\n params.parameter instanceof Uint8Array\n ? params.parameter\n : params.parameter.serialize(),\n );\n }\n if (params.coins) {\n deployParams.coins = params.coins.toString();\n }\n if (params.maxGas) {\n deployParams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n deployParams.fee = params.fee.toString();\n }\n if (params.maxCoins) {\n deployParams.maxCoins = params.maxCoins.toString();\n }\n\n const { operationId } = await deploySC(this.provider, deployParams);\n const op = new Operation(this, operationId);\n const deployedAddress = await op.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw errorHandler(operationType.DeploySC, error);\n }\n }\n\n async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient(this.provider);\n return client.getOperationStatus(opId);\n }\n\n async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient(this.provider);\n return client.getEvents(filter);\n }\n\n async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient(this.provider);\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const client = await getClient(this.provider);\n const filterBytes =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<(Uint8Array | null)[]> {\n const client = await getClient(this.provider);\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n\n async executeSC(params: ExecuteScParams): Promise<Operation> {\n try {\n const executeParams: MMExecuteSCParams = {\n bytecode: Array.from(params.byteCode),\n };\n if (params.datastore) {\n executeParams.datastore = Array.from(params.datastore.entries()).map(\n ([key, value]) => ({\n key: Array.from(key),\n value: Array.from(value),\n }),\n );\n }\n\n if (params.maxGas) {\n executeParams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n executeParams.fee = params.fee.toString();\n }\n if (params.maxCoins) {\n executeParams.maxCoins = params.maxCoins.toString();\n }\n\n const { operationId } = await executeSC(this.provider, executeParams);\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.ExecuteSC, error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Metam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,MAAM,IAAI,KAAK,CACb,4DAA4D,KAAK,EAAE,CACpE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["import { MetaMaskInpageProvider } from '@metamask/providers';\nimport {\n Address,\n CallSCParams,\n DeploySCParams,\n EventFilter,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n rpcTypes,\n ExecuteScParams,\n ExecuteSCReadOnlyParams,\n ExecuteSCReadOnlyResult,\n} from '@massalabs/massa-web3';\nimport { WalletName } from '../wallet';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport { networkInfos, getClient } from './utils/network';\nimport {\n buyRolls,\n callSC,\n deploySC,\n executeSC,\n getBalance,\n sellRolls,\n signMessage,\n transfer,\n} from './services';\nimport type {\n BuyRollsParams,\n SellRollsParams,\n TransferParams,\n CallSCParams as MMCallSCParams,\n DeploySCParams as MMDeploySCParams,\n ExecuteSCParams as MMExecuteSCParams,\n} from '@massalabs/metamask-snap';\n\nexport class MetamaskAccount implements Provider {\n constructor(\n public readonly address: string,\n private readonly provider: MetaMaskInpageProvider,\n ) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Metamask;\n }\n\n async balance(final = false): Promise<bigint> {\n const { finalBalance, candidateBalance } = await getBalance(this.provider, {\n address: this.address,\n });\n return BigInt(final ? finalBalance : candidateBalance);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const client = await getClient(this.provider);\n return client.balanceOf(addresses, final);\n }\n\n async networkInfos(): Promise<Network> {\n return networkInfos(this.provider);\n }\n\n async sign(inData: Uint8Array | string): Promise<SignedData> {\n try {\n const data = typeof inData === 'string' ? inData : Array.from(inData);\n const { publicKey, signature } = await signMessage(this.provider, {\n data,\n });\n\n return {\n publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async handleRollOperation(\n operation: 'buy' | 'sell',\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n try {\n const params: BuyRollsParams | SellRollsParams = {\n amount: amount.toString(),\n };\n if (opts?.fee) {\n params.fee = opts?.fee.toString();\n }\n\n const { operationId } = await (operation === 'buy'\n ? buyRolls(this.provider, params)\n : sellRolls(this.provider, params));\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(\n operation === 'buy' ? operationType.BuyRolls : operationType.SellRolls,\n error,\n );\n }\n }\n\n async buyRolls(amount: bigint, opts?: OperationOptions): Promise<Operation> {\n return this.handleRollOperation('buy', amount, opts);\n }\n\n async sellRolls(amount: bigint, opts?: OperationOptions): Promise<Operation> {\n return this.handleRollOperation('sell', amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n try {\n const params: TransferParams = {\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n if (opts?.fee) {\n params.fee = opts?.fee.toString();\n }\n const { operationId } = await transfer(this.provider, params);\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n async callSC(params: CallSCParams): Promise<Operation> {\n try {\n const callSCparams: MMCallSCParams = {\n functionName: params.func,\n at: params.target,\n };\n if (params.parameter) {\n callSCparams.args =\n params.parameter instanceof Uint8Array\n ? Array.from(params.parameter)\n : Array.from(params.parameter.serialize());\n }\n if (params.coins) {\n callSCparams.coins = params.coins.toString();\n }\n if (params.maxGas) {\n callSCparams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n callSCparams.fee = params.fee.toString();\n }\n\n const { operationId } = await callSC(this.provider, callSCparams);\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n async readSC(params: ReadSCParams): Promise<ReadSCData> {\n try {\n const client = await getClient(this.provider);\n const readOnlyParams = {\n ...params,\n caller: params.caller ?? this.address,\n };\n return client.readSC(readOnlyParams);\n } catch (error) {\n throw new Error(`Smart contract read failed: ${error.message}`);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const deployParams: MMDeploySCParams = {\n bytecode: Array.from(params.byteCode),\n };\n if (params.parameter) {\n deployParams.args = Array.from(\n params.parameter instanceof Uint8Array\n ? params.parameter\n : params.parameter.serialize(),\n );\n }\n if (params.coins) {\n deployParams.coins = params.coins.toString();\n }\n if (params.maxGas) {\n deployParams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n deployParams.fee = params.fee.toString();\n }\n if (params.maxCoins) {\n deployParams.maxCoins = params.maxCoins.toString();\n }\n\n const { operationId } = await deploySC(this.provider, deployParams);\n const op = new Operation(this, operationId);\n const deployedAddress = await op.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw errorHandler(operationType.DeploySC, error);\n }\n }\n\n async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient(this.provider);\n return client.getOperationStatus(opId);\n }\n\n async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient(this.provider);\n return client.getEvents(filter);\n }\n\n async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient(this.provider);\n return client.getNodeStatus();\n }\n\n async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const client = await getClient(this.provider);\n return client.getStorageKeys(address, filter, final);\n }\n\n async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<(Uint8Array | null)[]> {\n const client = await getClient(this.provider);\n return client.readStorage(address, keys, final);\n }\n\n async executeSC(params: ExecuteScParams): Promise<Operation> {\n try {\n const executeParams: MMExecuteSCParams = {\n bytecode: Array.from(params.byteCode),\n };\n if (params.datastore) {\n executeParams.datastore = Array.from(params.datastore.entries()).map(\n ([key, value]) => ({\n key: Array.from(key),\n value: Array.from(value),\n }),\n );\n }\n\n if (params.maxGas) {\n executeParams.maxGas = params.maxGas.toString();\n }\n if (params.fee) {\n executeParams.fee = params.fee.toString();\n }\n if (params.maxCoins) {\n executeParams.maxCoins = params.maxCoins.toString();\n }\n\n const { operationId } = await executeSC(this.provider, executeParams);\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.ExecuteSC, error);\n }\n }\n\n async executeSCReadOnly(\n params: ExecuteSCReadOnlyParams,\n ): Promise<ExecuteSCReadOnlyResult> {\n try {\n const readOnlyParams = {\n ...params,\n caller: params.caller ?? this.address,\n };\n\n const client = await getClient(this.provider);\n return client.executeSCReadOnly(readOnlyParams);\n } catch (error) {\n throw new Error(\n `Error during readonly smart contract bytecode execution: ${error}`,\n );\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcPublicProvider, Network } from '@massalabs/massa-web3';
|
|
2
2
|
import { MetaMaskInpageProvider } from '@metamask/providers';
|
|
3
3
|
export declare function networkInfos(metaMaskProvider: MetaMaskInpageProvider): Promise<Network>;
|
|
4
|
-
export declare function getClient(metaMaskProvider: MetaMaskInpageProvider): Promise<
|
|
4
|
+
export declare function getClient(metaMaskProvider: MetaMaskInpageProvider): Promise<JsonRpcPublicProvider>;
|
|
5
5
|
//# sourceMappingURL=network.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/metamaskSnap/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/metamaskSnap/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,OAAO,EAER,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAO7D,wBAAsB,YAAY,CAChC,gBAAgB,EAAE,sBAAsB,GACvC,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAED,wBAAsB,SAAS,CAC7B,gBAAgB,EAAE,sBAAsB,GACvC,OAAO,CAAC,qBAAqB,CAAC,CAMhC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcPublicProvider, getNetworkNameByChainId, } from '@massalabs/massa-web3';
|
|
2
2
|
import { getNetwork } from '../services/getNetwork';
|
|
3
3
|
// Use client singleton to benefit from caching
|
|
4
4
|
let client;
|
|
@@ -8,7 +8,7 @@ export async function networkInfos(metaMaskProvider) {
|
|
|
8
8
|
const res = await getNetwork(metaMaskProvider);
|
|
9
9
|
const url = res.rpcUrl;
|
|
10
10
|
if (!client || rpcUrl !== url) {
|
|
11
|
-
client =
|
|
11
|
+
client = JsonRpcPublicProvider.fromRPCUrl(url);
|
|
12
12
|
rpcUrl = url;
|
|
13
13
|
}
|
|
14
14
|
const networkName = getNetworkNameByChainId(BigInt(res.chainId));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/metamaskSnap/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/metamaskSnap/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAErB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,+CAA+C;AAC/C,IAAI,MAA6B,CAAC;AAClC,0CAA0C;AAC1C,IAAI,MAAc,CAAC;AAEnB,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,gBAAwC;IAExC,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IAEvB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE;QAC7B,MAAM,GAAG,qBAAqB,CAAC,UAAU,CAAC,GAAG,CAA0B,CAAC;QACxE,MAAM,GAAG,GAAG,CAAC;KACd;IAED,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE;QACpC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;QAC5B,GAAG;QACH,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,gBAAwC;IAExC,IAAI,CAAC,MAAM,EAAE;QACX,yBAAyB;QACzB,MAAM,YAAY,CAAC,gBAAgB,CAAC,CAAC;KACtC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n JsonRpcPublicProvider,\n Network,\n getNetworkNameByChainId,\n} from '@massalabs/massa-web3';\n\nimport { getNetwork } from '../services/getNetwork';\nimport { MetaMaskInpageProvider } from '@metamask/providers';\n\n// Use client singleton to benefit from caching\nlet client: JsonRpcPublicProvider;\n// Use rpcUrl to check if node has changed\nlet rpcUrl: string;\n\nexport async function networkInfos(\n metaMaskProvider: MetaMaskInpageProvider,\n): Promise<Network> {\n const res = await getNetwork(metaMaskProvider);\n const url = res.rpcUrl;\n\n if (!client || rpcUrl !== url) {\n client = JsonRpcPublicProvider.fromRPCUrl(url) as JsonRpcPublicProvider;\n rpcUrl = url;\n }\n\n const networkName = getNetworkNameByChainId(BigInt(res.chainId));\n return {\n name: networkName ? networkName : '',\n chainId: BigInt(res.chainId),\n url,\n minimalFee: BigInt(res.minimalFees),\n };\n}\n\nexport async function getClient(\n metaMaskProvider: MetaMaskInpageProvider,\n): Promise<JsonRpcPublicProvider> {\n if (!client) {\n // this initialize client\n await networkInfos(metaMaskProvider);\n }\n return client;\n}\n"]}
|