|
|
|
@@ -14,7 +14,7 @@ import Method from '../Method';
|
|
|
|
|
const ANCHOR_TOP = `<a id='top' style='text-decoration: none;'>`;
|
|
|
|
|
const LINK_BACK_TO_TOP = `<a href='#top' style='float: right; font-size: 1.6rem; font-weight: bold;'>Back To Top</a>`;
|
|
|
|
|
|
|
|
|
|
const DESC_EXTRINSICS = '\n\n_The following sections contain Extrinsics methods are part of the default Substrate runtime. Since an Extrinsic is a holder of an object that is just an array of bytes to be included, it does not have a return._\n';
|
|
|
|
|
const DESC_EXTRINSICS = '\n\n_The following sections contain Extrinsics methods are part of the default Substrate runtime._\n';
|
|
|
|
|
const DESC_EVENTS = '\n\nEvents are emitted for certain operations on the runtime. The following sections describe the events that are part of the default Substrate runtime.\n';
|
|
|
|
|
const DESC_RPC = '\n\n_The following sections contain RPC methods that are Remote Calls available by default and allow you to interact with the actual node, query, and submit. The RPCs are provided by Substrate itself._';
|
|
|
|
|
const DESC_STORAGE = '\n\n_The following sections contain Storage methods are part of the default Substrate runtime._\n';
|
|
|
|
@@ -23,24 +23,6 @@ function sectionLink (sectionName: string) {
|
|
|
|
|
return `- **[${stringCamelCase(sectionName)}](#${stringCamelCase(sectionName)})**\n\n`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateSectionLinks (sectionName: string, metadata: MetadataV0) {
|
|
|
|
|
switch (sectionName) {
|
|
|
|
|
case 'events':
|
|
|
|
|
return metadata.events.map((i) => i).sort().map((data: any) =>
|
|
|
|
|
sectionLink(data.name.toString())
|
|
|
|
|
).join('');
|
|
|
|
|
|
|
|
|
|
case 'extrinsics':
|
|
|
|
|
case 'storage':
|
|
|
|
|
return metadata.modules.map((i) => i).sort().map((runtimeModuleMetadata: any) =>
|
|
|
|
|
sectionLink(runtimeModuleMetadata.prefix.toString())
|
|
|
|
|
).join('');
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown section name provided to generate anchors');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateSectionHeader (md: string, sectionName: string) {
|
|
|
|
|
return `${md}\n___\n${LINK_BACK_TO_TOP}\n\n### <a id='${sectionName}'></a>${sectionName}\n`;
|
|
|
|
|
}
|
|
|
|
@@ -85,14 +67,16 @@ function sortExtrinsicsSectionMethods (a: any, b: any) {
|
|
|
|
|
function addEvents (metadata: MetadataV0) {
|
|
|
|
|
const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`;
|
|
|
|
|
const orderedSections = metadata.events.map((i) => i).sort();
|
|
|
|
|
const renderAnchors = generateSectionLinks('events', metadata);
|
|
|
|
|
|
|
|
|
|
return orderedSections.reduce((md, meta) => {
|
|
|
|
|
let renderAnchors = '';
|
|
|
|
|
const sections = orderedSections.reduce((md, meta) => {
|
|
|
|
|
if (!meta.events || !meta.events.length) {
|
|
|
|
|
return md;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sectionName = stringCamelCase(meta.name.toString());
|
|
|
|
|
|
|
|
|
|
renderAnchors += sectionLink(sectionName);
|
|
|
|
|
|
|
|
|
|
const renderSection = generateSectionHeader(md, sectionName);
|
|
|
|
|
|
|
|
|
|
const orderedMethods = meta.events.sort(sortExtrinsicsSectionMethods);
|
|
|
|
@@ -106,20 +90,24 @@ function addEvents (metadata: MetadataV0) {
|
|
|
|
|
|
|
|
|
|
return renderSignature + renderSummary;
|
|
|
|
|
}, renderSection);
|
|
|
|
|
}, renderHeading + renderAnchors);
|
|
|
|
|
}, '');
|
|
|
|
|
|
|
|
|
|
return renderHeading + renderAnchors + sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addExtrinsics (metadata: MetadataV0) {
|
|
|
|
|
const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`;
|
|
|
|
|
const orderedSections = metadata.modules.map((i) => i).sort();
|
|
|
|
|
const renderAnchors = generateSectionLinks('extrinsics', metadata);
|
|
|
|
|
|
|
|
|
|
return orderedSections.reduce((md, meta) => {
|
|
|
|
|
let renderAnchors = '';
|
|
|
|
|
const sections = orderedSections.reduce((md, meta) => {
|
|
|
|
|
if (!meta.module.call || !meta.module.call.functions.length) {
|
|
|
|
|
return md;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sectionName = stringCamelCase(meta.prefix.toString());
|
|
|
|
|
|
|
|
|
|
renderAnchors += sectionLink(sectionName);
|
|
|
|
|
|
|
|
|
|
const renderSection = generateSectionHeader(md, sectionName);
|
|
|
|
|
const orderedMethods = meta.module.call.functions.sort(sortExtrinsicsSectionMethods);
|
|
|
|
|
|
|
|
|
@@ -132,20 +120,24 @@ function addExtrinsics (metadata: MetadataV0) {
|
|
|
|
|
|
|
|
|
|
return renderSignature + renderSummary;
|
|
|
|
|
}, renderSection);
|
|
|
|
|
}, renderHeading + renderAnchors);
|
|
|
|
|
}, '');
|
|
|
|
|
|
|
|
|
|
return renderHeading + renderAnchors + sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addStorage (metadata: MetadataV0) {
|
|
|
|
|
const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`;
|
|
|
|
|
const orderedSections = metadata.modules.sort();
|
|
|
|
|
const renderAnchors = generateSectionLinks('storage', metadata) + sectionLink('substrate');
|
|
|
|
|
|
|
|
|
|
return orderedSections.reduce((md, moduleMetadata) => {
|
|
|
|
|
let renderAnchors = '';
|
|
|
|
|
const sections = orderedSections.reduce((md, moduleMetadata) => {
|
|
|
|
|
if (moduleMetadata.storage.isNone) {
|
|
|
|
|
return md;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sectionName = stringLowerFirst(moduleMetadata.storage.unwrap().prefix.toString());
|
|
|
|
|
|
|
|
|
|
renderAnchors += sectionLink('sectionName');
|
|
|
|
|
|
|
|
|
|
const renderSection = generateSectionHeader(md, sectionName);
|
|
|
|
|
const orderedMethods = moduleMetadata.storage.unwrap().functions.sort();
|
|
|
|
|
|
|
|
|
@@ -158,7 +150,9 @@ function addStorage (metadata: MetadataV0) {
|
|
|
|
|
|
|
|
|
|
return renderSignature + renderSummary;
|
|
|
|
|
}, renderSection);
|
|
|
|
|
}, renderHeading + renderAnchors);
|
|
|
|
|
}, '');
|
|
|
|
|
|
|
|
|
|
return renderHeading + renderAnchors + sectionLink('substrate') + sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeFile (name: string, ...chunks: Array<any>) {
|
|
|
|
|