From 4f3a2e149a611cccc060f0cda5aaf96999429547 Mon Sep 17 00:00:00 2001 From: Nathan HERVIER <113121626+Elli610@users.noreply.github.com> Date: Thu, 20 Jul 2023 09:55:07 +0200 Subject: [PATCH] remove getProtoFile (and move it to proto-cli) (#406) * remove getProtoFile * Delete MassaProtoFile.ts --- src/interfaces/MassaProtoFile.ts | 12 ----- src/web3/SmartContractsClient.ts | 86 -------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 src/interfaces/MassaProtoFile.ts diff --git a/src/interfaces/MassaProtoFile.ts b/src/interfaces/MassaProtoFile.ts deleted file mode 100644 index bb9f77cd..00000000 --- a/src/interfaces/MassaProtoFile.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This interface is used to represent proto files retrieved from smart contracts. - * - * @see data - The proto file data. - * @see filePath - The file path of the proto file. - * @see protoFuncName - The name of the proto function. - */ -export interface MassaProtoFile { - data: string; - filePath: string; - protoFuncName: string; -} diff --git a/src/web3/SmartContractsClient.ts b/src/web3/SmartContractsClient.ts index 4fbb89d7..09d39a8d 100644 --- a/src/web3/SmartContractsClient.ts +++ b/src/web3/SmartContractsClient.ts @@ -26,18 +26,13 @@ import { ISignature } from '../interfaces/ISignature'; import { ISmartContractsClient } from '../interfaces/ISmartContractsClient'; import { JSON_RPC_REQUEST_METHOD } from '../interfaces/JsonRpcMethods'; import { OperationTypeId } from '../interfaces/OperationTypes'; -import { MassaProtoFile } from '../interfaces/MassaProtoFile'; import { fromMAS } from '../utils/converters'; import { trySafeExecute } from '../utils/retryExecuteFunction'; import { wait } from '../utils/time'; -import { strToBytes } from '../utils/serializers/strings'; -import { bytesArrayToString } from '../utils/uint8ArrayToString'; import { BaseClient } from './BaseClient'; import { PublicApiClient } from './PublicApiClient'; import { WalletClient } from './WalletClient'; import { getBytesPublicKey } from '../utils/bytes'; -import { writeFileSync } from 'fs'; -import path from 'path'; const MAX_READ_BLOCK_GAS = BigInt(4_294_967_295); const TX_POLL_INTERVAL_MS = 10000; @@ -472,85 +467,4 @@ export class SmartContractsClient await wait(TX_POLL_INTERVAL_MS); } } - - /** - * Get the proto file of the contracts from the Massa Blockchain. - * - * @param contractAddresses - An array of contract addresses (as strings) - * - * @returns A promise that resolves to the array of IProtoFiles corresponding - * to the proto file associated with each contract or the values are null if the file is unavailable. - */ - public static async getProtoFiles( - contractAddresses: string[], - outputDirectory: string, - providerUrl: string, - ): Promise { - // prepare request body - const requestProtoFiles: object[] = []; - for (let address of contractAddresses) { - requestProtoFiles.push({ - address: address, - key: Array.from(strToBytes(MASSA_PROTOFILE_KEY)), - }); - } - const body = { - jsonrpc: '2.0', - method: JSON_RPC_REQUEST_METHOD.GET_DATASTORE_ENTRIES, - params: [requestProtoFiles], - id: 1, - }; - - // send request - let response = null; - try { - response = await fetch(providerUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(body), - }); - // parse response - const json = await response.json(); - let protoFiles: MassaProtoFile[] = []; - - // for each contract, get the proto files - for (let contract of json.result) { - if (!contract.final_value) { - throw new Error('No proto file found'); - } - - const retrievedProtoFiles = bytesArrayToString(contract.final_value); // converting the Uint8Array to string - // splitting all the proto functions to make separate proto file for each functions - const protos = retrievedProtoFiles.split(PROTO_FILE_SEPARATOR); - - // for proto file, save it and get the function name - for (let protoContent of protos) { - // remove all the text before the first appearance of the 'syntax' keyword - const proto = protoContent.substring(protoContent.indexOf('syntax')); - - // get the function name from the proto file - const functionName = proto - .substring(proto.indexOf('message '), proto.indexOf('Helper')) - .replace('message ', '') - .trim(); - // save the proto file - const filepath = path.join(outputDirectory, functionName + '.proto'); - writeFileSync(filepath, proto); - const extractedProto: MassaProtoFile = { - data: proto, - filePath: filepath, - protoFuncName: functionName, - }; - protoFiles.push(extractedProto); - } - } - return protoFiles; - } catch (ex) { - const msg = `Failed to retrieve the proto files.`; - console.error(msg, ex); - throw ex; - } - } }