Derek解读Bytom源码-protobuf生成比原核心代码
作者: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 3.4.0
./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生成比原核心代码的更多相关文章
- Derek解读Bytom源码-持久化存储LevelDB
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-创世区块
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-Api Server接口服务
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-孤块管理
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-P2P网络 upnp端口映射
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-启动与停止
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Derek解读Bytom源码-P2P网络 地址簿
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Zepto源码分析(一)核心代码分析
本文只分析核心的部分代码,并且在这部分代码有删减,但是不影响代码的正常运行. 目录 * 用闭包封装Zepto * 开始处理细节 * 正式处理数据(获取选择器选择的DOM) * 正式处理数据(添加DOM ...
- 入口开始,解读Vue源码(一)-- 造物创世
Why? 网上现有的Vue源码解析文章一搜一大批,但是为什么我还要去做这样的事情呢?因为觉得纸上得来终觉浅,绝知此事要躬行. 然后平时的项目也主要是Vue,在使用Vue的过程中,也对其一些约定产生了一 ...
随机推荐
- codeforces 979B Treasure Hunt
题意: 给出三个字符串,每个字符串长度相同,给出n,要求在n轮内,每一个字符串必须改变一个字符. 问最后哪个字符串中拥有最多相同的字符,即美丽度最大. 思路: 首先,很不容易想到的一点是从a变到a,有 ...
- windows下配置lua环境
1.进入lua官网http://www.lua.org/ 2.点击download 3.点击get a binary 4.点击[Lua - joedf's Builds] 5.选择适合自己的版本下载, ...
- 谈谈Groovy闭包
A closure is a function with variables bound to a context or environment in which it executes. 概述 闭包 ...
- 使用AJAX技术发送异步请求,HTTP服务端推送
使用AJAX技术发送异步请求 什么是AJAX AJAX指一步Javascript和XML(Asynchronous JavaScript And XML),它是一些列技术的组合,简单来说AJAX基于X ...
- c# 设置控件的前景颜色和背景颜色
AutoSize:设置为false取消自动计算尺寸功能,控件的大小则按照设定的Size来呈现,设置为true自动计算大小 TextAlign:设置对齐方式 // // 摘要: // 用默认的所有者运行 ...
- golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题
golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题 今天测试了重新建一个项目生成新的表,然后复制到旧的项目 ...
- ymPrompt,jcs缓存架构
jcs.auxiliary.LTCP=org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory#jcs.auxiliary. ...
- Git在Eclipse中的使用
一.把远程仓库的项目clone到eclipse里面: 最新版的Eclipse上已经集成了Git插件.所以在Eclipse中可以很方便的使用Git的功能. 在使用Git功能之前,需要先进行下简单的设置. ...
- [转载]C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
原文出处:https://www.cnblogs.com/wuhuisheng/archive/2011/03/23/1992652.html 验证电话号码的主要代码如下: public bool I ...
- Step1:SQL Server 复制介绍
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 前言(Introduction) 复制逻辑结构图(Construction) 系列文章索引(Catalog) 总结&am ...