Skip to content

Instantly share code, notes, and snippets.

View webmaster128's full-sized avatar

Simon Warta webmaster128

View GitHub Profile
@webmaster128
webmaster128 / return_escrows.ts
Last active September 25, 2019 18:53
Example code how to return escrows using the IOV-Core CLI on Catnet 🐈
const nodeUrl = "wss://rpc-private-a-vip-catnet.iov.one";
const mnemonic = "twin document gold guide asset false rival rib civil squeeze they upper";
const escrowIds = [3, 4, 8, 10, 22, 34, 46, 58];
const profile = new UserProfile();
const signer = new MultiChainSigner(profile);
const { connection } = await signer.addChain(createBnsConnector(nodeUrl));
const chainId = connection.chainId();
const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic(mnemonic));
@webmaster128
webmaster128 / mnemonic_restore.js
Created August 4, 2019 16:34
Retoring original mnemonic from part 1 and part 2 using @iov/crypto
const part1 = 'pencil accuse tennis element peanut tent venue message process stove glory gym'
const part2 = 'panic roof boil axis mom enjoy change margin stove heavy forum food'
const part1Entropy = Bip39.decode(new EnglishMnemonic(part1))
const part2Entropy = Bip39.decode(new EnglishMnemonic(part2))
const restoredEntropy = part1Entropy.map((byte, index) => byte ^ part2Entropy[index])
const restored = Bip39.encode(restoredEntropy).toString()
// 'dial ring shiver firm connect nominee stairs army large rubber deal crater'
@webmaster128
webmaster128 / mnemonic_split.js
Created August 4, 2019 16:16
Split mnemonic in two parts using @iov/crypto
const original = 'dial ring shiver firm connect nominee stairs army large rubber deal crater'
const entropy = Bip39.decode(new EnglishMnemonic(original))
const part1Entropy = await Random.getBytes(entropy.length /* 16 bytes */)
const part2Entropy = entropy.map((byte, index) => byte ^ part1Entropy[index])
const part1 = Bip39.encode(part1Entropy).toString()
// 'pencil accuse tennis element peanut tent venue message process stove glory gym'
const part2 = Bip39.encode(part2Entropy).toString()
@webmaster128
webmaster128 / mnemonic_entropy.js
Created August 4, 2019 14:11
Example code how to convert between the raw entropy and the english mnemonic using @iov/cli
const entropy = await Random.getBytes(16);
toHex(entropy)
// '9f163e1de86807e8370baee878b9d64d'
Bip39.encode(entropy).toString()
// 'pair rapid manual speak lesson village switch into trick shift intact orange'
toHex(Bip39.decode(new EnglishMnemonic('pair rapid manual speak lesson village switch into trick shift intact orange')))
// '9f163e1de86807e8370baee878b9d64d'
// create some methods in the background script that can be called from the UI
window.getBinary = () => new Uint8Array([1, 2, 3]);
window.getUint8ArrayConstructor = () => Uint8Array;
function structuredClone(input) {
// One of 3 ways to access the native implementation of the structured clone
// algorithm in browsers. See https://dassur.ma/things/deep-copy/
return new Notification("", { data: input, silent: true }).data;
}
it("instanceof works for structured cloning", () => {
const original = new Uint8Array([1, 2, 3]);
const clone = structuredClone(original);
env:
node: true
es6: true
globals:
Atomics: readonly
SharedArrayBuffer: readonly
# jest
describe: readonly
expect: readonly
it: readonly

On a development machine get a recent Lisk mainnet snapshot and

dropdb --if-exists lisk_main
createdb lisk_main
gunzip -fcq lisk_main_backup-*.gz | psql --quiet --dbname lisk_main

Use a SQL tool to perform this query and export data (e.g. as CSV)

2019-01-20 20:16:24 Substrate Node
2019-01-20 20:16:24 version 0.10.0-78bb4c0-x86_64-linux-gnu
2019-01-20 20:16:24 by Parity Technologies <[email protected]>, 2017, 2018
2019-01-20 20:16:24 Chain specification: TSP antnet
2019-01-20 20:16:24 Node name: fair-poison-4982
2019-01-20 20:16:24 Roles: FULL
2019-01-20 20:16:24 Generated a new keypair: bf207ddf3aa5af6467c9ec590392db8c31f2ffe3a0771282f40450b1db931382 (5GPJexJM...)
2019-01-20 20:16:26 Initialising Genesis block/state (state: 0xbcd0…c65e, header-hash: 0x7445…5a5e)
2019-01-20 20:16:26 Loaded block-time = 40 seconds from genesis on first-launch
2019-01-20 20:16:26 Loading GRANDPA authorities from genesis on what appears to be first startup.
========== Build started: Building clFolder01 (kernel.cl) for 22 devices. ==========
========== Build started: Building C:\project\kernel.cl for 22 devices. ==========
1> kernel for Baffin:
Target GPU detected:
Baffin (Graphics IP v8)
AMD Radeon (TM) E9260
AMD Radeon Pro 465
Radeon (TM) Pro V5300X
Radeon (TM) Pro WX 4100