You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.6 KiB

package service
import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"encoding/json"
"fmt"
)
func (t *ServiceSetup) SaveEdu(edu Education) (string, error) {
eventID := "eventAddEdu"
reg, notifier := regitserEvent(t.Client, t.ChaincodeID, eventID)
defer t.Client.UnregisterChaincodeEvent(reg)
// 将edu对象序列化成为字节数组
b, err := json.Marshal(edu)
if err != nil {
return "", fmt.Errorf("指定的edu对象序列化时发生错误")
}
req := channel.Request{ChaincodeID: t.ChaincodeID, Fcn: "addEdu", Args: [][]byte{b, []byte(eventID)}}
respone, err := t.Client.Execute(req)
if err != nil {
return "", err
}
err = eventResult(notifier, eventID)
if err != nil {
return "", err
}
return string(respone.TransactionID), nil
}
func (t *ServiceSetup) FindEduInfoByEntityID(entityID string) ([]byte, error){
req := channel.Request{ChaincodeID: t.ChaincodeID, Fcn: "queryEduInfoByEntityID", Args: [][]byte{[]byte(entityID)}}
respone, err := t.Client.Query(req)
if err != nil {
return []byte{0x00}, err
}
return respone.Payload, nil
}
func (t *ServiceSetup) FindEduByCertNoAndName(certNo, name string) ([]byte, error){
req := channel.Request{ChaincodeID: t.ChaincodeID, Fcn: "queryEduByCertNoAndName", Args: [][]byte{[]byte(certNo), []byte(name)}}
respone, err := t.Client.Query(req)
if err != nil {
return []byte{0x00}, err
}
return respone.Payload, nil
}
func (t *ServiceSetup) ModifyEdu(edu Education) (string, error) {
eventID := "eventModifyEdu"
reg, notifier := regitserEvent(t.Client, t.ChaincodeID, eventID)
defer t.Client.UnregisterChaincodeEvent(reg)
// 将edu对象序列化成为字节数组
b, err := json.Marshal(edu)
if err != nil {
return "", fmt.Errorf("指定的edu对象序列化时发生错误")
}
req := channel.Request{ChaincodeID: t.ChaincodeID, Fcn: "updateEdu", Args: [][]byte{b, []byte(eventID)}}
respone, err := t.Client.Execute(req)
if err != nil {
return "", err
}
err = eventResult(notifier, eventID)
if err != nil {
return "", err
}
return string(respone.TransactionID), nil
}
func (t *ServiceSetup) DelEdu(entityID string) (string, error) {
eventID := "eventDelEdu"
reg, notifier := regitserEvent(t.Client, t.ChaincodeID, eventID)
defer t.Client.UnregisterChaincodeEvent(reg)
req := channel.Request{ChaincodeID: t.ChaincodeID, Fcn: "delEdu", Args: [][]byte{[]byte(entityID), []byte(eventID)}}
respone, err := t.Client.Execute(req)
if err != nil {
return "", err
}
err = eventResult(notifier, eventID)
if err != nil {
return "", err
}
return string(respone.TransactionID), nil
}