locklift
Version:
Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.
45 lines (44 loc) • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TracingGqlConnection = void 0;
const httpService_1 = require("../../httpService");
const lodash_1 = __importDefault(require("lodash"));
class TracingGqlConnection {
provider;
gqlEndpoint;
constructor(provider, gqlEndpoint) {
this.provider = provider;
this.gqlEndpoint = gqlEndpoint;
}
async getAccountData(account) {
return (await this.getAccountsData([account]))[0];
}
async _getAccountsData(accounts) {
const msgQuery = `{
accounts(
filter: {
id: {
in: ${JSON.stringify(accounts.map(account => account.toString()))}
}
}
) {
code_hash
id
}
}`;
const response = await httpService_1.httpService
.post(this.gqlEndpoint, { query: msgQuery })
.then(res => res.data.data);
// eslint-disable-next-line camelcase
return response.accounts.map(({ id, code_hash }) => ({ id, codeHash: code_hash }));
}
async getAccountsData(accounts) {
const chunked = lodash_1.default.chunk(accounts, 100);
const result = await Promise.all(chunked.map(chunk => this._getAccountsData(chunk)));
return lodash_1.default.flatten(result);
}
}
exports.TracingGqlConnection = TracingGqlConnection;