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); } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM