PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/@substrate/txwrapper-registry/lib
Просмотр файла: index.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRegistry = exports.createRegistry = exports.knownChainProperties = void 0;
/**
* Registry creation support, catering to chains with types in [@polkadot/apps-config](https://github.com/polkadot-js/apps/tree/master/packages/apps-config/README.md).
*
* @module txwrapper-registry
*/
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
const networks_1 = require("@polkadot/networks");
const types_1 = require("@polkadot/types");
const types_known_1 = require("@polkadot/types-known");
const txwrapper_core_1 = require("@substrate/txwrapper-core");
const fs_1 = __importDefault(require("fs"));
/**
* Known chain properties based on the substrate ss58 registry.
* Chain properties are derived from the substrate ss58 registry:
* https://raw.githubusercontent.com/paritytech/substrate/master/ss58-registry.json
*
* Alternatively, chain properties can be dynamically fetched through the
* `system_properties` RPC call.
*/
exports.knownChainProperties = networks_1.allNetworks.reduce((acc, { decimals, network, symbols, prefix }) => {
if (network !== null) {
acc[network] = {
tokenDecimals: decimals,
tokenSymbol: symbols,
ss58Format: prefix,
};
}
return acc;
}, {});
function parseTypesBundle(path) {
if (!path)
return undefined;
let parsedJson;
try {
const rawData = fs_1.default.readFileSync(path, { encoding: 'utf-8' });
parsedJson = JSON.parse(rawData);
}
catch (e) {
console.error(`Invalid file path or not able to parse file to JSON: ${e}`);
}
return parsedJson;
}
const envTypesBundle = parseTypesBundle(!txwrapper_core_1.isBrowser && typeof ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.TX_TYPES_BUNDLE) !== 'undefined'
? process.env.TX_TYPES_BUNDLE
: undefined);
/**
* Create a registry with `knownTypes` via env variables.
* ie: STX_TYPES_BUNDLE; STX_TYPES_CHAIN
*/
function createRegistry(typesBundle) {
const registry = new types_1.TypeRegistry();
registry.setKnownTypes({
typesBundle: typesBundle || envTypesBundle,
});
return registry;
}
exports.createRegistry = createRegistry;
/**
* Create a registry based on specName, chainName, specVersion and metadataRPC. This should work for
* Polkadot, Kusama, Westend and any chain which has up-to-date types in @polkadot/apps-config.
*
* @param GetRegistryOptions specName, chainName, specVersion, and metadataRpc of the current runtime
*/
function getRegistry({ specName, chainName, specVersion, metadataRpc, properties, asCallsOnlyArg, typesBundle, additionalTypes, }) {
const registry = createRegistry();
return (0, txwrapper_core_1.getRegistryBase)({
chainProperties: properties || exports.knownChainProperties[specName],
// `getSpecTypes` is used to extract the chain specific types from the registries `knownTypes`
specTypes: (0, types_known_1.getSpecTypes)(registry, chainName, specName, specVersion),
metadataRpc,
asCallsOnlyArg,
typesBundle,
additionalTypes,
});
}
exports.getRegistry = getRegistry;
//# sourceMappingURL=index.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!