mirror of https://github.com/lukechilds/docs.git
committed by
Alexander Graebe
5 changed files with 502 additions and 1 deletions
@ -0,0 +1,118 @@ |
|||
import { renderMdx } from '@common/data/mdx'; |
|||
import BNS_REFERENCE from '../../_data/boot-contracts-reference.json'; |
|||
|
|||
const wrapInClarityTicks = (string: string) => { |
|||
let newString = '```clarity'; |
|||
newString += ` |
|||
`;
|
|||
newString += string.trim(); |
|||
newString += ` |
|||
`;
|
|||
newString += '```'; |
|||
return newString; |
|||
}; |
|||
|
|||
const inlineCode = (string: string) => { |
|||
let newString = '`'; |
|||
newString += string.trim(); |
|||
newString += '`'; |
|||
|
|||
if (newString === '``') { |
|||
newString = ''; |
|||
} |
|||
|
|||
return newString; |
|||
}; |
|||
|
|||
const generateMarkdown = () => { |
|||
let publicFunctions = ''; |
|||
let readonlyFunctions = ''; |
|||
let errorCodes = ''; |
|||
|
|||
BNS_REFERENCE.bns.public_functions.forEach(entry => { |
|||
publicFunctions += ` |
|||
### ${entry.name} |
|||
|
|||
**Signature:** ${inlineCode(entry.signature)} |
|||
|
|||
|
|||
**Input:** ${inlineCode(entry.input_type)} |
|||
|
|||
|
|||
**Output:** ${inlineCode(entry.output_type)} |
|||
|
|||
${entry.description.trim()} |
|||
`;
|
|||
}); |
|||
|
|||
BNS_REFERENCE.bns.read_only_functions.forEach(entry => { |
|||
readonlyFunctions += ` |
|||
### ${entry.name} |
|||
|
|||
**Signature:** ${inlineCode(entry.signature)} |
|||
|
|||
|
|||
**Input:** ${inlineCode(entry.input_type)} |
|||
|
|||
|
|||
**Output:** ${inlineCode(entry.output_type)} |
|||
|
|||
${entry.description.trim()} |
|||
`;
|
|||
}); |
|||
|
|||
BNS_REFERENCE.bns.error_codes.forEach(entry => { |
|||
errorCodes += `### ${entry.name} |
|||
|
|||
**Type:** ${inlineCode(entry.type)} |
|||
|
|||
**Value:** ${inlineCode(entry.value)} |
|||
`;
|
|||
}); |
|||
|
|||
return { |
|||
publicFunctions, |
|||
readonlyFunctions, |
|||
errorCodes, |
|||
}; |
|||
}; |
|||
|
|||
const getHeadings = arr => |
|||
arr.map(entry => ({ |
|||
content: entry.name, |
|||
level: 1, |
|||
})); |
|||
|
|||
export const convertBNSRefToMdx = async () => { |
|||
const markdown = generateMarkdown(); |
|||
const [_publicFunctions, _readonlyFunctions, _errorCodes] = await Promise.all([ |
|||
renderMdx(markdown.publicFunctions), |
|||
renderMdx(markdown.readonlyFunctions), |
|||
renderMdx(markdown.errorCodes), |
|||
]); |
|||
|
|||
const publicFunctions = { |
|||
content: _publicFunctions, |
|||
headings: getHeadings(BNS_REFERENCE.bns.public_functions), |
|||
}; |
|||
|
|||
const readonlyFunctions = { |
|||
content: _readonlyFunctions, |
|||
headings: getHeadings(BNS_REFERENCE.bns.read_only_functions), |
|||
}; |
|||
|
|||
const errorCodes = { |
|||
content: _errorCodes, |
|||
headings: getHeadings(BNS_REFERENCE.bns.error_codes), |
|||
}; |
|||
|
|||
return { |
|||
props: { |
|||
mdx: { |
|||
publicFunctions, |
|||
readonlyFunctions, |
|||
errorCodes, |
|||
}, |
|||
}, |
|||
}; |
|||
}; |
@ -0,0 +1,27 @@ |
|||
import React from 'react'; |
|||
import { Components } from '@components/mdx/mdx-components'; |
|||
import { TableOfContents } from '@components/toc'; |
|||
import hydrate from 'next-mdx-remote/hydrate'; |
|||
import { space } from '@stacks/ui'; |
|||
|
|||
export const BNSErrorcodeReference = React.memo(({ content, headings }: any) => { |
|||
return ( |
|||
<> |
|||
<TableOfContents mb={space('extra-loose')} label="Contents" headings={headings} /> |
|||
{hydrate(content, { components: Components })} |
|||
</> |
|||
); |
|||
}); |
|||
export const BNSFunctionReference = React.memo(({ content, headings }: any) => { |
|||
return ( |
|||
<> |
|||
<TableOfContents |
|||
mb={space('extra-loose')} |
|||
columns={[2, 2, 3]} |
|||
label="Contents" |
|||
headings={headings} |
|||
/> |
|||
{hydrate(content, { components: Components })} |
|||
</> |
|||
); |
|||
}); |
@ -0,0 +1,25 @@ |
|||
--- |
|||
title: BNS Contract |
|||
description: See a detailed list of all functions and error codes of the BNS contract. |
|||
--- |
|||
|
|||
export { convertBNSRefToMdx as getStaticProps } from '@common/data/bns-ref' |
|||
import { BNSErrorcodeReference, BNSFunctionReference } from '@components/bns-ref' |
|||
|
|||
## Introduction |
|||
|
|||
The [Blockchain Naming System (BNS)](/technology/naming-system) is implemented as a smart contract using Clarity. |
|||
|
|||
Below is a list of public and read-only functions as well as error codes that can be returned by those methods. |
|||
|
|||
## Public functions |
|||
|
|||
<BNSFunctionReference {...props.mdx.publicFunctions} /> |
|||
|
|||
## Read-only functions |
|||
|
|||
<BNSFunctionReference {...props.mdx.readonlyFunctions} /> |
|||
|
|||
## Error codes |
|||
|
|||
<BNSErrorcodeReference {...props.mdx.errorCodes} /> |
Loading…
Reference in new issue