75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package core
|
||
|
||
import (
|
||
pb "schain/proto"
|
||
)
|
||
|
||
// 根据编号删除相应交易
|
||
func DeleteTx(arr []string, id string) []string {
|
||
for i := 0; i < len(arr); i++ {
|
||
if id == arr[i] {
|
||
arr = append(arr[:i], arr[i+1:]...)
|
||
}
|
||
}
|
||
return arr
|
||
}
|
||
|
||
/*func DeleteTx(arr []string, id string) []string {
|
||
result := make([]string, 0)
|
||
|
||
for _, item := range arr {
|
||
if item != id {
|
||
result = append(result, item)
|
||
}
|
||
}
|
||
|
||
return result
|
||
}*/
|
||
|
||
// 在 fabric 中,一个区块结构 Block 的主要数据部分是由一个或多个交易(或者配置)数据结构 Envelope 组成。出块即是将一个或多个 Envelope 打包成一个 Block,这个工作由 orderer 完成。
|
||
func GetEnvelope(txID string, envelopes []*pb.Envelope) (*pb.Envelope, []*pb.Envelope) {
|
||
for index, envelope := range envelopes {
|
||
if envelope.TxID == txID {
|
||
envelopes = append(envelopes[:index], envelopes[index+1:]...)
|
||
return envelope, envelopes
|
||
}
|
||
}
|
||
return nil, envelopes
|
||
}
|
||
|
||
/*GetEnvelope更好的实现方案
|
||
func GetEnvelope(txID string, envelopes []*pb.Envelope) (*pb.Envelope, []*pb.Envelope) {
|
||
var foundEnvelope *pb.Envelope
|
||
var remainingEnvelopes []*pb.Envelope
|
||
|
||
for _, envelope := range envelopes {
|
||
if envelope.TxID == txID {
|
||
foundEnvelope = envelope
|
||
} else {
|
||
remainingEnvelopes = append(remainingEnvelopes, envelope)
|
||
}
|
||
}
|
||
|
||
return foundEnvelope, remainingEnvelopes
|
||
}
|
||
*/
|
||
|
||
/*type Envelope struct {
|
||
state protoimpl.MessageState
|
||
sizeCache protoimpl.SizeCache
|
||
unknownFields protoimpl.UnknownFields
|
||
|
||
TxID string `protobuf:"bytes,1,opt,name=txID,proto3" json:"txID,omitempty"`
|
||
Payload []byte `protobuf:"bytes,2,opt,name=Payload,proto3" json:"Payload,omitempty"`
|
||
Signature []byte `protobuf:"bytes,3,opt,name=Signature,proto3" json:"Signature,omitempty"`
|
||
}
|
||
|
||
func (*pb.Envelope).Descriptor() ([]byte, []int)
|
||
func (*pb.Envelope).GetPayload() []byte
|
||
func (*pb.Envelope).GetSignature() []byte
|
||
func (*pb.Envelope).GetTxID() string
|
||
func (*pb.Envelope).ProtoMessage()
|
||
func (*pb.Envelope).ProtoReflect() protoreflect.Message
|
||
func (*pb.Envelope).Reset()
|
||
func (*pb.Envelope).String() string*/
|