项目作者: dfoderick

项目描述 :
Bitqueries for mapping bitcoin data. Bitcoin protocol legends.
高级语言:
项目地址: git://github.com/dfoderick/bitcoin-map-legend.git
创建时间: 2019-01-11T15:09:36Z
项目社区:https://github.com/dfoderick/bitcoin-map-legend

开源协议:

下载


Bitcoin protocol queries

Knowing Bitquery helps form a mental map of what is being written to the bitcoin blockchain. Some maps need a legend.

The purpose of this repo is to document specific queries that would be useful for real applications
using the various bitcoin protocols. It is not intended to be a general guide to learning bitquery.

Nevertheless, we begin with some background materials for getting up to speed with bitquery.

Bitquery is the language of
bitdb and
bitsocket from
unwriter.
It is based on the mongo db query over documents.

The structure of the bitcoin transactions are called tna - as documented here.

The following links are useful to discover more query examples.
Bitquery playlist
More Bitsocket Examples
More Bitdb Examples

Sites

Genesis is starting point for all queries.
https://genesis.bitdb.network/

Explorer Endpoint:

  1. API Endpoint:
  2. ```https://genesis.bitdb.network/q/1FnauZ9aUH2Bex6JzdcV4eNX7oLSSEbxtN/<query>

General queries

A few queries not specific to any protocol can be helpful for debugging or building apps on bitcoin.

Find specific transaction by txid. When you just created a transaction and you want to see how bitdb shreaded the transaction.
Try it

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {"tx.h": "6f7147a7a6656139a1a3fb1e45c266c2534c8827fba9f0e71c07e2b45276265f"}
  5. }
  6. }

Find transactions going to an address. When your app needs to find out when it is being called.

Important! Genesis uses original bitcoin format for addresses. Make sure you are querying for the correct address format.

Try it

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {
  5. "out.e.a": "19fhPw9rheNT9kT4BcLsNCyZhjo1QRivd8"
  6. }
  7. }
  8. }

Use Raw Stream for BitSocket only to live stream all transactions when you just want to look at something. Makes for great Saturday night entertainment.

  1. {
  2. "v": 3,
  3. "q": { "find": {} }
  4. }

Get random transactions. Might useful for your SPV wallet to obfuscate your address monitoring in case someone is watching you.
Try it

  1. {
  2. "v": 3,
  3. "q": {
  4. "db": ["c"],
  5. "aggregate": [{ "$sample": { "size": 10 } }]
  6. }
  7. }

Protocols

Protocol Docs
memo memo docs
matter matter docs
blockpress blockpress docs
tokenized tokenized docs
bitcoin token bitcointoken docs
SLP SLP docs
bitcoinfiles bitcoinfiles docs

memo

Memo Protocol document

Example: Find memo posts.

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {
  5. "out.b0": { "op": 106 },
  6. "out.h1": "6d02"
  7. },
  8. "limit": 10
  9. }
  10. }

Example: Find memo posts and posts with topics.

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {
  5. "out.b0": { "op": 106 },
  6. "out.h1": { "$in": ["6d02", "6d0c"] }
  7. },
  8. "limit": 10
  9. }
  10. }

tokenized

Tokenized Protocol document

Tokenized is a plethora of smart contract definitions where all the use cases have been carefully analyzed.
Tokenized protocol is implemented as a fixed width message with a prefix 00000020

Example: Find tokenized data. This example is great because it shows how to transform the transactions to just select the outs with the data that you want.

  1. {
  2. "v": 3,
  3. "q": {
  4. "db": ["c"],
  5. "find": {
  6. "out.b0": { "op": 106 },
  7. "out.str": { "$regex": "^OP_RETURN 00000020" }
  8. },
  9. "limit": 3,
  10. "project": { "tx": 1, "out": 1, "_id": 0 }
  11. },
  12. "r": {
  13. "f": "[ .[] | (.out[] | select(.b0.op==106)) as $outWithData | {tx: .tx.h, msg: $outWithData.s1}]"
  14. }
  15. }

bitcointoken

bitcointoken site
bitcointoken docs

BitcoinToken is interesting because the project is working on the concept of data ownership, data that is “updatable” on the blockchain by the data owner and can be “shared” with other co-owners.

Data stored in this way comes with a very strong guaranty: only the person in possession of the private key for 0x03a70e0e5f7… can spend the output containing the data. We call that user the owner of the data. By default the user to issue the command is the owner, to designate a different owner, pass in that users public key as the second argument. Multiple public keys can be passed in to model co-ownership of data.

Also, check out how they are storing json on the blockchain (i.e. key-value pairs).

  1. const outputId = await db.put({
  2. text: 'Lorem ipsum',
  3. author: 'Alice'
  4. })

The above json encoded on the blockchain.

  1. 4 0x74657874 OP_DROP // text
  2. 11 0x4c6f72656d20697073756d OP_DROP // Lorem ipsum
  3. 6 0x617574686f72 OP_DROP // author
  4. 13 0x416c69636520616e6420426f62 OP_DROP // Alice and Bob

matter

Matter Protocol document

Example: Find all posts.

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {
  5. "out.b0": { "op": 106 },
  6. "out.h1": "9d02"
  7. },
  8. "limit": 10
  9. }
  10. }

blockpress

blockpress protocol document

Example: Find blockpress posts.

  1. {
  2. "v": 3,
  3. "q": {
  4. "find": {
  5. "out.b0": { "op": 106 },
  6. "out.h1": "8d02"
  7. },
  8. "limit": 10
  9. }
  10. }