Giter VIP home page Giter VIP logo

difficulty-lock's Introduction

DifficultyLock

Build

npm run build

Testing Locally

npm run test

Run Tests on the Bitcoin Testnet

npm run test:testnet

Config

static readonly MAX_HEADERS = 52n
// maximum number of block headers that can be processed in a single transaction call
// 52596n = 1 year's worth of blocks at 10 minutes per block.
// Smaller values will produce a smaller bitcoin transactions, but recordBlocks
// will need to be called more timesin order to unlock the contract

Methods

Constructor

  • benificiary: Addr - recipient of funds if difficulty is reached
  • issuer: Addr - issuer of contract
  • satoshis: bigint - satoshis being locked in contract
  • prevHeader: ByteString - previous block header. Submit header from few blocks back to ensure a reorg does not invalidate contract
  • prevHeight: bigint - height associated with previous block header
  • targetDifficulty: bigint - Difficulty which much be acheived to unlock contract
  • requiredTargetCount: bigint - number of blocks at target difficulty required
  • expirationHeight: bigint - Block height at which issuer can refund the contract

recordBlocks

  • sig: Sig - beneficiary signature
  • pubkey: PubKey - beneficiary pubkey
  • headers: ByteString - Up to MAX_HEADERS 80-byte block headers
  • trailingOuts: ByteString - Transaction outputs after the contract output and before change output.

refund

  • sig: Sig - issuer signature
  • pubkey: PubKey - issuer pubkey nLockTime must be on or after expiration height nSequence must be less that 0xffffffff

transferBenificiary

  • sig: Sig - beneficiary signature
  • pubkey: PubKey - beneficiary pubkey
  • benificiary: Addr - new beneficiary pubkeyhash
  • trailingOuts: ByteString - Transaction outputs after the contract output and before change output.

transferIssuer

  • sig: Sig - issuer signature
  • pubkey: PubKey - old issuer pubkey
  • issuer: Addr - new issuer pubkeyhash
  • trailingOuts: ByteString - Transaction outputs after the contract output and before change output.

Convert to target from bits field in block

static bits2Target(bits: ByteString): bigint {
    const exponent = Utils.fromLEUnsigned(slice(bits, 3n))
    const coefficient = Utils.fromLEUnsigned(slice(bits, 0n, 3n))
    const n = 8n * (exponent - 3n)
    return lshift(coefficient, n)
}

Bounty Payments

1shrgL5Hd3XDnm8AChvKmi1nFpkVa6kxz

difficulty-lock's People

Contributors

shruggr avatar

Stargazers

Shirish Sarkar avatar xhliu avatar Florian Ludewig avatar Ryan Wold avatar  avatar Eamon McDermott avatar

Watchers

 avatar

Forkers

pmitchev

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.