Skip to content

Commit a9f189d

Browse files
fixup! Reuse simpletxidstore
Signed-off-by: Alexandros Filios <[email protected]>
1 parent a473952 commit a9f189d

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

platform/common/core/generic/vault/iterator.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0
66

77
package vault
88

9+
import "github.com/hyperledger-labs/fabric-smart-client/platform/common/core"
10+
911
type ValidationCode interface {
1012
comparable
1113
}
@@ -22,15 +24,15 @@ type SeekStart struct{}
2224
type SeekEnd struct{}
2325

2426
type SeekPos struct {
25-
Txid string
27+
Txid core.TxID
2628
}
2729

2830
type SeekSet struct {
29-
TxIDs []string
31+
TxIDs []core.TxID
3032
}
3133

3234
type ByNum[V comparable] struct {
33-
TxID string
35+
TxID core.TxID
3436
Code V
3537
Message string
3638
}
@@ -41,6 +43,6 @@ type TxIDIterator[V comparable] interface {
4143
}
4244

4345
type TXIDStore[V comparable] interface {
44-
GetLastTxID() (string, error)
46+
GetLastTxID() (core.TxID, error)
4547
Iterator(pos interface{}) (TxIDIterator[V], error)
4648
}

platform/common/core/generic/vault/txidstore/simpletxidstore.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math"
1212

1313
errors2 "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
14+
"github.com/hyperledger-labs/fabric-smart-client/platform/common/core"
1415
"github.com/hyperledger-labs/fabric-smart-client/platform/common/core/generic/vault"
1516
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
1617
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver"
@@ -65,7 +66,7 @@ func NewSimpleTXIDStore[V vault.ValidationCode](persistence driver.Persistence,
6566
}, nil
6667
}
6768

68-
func (s *SimpleTXIDStore[V]) get(txID string) (*ByTxid, error) {
69+
func (s *SimpleTXIDStore[V]) get(txID core.TxID) (*ByTxid, error) {
6970
bytes, err := s.persistence.GetState(txidNamespace, keyByTxID(txID))
7071
if err != nil {
7172
return nil, errors.Errorf("error retrieving txid %s [%s]", txID, err.Error())
@@ -84,7 +85,7 @@ func (s *SimpleTXIDStore[V]) get(txID string) (*ByTxid, error) {
8485
return bt, nil
8586
}
8687

87-
func (s *SimpleTXIDStore[V]) Get(txID string) (V, string, error) {
88+
func (s *SimpleTXIDStore[V]) Get(txID core.TxID) (V, string, error) {
8889
bt, err := s.get(txID)
8990
if err != nil {
9091
return s.vcProvider.Unknown(), "", err
@@ -97,7 +98,7 @@ func (s *SimpleTXIDStore[V]) Get(txID string) (V, string, error) {
9798
return s.vcProvider.FromInt32(bt.Code), bt.Message, nil
9899
}
99100

100-
func (s *SimpleTXIDStore[V]) Set(txID string, code V, message string) error {
101+
func (s *SimpleTXIDStore[V]) Set(txID core.TxID, code V, message string) error {
101102
// NOTE: we assume that the commit is in progress so no need to update/commit
102103
// err := s.persistence.BeginUpdate()
103104
// if err != nil {
@@ -161,7 +162,7 @@ func (s *SimpleTXIDStore[V]) Set(txID string, code V, message string) error {
161162
return nil
162163
}
163164

164-
func (s *SimpleTXIDStore[V]) GetLastTxID() (string, error) {
165+
func (s *SimpleTXIDStore[V]) GetLastTxID() (core.TxID, error) {
165166
v, err := s.persistence.GetState(txidNamespace, lastTX)
166167
if err != nil {
167168
return "", errors.Wrapf(err, "failed to get last TxID")
@@ -248,12 +249,6 @@ func (i *SimpleTxIDIterator) Next() (*ByNum, error) {
248249
return nil, err
249250
}
250251
return bn, err
251-
252-
//return &vault.ByNum[V]{
253-
// TxID: bn.Txid,
254-
// Code: fdriver.ValidationCode(bn.Code),
255-
// Message: bn.Message,
256-
//}, nil
257252
}
258253

259254
func (i *SimpleTxIDIterator) Close() {
@@ -267,7 +262,7 @@ func keyByCtr(ctr uint64) string {
267262
return byCtrPrefix + string(ctrBytes[:])
268263
}
269264

270-
func keyByTxID(txID string) string {
265+
func keyByTxID(txID core.TxID) string {
271266
return byTxidPrefix + txID
272267
}
273268

0 commit comments

Comments
 (0)