Fabric智能合约(base)
2024-09-06 20:25:18
这里的智能合约仅包含Init函数和Invoke函数。
为什么一定是这两个方法?
因为在源码中的智能合约模块有这样的接口,如果要完成智能合约的相关编程,就需要实现源码中定义的接口,接口中定义了这两个方法。空口无凭,下面我给大家看一个图:
文件路径:github.com/hyperledger/fabric/core/chaincode/shim
这个文件中的内容如下:
go语言
package main import ( "github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
) var logger = shim.NewLogger("example_cc0") // SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct { } // Init initializes the chaincode state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { } // Invoke makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { } func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
logger.Errorf("Error starting Simple chaincode: %s", err)
}
}
java语言
package org.hyperledger.fabric.example; import io.netty.handler.ssl.OpenSsl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperledger.fabric.shim.ChaincodeBase;
import org.hyperledger.fabric.shim.ChaincodeStub; public class SimpleChaincode extends ChaincodeBase { private static Log logger = LogFactory.getLog(SimpleChaincode.class); @Override
public Response init(ChaincodeStub stub) { } @Override
public Response invoke(ChaincodeStub stub) { } public static void main(String[] args) {
logger.info("OpenSSL avaliable: " + OpenSsl.isAvailable());
new SimpleChaincode().start(args);
} }
最新文章
- web应用程序
- Plyr – 简单,灵活的 HTML5 媒体播放器
- 编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值
- 在项目中引用GreenDroid库
- 《JavaScript高级程序设计》学习笔记
- CodeForces 527B Error Correct System
- 20169210《Linux内核原理与分析》第八周作业
- C# ,asp.net 获取当前,相对,绝对路径(转)
- BT Smart vs ANT+ 技术孰优孰劣?
- http状态码及解释
- (转)ZXing生成二维码和带logo的二维码,模仿微信生成二维码效果
- ssm框架的整合
- Linux-KVM虚拟化
- LeetCode算法题-Fibonacci Number(Java实现)
- mysql的group by查询
- jquery 語法
- luogu 2294 狡猾的商人 带权并查集
- hdoj:2033
- 使用SQL Developer导入文件时出现的一个奇怪的问题
- in linux system of ftp command