hhstore/blog

blockchain: btc(bitcoin)

hhstore opened this issue · 9 comments

blockchain: btc(bitcoin)

ref:

官网:

下载地址:

源码库:

book:

Insight API:

官方:

参考:

  • src - bitcoin core: 源码调用关系图

  • 区块链技术与应用回顾

    • Bitcoin/Ethereum/Ripple/Hyperledger的对比
  • 比特币Bitcoin源代码安装编译

  • Insight API开源项目介绍

  • Insight API - github

    • 传参示例
  • 首先,在阅读本文以前假设您已经了解比特币Bitcoin基本原理。

  • Insight API是一个开源基于比特币Bitcoin blockchain的REST风格的API框架。

  • Insight API运行于NodeJS环境,使用LevelDB做数据存储。

  • 使用Insight API可以开发基于Bitcoin的应用程序,如获取blockchain信息的钱包。

  • 这里我们介绍此刻最新版本2.7,它还有一个前端项目Insight。生产环境运行在这儿。

  • Insight-API就是一个基于Node.js平台的REST WEB API项目.

  • Insight-API封装了BitCore实现WEB API,BitCore是基于JSON PRC的API,它服务于Bitcoind.

  • Insight-API也是node.js服务端应用示例之一。

本地环境:

https://github.com/bitpay/insight

npm install -g bitcore-node

# create:
bitcore-node create mynode

cd mynode
bitcore-node install insight-api
bitcore-node install insight-ui

# start:
bitcore-node start


# Open a web browser to 
# http://localhost:3001/insight/

# dev:
npm run build
npm run watch

restful api:

https://github.com/bitpay/insight-api
https://www.npmjs.com/package/insight-bitcore-api

/insight-api/tx/[:txid]
/insight-api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
/insight-api/rawtx/[:rawid]
/insight-api/rawtx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c

/insight-api/addr/[:addr]/balance
/insight-api/addr/[:addr]/totalReceived
/insight-api/addr/[:addr]/totalSent
/insight-api/addr/[:addr]/unconfirmedBalance

/insight-api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c

# 示例:
https://insight.bitpay.com/api/tx/e5ceadf7a87888b11d71f5a216620ab9a0c26444490d146f1e64c1c115c1d833

https://insight.bitpay.com/api/rawtx/e5ceadf7a87888b11d71f5a216620ab9a0c26444490d146f1e64c1c115c1d833

# test env:
https://test-insight.bitpay.com/api/tx/d193a7ed1cea05a6e191ccacd381d1cb13b9065dd39b90189c2b55b835c267f7
https://test-insight.bitpay.com/api/rawtx/d193a7ed1cea05a6e191ccacd381d1cb13b9065dd39b90189c2b55b835c267f7


bitcoin API:

rpc:

python lib:

https://github.com/petertodd/python-bitcoinlib

https://pypi.python.org/pypi/bitcoin-python/0.3

# 客户端:

>>> import jsonrpclib
>>> server = jsonrpclib.Server('http://localhost:8080')
>>> server.add(5,6)
11
>>> print jsonrpclib.history.request
{"jsonrpc": "2.0", "params": [5, 6], "id": "gb3c9g37", "method": "add"}
>>> print jsonrpclib.history.response
{'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}
>>> server.add(x=5, y=10)
15
>>> server._notify.add(5,6)
# No result returned...
>>> batch = jsonrpclib.MultiCall(server)
>>> batch.add(5, 6)
>>> batch.ping({'key':'value'})
>>> batch._notify.add(4, 30)
>>> results = batch()
>>> for result in results:
>>> ... print result
11
{'key': 'value'}
# Note that there are only two responses -- this is according to spec.


# 服务器端:
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer

server = SimpleJSONRPCServer(('localhost', 8080))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.register_function(lambda x: x, 'ping')
server.serve_forever()

其他:

http://8btc.com/forum.php?mod=viewthread&tid=2549

查询测试API:

btc, etc, eth:

https://kovan.etherscan.io/tx/0x15860b8a6c8040312da2aa6004854e1e9ebb5ea29ed046d8a3a6f3dbb93a582c


https://test-insight.bitpay.com/tx/03cb5264525f2105b4a98f8172864ec62889bd9f31b199f19c44fa75eec80206

web3.py

pip install web3