Skip to content
YuanZhenxia edited this page Mar 25, 2019 · 10 revisions

VNT轻客户端系统设计文档

轻客户端在功能上,分为三个:

  1. 区块链基础浏览
  2. 开发者指南
  3. 钱包

一、数据库设计

需要通过关系型数据库记录链上信息,有如下三个表:

区块表blocks

字段名 说明 类型 特性
number 区块高度 整形 主键
timestamp 时间戳 时间
txCount 交易个数 整形
hash 哈希值 字符串 建索引
parentHash 父哈希值 字符串 外键blocks.hash
producer 出块者 字符串 外键accounts.address
size 容量 整形
gasUsed 燃料费用 整形
gasLimit 燃料限制 整形
blockReward 区块奖励 整形 该字段需要从交易中恢复出来存下来,单位wei
extraData 额外数据 字符串
tps tps 浮点型
witnesses 见证人列表 列表 外键nodes.address

交易表transactions

字段名 说明 类型 特性
hash 哈希值 字符串 主键
blockNumber 区块号 整形 外键blocks.number
timestamp 时间戳 时间 实际上是blocks.timestamp
from 发送发 字符串 外键accounts.hash
to 接收方 字符串 外键accounts.hash,有可能是一个合约地址
value 价值 整形
gasLimit 燃料限制 整形
gasPrice 燃料价格 整形
gasUsed 燃料消耗 整形
nonce nonce值 整形
index 交易序号 整形
input 输入 字符串 合约调用的input,可以用来解析出代币合约
status 交易状态 整形 成功(1)还是失败(0)
ContractAddr 创建的合约地址 字符串
isToken 是否是代币交易 bool 需要根据to字段来判断
tokenFrom 代币发送者 字符串 建索引,通过input字段解析出来
tokenTo 代币接收者 字符串 外键accounts.hash,通过input字段解析出来
tokenAmount 代币转账额 整形 通过input字段解析出来

账户表accounts

字段名 说明 类型 特性
address 地址hash 字符串 主键
vname 地址别称,通过域名系统注册的名称 字符串 建索引
balance 余额,需要从交易中恢复,单位为wei 整形
txCount 交易数量,包括普通交易与代币交易,需实时更新 整形
isContract 是否是合约 bool
contractName 合约名称 字符串
contractOwner 合约创建者 字符串 外键accounts.address
code 合约源代码 字符串
abi abi json代码 字符串
home 合约官网 字符串
initTx 合约创建交易hash 字符串 外键transactions.hash
lastTx 合约最近调用交易hash 字符串
isToken 是否是代币合约 bool
tokenType 代币种类:erc20, erc21, erc720, erc721等等 bool
tokenSymbol 代币符号 字符串
tokenLogo 代币logo图片地址 字符串
tokenAmount 代币总量 整型
tokenDecimals 整型
tokenAcctCount 持有者数量 整形
firstBlock 最先出现的区块 整形
lastBlock 最后出现的区块 整形
percent vnt占比 浮点型

代币余额表tokenbalances

字段名 说明 类型 特性
id 主键 整形 主键
address 账户地址hash 字符串 外键accounts.address
tokenAddress 代币地址 字符串 外键accounts.address
balance 余额,需要从代币交易中恢复,并实时更新 整形
percent 余额占比 字符串

超级节点表nodes

字段名 说明 类型 特性
id 主键 整形 主键
address 节点地址hash 字符串 外键accounts.address
vname 节点名称 字符串
home 官方网站 字符串
logo 节点logo网址 字符串
ip 节点ip地址 字符串
status 节点状态 整形
votes 票数 整形
TotalBounty 节点获得总奖励 整形
ExtractedBounty 节点已提取的奖励 整形
LastExtractTime 上次提取时间 整形
Longitude 节点所在经度 浮点型
Latitude 节点所在维度 浮点型

网络表 networks

这个表格不需要,通过配置文件来做。

字段名 说明 类型 特性
id 主键 整形 主键
networkId 网络编号 整形
vname 网络名称 字符串
rpc rpc链接 字符串
ws ws链接 字符串

水龙头数据表hydrant

字段名 说明 类型 特性
address 节点地址hash 字符串 主键
timestamp 记录上次通过水龙头发放代币的时间戳 字符串

二、接口设计

前置说明

  • 接口采用rest技术。
  • 返回结果为json格式,结构包含三个字段:
    • ok:表示结果是否正常,1正常,0异常
    • error:如果ok=0,就需要error字段,error字段包含:
      • msg:出错文字提示,例如:区块不存在
      • code:1。(可以在后台维护一些error,提前定义好其msg和code,用的时候直接使用)
    • data:数据字段

1. 区块链网络相关

获取网络概览

接口

GET /v1/stats

参数

  • url参数
    • "number": 网络number
  • query参数:无
  • body参数:无

返回

{
    "ok": 1,
    "err": null,
    "data": {
        "blockHeight": 7047657,
        "txCount": 657657456,
        "currTps": 1000,
        "topTps": 2000,
        "accoutCount": 453242,
        "superNode": 21,
        "candiNode": 100
    }
}

2. 区块相关

获取区块列表

接口

GET /v1/blocks

参数

  • url参数:无
  • query参数
    • offset: 分页起码位置
    • limit:分页大小
    • order:基于区块号的排序顺序,取值为desc或asc,默认为desc
    • fields:获取的字段列表,如区块链概览页中的区块列表需要字段为"number,txCount,blockReward,producer,timestamp"。对于字段中的外键,比方说producer,需在后台做关联查询。
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": [        {
            "Number": 200,
            "TimeStamp": 1551855247,
            "TxCount": 0,
            "Hash": "0x824be30f53497efbb1bb6baead1c61dca91d2a9696165e6293361ea7d8edce30",
            "ParentHash": "0xc405b9af803ac258d38a5d73e3e7f2dd9afcca94d5dd10838f1043ab7f3ce8c2",
            "Producer": "0xbf66d398226f200467cd27b14e85b25a8c232384",
            "Size": "975",
            "GasUsed": 0,
            "GasLimit": 4712388,
            "BlockReward": "6.000000 VNT (6.000000 + 0.000000)",
            "ExtraData": "0x000000005c7f6d01",
            "Tps": 0,
            "Witnesses": null
        },
        {
            "Number": 199,
            "TimeStamp": 1551855245,
            "TxCount": 0,
            "Hash": "0xc405b9af803ac258d38a5d73e3e7f2dd9afcca94d5dd10838f1043ab7f3ce8c2",
            "ParentHash": "0x50aa16994e95b015f7221e89055232e7d461ea5187a4b6212c78c448413bbaa7",
            "Producer": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
            "Size": "975",
            "GasUsed": 0,
            "GasLimit": 4712388,
            "BlockReward": "6.000000 VNT (6.000000 + 0.000000)",
            "ExtraData": "0x000000005c7f6d01",
            "Tps": 0,
            "Witnesses": null
        },
        {
            "Number": 198,
            "TimeStamp": 1551855243,
            "TxCount": 0,
            "Hash": "0x50aa16994e95b015f7221e89055232e7d461ea5187a4b6212c78c448413bbaa7",
            "ParentHash": "0xd7f85729b19d6d07aabfa3c7e59924a0b86afeea78595e06eaaa1a7d0826d0cb",
            "Producer": "0x42a875ac43f2b4e6d17f54d288071f5952bf8911",
            "Size": "975",
            "GasUsed": 0,
            "GasLimit": 4712388,
            "BlockReward": "6.000000 VNT (6.000000 + 0.000000)",
            "ExtraData": "0x000000005c7f6d01",
            "Tps": 0,
            "Witnesses": null
        }]
}

获取区块总数

接口

GET /v1/blocks/count

参数

  • url参数:无
  • query参数:无
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": 200
}

获取区块详情

接口

GET /v1/block/:number_or_hash

参数

  • url参数
    • number_or_hash:区块号或区块哈希
  • query参数
    • <不再支持>fields:获取的字段列表。对于字段中的外键,比方说producer,需在后台做关联查询。
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": {
        "Number": 200,
        "TimeStamp": 1551855247,
        "TxCount": 0,
        "Hash": "0x824be30f53497efbb1bb6baead1c61dca91d2a9696165e6293361ea7d8edce30",
        "ParentHash": "0xc405b9af803ac258d38a5d73e3e7f2dd9afcca94d5dd10838f1043ab7f3ce8c2",
        "Producer": "0xbf66d398226f200467cd27b14e85b25a8c232384",
        "Size": "975",
        "GasUsed": 0,
        "GasLimit": 4712388,
        "BlockReward": "6.000000 VNT (6.000000 + 0.000000)",
        "ExtraData": "0x000000005c7f6d01",
        "Tps": 0,
        "Witnesses": null
    }
}

3. 交易相关

获取交易列表

接口

GET /v1/txs/

参数

  • url参数:无
  • query参数
    • block:区块号或hash,如果指定该参数,则只返回该区块下的交易
    • account:账户地址,如果指定该参数,则只返回该账户下的交易
    • istoken:是否是代币交易,如果是0,则返回所有交易,是1则仅返回代币交易。
    • offset: 分页起码位置
    • limit:分布大小
    • order:基于timestamp字段的排序顺序,取值为desc或asc,默认为desc
    • fields:获取的字段列表,如区块链概览页中的交易列表需要字段为"hash,from,to,value,timestamp"。对于字段中的外键,比方说producer,需在后台做关联查询。
  • body参数:无

返回

{
    "ok": 1,
    "err": null,
    "data": [{
    "ok": 1,
    "err": "",
    "data": [
        {
            "Hash": "0x7aab84c6b210ca133a103511c93012654ae390ce8c75e96473a1054bad5a312e",
            "TimeStamp": 1551855241,
            "From": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 2000000,
            "GasPrice": "500000000000",
            "GasUsed": 43052,
            "Nonce": 2,
            "Index": 0,
            "Input": "0x23b872dd000000000000000000000000122369f04f32269598789998de33e3d56e2c507a0000000000000000000000003ea7a559e44e8cabc362ca28b6211611467c76f70000000000000000000000000000000000000000000000000000000000000064",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369F04f32269598789998de33e3d56E2C507a",
            "TokenTo": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
            "TokenAmount": "100",
            "BlockNumber": 197
        },
        {
            "Hash": "0x7a5813c8bb9d2c452f79972193c8272557865853d80331389015d0c42f6b6382",
            "TimeStamp": 1551855229,
            "From": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 2000000,
            "GasPrice": "500000000000",
            "GasUsed": 43052,
            "Nonce": 1,
            "Index": 0,
            "Input": "0x23b872dd000000000000000000000000122369f04f32269598789998de33e3d56e2c507a0000000000000000000000003ea7a559e44e8cabc362ca28b6211611467c76f70000000000000000000000000000000000000000000000000000000000000064",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369F04f32269598789998de33e3d56E2C507a",
            "TokenTo": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
            "TokenAmount": "100",
            "BlockNumber": 191
        },
        {
            "Hash": "0x4994a430a52ea7dc0e11405f0fea6dcefc95dce2608c5ceaac5fdddf90a6d0d8",
            "TimeStamp": 1551855205,
            "From": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 2000000,
            "GasPrice": "500000000000",
            "GasUsed": 43052,
            "Nonce": 0,
            "Index": 0,
            "Input": "0x23b872dd000000000000000000000000122369f04f32269598789998de33e3d56e2c507a0000000000000000000000003ea7a559e44e8cabc362ca28b6211611467c76f70000000000000000000000000000000000000000000000000000000000000064",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369F04f32269598789998de33e3d56E2C507a",
            "TokenTo": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
            "TokenAmount": "100",
            "BlockNumber": 179
        },
        {
            "Hash": "0x587a84dd408b04c892f591252860c19b75a073e8b6b47e796114d3f321db513d",
            "TimeStamp": 1551855175,
            "From": "0x122369f04f32269598789998de33e3d56e2c507a",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 90000,
            "GasPrice": "500000000000",
            "GasUsed": 29867,
            "Nonce": 5,
            "Index": 0,
            "Input": "0x095ea7b30000000000000000000000003dcf0b3787c31b2bdf62d5bc9128a79c2bb1882900000000000000000000000000000000000000000000000000000000000001f4",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "",
            "TokenTo": "",
            "TokenAmount": "",
            "BlockNumber": 164
        },
        {
            "Hash": "0xca90fa70dcc00657da706643b3324a989f983a653a07b17e78620ac724261d8f",
            "TimeStamp": 1551855123,
            "From": "0x122369f04f32269598789998de33e3d56e2c507a",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 4000000,
            "GasPrice": "30000000000000",
            "GasUsed": 36136,
            "Nonce": 4,
            "Index": 0,
            "Input": "0xa9059cbb0000000000000000000000003dcf0b3787c31b2bdf62d5bc9128a79c2bb1882900000000000000000000000000000000000000000000000000000000000003e8",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369f04f32269598789998de33e3d56e2c507a",
            "TokenTo": "0x3DcF0b3787C31B2bdF62d5bC9128A79c2bb18829",
            "TokenAmount": "1000",
            "BlockNumber": 138
        },
        {
            "Hash": "0xd9a3ffd3c1a7343bf6bf86853ff0e8c62431476d4cebec2a7f976c5f09cf01e8",
            "TimeStamp": 1551855053,
            "From": "0x122369f04f32269598789998de33e3d56e2c507a",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 4000000,
            "GasPrice": "30000000000000",
            "GasUsed": 36136,
            "Nonce": 3,
            "Index": 0,
            "Input": "0xa9059cbb0000000000000000000000003dcf0b3787c31b2bdf62d5bc9128a79c2bb1882900000000000000000000000000000000000000000000000000000000000003e8",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369f04f32269598789998de33e3d56e2c507a",
            "TokenTo": "0x3DcF0b3787C31B2bdF62d5bC9128A79c2bb18829",
            "TokenAmount": "1000",
            "BlockNumber": 103
        }]
}

获取交易总数

接口

GET /v1/txs/count

参数

  • url参数:无
  • query参数
    • block:区块号或hash,如果指定该参数,则只返回该区块下的交易
    • account:账户地址,如果指定该参数,则只返回该账户下的交易
    • istoken:是否是代币交易,如果是0,则返回所有交易,是1则仅返回代币交易。
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": 9
}

获取交易历史

接口

GET /v1/txs/history

参数

  • url参数:无
  • query参数:
    • days:要查询的历史天数,最多可以获取100天
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        9,
        0,
        0
    ]
}

获取交易详情

接口

GET /v1/tx/:tx_hash

参数

  • url参数
    • tx_hash:交易哈希
  • query参数
    • fields:获取的字段列表。对于字段中的外键,比方说producer,需在后台做关联查询。
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": {
        "Hash": "0x7aab84c6b210ca133a103511c93012654ae390ce8c75e96473a1054bad5a312e",
        "TimeStamp": 1551855241,
        "From": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
        "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
        "Value": "0",
        "GasLimit": 2000000,
        "GasPrice": "500000000000",
        "GasUsed": 43052,
        "Nonce": 2,
        "Index": 0,
        "Input": "0x23b872dd000000000000000000000000122369f04f32269598789998de33e3d56e2c507a0000000000000000000000003ea7a559e44e8cabc362ca28b6211611467c76f70000000000000000000000000000000000000000000000000000000000000064",
        "Status": 1,
        "ContractAddr": "",
        "IsToken": true,
        "TokenFrom": "0x122369F04f32269598789998de33e3d56E2C507a",
        "TokenTo": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
        "TokenAmount": "100",
        "BlockNumber": 197
    }
}

4. 账户相关

获取账户列表

接口

GET /v1/accounts

参数

  • url参数:无
  • query参数
    • offset: 分页起码位置
    • limit:分布大小
    • isContract:是否是合约账户,0则返回所有账户,1只返回合约账户
    • isToken:是否是代币合约账户,0则以isContract为准,1则只返回代币账户
    • order:基于balance字段的排序顺序,取值为desc或asc,默认为desc
    • fields:获取的字段列表,如账户列表页的交易列表需要字段为"address,vname,balance,txCount"。对于字段中的外键,比方说contractOwner,需在后台做关联查询。
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": [
        {
            "Address": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Vname": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Balance": "1000000000000000000000",
            "TxCount": 8,
            "IsContract": true,
            "ContractName": "bitcoin",
            "ContractOwner": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Code": "",
            "Abi": "",
            "Home": "",
            "InitTx": "0x8b60e26ff66e2a63d93bc35f34268741c933f5322548152e68c63dc9876d64ba",
            "LastTx": "0x7aab84c6b210ca133a103511c93012654ae390ce8c75e96473a1054bad5a312e",
            "IsToken": true,
            "TokenType": 0,
            "TokenSymbol": "BTC",
            "TokenLogo": "",
            "TokenAmount": "100000000000000000",
            "TokenDecimals": 8,
            "TokenAcctCount": "0",
            "FirstBlock": 61,
            "LastBlock": 197
        },
        {
            "Address": "0xbf66d398226f200467cd27b14e85b25a8c232384",
            "Vname": "0xbf66d398226f200467cd27b14e85b25a8c232384",
            "Balance": "1000000300014933500000000000",
            "TxCount": 1,
            "IsContract": false,
            "ContractName": "",
            "ContractOwner": "",
            "Code": "",
            "Abi": "",
            "Home": "",
            "InitTx": "",
            "LastTx": "",
            "IsToken": false,
            "TokenType": 0,
            "TokenSymbol": "",
            "TokenLogo": "",
            "TokenAmount": "0",
            "TokenDecimals": 0,
            "TokenAcctCount": "0",
            "FirstBlock": 1,
            "LastBlock": 200
        }]
}

获取账户总数

接口

GET /v1/accounts/count

参数

  • url参数:无
  • query参数:
    • isContract:是否是合约账户,0则返回所有账户,1只返回合约账户
    • isToken:是否是代币合约账户,0则以isContract为准,1则只返回代币账户
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": 6
}

获取账户详情

接口

GET /v1/accounts/:address

参数

  • url参数
    • Address:账户地址
  • query参数:无
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": {
        "Address": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
        "Vname": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
        "Balance": "1000000000000000000000",
        "TxCount": 8,
        "IsContract": true,
        "ContractName": "bitcoin",
        "ContractOwner": "0x122369f04f32269598789998de33e3d56e2c507a",
        "Code": "",
        "Abi": "",
        "Home": "",
        "InitTx": "0x8b60e26ff66e2a63d93bc35f34268741c933f5322548152e68c63dc9876d64ba",
        "LastTx": "0x7aab84c6b210ca133a103511c93012654ae390ce8c75e96473a1054bad5a312e",
        "IsToken": true,
        "TokenType": 0,
        "TokenSymbol": "BTC",
        "TokenLogo": "",
        "TokenAmount": "100000000000000000",
        "TokenDecimals": 8,
        "TokenAcctCount": "0",
        "FirstBlock": 61,
        "LastBlock": 197
    }
}

获取账户代币余额

接口

GET /v1/account/:address/tokens

参数

  • url参数
    • Address:账户地址
  • query参:无
  • body参数:无

返回

//设计的结构
{
    "ok": 1,
    "err": null,
    "data": [{
        "address": "0x75771dedde9707fbb78d9f0dbdc8a4d4e7784794",
        "token": {
            "address": "0x75771dedde9707fbb78d9f0dbdc8a4d4e7784794",
            "tokenSymbol": "MAM"
        },
        "price": {
            "usd": "0.00000023",
            "cny": "0.00004",
            "vnt": "0.0001"
        },
        "balance": 2000000000000
    }, {
        "address": "0x75771dedde9707fbb78d9f0dbdc8a4d4e7784794",
        "token": {
            "address": "0x75771dedde9707fbb78d9f0dbdc8a4d4e7784793",
            "tokenSymbol": "KITTY"
        },
        "price": {
            "usd": "0.00000023",
            "cny": "0.00004",
            "vnt": "0.0001"
        },
        "balance": 2000000000000
    }]
}


//目前实现的结构
{
    "ok": 1,
    "err": "",
    "data": [
        {
            "Id": 1,
            "Account": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Token": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Balance": "99999999999997700"
        }
    ]
}

5. 代币相关

获取持有人

接口

GET /v1/token/:address/holders

参数

  • url参数:
    • "address": 代币的合约地址
  • query参数
    • offset: 分页起码位置
    • limit:分布大小
    • order:基于balance字段的排序顺序,取值为desc或asc,默认为desc
  • body参数:无

返回

{
    "ok": 1,
    "err": "",
    "data": [
        {
            "Id": 1,
            "Account": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Token": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Balance": "99999999999997700"
        },
        {
            "Id": 2,
            "Account": "0x3DcF0b3787C31B2bdF62d5bC9128A79c2bb18829",
            "Token": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Balance": "2000"
        },
        {
            "Id": 3,
            "Account": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
            "Token": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Balance": "300"
        }
    ]
}

6. 超级结点相关

取超级节点列表

接口

GET /v1/nodes/

参数

  • url参数:无
  • query参数
    • offset: 分页起码位置
    • limit:分布大小
    • order:基于votes字段的排序顺序,取值为desc或asc,默认为desc
  • body参数:无

返回

{
  "ok": 1,
  "err": "",
  "data": [
    {
      "Address": "0x42a875Ac43f2b4e6D17f54D288071f5952bF8911",
      "Vname": "greatvnt2",
      "Home": "www.greatvnt2.com",
      "Logo": "",
      "Ip": "127.0.0.1",
      "Status": 1,
      "Votes": "17",
      "VotesFloat": 0,
      "VotesPercent": 44.736843,
      "TotalBounty": "697246784688995215306468",
      "ExtractedBounty": "0",
      "LastExtractTime": "0",
      "Longitude": 0,
      "Latitude": 0,
      "Block": null
    },
    {
      "Address": "0x3DcF0b3787C31B2bdF62d5bC9128A79c2bb18829",
      "Vname": "greatvnt1",
      "Home": "www.greatvnt1.com",
      "Logo": "",
      "Ip": "127.0.0.1",
      "Status": 1,
      "Votes": "11",
      "VotesFloat": 0,
      "VotesPercent": 28.947369,
      "TotalBounty": "451159684210526315771328",
      "ExtractedBounty": "0",
      "LastExtractTime": "0",
      "Longitude": 0,
      "Latitude": 0,
      "Block": null
    }]
}

获取超级节点数目

接口

GET /v1/nodes/count

参数

  • url参数:无
  • query参数:无
  • body参数:无

返回

{
  "ok": 1,
  "err": "",
  "data": {
    "Super": 4,       
    "Candi": 1,       
    "Total": 5
  }
}

获取超级节点详情

接口

GET /v1/node/:address

参数

  • url参数
    • Address:账户地址
  • query参数:无
  • body参数:无

返回

{
  "ok": 1,
  "err": "",
  "data": {
    "Address": "0x42a875Ac43f2b4e6D17f54D288071f5952bF8911",
    "Vname": "greatvnt2",
    "Home": "www.greatvnt2.com",
    "Logo": "",
    "Ip": "127.0.0.1",
    "Status": 1,
    "Votes": "17",
    "VotesFloat": 0,
    "VotesPercent": 44.736843,
    "TotalBounty": "695636258373205741622268",
    "ExtractedBounty": "0",
    "LastExtractTime": "0",
    "Longitude": 0,
    "Latitude": 0,
    "Block": null
  }
}

7. 统一搜索接口

通过关键字搜索区块、交易或账户

接口

GET /v1/search/:keyword

参数

  • url参数:
    • "Keyword": 关键字,可以是区块号,区块hash,交易hash或账户地址
  • query参数
  • body参数:无

返回

搜索到交易:

{
    "ok": 1,
    "err": "",
    "data": {
        "Block": null,
        "Tx": {
            "Hash": "0x7aab84c6b210ca133a103511c93012654ae390ce8c75e96473a1054bad5a312e",
            "TimeStamp": 1551855241,
            "From": "0x3dcf0b3787c31b2bdf62d5bc9128a79c2bb18829",
            "To": "0x1b620636c39e68cb700add12a7e53302a3b3f485",
            "Value": "0",
            "GasLimit": 2000000,
            "GasPrice": "500000000000",
            "GasUsed": 43052,
            "Nonce": 2,
            "Index": 0,
            "Input": "0x23b872dd000000000000000000000000122369f04f32269598789998de33e3d56e2c507a0000000000000000000000003ea7a559e44e8cabc362ca28b6211611467c76f70000000000000000000000000000000000000000000000000000000000000064",
            "Status": 1,
            "ContractAddr": "",
            "IsToken": true,
            "TokenFrom": "0x122369F04f32269598789998de33e3d56E2C507a",
            "TokenTo": "0x3eA7a559E44e8cABC362ca28b6211611467c76f7",
            "TokenAmount": "100",
            "BlockNumber": 197
        },
        "Account": null
    }
}

搜索到区块:

{
    "ok": 1,
    "err": "",
    "data": {
        "Block": {
            "Number": 197,
            "TimeStamp": 1551855241,
            "TxCount": 1,
            "Hash": "0xd7f85729b19d6d07aabfa3c7e59924a0b86afeea78595e06eaaa1a7d0826d0cb",
            "ParentHash": "0x81bfb1b9d7e93417b4ea733d5d02880e8d2935bf85c56a129348a09c43a5cd59",
            "Producer": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Size": "1184",
            "GasUsed": 43052,
            "GasLimit": 4712388,
            "BlockReward": "6.021526 VNT (6.000000 + 0.021526)",
            "ExtraData": "0x000000005c7f6d01",
            "Tps": 0.5,
            "Witnesses": null
        },
        "Tx": null,
        "Account": null
    }
}

搜索到账号

{
    "ok": 1,
    "err": "",
    "data": {
        "Block": null,
        "Tx": null,
        "Account": {
            "Address": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Vname": "0x122369f04f32269598789998de33e3d56e2c507a",
            "Balance": "1000000997838432500000000000",
            "TxCount": 7,
            "IsContract": false,
            "ContractName": "",
            "ContractOwner": "",
            "Code": "",
            "Abi": "",
            "Home": "",
            "InitTx": "",
            "LastTx": "0x587a84dd408b04c892f591252860c19b75a073e8b6b47e796114d3f321db513d",
            "IsToken": false,
            "TokenType": 0,
            "TokenSymbol": "",
            "TokenLogo": "",
            "TokenAmount": "0",
            "TokenDecimals": 0,
            "TokenAcctCount": "0",
            "FirstBlock": 1,
            "LastBlock": 2000
        }
    }
}

8. 开发者水龙头接口

向平台请求向指定账户发送vnt用以测试

接口

POST /v1/hydrant

参数

  • url参数:无
  • query参数: 无
  • body参数:
{
 "address": "0x..." 
}

返回

{
    "ok": 1,
    "err": "",
    "data": {
        "jsonrpc": "2.0",
        "id": 1,
        "Result": "0xebef711dbb92a2b635b4ccc93d5e28dad5d9f31a9c99d0c7f2055e9df2f8c290", 
        "Error": null
    }
}

三、模块设计

设计图

1. 数据库ORM模块

负责如下功能:

  • 数据库连接
  • 数据表Model定义与同步
  • 通过Model进行数据的读写

2. 数据爬取模块vGrabber

负责从区块数据中,爬取区块、交易、账户、合约、代币数据,进入数据库中。

该模块须是一个独立的进程,且实时监听区块的更新。

该模块可以嵌入到go-vnt区块同步模块中:给go-vnt增加一个配置项syncmysql, mysql-host, mysqluser, mysql-password, mysql-port等配置,使go-vnt在同步区块数据的同时,同步解析数据到mysql数据库中。

该模块也可以是一个独立的程序,通过rpc连接全节点来同步数据。


3. 接口模块API

实现二、接口设计中的接口

四、任务表

1. 数据库ORM模块

结构体:

  • Block
  • Transaction
  • Account
  • TokenBalance
  • Node
  • Network

数据库接口

网络相关
  • Network.List() 获取所有的网络,读取配置文件,或者内存中的数据
  • Network.Get(netnumber) 根据网络号获取某个网络的详情
区块相关
  • Block.Insert(block) 插入区块数据
  • Block.List()获取区块列表,需支持分页,支持动态的字段,支持外键关联查询,支持以number字段进行排序
  • Block.Count() 获取区块总数
  • Block.Get(hash_or_number) 获取区块详情,支持动态字段,支持外键关联查询
交易相关
  • Transaction.Insert(tx)插入交易数据
  • Transaction.List(block, account, istoken) 获取交易列表,支持分页,支持通过区块、账户、是否是token等字段的过滤,支持动态字段,支持外键关联查询
  • Transaction.Count() 交易总数
  • Transaction.Get(txHash) 获取交易详情,支持动态字段,支持外键关联查询
账户相关
  • Account.Insert(account) 插入账户
  • Account.List()获取账户列表,支持分页,支持通过istoken,isContract等字段进行过滤,支持通过balance字段进行排序,支持动态字段获取
  • Account.Get(address) 获取账户详情,支持动态字段,支持外键关联查询
  • Account.Count() 获取账户总数
代币相关
  • TokenBalance.GetHolders(tokenAddress) 获取代币的持有人列表
超级节点相关
  • Node.List() 获取超级节点列表,支持以votes字段进行排序

2. 数据同步模块

3. 接口模块

网络相关

区块相关

交易相关

账户相关

代币相关

超级节点相关

五、时间安排

2月25 数据库结构体定义

杨红星:Blocks,Transactions, Nodes

苑振霞:Accounts,TokenBalances, Networks

闫凤喜:基础环境搭建

2月26号-2月27号 数据库接口开发

杨红星:Blocks,Transactions

苑振霞:Accounts,TokenBalances

闫凤喜:Nodes, Networks

闫凤喜:数据库表dbsync功能:根据结构体,自动生成对应的表格;结构体关联查询功能。

2月28-3月6号 数据同步模块

闫凤喜

2月28-3月6号 http接口开发

杨红星:区块、交易、网络相关

苑振霞:账户,代币、超级节点相关

3月6号-3月10号 联调