我是靠谱客的博主 舒服小松鼠,这篇文章主要介绍fabric智能合约,现在分享给大家,希望可以做个参考。

基础:
go语言、区块链概念、linux、Docker git等
Chaincode源代码的基本结构
1.包名
一个chaincode通常是一个 Goalng源文件,包名必须是main

package main

2.引入包

import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

3、定义结构体

type StudentChaincode struct{
}

实现的两个方法

func (t *StudentChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
// 在该方法中实现链码初始化或升级时的处理逻辑
// 编写时可灵活使用stub中的API
return shim.Success(nil)
}
func (t *StudentChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
// 在该方法中实现链码初始化或升级时的处理逻辑
// 编写时可灵活使用stub中的API
return shim.Success(nil)
}

最后

以上就是舒服小松鼠最近收集整理的关于fabric智能合约的全部内容,更多相关fabric智能合约内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(119)

评论列表共有 0 条评论

立即
投稿
返回
顶部