sub-script

Crates.iosub-script
lib.rssub-script
version0.8.0
sourcesrc
created_at2022-05-20 14:34:11.520184
updated_at2022-05-23 13:21:50.940107
descriptionScripting tool for Substrate chains
homepagehttps://github.com/PolymeshAssociation/sub-script
repositoryhttps://github.com/PolymeshAssociation/sub-script
max_upload_size
id590315
size292,180
Adam Dossa (adamdossa)

documentation

README

Sub-script

A simple scripting interface for Substrate nodes. It uses Rhai for the scripting engine.

Features

  • Auto generate key pairs for named users by accessing USER.<UserName>.
  • Loads chain metadata for all modules, extrinsics, events, storages and types (for v14+ Metadata chains).
  • Easy to sign and submit extrinsic calls.
  • Spawning sub-task (threads) for load testing.

Goals

  • Flexible - Load chain metadata from node and all custom types from schema.json file. No recompile needed.
  • Mocking - Easy to share scripts for mocking large number of users, assets, etc.. on a local node for testing UIs.
  • Debuging - Provides a low-level interface to the node. Easy to change schema types for testing encoding issues.

Non-Goals

  • This doesn't replace SDKs for other languages. The available libraries will be very limited.
  • Please don't use on Mainnet.

Todo

  • Subscribe to storage updates.
  • Add REPL support for quickly making extrinsic calls.

Examples

// Use Alice for mocking cdd.
let alice = USER.Alice;

// Generate a test user.  Key generated from "//Test123" seed.
let user = USER.Test123;

// Mock Cdd for user and make sure they have some POLYX.
let res = alice.submit(TestUtils.mock_cdd_register_did(user));
if res.is_success {
	// New account send them some POLYX.
	alice.submit(Balances.transfer(user, 5.0));
}

// Generate another test user.  Key generated from "//Key1" seed.
let key = USER.Key1; // Don't mock cdd for this user.

// Add JoinIdentity authorization for `key` to join `user`.
let res = user.submit(Identity.add_authorization(#{
	Account: key
}, #{
	JoinIdentity: #{
		asset: #{ These: ["ACME"] },
		extrinsic: #{ Whole: () },
		portfolio: #{ Whole: () },
	}
}, ()));
if res.is_success {
	// call successful.
} else {
	// call failed.
	print(`failed: ${res.result}`);
}

// Process all events emitted by the call.
for event in res.events {
	print(`EventName: ${event.name}`);
	print(`  Args: ${event.args}`);
}
// Process events matching prefix 'Identity.Auth'.
for event in res.events("Identity.Auth") {
	print(`EventName: ${event.name}`);
	print(`  Args: ${event.args}`);
}

See other examples scripts in ./scripts/ folder.

Commit count: 222

cargo fmt