mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-20 00:25:09 +00:00
Implement Transaction interface
For the GetCreator() method return the identity.Identity interface was also implemented. Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
This commit is contained in:
parent
81743872bd
commit
1eaf609711
1 changed files with 65 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/hyperledger/fabric-protos-go-apiv2/common"
|
"github.com/hyperledger/fabric-protos-go-apiv2/common"
|
||||||
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset"
|
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset"
|
||||||
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset"
|
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset"
|
||||||
|
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
|
||||||
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
|
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
@ -17,15 +18,6 @@ type Block interface {
|
||||||
ToProto() *common.Block
|
ToProto() *common.Block
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transaction interface {
|
|
||||||
GetChannelHeader() *common.ChannelHeader
|
|
||||||
GetCreator() identity.Identity
|
|
||||||
GetValidationCode() uint64
|
|
||||||
IsValid() bool
|
|
||||||
GetNamespaceReadWriteSets() []NamespaceReadWriteSet
|
|
||||||
ToProto() *common.Payload
|
|
||||||
}
|
|
||||||
|
|
||||||
type ParsedBlock struct {
|
type ParsedBlock struct {
|
||||||
block *common.Block
|
block *common.Block
|
||||||
validationCodes []byte
|
validationCodes []byte
|
||||||
|
|
@ -52,6 +44,70 @@ func (pb *ParsedBlock) ToProto() *common.Block {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements identity.Identity Interface
|
||||||
|
type IdentityImpl struct {
|
||||||
|
creator *msp.SerializedIdentity
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IdentityImpl) MspID() string {
|
||||||
|
return i.creator.GetMspid()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IdentityImpl) Credentials() []byte {
|
||||||
|
return i.creator.GetIdBytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
type Transaction interface {
|
||||||
|
GetChannelHeader() *common.ChannelHeader
|
||||||
|
GetCreator() identity.Identity
|
||||||
|
GetValidationCode() int32
|
||||||
|
IsValid() bool
|
||||||
|
GetNamespaceReadWriteSets() []NamespaceReadWriteSet
|
||||||
|
ToProto() *common.Payload
|
||||||
|
}
|
||||||
|
|
||||||
|
type TransactionImpl struct {
|
||||||
|
payload Payload
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTransaction(payload Payload) Transaction {
|
||||||
|
return &TransactionImpl{payload}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) GetChannelHeader() *common.ChannelHeader {
|
||||||
|
return t.payload.GetChannelHeader()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) GetCreator() identity.Identity {
|
||||||
|
creator := &msp.SerializedIdentity{}
|
||||||
|
if err := proto.Unmarshal(t.payload.GetSignatureHeader().GetCreator(), creator); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &IdentityImpl{creator}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) GetNamespaceReadWriteSets() []NamespaceReadWriteSet {
|
||||||
|
result := []NamespaceReadWriteSet{}
|
||||||
|
for _, readWriteSet := range t.payload.GetEndorserTransaction().GetReadWriteSets() {
|
||||||
|
result = append(result, readWriteSet.GetNamespaceReadWriteSets()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) GetValidationCode() int32 {
|
||||||
|
return t.payload.GetTransactionValidationCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) IsValid() bool {
|
||||||
|
return t.payload.IsValid()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TransactionImpl) ToProto() *common.Payload {
|
||||||
|
return t.payload.ToProto()
|
||||||
|
}
|
||||||
|
|
||||||
type EndorserTransaction interface {
|
type EndorserTransaction interface {
|
||||||
GetReadWriteSets() []ReadWriteSet
|
GetReadWriteSets() []ReadWriteSet
|
||||||
ToProto() *peer.Transaction
|
ToProto() *peer.Transaction
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue