Closed shohu closed 7 years ago
Get blockhash of data synchronized on September 5
ubuntu@c0ban14-01:~$ c0ban-cli getblockchaininfo
{
"chain": "main",
"blocks": 704441,
"headers": 704441,
"bestblockhash": "0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918",
"difficulty": 455062.7470356631,
"mediantime": 1504586118,
"verificationprogress": 0.002809371385441663,
"chainwork": "00000000000000000000000000000000000000000000004056b226984cefdae6",
get txid from block
$ c0ban-cli getblock 0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918
{
"hash": "0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918",
"confirmations": 1,
"strippedsize": 276,
"size": 276,
"weight": 1104,
"height": 704441,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "e1c7faa08246434aa6f4c992b845db625e12f9af310cbba2817511131cf80ce8",
"tx": [
"e1c7faa08246434aa6f4c992b845db625e12f9af310cbba2817511131cf80ce8"
],
"time": 1504586419,
"mediantime": 1504586118,
"nonce": 2924635880,
"bits": "1a24de0b",
"difficulty": 455062.7470356631,
"chainwork": "00000000000000000000000000000000000000000000004056b226984cefdae6",
"reward": 0,
"previousblockhash": "0000000000001da0aea758f022d653a50f38bf7b7942ac3e142f6c6a6c0c44ad"
}
get transaction detail information
$ c0ban-cli getrawtransaction e1c7faa08246434aa6f4c992b845db625e12f9af310cbba2817511131cf80ce8 1
{
"hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4c03b9bf0a04572cae5908fabe6d6d3d20273231392e3132322e392e31376d6dbefa0859ae285c040abf9a034cffff01000000000000001fffffc2f5d200000d2f6e6f64655374726174756d2f000000000200000000000000001976a914f28e1e4723e028af90c4f28943314080814eb5ec88ac00000000000000001976a9147009129d6d5c318884ec288c525b26cf0a2fac9e88ac00000000",
"txid": "e1c7faa08246434aa6f4c992b845db625e12f9af310cbba2817511131cf80ce8",
"hash": "e1c7faa08246434aa6f4c992b845db625e12f9af310cbba2817511131cf80ce8",
"size": 195,
"vsize": 195,
"version": 1,
"locktime": 0,
"vin": [
{
"coinbase": "03b9bf0a04572cae5908fabe6d6d3d20273231392e3132322e392e31376d6dbefa0859ae285c040abf9a034cffff01000000000000001fffffc2f5d200000d2f6e6f64655374726174756d2f",
"sequence": 0
}
],
"vout": [
{
"value": 0.00000000,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 f28e1e4723e028af90c4f28943314080814eb5ec OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914f28e1e4723e028af90c4f28943314080814eb5ec88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"8dCNVvqf1WU64Qop8GnhEV49bx6sdeh9CP"
]
}
},
{
"value": 0.00000000,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 7009129d6d5c318884ec288c525b26cf0a2fac9e OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a9147009129d6d5c318884ec288c525b26cf0a2fac9e88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"8RJFGpj46ENtpMHyyVmK6zdvXbnicM5Dk3"
]
}
}
],
"blockhash": "0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918",
"confirmations": 1,
"time": 1504586419,
"blocktime": 1504586419
}
Get 1504586419 by following values.
$ c0ban-cli getblock 0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918
{
"hash": "0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918",
:
"time": 1504586419,
Run follow program. so, get 709843.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import requests
TOP_BLOCK_HASH='0000000000000697fda530f8ade57a82029fd4939fd8a7c97bd649d2bb76b918'
def get_json(block_id):
url = "http://hoge:fuga@localhost:3882/"
headers = {'content-type': 'application/json'}
# Example echo method
payload = {
"method": "getblock",
"params": [block_id],
"jsonrpc": "1.0",
"id": block_id,
}
return requests.post(
url, data=json.dumps(payload), headers=headers).json()
def main():
counter = 0
tran_counter = 0
# 1. ブロックを前におっていく。genesisblockになったら停止
target_block_id = TOP_BLOCK_HASH
while counter < 704441:
# getblock
res_json = get_json(target_block_id)
#import pdb; pdb.set_trace()
# transaction count
tran_counter = tran_counter + len(res_json["result"]["tx"])
# prevhash
counter = counter + 1
if counter % 500 == 0:
print "counter = {}, tran_counter = {}".format(counter, tran_counter)
target_block_id = res_json["result"]["previousblockhash"]
print "finish. counter = {}, tran_counter = {}".format(counter, tran_counter)
if __name__ == "__main__":
main()
2(total transaction count) / [1 of transaction time] - [genesis block timestamp] 0.02665774824 = 709843 / (1504586419 - 1477958401)
Fix the following parameters for cban