@1hive/connect-core
Version:
Access and interact with Aragon Organizations and their apps.
81 lines • 3.68 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryDescribingUpdateAppIntent = exports.tryEvaluatingRadspec = void 0;
const radspec = __importStar(require("@1hive/radspec"));
const address_1 = require("../address");
const app_1 = require("../app");
const intent_1 = require("../intent");
/**
* Attempt to describe intent via radspec.
*/
async function tryEvaluatingRadspec(intent, installedApps, provider // Decorated intent with description, if one could be made
) {
const app = installedApps.find((app) => address_1.addressesEqual(app.address, intent.to));
// If the intent matches an installed app, use only that app to search for a
// method match, otherwise fallback to searching all installed apps
const appsToSearch = app ? [app] : installedApps;
const method = appsToSearch.reduce((found, app) => {
if (found) {
return found;
}
const method = app_1.findAppMethodFromData(app, intent.data);
if (method)
return method;
}, undefined);
let evaluatedNotice;
if (method && method.notice) {
try {
evaluatedNotice = await radspec.evaluate(method.notice, {
abi: app === null || app === void 0 ? void 0 : app.abi,
transaction: intent,
}, { provider: provider });
}
catch (err) {
console.error(`Could not evaluate a description for given transaction data: ${intent.data}`, err);
}
}
return { ...intent, description: evaluatedNotice };
}
exports.tryEvaluatingRadspec = tryEvaluatingRadspec;
/**
* Attempt to describe a setApp() intent. Only describes the APP_BASE namespace.
*
* @param {Object} intent transaction intent
* @param {Object} wrapper
* @return {Promise<Object>} Decorated intent with description, if one could be made
*/
async function tryDescribingUpdateAppIntent(intent, installedApps) {
const upgradeIntentParams = intent_1.filterAndDecodeAppUpgradeIntents([intent], installedApps)[0];
if (Array.isArray(upgradeIntentParams) && upgradeIntentParams.length === 0)
return undefined;
const { appId, appAddress } = upgradeIntentParams;
const app = installedApps.find((app) => app.address === appAddress);
const repo = await (app === null || app === void 0 ? void 0 : app.repo());
return {
...intent,
description: `Upgrade ${appId} app instances to v${repo === null || repo === void 0 ? void 0 : repo.lastVersion}`,
};
}
exports.tryDescribingUpdateAppIntent = tryDescribingUpdateAppIntent;
var postprocess_1 = require("./postprocess");
Object.defineProperty(exports, "postprocessRadspecDescription", { enumerable: true, get: function () { return postprocess_1.postprocessRadspecDescription; } });
//# sourceMappingURL=index.js.map