The Rain language (dotrain and rainlang) standalone, that encapsulates Language Serivces (in LSP spec) and compiler/decompiler for NodeJs and Browser environments
npm install @rainprotocol/rainlangThe primary goal of the Rain language is to make smart contract development accessible for as many people as possible. This is fundamentally grounded in our belief that accessibility is the difference between theoretical and practical decentralisation. There are many people who would like to participate in authoring and auditing crypto code but currently cannot. When someone wants/needs to do something but cannot, then they delegate to someone who can, this is by definition centralisation.
For more info and details, please read this article
If you find an issue or you want to propose an improvement, please feel free to post it on: issues
bash
npm install @rainprotocol/rainlang
`
or
`bash
yarn add @rainprotocol/rainlang
`
$3
Rain Language Services provide validation of a Rain document and services like completion, hover, etc.
`typescript
// importing
import { getRainLanguageServices } from "@rainprotocol/rainlang";// initiating the services (clientCapabilities and metaStore are optional arguments)
const langServices = getRainLanguageServices({clientCapabilities, metaStore});
// getting validation results (lsp Diagnostics)
const diagnostics = await langServices.doValidate(myTextDocument);
`
$3
- Compiling a RainDocument aka dotrain instances:
`typescript
// importing
import { Compile } from "@rainprotocol/rainlang";// compiling a RainDocument to get ExpressionConfig
const expressionConfig = await Compile.RainDocument(myDocument, ["entrypoint-1" , "entrypoint-2"], options);
`
- Compiling
Rainlang instances:
`typescript
// importing
import { Compile } from "@rainprotocol/rainlang";// compiling a rainlang text to get ExpressionConfig
const expressionConfig = await Compile.Rainlang(rainlangText, bytecodeSource, entrypoints, options);
`
CLI
npx command to compile dotrain file(s) to ExpressionConfig in json format.
- if on current repo:
`bash
node cli/dotrain [options] [command]
`
- if the package is already installed:
`bash
npx dotrain [options] [command]
`
- if package is not installed (executing remotely):
--yes will accept the prompt to cache the package for execution
`bash
npx @rainprotocol/rainlang [options] [command] --yes
`
or
`bash
npx --p @rainprotocol/rainlang dotrain [options] [command] --yes
`
Command details: Usage: dotrain [options] [command]
CLI command to run dotrain compiler.
Options:
-c, --config Path to the rainconfig json file(default is './rainconfig.json' or './.rainconfig.json' if not specified) that contains configurations, see './example.rainconfig.json' for more details.
-s, --silent Print no std logs.
-V, --version output the version number
-h, --help display help for command
Commands:
compile [options] compile a single .rain file.
rainconfig show detailed information about rainconfig.json
Compile subcommand details (compiling specific file):
Usage: dotrain compile [options]
compile a single .rain file.
Options:
-e, --entrypoints Entrypoints to compile
-i, --input Path to .rain file
-o, --output Path to output file, output format is .json
-l, --log Log the compilation result in terminal
-c, --config Path to the rainconfig json file(default is './rainconfig.json' or './.rainconfig.json' if not specified) that contains configurations, see './example.rainconfig.json' for more details.
-s, --silent Print no informative logs, except compilation results if --log is used
-h, --help display help for command
rainconfig information:
Description:
rainconfig.json provides configuration details and information required for .rain compiler.
usually it should be placed at the root directory of the working workspace and named as
'rainconfig.json' or '.rainconfig.json', as by doing so it will automatically be read
and having rainlang vscode extension, it will provide autocomplete and information on
each field, however if this is not desired at times, it is possible to pass any path for
rainconfig when using the dotrain command using --config option.
all fields in the rainconfig are optional and are as follows:
- src: Specifies list of .rain source files mappings for compilation, where specified
.rain input files will get compiled and results written into output json file.
- include: Specifies a list of directories (files/folders) to be included and watched.
'src' files are included by default and folders will be watched recursively for .rain files.
These files will be available as dotrain meta in the cas so if their hash is specified in a
compilation target they will get resolved.
- subgraphs: Additional subgraph endpoint URLs to include when searching for metas of
specified meta hashes in a rainlang document.
- meta: Lis of paths (or object of path and hash) of local meta files as binary or utf8
encoded text file containing hex string starting with 0x. Binary meta files should go
under 'meta.binary' field and hex meta files should go under 'meta.hex' field.
example of a config file content (see
./example.rainconfig.json):
`json
{
"include": ["./folder1", "./folder2"],
"src": [
{
"input": "./path/to/file1.rain",
"output": "./path/to/compiled-file1.json",
"entrypoints": ["entrypoint1", "entrypoint2"]
},
{
"input": "./path/to/file2.rain",
"output": "./path/to/compiled-file2.json",
"entrypoints": ["entrypoint1", "entrypoint2"]
}
],
"meta": {
"binary": [
"./path/to/binary-meta",
{
"path": "./path/to/another-binary-meta",
"hash": "0x123456789abcdef..."
}
],
"hex": [
"./path/to/hex-meta",
{
"path": "./path/to/another-hex-meta",
"hash": "0x123456789abcdef..."
}
]
},
"subgraphs": [
"https://subgraph1-uril",
"https://subgraph2-uril",
"https://subgraph3-uril"
]
}
`Developers
To get started, clone the repo and install the dependencies:
`bash
git clone https://github.com/rouzwelt/rainlang.git
cd rainlang
npm install
`
To build from source code:
`bash
npm run build
`
To generate documents:
`bash
npm run docgen
`
To run tests:
`bash
npm test
``