Giter Club home page Giter Club logo

ledger's Introduction

Subspace Ledger Module

A mock proof of space ledger for completeness.

External Usage

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')

API

ledger.createProof(key: string, space: integer) proof: object

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 key
  • space - amount of space to be pledged in GB

Returns a proof of space.

ledger.ValidateProof()

Pledges are validated ineffeciently by recreating the full proof at each node.

ledger.createTx()

Create a tx locally to transfer credits from your address to another address.

ledger.validateTx()

Validate a tx submitted before including a block or when validating a block contents.

ledger.createContract()

Locks earned subspace credits into a storage contract and publishes as a tx

ledger.validateContract()

Validates if a pending or published contract is valid

ledger.getBlockSolution()

Searches the local proofs for the best block solution to start building a new block in response to a new valid published block.

legder.validateBlockSolution()

Validates that a block solution is valid for a given public key

publishBlock()

Publishes the current block 1 minute after last block is published

validateBlock()

Validates a received block

saveBlock()

Saves a valid block to local storage

computeUtxo()

Computes the UTXO balance for all addresses

getBalance()

Get's current UTXO balance for an address

ledger.on('block')

Validates the block and solution. If valid finds the best solution to the next block and listens for transactions to add.

ledger.on('tx')

Validates tx's and adds them to the current block.

Development Use

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.

Testing

Write tests in src/main.tests.ts (example provided) and run with

$ npx jest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.