stub.GetTxTimestamp()是获得创建交易时的时间戳
t1, _ := stub.GetTxTimestamp()
time1 := time.Unix(t1.Seconds, int64(t1.Nanos)).String()
logger.Infof("===========time1======time1=========%s", time1)
stub.GetCreator()是客户端的证书
creatorByte, _ := stub.GetCreator()
注意 返回类型是[]byte类型的
可以根据证书解析出name
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----BEGIN")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
uname := cert.Subject.CommonName
fmt.Println("Name:" + uname)
logger.Infof("===========Name======Name=========%s", uname)
运行结果
运行结果
网友评论