我正在尝试使用超级账本构建链代码。我正在使用 GoLang 编写合同,在构建合同时我面临以下错误:
cannot refer to unexported name shim.success
undefined: shim.success
可能很少有变量未定义的错误。由于我的代码没有构建,我无法调试代码。请找到我正在使用的代码。我无法找到上述错误的原因。请帮我解决这个问题。
import (
"encoding/json"
"fmt"
"bytes"
"time"
"strings"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
func (t *check) SurrenderSaves(stub shim.ChaincodeStubInterface,
args []string) pb.Response {
fmt.Println("Entering CodeSurrenderSaves")
var err error
var lastImportDatekey string
var lastImportDate []byte
lastImportDate, err= stub.GetState("lastImprtDatesaved")
fmt.Println("lastImportDate ...... ", lastImportDate)
err = json.Unmarshal(lastImportDate, &lastImportDatekey)
if err != nil {
fmt.Printf("Unable to unmarshal lastImportDate input
lastImportDatekey: %s\n", err)
return shim.Error(err.Error())
}
fmt.Println("lastImportDatekey ...... ", lastImportDatekey)
if (lastImportDate == nil){
currentTime := time.Now()
var timeString = currentTime.Format("2006-01-02")
lastImportDatekey = timeString
fmt.Println("lastImportDatekey ...... ", lastImportDatekey)
} else {
err = json.Unmarshal(lastImportDate, &lastImportDatekey)
if err != nil {
fmt.Printf("Unable to unmarshal lastImportDate input
lastImportDate: %s\n", err)
return shim.Error(err.Error())
}
fmt.Println(" lastImportDatekey end:",lastImportDatekey)
}
return shim.Success(nil)
}
func (t *check) Init(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("Initiate the chaincde")
return shim.Success(nil)
}
func (t *check) Invoke(stub shim.ChaincodeStubInterface) pb.Response
{
function, args := stub.GetFunctionAndParameters()
if function == "SurrenderSaves" {
return t.SurrenderSaves(stub, args)
}
fmt.Println("Function not found")
return shim.Error("Received unknown function invocation")
return nil, nil
}