1.1.0 • Published 4 years ago

halva-spec-builder v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Spec-Builder

This npm module is a chain specification file modifier for a Substrate node.

Features


  • Key generation type sr25519 and ed25519
  • Custom middleware support
  • Built-in cli

Installation


npm install @halva-suite/halva-spec-builder

Use Module


Use middleware runner

const spec = await HalvaSpecModifier.init('path/to/spec.json', 100, 10)
  .apply(auraMiddleware)
  .apply(balanceMiddleware)
  .apply(grandpaMiddleware)
  .run();
spec.output('/path/from/save/shc.json');

Create custom middleware

 .apply((context: HalvaMiddlewareContext): any => {
 const ed25519pairs = context.ed25519Keys.getPairs();
 for (let i = 0; i < ed25519pairs.length; i++) {
   context.jsonSchema.genesis.runtime.customObject.customField.push(ed25519pairs[i].address);
 }
 return context.jsonSchema;
})

Context structure

interface HalvaMiddlewareContext {
jsonSchema: any;
ed25519Keys: Keyring;
sr25519Keys: Keyring;
customArgs: any;
path: string;
mnemonic: string;
balance: number;
count: number;
}

Use cli

spec-builder -i /path/to/spec.json 
spec-builder -i /path/to/spec.json -a 100 -b 1152921504606847000
spec-builder -i /path/to/spec.json -a 100 -b 1152921504606847000 -m clip organ olive upper oak void inject side suit toilet stick narrow

You can also use separate middleware when working with cli

spec-builder -i /path/to/spec.json --am --bm # am - AuraMiddleware bm - BalanceMiddleware 
                                             #The grandpa block will not be filled, because the --gm argument is missing

Script Commands


  • yarn test -- Runs tests.
  • yarn typecheck -- Checks TypeScript types for correctness. This is disabled during tests for performance reasons.
  • yarn lint -- Runs linting.
  • yarn format -- Reformats all of the .ts and .tsx files with Prettier.
  • yarn build -- Regenerates dist folder that gets included into NPM module.

Contributing


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT