UNPKG

client-aftermath-ts-sdk

Version:
59 lines (58 loc) 3.24 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InspectionsApiHelpers = void 0; class InspectionsApiHelpers { // ========================================================================= // Constructor // ========================================================================= constructor(Provider) { this.Provider = Provider; // ========================================================================= // Public Methods // ========================================================================= // ========================================================================= // Fetching // ========================================================================= // TODO: replace all bytes types with uint8array type this.fetchFirstBytesFromTxOutput = (inputs) => __awaiter(this, void 0, void 0, function* () { return (yield this.fetchAllBytesFromTxOutput(inputs))[0]; }); this.fetchAllBytesFromTxOutput = (inputs) => __awaiter(this, void 0, void 0, function* () { const { allBytes } = yield this.fetchAllBytesFromTx(inputs); return allBytes[allBytes.length - 1]; }); this.fetchAllBytesFromTx = (inputs) => __awaiter(this, void 0, void 0, function* () { var _a; const sender = (_a = inputs.sender) !== null && _a !== void 0 ? _a : InspectionsApiHelpers.constants.devInspectSigner; const response = yield this.Provider.provider.devInspectTransactionBlock({ sender, transactionBlock: inputs.tx, }); if (response.effects.status.status === "failure") { console.error(response.error); throw Error(response.effects.status.error); } if (!response.results) throw Error("dev inspect move call returned no results"); const resultBytes = response.results.map((result) => { var _a, _b; return (_b = (_a = result.returnValues) === null || _a === void 0 ? void 0 : _a.map((val) => val[0])) !== null && _b !== void 0 ? _b : []; }); return { events: response.events, effects: response.effects, allBytes: resultBytes, }; }); } } exports.InspectionsApiHelpers = InspectionsApiHelpers; InspectionsApiHelpers.constants = { devInspectSigner: "0xacb7cb045c3afac61381cdf272cd24ebe115f86361c9f06490482c238765aeb5", };