作者:Derek

简介

Github地址:https://github.com/Bytom/bytom

Gitee地址:https://gitee.com/BytomBlockchain/bytom

本章介绍bytom代码Api-Server接口服务

作者使用MacOS操作系统,其他平台也大同小异

Golang Version: 1.8

protobuf生成比原核心代码

protobuf介绍

Protocol buffers是一个灵活的、高效的、自动化的用于对结构化数据进行序列化的协议。Protocol buffers序列化后的码流更小、速度更快、操作更简单。只需要将序列化的数据结构(.proto文件),便可以生成的源代码。

protobuf 3.0语法介绍

protobuf 语法

protobuf 安装

安装protobuf 3.4.0

protobuf download

./configure
make
make install
protoc —version

安装grpc-go

export PATH=$PATH:$GOPATH/bin
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go

查看比原bc.proto核心文件

protocol/bc/bc.proto

syntax = "proto3";

package bc;

message Hash {
fixed64 v0 = 1;
fixed64 v1 = 2;
fixed64 v2 = 3;
fixed64 v3 = 4;
} message Program {
uint64 vm_version = 1;
bytes code = 2;
} // This message type duplicates Hash, above. One alternative is to
// embed a Hash inside an AssetID. But it's useful for AssetID to be
// plain old data (without pointers). Another alternative is use Hash
// in any protobuf types where an AssetID is called for, but it's
// preferable to have type safety.
message AssetID {
fixed64 v0 = 1;
fixed64 v1 = 2;
fixed64 v2 = 3;
fixed64 v3 = 4;
} message AssetAmount {
AssetID asset_id = 1;
uint64 amount = 2;
} message AssetDefinition {
Program issuance_program = 1;
Hash data = 2;
} message ValueSource {
Hash ref = 1;
AssetAmount value = 2;
uint64 position = 3;
} message ValueDestination {
Hash ref = 1;
AssetAmount value = 2;
uint64 position = 3;
} message BlockHeader {
uint64 version = 1;
uint64 height = 2;
Hash previous_block_id = 3;
uint64 timestamp = 4;
Hash transactions_root = 5;
Hash transaction_status_hash = 6;
uint64 nonce = 7;
uint64 bits = 8;
TransactionStatus transaction_status = 9;
} message TxHeader {
uint64 version = 1;
uint64 serialized_size = 2;
uint64 time_range = 3;
repeated Hash result_ids = 4;
} message TxVerifyResult {
bool status_fail = 1;
} message TransactionStatus {
uint64 version = 1;
repeated TxVerifyResult verify_status = 2;
} message Mux {
repeated ValueSource sources = 1; // issuances, spends, and muxes
Program program = 2;
repeated ValueDestination witness_destinations = 3; // outputs, retirements, and muxes
repeated bytes witness_arguments = 4;
} message Coinbase {
ValueDestination witness_destination = 1;
bytes arbitrary = 2;
} message Output {
ValueSource source = 1;
Program control_program = 2;
uint64 ordinal = 3;
} message Retirement {
ValueSource source = 1;
uint64 ordinal = 2;
} message Issuance {
Hash nonce_hash = 1;
AssetAmount value = 2;
ValueDestination witness_destination = 3;
AssetDefinition witness_asset_definition = 4;
repeated bytes witness_arguments = 5;
uint64 ordinal = 6;
} message Spend {
Hash spent_output_id = 1;
ValueDestination witness_destination = 2;
repeated bytes witness_arguments = 3;
uint64 ordinal = 4;
}

根据bc.proto生成bc.pb.go代码

protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
--go_out=plugins=grpc:. \
./*.proto

执行完上面命令,我们会看到当前目录下生成的bc.pb.go文件,该文件在比原链中承载这block、transaction、coinbase等重要数据结构

Derek解读Bytom源码-protobuf生成比原核心代码的更多相关文章

  1. Derek解读Bytom源码-持久化存储LevelDB

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  2. Derek解读Bytom源码-创世区块

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  3. Derek解读Bytom源码-Api Server接口服务

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  4. Derek解读Bytom源码-孤块管理

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  5. Derek解读Bytom源码-P2P网络 upnp端口映射

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  6. Derek解读Bytom源码-启动与停止

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  7. Derek解读Bytom源码-P2P网络 地址簿

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  8. Zepto源码分析(一)核心代码分析

    本文只分析核心的部分代码,并且在这部分代码有删减,但是不影响代码的正常运行. 目录 * 用闭包封装Zepto * 开始处理细节 * 正式处理数据(获取选择器选择的DOM) * 正式处理数据(添加DOM ...

  9. 入口开始,解读Vue源码(一)-- 造物创世

    Why? 网上现有的Vue源码解析文章一搜一大批,但是为什么我还要去做这样的事情呢?因为觉得纸上得来终觉浅,绝知此事要躬行. 然后平时的项目也主要是Vue,在使用Vue的过程中,也对其一些约定产生了一 ...

随机推荐

  1. Java基础(basis)-----代码块详解

    1.静态代码块 格式: static{ 内容..... } 随着类的加载而加载,而且只被加载一次 多个静态代码块之间按照顺序结构执行 优先其他各种代码块以及构造函数先执行 静态的代码块中只能执行静态的 ...

  2. QT 通过QNetworkReply *获取对应请求的URL地址

    [1]QT 通过QNetworkReply *获取对应请求的URL地址 reply->url().toString(); Good Good Study, Day Day Up. 顺序 选择 循 ...

  3. volatile 线程内存模型

  4. 财务自由VS精神自由

    财务自由 财务自由,在物质层面改善人的生活.它使人不愁生计.住更宽敞明亮的房间,穿锦衣绸缎,自由自在地游玩,做自己想做的事儿.可是,这就是它的能力所及了.钱无法改变人的品味.审美和人格.它也无法告诉人 ...

  5. Linux基础命令---ifconfig

    ifconfig ifconfig指令用来配置网络接口参数,同时还可以显示当前内核网络接口的工作状态.如果没有提供参数,则ifconfig将显示当前活动接口的状态.如果给定单个接口参数,则只显示给定接 ...

  6. Linux基础命令---显示主机名hostname

    hostname hostname指令用于设置或者显示系统主机名,没有任何参数就会返回gethostname()函数的返回值.使用hostname指令之后,主机名会立马被修改,但是重启系统之后就失效了 ...

  7. Ubuntu 为 root 帐号开启 SSH 登录

    1. 修改 root 密码sudo passwd root 2. 以其他账户登录,通过 sudo nano 修改 /etc/ssh/sshd_config :xxx@ubuntu:~$ su - ro ...

  8. IPERF 网络性能测试

    Iperf 是一个网络性能测试工具.Iperf可以测试最大TCP和UDP带宽性能.Iperf具有多种参数和UDP特性,可以根据需要调整.Iperf可以报告带宽,延迟抖动和数据包丢失. Iperf 参数 ...

  9. kivy 滑动

    from kivy.uix.gridlayout import GridLayout from kivy.app import App from kivy.lang.builder import Bu ...

  10. MySQL 跨库主从

    一个线上需求,要求主从两库的数据库名字不一样, 在从库上做如下配置: replicate-rewrite-db=DB_1->DB_1_online replicate-rewrite-db=DB ...