zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
67 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtrinsicManager = void 0;
const index_js_1 = require("../../../api/extrinsic/index.js");
const index_js_2 = require("../../../api/estimate/index.js");
const index_js_3 = require("../../../utils/helpers/index.js");
class ExtrinsicManager {
constructor(connectionManager) {
this.connectionManager = connectionManager;
}
/**
* Creates a SubmittableExtrinsic using formatted proof details to enable submitting a proof.
*
* @param {ProofType} proofType - The type of proof, to decide which pallet to use.
* @param {FormattedProofData} params - Formatted Proof Parameters required by the extrinsic.
* @param domainId
* @returns {SubmittableExtrinsic<'promise'>} The generated SubmittableExtrinsic for submission.
* @throws {Error} - Throws an error if the extrinsic creation fails.
*/
async createSubmitProofExtrinsic(proofType, params, domainId) {
return (0, index_js_1.createSubmitProofExtrinsic)(this.connectionManager.api, proofType, params, domainId);
}
/**
* Generates the hex representation of a SubmittableExtrinsic using formatted proof details.
*
* @param {ProofType} proofType - The type of supported proof, used to select the correct pallet.
* @param {FormattedProofData} params - Formatted Proof Parameters required by the extrinsic.
* @param domainId
* @returns {string} Hex-encoded string of the SubmittableExtrinsic.
* @throws {Error} - Throws an error if the hex generation fails.
*/
async createExtrinsicHex(proofType, params, domainId) {
return (0, index_js_1.createExtrinsicHex)(this.connectionManager.api, proofType, params, domainId);
}
/**
* Recreates an extrinsic from its hex-encoded representation.
*
* @param {string} extrinsicHex - Hex-encoded string of the SubmittableExtrinsic.
* @returns {SubmittableExtrinsic<'promise'>} The reconstructed SubmittableExtrinsic.
* @throws {Error} - Throws an error if the reconstruction from hex fails.
*/
async createExtrinsicFromHex(extrinsicHex) {
return (0, index_js_1.createSubmittableExtrinsicFromHex)(this.connectionManager.api, extrinsicHex);
}
/**
* Estimates the cost of a given extrinsic.
*
* @param {SubmittableExtrinsic<'promise'>} extrinsic - The extrinsic to estimate.
* @param {string} [accountAddress] - The account address to use for estimation.
* If not provided, the first available account will be used.
* @returns {Promise<ExtrinsicCostEstimate>} A promise that resolves to an object containing the estimated fee and extrinsic details.
* @throws {Error} If the session is in read-only mode or no account is available.
*/
async estimateCost(extrinsic, accountAddress) {
(0, index_js_3.checkReadOnly)(this.connectionManager.connectionDetails);
let selectedAccount;
if (accountAddress !== undefined) {
selectedAccount = this.connectionManager.getAccount(accountAddress);
}
else {
selectedAccount = this.connectionManager.getAccount();
}
return (0, index_js_2.estimateCost)(this.connectionManager.api, extrinsic, selectedAccount);
}
}
exports.ExtrinsicManager = ExtrinsicManager;
//# sourceMappingURL=index.js.map