Add documentation and examples (#145)

* Add documentation

* Justification u8a decoding and json encoding (#146)

* Decode Justifications

* Json encoding for justifications

* Bump deps

* Allow extrinsic length encoding to operate on u8a[] (#148)

* Fix config and move generated doc to a subfolder

* Cleanup extrinsic encoding (#150)

* Cleanup extrinsic encoding

* Removed now-defunct type

* Add uncheckedLength encoding

* Add examples

* Ignore package-lock since we use yarn

* Cleanup examples

* Add gitbook config and some base files for the doc

* Do not make full doc mandatory for now

* Add contributing guide, polish doc and samples

* Update the deps of all samples and add yarn scripts
Fix and regenerate the doc

* Fix Contributing guide
This commit is contained in:
Chevdor
2018-09-15 09:11:56 +02:00
committed by Jaco Greeff
parent 7fffcb3747
commit 0981a30d84
61 changed files with 6937 additions and 105 deletions
@@ -0,0 +1,8 @@
= Read storage
Many important variable are available through the storage API. This example shows how to call a few of those APIs.
[source, javascript]
----
include::index.js[]
----
+33
View File
@@ -0,0 +1,33 @@
const Api = require('@polkadot/api').default
const WsProvider = require('@polkadot/api-provider/ws').default
const storage = require('@polkadot/storage').default
const BN = require('bn.js')
const provider = new WsProvider('ws://127.0.0.1:9944')
const api = new Api(provider)
async function getAccountIndex (address) {
return api.state.getStorage([storage.system.public.accountIndexOf, address])
}
async function getValidators () {
return api.state.getStorage([storage.session.public.validators])
}
async function getBlockPeriod () {
return api.state.getStorage([storage.timestamp.public.blockPeriod])
}
async function main () {
const address = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ'
const validators = await getValidators()
const bn = await getAccountIndex(address)
const blockPeriod = await getBlockPeriod()
const index = new BN(bn)
console.log(`BlockPeriod: ${new BN(blockPeriod).toString(10)} seconds`)
console.log(`Account Index of ${address}: ${index.toString(10)}`)
console.log('Current validators', validators)
}
main().finally(_ => process.exit())
@@ -0,0 +1,19 @@
{
"name": "04_read_storage",
"version": "0.1.0",
"description": "Example showing how to transfer DOTs",
"main": "index.js",
"author": "chevdor",
"license": "MIT",
"scripts": {
"clean": "rimraf node_modules",
"start": "node index.js"
},
"dependencies": {
"@polkadot/api": "0.29.1",
"bn.js": "^4.11.8"
},
"devDependencies": {
"rimraf": "2.6.2"
}
}