代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package server
import (
"time"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"gitee.com/hyperledger-fabric-gm/fabric/common/util"
"gitee.com/hyperledger-fabric-gm/fabric/protos/token"
"github.com/pkg/errors"
)
// UnmarshalCommand unmarshal token.Command messages
func UnmarshalCommand(raw []byte) (*token.Command, error) {
command := &token.Command{}
err := proto.Unmarshal(raw, command)
if err != nil {
return nil, err
}
return command, nil
}
type TimeFunc func() time.Time
// ResponseMarshaler produces token.SignedCommandResponse
type ResponseMarshaler struct {
Signer Signer
Creator []byte
Time TimeFunc
}
func NewResponseMarshaler(signerID SignerIdentity) (*ResponseMarshaler, error) {
creator, err := signerID.Serialize()
if err != nil {
return nil, err
}
return &ResponseMarshaler{
Signer: signerID,
Creator: creator,
Time: time.Now,
}, nil
}
func (s *ResponseMarshaler) MarshalCommandResponse(command []byte, responsePayload interface{}) (*token.SignedCommandResponse, error) {
cr, err := commandResponseFromPayload(responsePayload)
if err != nil {
return nil, err
}
ts, err := ptypes.TimestampProto(s.Time())
if err != nil {
return nil, err
}
cr.Header = &token.CommandResponseHeader{
Creator: s.Creator,
CommandHash: util.ComputeSHA256(command),
Timestamp: ts,
}
return s.createSignedCommandResponse(cr)
}
func (s *ResponseMarshaler) createSignedCommandResponse(cr *token.CommandResponse) (*token.SignedCommandResponse, error) {
raw, err := proto.Marshal(cr)
if err != nil {
return nil, err
}
signature, err := s.Signer.Sign(raw)
if err != nil {
return nil, err
}
return &token.SignedCommandResponse{
Response: raw,
Signature: signature,
}, nil
}
func commandResponseFromPayload(payload interface{}) (*token.CommandResponse, error) {
switch t := payload.(type) {
case *token.CommandResponse_TokenTransaction:
return &token.CommandResponse{Payload: t}, nil
case *token.CommandResponse_Err:
return &token.CommandResponse{Payload: t}, nil
case *token.CommandResponse_UnspentTokens:
return &token.CommandResponse{Payload: t}, nil
default:
return nil, errors.Errorf("command type not recognized: %T", t)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。