zoukankan      html  css  js  c++  java
  • Fabric智能合约(base)

    这里的智能合约仅包含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);
        }
    
    }
  • 相关阅读:
    常用的DOCS命令
    [51NOD1126]求递推序列的第n项(矩阵快速幂)
    [HDOJ2830]Matrix Swapping II(胡搞)
    [每天一道A+B]签到检测程序
    [HIHO1260]String Problem I(trie树)
    [HIHO1300]展胜地的鲤鱼旗(栈,dp)
    [HIHO1299]打折机票(线段树)
    [51NOD1087]1 10 100 1000(规律,二分)
    [POJ2002]Squares(计算几何,二分)
    [HDOJ1015]Safecracker(DFS, 组合数学)
  • 原文地址:https://www.cnblogs.com/jockming/p/12208343.html
Copyright © 2011-2022 走看看