npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bithook

v0.0.1

Published

Payment lifecycle handler over bitcoind

Downloads

3

Readme

Bithook

Bithook is a simple mechanism/heuristic that let you precisely react to specific events occuring during the payment cycle of a given Bitcoin address. It's a zero dependency utility, directly connected to your bitcoind (bitcoin-core) instance.

Bitcoin is an asynchronous protocol, transactions are sent to the network, then eventually included in a block, on top of which other blocks keeps getting added. It's hard to gather all the relevant informations, at different time in space, and converge to a comprehensive payment framework/unit. Bithook abstracts that complexity, and let you interact at any step of the payment cycle, providing all the context necessary to make custom business logic decisions.

Install

// install
npm install bithook --save

// import
import bithook from 'bithook'

Use

Connect to your bitcoind server :

const chain = new bithook({ bitcoind: 'bitcoind://rpcuser:[email protected]:8332' })

Hook onto a bitcoin address with chain.hook().

  • 1st param is the address you want to track
  • 2nd param (the hook handler function) is where you write your custom logic
chain.hook("1CNgN2HJvQMi1RvLDA7fazc5SyQLQAoX1W", (data, hook) => {
  // Custom business logic goes here

  // use any relevant informations for your logic
  const { status, confs } = data

  // ex: forward data (to an url, or a database)
  if(status == "received") db.save(data)
  if(status == "confirmed") http.post('some.url', data)

  // don't forget to kill the hook at some point
  if(confs > 6) hook.kill()
})

handler(data, hook)

You can think of the handler as a map reduce through the Payment cycle, which combine the 3 following events :

  • A) the tx is received by your node (just received, not included in block yet).
  • B) the tx is included in a block. (first block confirmation)
  • C) on every new block if B) has happened, untill you kill the hook with hook.kill().

At the moment you create a hook and define it's handler, the handler get's called whenever event A, B or C happens. Events always happen in the same order: A then B then C.

The data object mutates through the payment cycles :

Event A:

  • data.status == "received"
  • data.confs == 0
  • data.txhash

Event B:

  • data.status == "confirmed"
  • data.confs == 1
  • data.blockhash actual block hash
  • data.height actual block height
  • data.ts actual timestamp

Event C:

  • only data.confs changes

A hook handler receive a data object as 1st argument. You write your business logic against the values of the different fields of that data object.