0
点赞
收藏
分享

微信扫一扫

扫描区块技术Block scan

Greatiga 2022-09-14 阅读 74


扫描区块技术Block scan

笔记码住

扫描区块技术Block scan_f5

     def init_table(conn):
tables = []
tb_block = '''
create table if not EXISTS block (
number bigint primary KEY ,
hash char(64) not null,
bits bigint,
transaction_count INTEGER ,
mixhash VARCHAR (128),
version char(8) ,
merkle_tree_hash char(64),
previous_block_hash CHAR (64),
nonce varchar(128) ,
time_stamp bigint
) DEFAULT charset=utf8;
'''

tb_tx = '''
create table if not EXISTS tx (
id bigint PRIMARY KEY ,
block_height bigint REFERENCES block(id),
hash char(64) not null
)DEFAULT charset=utf8 ;'''

tb_address = '''
create table if not EXISTS address(
id int PRIMARY KEY ,
address VARCHAR (64) UNIQUE
)DEFAULT charset=utf8;
'''

tb_output = '''
create table if not EXISTS tx_output(
id bigint PRIMARY key,
hash char(64) NOT NULL ,
tx_id bigint REFERENCES tx(id),
output_index bigint not null,
output_value bigint,
address_id bigint REFERENCES address(id),
script varchar(1024),
asset varchar(64),
decimal_number varchar(8)
)DEFAULT charset=ascii;
'''

tb_output_fork = '''
create table if not EXISTS tx_output_fork(
id bigint PRIMARY key,
hash char(64) NOT NULL ,
tx_id bigint,
output_index bigint not null,
output_value bigint,
address_id bigint,
script varchar(1024),
asset varchar(64),
decimal_number varchar(8)
)DEFAULT charset=ascii;
'''
tb_tx_fork = '''
create table if not EXISTS tx_fork (
id bigint PRIMARY KEY ,
block_height bigint,
hash char(64) not null
)DEFAULT charset=ascii ;'''

tb_input_fork = '''
create table if not EXISTS tx_input_fork(
id bigint PRIMARY key,
tx_id bigint,
belong_tx_id bigint,
tx_index bigint,
tx_value bigint not null,
script varchar(1024),
address_id bigint,
asset varchar(64),
decimal_number varchar(8)
)DEFAULT charset=ascii;
'''

tb_block_fork = '''
create table if not EXISTS block_fork (
number bigint primary KEY ,
hash char(64) not null,
bits bigint,
transaction_count INTEGER ,
mixhash VARCHAR (128),
version char(8) ,
merkle_tree_hash char(64),
previous_block_hash CHAR (64),
nonce varchar(128) ,
time_stamp bigint
) DEFAULT charset=ascii;
'''
tb_output_asset = '''
create table if not EXISTS tx_output_asset(
id bigint PRIMARY key,
hash char(64) NOT NULL ,
tx_id bigint REFERENCES tx(id),
output_index bigint not null,
output_value bigint,
address_id bigint REFERENCES address(id),
asset_name varchar(64),
issuer varchar(64),
asset_type varchar(8),
description varchar(64)
)DEFAULT charset=utf8;
'''

tb_input = '''
create table if not EXISTS tx_input(
id bigint PRIMARY key,
tx_id bigint REFERENCES tx(id),
belong_tx_id bigint REFERENCES tx(id),
tx_index bigint REFERENCES tx_output(output_index),
tx_value bigint not null,
script varchar(1024),
address_id bigint REFERENCES address(id),
asset varchar(64),
decimal_number varchar(8)
)DEFAULT charset=ascii;
'''

扫描区块技术Block scan_5e_02


{
"header" :
{
"result" :
{
"bits" : "7097242144892",
"hash" : "cb36f2a1cbbf6a6300f4bf4915a5f54476ab603f2703a99e5d8d2db7ae2b37ed",
"merkle_tree_hash" : "3457b988bc6b61a7ad803f0742a68064c622ec618b833d99d153b92cba264d53",
"mixhash" : "47266114351983928450891657703600980449927404535067001902399906817438963939929",
"nonce" : "1864926684099479906",
"number" : 1000000,
"previous_block_hash" : "049257f31f4412bf115ed44a9305012ccea888cf842c2f0b66a528f258016e50",
"time_stamp" : 1520339120,
"transaction_count" : 1,
"version" : 1
}
},
"txs" :
{
"transactions" :
[
{
"hash" : "3457b988bc6b61a7ad803f0742a68064c622ec618b833d99d153b92cba264d53",
"inputs" :
[
{
"previous_output" :
{
"hash" : "0000000000000000000000000000000000000000000000000000000000000000",
"index" : 4294967295
},
"script" : "[ 0340420f ]",
"sequence" : 0
}
],
"lock_time" : "0",
"outputs" :
[
{
"address" : "MUiW2CViWLQBg2TQDsRt1Pcj7KyrdqFPj7",
"attachment" :
{
"type" : "etp"
},
"index" : 0,
"locked_height_range" : 0,
"script" : "dup hash160 [ e45695c2c390625376a7225a7ebea90dbb4147cf ] equalverify checksig",
"value" : 270750000
}
],
"version" : "1"
}
]
}
}

扫描区块技术Block scan_5e_03

tb_block <-- 区块高度 --> tb_tx <-- 交易哈希 --> tb_input/tb_output

完整代码:​​https://github.com/mvs-org/mvsd-mysql-sync/blob/master/tools/sync.py​​


举报

相关推荐

0 条评论