Skip to content

Commit

Permalink
Correct types for batch records
Browse files Browse the repository at this point in the history
Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Jan 17, 2025
1 parent ce5a571 commit 126c4a8
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions shim/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import (
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
)

type batchRecordType int

const (
dataKeyType batchRecordType = iota
metadataKeyType
)

type batchKey struct {
Collection string
Key string
Type peer.WriteRecord_Type
Type batchRecordType
}

type writeBatch struct {
Expand All @@ -37,7 +44,7 @@ func (b *writeBatch) Writes() []*peer.WriteRecord {
}

func (b *writeBatch) PutState(collection string, key string, value []byte) {
b.write(&peer.WriteRecord{
b.writeData(&peer.WriteRecord{
Key: key,
Value: value,
Collection: collection,
Expand All @@ -46,7 +53,7 @@ func (b *writeBatch) PutState(collection string, key string, value []byte) {
}

func (b *writeBatch) PutStateMetadataEntry(collection string, key string, metakey string, metadata []byte) {
b.write(&peer.WriteRecord{
b.writeMetadata(&peer.WriteRecord{
Key: key,
Collection: collection,
Metadata: &peer.StateMetadata{Metakey: metakey, Value: metadata},
Expand All @@ -55,26 +62,35 @@ func (b *writeBatch) PutStateMetadataEntry(collection string, key string, metake
}

func (b *writeBatch) DelState(collection string, key string) {
b.write(&peer.WriteRecord{
b.writeData(&peer.WriteRecord{
Key: key,
Collection: collection,
Type: peer.WriteRecord_DEL_STATE,
})
}

func (b *writeBatch) PurgeState(collection string, key string) {
b.write(&peer.WriteRecord{
b.writeData(&peer.WriteRecord{
Key: key,
Collection: collection,
Type: peer.WriteRecord_PURGE_PRIVATE_DATA,
})
}

func (b *writeBatch) write(record *peer.WriteRecord) {
func (b *writeBatch) writeData(record *peer.WriteRecord) {
key := batchKey{
Collection: record.Collection,
Key: record.Key,
Type: dataKeyType,
}
b.writes[key] = record
}

func (b *writeBatch) writeMetadata(record *peer.WriteRecord) {
key := batchKey{
Collection: record.Collection,
Key: record.Key,
Type: record.Type,
Type: metadataKeyType,
}
b.writes[key] = record
}

0 comments on commit 126c4a8

Please sign in to comment.