Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (gene.chain) {
this.chain = gene.chain;
this.chainPath = (this.chain.path ? this.chain.path : process.cwd() + "/chain");
if (!fs.existsSync(this.chainPath)) fs.mkdirSync(this.chainPath, { recursive: true })
}
// RPC
const rpcconfig = Object.assign({
protocol: "http",
host: "127.0.0.1",
port: "8332",
}, (gene && gene.rpc ? gene.rpc : {}))
this.rpc = new RpcClient(rpcconfig)
// PEER
let m = new Messages({ Block: bsv.Block, BlockHeader: bsv.BlockHeader, Transaction: bsv.Transaction, MerkleBlock: bsv.MerkleBlock, network: bsv.Networks.defaultNetwork })
let g = Object.assign({ host: "127.0.0.1", messages: m }, (gene && gene.peer ? gene.peer : {}))
this.peer = new Peer(g)
this.peer.on("disconnect", function() { console.log("disconnected") })
this.peer.on("error", function(e) { console.log("Err", e) })
this.peer.on("notfound", function(e) { console.log("notfound", e) })
this.peer.on("reject", function(e) { console.log("reject", e) })
this.peer.on('block', async (e) => {
let header = e.block.header.toObject()
if (this.onblock) {
if (this.request.type.includes('block')) {
let index = this.request.type.indexOf("block");
if (index > -1) this.request.type.splice(index, 1)
header.height = this.current_block.height
} else if (this.request.type.includes('onblock')) {
header.height = await this.height(header.hash)
}
const log = require("debug")("hummingbird");
const { Peer, Messages } = require("bsv-p2p");
import bsv from "bsv"
import RPCClient from "bitcoind-rpc"
import txo from "txo"
import Queue from "promise-queue"
import * as tape from "./tape"
import { sleep } from "./helpers"
const messages = new Messages({ Block: bsv.Block, BlockHeader: bsv.BlockHeader, Transaction: bsv.Transaction, MerkleBlock: bsv.MerkleBlock });
const STATE = {
DISCONNECTED: "DISCONNECTED",
CONNECTING: "CONNECTING",
CRAWLING: "CRAWLING",
LISTENING: "LISTENING",
};
const MODE = {
BOTH: "BOTH",
MEMPOOL: "MEMPOOL",
BLOCK: "BLOCK",
};
export default class Hummingbird {