Skip to content

Commit

Permalink
remove getProtoFile (and move it to proto-cli) (#406)
Browse files Browse the repository at this point in the history
* remove getProtoFile

* Delete MassaProtoFile.ts
  • Loading branch information
Elli610 authored Jul 20, 2023
1 parent efdfecb commit 4f3a2e1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
12 changes: 0 additions & 12 deletions src/interfaces/MassaProtoFile.ts

This file was deleted.

86 changes: 0 additions & 86 deletions src/web3/SmartContractsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MassaProtoFile[]> {
// 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;
}
}
}

0 comments on commit 4f3a2e1

Please sign in to comment.