1. 程序地址:https://gitee.com/Jame_sz/beijing_go_term2.git

2. 程序编写流程:

//1. 定义结构(区块头的字段比正常的少)

  //>1. 前区块哈希

  //>2. 当前区块哈希

  //>3. 数据

//2. 创建区块

//3. 生成哈希

//4. 引入区块链

//5. 添加区块

//6. 重构代码

3. 程序代码:

 1 go:
2 package main
3
4 import "fmt"
5
6 //定义区块结构
7 type Block struct {
8 //前区块哈希
9 PrevBlockHash [] byte
10 //当前区块哈希
11 Hash [] byte
12 //数据,目前使用字节流,v4开始使用交易代替
13 Data [] byte
14 }
15
16 const genesisInfo = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
17
18 //创建区块,对Block的每一个字段填充数据
19 func NewBlock(data string, prevBlockHash []byte) *Block{
20 block := Block{
21 PrevBlockHash: prevBlockHash,
22 Hash: []byte{}, //先填充为空
23 Data: []byte(data),
24 }
25 return &block
26 }
27
28
29 func main() {
30 fmt.Printf("HelloWorld!!!\n")
31
32 //区块实例化
33 block := NewBlock(genesisInfo,[]byte{0x0000000000000000})
34
35 //区块打印
36 fmt.Printf("PrevBlockHash : %x\n", block.PrevBlockHash)
37 fmt.Printf("Hash : %x\n", block.Hash)
38 fmt.Printf("Data : %s\n", block.Data)
39 }

4. 输出效果:

5. 终端Git命令

 1 //代码克隆拉取,默认分支为Master
2 git clone https://gitee.com/Jame_sz/beijing_go_term2.git
3
4 //本地仓库获取v1分支
5 git fetch origin v1:v1
6
7 //切换分支
8 git checkout v1
9
10 //远程有提交,需要更新本地仓库时
11 git pull

最新文章

  1. zen Code 支持的代码样式
  2. Timer的故事----Jdk源码解读
  3. UIkit框架之uiUIapplication
  4. 为什么我的新项目选择了Quick-cocos2d-x
  5. 协作图 Collaboration diagram
  6. oracle-表空间满了
  7. raft如何实现Linearizable Read
  8. linux ss 命令
  9. windows server 2008 R2 NPS(网络连接策略服务)设置radius,实现telent登陆交换机路由器权限分配
  10. Python 下划线
  11. Spring Boot + Spring Cloud 构建微服务系统(九):配置中心(Spring Cloud Config)
  12. django ---forms组件
  13. JSP:注册&登录
  14. 从 prototype.js 深入学习 javascript 的面向对象特性
  15. zookeeper 初步学习
  16. Eclipse开发工具常用快捷键的使用技巧
  17. .net core中automapper的使用
  18. 【[SCOI2016]背单词】
  19. GCD的基本概念
  20. Servlet初始化及处理HTTP请求

热门文章

  1. 小白:String函数总结
  2. insert into select 和select into from 备份表
  3. (二)http请求方法和状态码
  4. 手把手教你使用容器服务 TKE 集群审计排查问题
  5. Java集合系列-HashSet
  6. html+js+highcharts绘制圆饼图表的简单实例
  7. 搭建面向NET Framework的CI/CD持续集成环境(一)
  8. 经典c程序100例==91--100
  9. nginx&http 第五章 https non-fd 读写检测
  10. Android状态栏与布局重叠解决方案