Giter Site home page Giter Site logo

go-bitdb's Introduction

go-bitdb

Using go-bitdb you can query a bitdb node and connect to a bitsocket node in golang.

BitDB

BitDb is an autonomous database that continuously synchronizes itself with Bitcoin. BitDB stores every bitcoin transaction in a structured document format that can be queried against like a regular database. With a simple MongoDB query, anyone can easily query, filter, and build powerful decentralized applications on Bitcoin.

Bitsocket

Bitsocket is a bitcoin notification service. By constructing a bitquery, you can subscribe to the bitcoin blockchain and recieve transactions that meet a certain criteria.

Install

go get github.com/dylankilkenny/go-bitdb

BitDb Usage

The following code creates a BitDb instance and queries a bitdb node for a transaction by its TxID. The jq string is the processing function which will return an object containing the amount in the first output of the transaction

version := 3 // API version
bitdbURL := "https://bitdb.network/q/" // API url
apiKey := "qq54zc33pttdp6l8ycnnj99ahan8a2hfrygqyz0fc3"
BitDb := bitdb.New(version, bitdbURL, apiKey) // Create new instance

txHash := BitDb.TxHash{Hash: "ffff5c6d0660068381b26fe3546eb2a51faf1a0a1a707db1ca32a5b168a7301b"}
jq := ".[] | .out[0] | {amount: .e.v}"
response, err := BitDb.Request(txHash, jq)
if err != nil {
  fmt.Println(err)
}
confirmed, _ := response.Confirmed.(map[string]interface{})
fmt.Println(confirmed["amount"])

Output:

7051

Rather than using structs you can query with a json string:

var bitquery = []byte(`
{
  "v": 3,
  "q": {
    "find": {
      "tx.h": "ffff5c6d0660068381b26fe3546eb2a51faf1a0a1a707db1ca32a5b168a7301b"
    }
  },
  "r": {
    "f": ".[] | .out[0] | {amount: .e.v}"
  }
}
`)
response, err := BitDb.RawRequest(bitquery)
if err != nil {
  fmt.Println(err)
}
confirmed, _ := response.Confirmed.(map[string]interface{})
fmt.Println(confirmed["amount"])

Bitsocket Usage

version := 3
bitdbURL := "https://bitdb.network/q/"
bitsocket := bitdb.NewSocket(version, bitdbURL)

events, err := bitsocket.Stream("", ".[] | .out[0] | {amount: .e.v}")
if err != nil {
  t.Error(err)
}
for tx := range events {
  // do something with transaction
}

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.