作者: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. Born Slippy (超大背包问题 + 树形DP)

    首先是需要我们知道的是假设又一条链给你让你求最大值,你会求吗?当然会,就是时间有点爆炸O(n2).那不行,要是如果我把到达每个点的最大值以及他对后面的贡献情况都求出来后放在数组里面,然后到了新的节点直 ...

  2. C# 自定义承载控件

    例如ToolStripTextBox类,里面的封装就是一个TextBox控件..NET的类库提供了ToolStripComBox和ToolStripProgressBar两个类.这些类都是从ToolS ...

  3. 证券化代币的时代已经到来,STO将引爆区块链经济

    STOs 似乎会在 2019 年取代 ICOs,即使不是完全取代,但置换的比例也会相当大.所有在美上市的公司都将按照 SEC 制定的相关规定进行交易.Vellum Capital 的 CEO 兼管理合 ...

  4. JAVA基本语法测试

    一: 1,JAVA的基本运行单位是类 2,类的成员:成员变量,构造方法,普通方法和内部类 3,成员变量种类:字符类型:char        布尔类型:boolean     数值类型:byte, s ...

  5. Java 线程类的一些常用方法

    线程类的一些常用方法: sleep(): 强迫一个线程睡眠N毫秒.  isAlive(): 判断一个线程是否存活.  join(): 等待线程终止.  activeCount(): 程序中活跃的线程数 ...

  6. Eclipse导入MyEclipse创建的WEB项目无法识别的解决方案

    Eclipse导入MyEclipse创建的WEB项目无法识别的解决方案

  7. Zynq ZC706 传统方式移植Linux -- 编译kernel 文件系统 devicetree

    1.kernel 实际操作时候,下面两条命令就够了. make ARCH=arm xilinx_zynq_defconfig make ARCH=arm CROSS_COMPILE=arm-xilin ...

  8. Web开发相关笔记 #05# MySQL中文无法匹配

    2018-06-02 在 Class.forName 的时候记得先尝试 import 一下. 2018-06-04 1.JDBC SELECT 查询,中文条件查不出东西,可能是字符编码问题: Stri ...

  9. 虚拟机下Linux系统如何设置IP地址

    虚拟机下Linux系统设置IP地址三种方法 文章来源:https://jingyan.baidu.com/article/ea24bc399ffeb9da62b3318f.html 工具/原料   V ...

  10. Python调用大漠插件

    Python版本要用32位的?我去官网下载,太慢了,就在腾讯软件里面下载了一个,结果实验成功 import win32com.client dm = win32com.client.Dispatch( ...