Socket
Socket
Sign inDemoInstall

bitcoin-inventory

Package Overview
Dependencies
27
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bitcoin-inventory

Exchange transactions with peers


Version published
Weekly downloads
9
increased by50%
Maintainers
1
Install size
610 kB
Created
Weekly downloads
 

Readme

Source

bitcoin-inventory

npm version Build Status Dependency Status

Exchange transactions with peers

Usage

npm install bitcoin-inventory

var Inventory = require('bitcoin-inventory')

// "peers" is a PeerGroup or Peer from the `bitcoin-net` package
var inv = Inventory(peers)

// get a tx that was sent to us
inv.get(hash) // returns tx

// add a tx and announce its hash to our peers
inv.broadcast(tx)

inv.on('tx', (tx) => { /* got tx */ })
inv.on('tx:<txid>', (tx) => { /* got tx with hex hash `txid` */ })

Inventory handles the exchange of Bitcoin transactions with peers.

When a peer discovers a new transaction, they send us a message (inv) announcing its hash. If we have not yet seen this transaction, Inventory will request it from the peer and add it to the inventory.

If we create a new transaction, Inventory will announce the hash to our peers, and send the transaction data to them if they request it.


new Inventory(peers, [opts])

Creates an Inventory which listens for and fetches new transactions from peers, and announces transactions to peers.

Transactions are only kept in the Inventory for a limited amount of time, after which they are automatically pruned. (The amount of time is configurable via the ttl option).

peers should be an instance of PeerGroup or Peer, from the bitcoin-net package.

opts may be an object containing:

  • ttl Number (default: 120000 (2 minutes)) - the amount of time to keep transactions in the inventory before pruning them (in ms)

inv.get(hash)

Returns the transaction from the inventory with the specified hash (which is a Buffer).


inv.broadcast(tx)

Adds tx to the inventory, and announces its hash to the peers. Also listens for peers to request the full transaction from us.


inv.close()

Closes the inventory and clears timers.

Keywords

FAQs

Last updated on 08 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc