Skip to content

Commit

Permalink
Integrated new FSC version
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios committed Jul 6, 2024
1 parent f48b6fc commit 64c9cd1
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion integration/token/fungible/views/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (a *AuditView) Call(context view.Context) (interface{}, error) {
}
}

kvsInstance := kvs.GetService(context)
kvsInstance := GetKVS(context)

for _, rID := range inputs.RevocationHandles() {
rh := hash.Hashable(rID).String()
Expand Down
2 changes: 1 addition & 1 deletion integration/token/fungible/views/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RevokeUserView struct {
func (u *RevokeUserView) Call(context view.Context) (interface{}, error) {
rh := hash.Hashable(u.RH).String()
logger.Infof("revoke [%s][%s]", u.RH, rh)
kvsInstance := kvs.GetService(context)
kvsInstance := GetKVS(context)
k := kvs.CreateCompositeKeyOrPanic("revocationList", []string{rh})
assert.False(kvsInstance.Exists(k), "Identity already in revoked state")
assert.NoError(kvsInstance.Put(k, rh), "failed to put revocation handle")
Expand Down
11 changes: 10 additions & 1 deletion integration/token/fungible/views/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"strings"

view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokendb"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
Expand Down Expand Up @@ -51,7 +52,7 @@ type SetKVSEntryView struct {
}

func (s *SetKVSEntryView) Call(context view.Context) (interface{}, error) {
assert.NoError(kvs.GetService(context).Put(s.Key, s.Value), "failed to put in KVS [%s:%s]", s.Key, s.Value)
assert.NoError(GetKVS(context).Put(s.Key, s.Value), "failed to put in KVS [%s:%s]", s.Key, s.Value)
return nil, nil
}

Expand Down Expand Up @@ -81,3 +82,11 @@ func TxOpts(tmsId *token.TMSID) []ttx.TxOption {
}
return txOpts
}

func GetKVS(sp view2.ServiceProvider) *kvs.KVS {
kvss, err := sp.GetService(&kvs.KVS{})
if err != nil {
panic(err)
}
return kvss.(*kvs.KVS)
}
3 changes: 1 addition & 2 deletions integration/token/fungible/views/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/kvs"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (p *WithdrawalResponderView) Call(context view.Context) (interface{}, error
var tx *ttx.Transaction
var auditorID string
if len(p.Auditor) == 0 {
assert.NoError(kvs.GetService(context).Get("auditor", &auditorID), "failed to retrieve auditor id")
assert.NoError(GetKVS(context).Get("auditor", &auditorID), "failed to retrieve auditor id")
} else {
auditorID = p.Auditor
}
Expand Down
5 changes: 3 additions & 2 deletions token/core/zkatdlog/crypto/audit/auditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ func (f *fakeProv) TranslatePath(path string) string {

func getIdemixInfo(dir string) (driver.Identity, *msp3.AuditInfo) {
registry := registry2.New()
Expect(registry.RegisterService(&fakeProv{typ: "memory"})).NotTo(HaveOccurred())
configService := &fakeProv{typ: "memory"}
Expect(registry.RegisterService(configService)).NotTo(HaveOccurred())

backend, err := kvs.New(registry, &mem.Driver{}, "")
backend, err := kvs.NewWithConfig(&mem.Driver{}, "", configService)
Expect(err).NotTo(HaveOccurred())
err = registry.RegisterService(backend)
Expect(err).NotTo(HaveOccurred())
Expand Down
5 changes: 3 additions & 2 deletions token/core/zkatdlog/crypto/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ func (f *fakeProv) TranslatePath(path string) string {

func getIdemixInfo(dir string) (driver.Identity, *msp3.AuditInfo, driver.SigningIdentity) {
registry := registry2.New()
Expect(registry.RegisterService(&fakeProv{typ: "memory"})).NotTo(HaveOccurred())
configService := &fakeProv{typ: "memory"}
Expect(registry.RegisterService(configService)).NotTo(HaveOccurred())

backend, err := kvs.New(registry, &mem.Driver{}, "")
backend, err := kvs.NewWithConfig(&mem.Driver{}, "", configService)
Expect(err).NotTo(HaveOccurred())
err = registry.RegisterService(backend)
Expect(err).NotTo(HaveOccurred())
Expand Down
1 change: 1 addition & 0 deletions token/sdk/dig/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (p *SDK) Install() error {

// Backward compatibility with SP
err = errors2.Join(
digutils.Register[*kvs.KVS](p.Container()),
digutils.Register[*network.Provider](p.Container()),
digutils.Register[*token.ManagementServiceProvider](p.Container()),
digutils.Register[*ttxdb.Manager](p.Container()),
Expand Down
6 changes: 3 additions & 3 deletions token/services/network/orion/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ func (n *Network) AddFinalityListener(namespace string, txID string, listener dr
net: n,
root: listener,
network: n.n.Name(),
sp: n.n.SP,
namespace: namespace,
retryRunner: db.NewRetryRunner(-1, time.Second, true),
viewManager: n.viewManager,
}
n.subscribers.Set(txID, listener, wrapper)
return n.n.Committer().AddFinalityListener(txID, wrapper)
Expand Down Expand Up @@ -332,10 +332,10 @@ func (l *ledger) Status(id string) (driver.ValidationCode, error) {
type FinalityListener struct {
net *Network
root driver.FinalityListener
sp token2.ServiceProvider
network string
namespace string
retryRunner db.RetryRunner
viewManager *view2.Manager
}

func (t *FinalityListener) OnStatus(txID string, status int, message string) {
Expand All @@ -346,7 +346,7 @@ func (t *FinalityListener) OnStatus(txID string, status int, message string) {

func (t *FinalityListener) runOnStatus(txID string, status int, message string) (err error) {
defer func() { err = wrapRecover(recover()) }()
boxed, err := view2.GetManager(t.sp).InitiateView(NewRequestTxStatusView(t.network, t.namespace, txID), context.TODO())
boxed, err := t.viewManager.InitiateView(NewRequestTxStatusView(t.network, t.namespace, txID), context.TODO())
if err != nil {
return fmt.Errorf("failed retrieving token request [%s]: [%s]", txID, err)
}
Expand Down
6 changes: 4 additions & 2 deletions token/services/nfttx/uniqueness/uniqueness.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func (s *Service) ComputeID(state interface{}) (string, error) {

// GetService returns the uniqueness service.
func GetService(sp token.ServiceProvider) *Service {
return &Service{
kvs: kvs.GetService(sp),
kvss, err := sp.GetService(&kvs.KVS{})
if err != nil {
panic(err)
}
return &Service{kvs: kvss.(*kvs.KVS)}
}
4 changes: 3 additions & 1 deletion token/services/ttx/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (s *AcceptView) respondToSignatureRequests(context view.Context) error {
return errors.Wrap(err, "failed to generate key to store signature request")
}
var srRaw []byte
if err := kvs.GetService(context).Get(k, &srRaw); err != nil {
if kvss, err := context.GetService(&kvs.KVS{}); err != nil {
return errors.Wrap(err, "failed to get KVS from context")
} else if err := kvss.(*kvs.KVS).Get(k, &srRaw); err != nil {
return errors.Wrap(err, "failed to to store signature request")
}
if err := Unmarshal(srRaw, signatureRequest); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion token/services/ttx/endorse.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ func (f *ReceiveTransactionView) unmarshalAsSignatureRequest(context view.Contex
if err != nil {
return nil, errors.Wrap(err, "failed to generate key to store signature request")
}
if err := kvs.GetService(context).Put(k, raw); err != nil {
if kvss, err := context.GetService(&kvs.KVS{}); err != nil {
return nil, errors.Wrap(err, "failed to get KVS from context")
} else if err := kvss.(*kvs.KVS).Put(k, raw); err != nil {
return nil, errors.Wrap(err, "failed to to store signature request")
}
return tx, nil
Expand Down

0 comments on commit 64c9cd1

Please sign in to comment.