Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
bitcoin-inventory
Advanced tools
Exchange transactions with peers
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.
FAQs
Exchange transactions with peers
The npm package bitcoin-inventory receives a total of 2 weekly downloads. As such, bitcoin-inventory popularity was classified as not popular.
We found that bitcoin-inventory demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.