A mock proof of space ledger for completeness.
Install this module as a dependency into another project
$ yarn add https://www.github.com/subspace/ledger.git
Require this module inside a script
const ledger = require('@subspace/ledger')
Generates a simple representative proof of space by iteratively hashing a nodes public key, once for each MB pledged, or 1000 times for a gigabyte of storage. The hashes are sorted into a binary tree and stored as solutions to the block challenge.
key
- string encoed 32 byte ECDSA public keyspace
- amount of space to be pledged in GB
Returns a proof of space.
Pledges are validated ineffeciently by recreating the full proof at each node.
Create a tx locally to transfer credits from your address to another address.
Validate a tx submitted before including a block or when validating a block contents.
Locks earned subspace credits into a storage contract and publishes as a tx
Validates if a pending or published contract is valid
Searches the local proofs for the best block solution to start building a new block in response to a new valid published block.
Validates that a block solution is valid for a given public key
Publishes the current block 1 minute after last block is published
Validates a received block
Saves a valid block to local storage
Computes the UTXO balance for all addresses
Get's current UTXO balance for an address
Validates the block and solution. If valid finds the best solution to the next block and listens for transactions to add.
Validates tx's and adds them to the current block.
Clone and install the repo locally
$ git clone https://www.github.com/subspace/ledger
$ cd ledger
$ yarn
Start writing code in src/main.ts
Build manually:
$ npm run build
Watch for file changes:
$ npm run watch
Instructions to automate with visual studio code.
Write tests in src/main.tests.ts (example provided) and run with
$ npx jest