Skip to content

Commit

Permalink
Use lazy providers from FSC
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <alexandros.filios@ibm.com>
  • Loading branch information
alexandrosfilios committed Aug 12, 2024
1 parent 074a48a commit e312123
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 308 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/IBM/mathlib v0.0.3-0.20231011094432-44ee0eb539da
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/hashicorp/go-uuid v1.0.2
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240808130420-c90da8a1647a
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240812073223-219f2a84da8f
github.com/hyperledger-labs/fabric-token-sdk/txgen v0.0.0-00010101000000-000000000000
github.com/hyperledger-labs/orion-sdk-go v0.2.10
github.com/hyperledger-labs/orion-server v0.2.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY=
github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240808130420-c90da8a1647a h1:eBVE/gOE4sSHmB+AjFSNAjn7jgi7p979NCfpNRtO1x0=
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240808130420-c90da8a1647a/go.mod h1:962enO5D++R5KW+rPA2FD85h619hap+4voLAU+Pk9WY=
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240812073223-219f2a84da8f h1:VcSMlP8EWx6mzSIeCTaIVpVtI/08lKoUa079aJ3dM2o=
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20240812073223-219f2a84da8f/go.mod h1:962enO5D++R5KW+rPA2FD85h619hap+4voLAU+Pk9WY=
github.com/hyperledger-labs/orion-sdk-go v0.2.10 h1:lFgWgxyvngIhWnIqymYGBmtmq9D6uC5d0uLG9cbyh5s=
github.com/hyperledger-labs/orion-sdk-go v0.2.10/go.mod h1:iN2xZB964AqwVJwL+EnwPOs8z1EkMEbbIg/qYeC7gDY=
github.com/hyperledger-labs/orion-server v0.2.10 h1:G4zbQEL5Egk0Oj+TwHCZWdTOLDBHOjaAEvYOT4G7ozw=
Expand Down
6 changes: 3 additions & 3 deletions token/services/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package config
import (
"reflect"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -82,7 +82,7 @@ type Service struct {

version string
enabled bool
tmsCache utils.LazyGetter[map[string]Configuration]
tmsCache lazy.Getter[map[string]Configuration]
}

// NewService creates a new Service configuration.
Expand All @@ -97,7 +97,7 @@ func NewService(cp configProvider) *Service {
cp: cp,
version: version,
enabled: enabled,
tmsCache: utils.NewLazyGetter(loader.load),
tmsCache: lazy.NewGetter(loader.load),
}
}

Expand Down
6 changes: 3 additions & 3 deletions token/services/db/sql/common/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"database/sql"

utils2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db"
sql2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/common"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/pkg/errors"
_ "modernc.org/sqlite"
Expand All @@ -37,7 +37,7 @@ type NewDBOpts struct {
}

type Opener[V any] struct {
dbCache utils.LazyProvider[Opts, V]
dbCache lazy.Provider[Opts, V]
optsKey string
envVarKey string
}
Expand All @@ -63,7 +63,7 @@ func NewOpenerFromMap[V any](optsKey, envVarKey string, constructors map[common.

func NewOpener[V any](optsKey, envVarKey string, constructors OpenDBFunc[V]) *Opener[V] {
return &Opener[V]{
dbCache: utils.NewLazyProviderWithKeyMapper(key, constructors),
dbCache: lazy.NewProviderWithKeyMapper(key, constructors),
optsKey: optsKey,
envVarKey: envVarKey,
}
Expand Down
6 changes: 3 additions & 3 deletions token/services/network/fabric/endorsement/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package endorsement
import (
"context"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
Expand All @@ -17,7 +18,6 @@ import (
token2 "github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/network/common"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/network/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/pkg/errors"
)

Expand All @@ -40,7 +40,7 @@ type ViewManager interface {
type ViewRegistry = driver2.Registry

type ServiceProvider struct {
utils.LazyProvider[token2.TMSID, Service]
lazy.Provider[token2.TMSID, Service]
}

func NewServiceProvider(
Expand All @@ -59,7 +59,7 @@ func NewServiceProvider(
identityProvider: identityProvider,
tmsProvider: tmsProvider,
}
return &ServiceProvider{LazyProvider: utils.NewLazyProviderWithKeyMapper(key, l.load)}
return &ServiceProvider{Provider: lazy.NewProviderWithKeyMapper(key, l.load)}
}

type Service interface {
Expand Down
12 changes: 6 additions & 6 deletions token/services/network/fabric/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/chaincode"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/services/network/fabric/endorsement"
tokens2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/tokens"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault"
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/hyperledger/fabric-protos-go/peer"
Expand Down Expand Up @@ -155,8 +155,8 @@ type Network struct {
tokensProvider *tokens2.Manager
finalityTracer trace.Tracer

vaultLazyCache utils.LazyProvider[string, driver.Vault]
tokenVaultLazyCache utils.LazyProvider[string, driver.TokenVault]
vaultLazyCache lazy.Provider[string, driver.Vault]
tokenVaultLazyCache lazy.Provider[string, driver.TokenVault]
subscribers *events.Subscribers

endorsementServiceProvider *endorsement.ServiceProvider
Expand Down Expand Up @@ -189,8 +189,8 @@ func NewNetwork(
configuration: configuration,
filterProvider: filterProvider,
tokensProvider: tokensProvider,
vaultLazyCache: utils.NewLazyProvider(loader.loadVault),
tokenVaultLazyCache: utils.NewLazyProvider(loader.loadTokenVault),
vaultLazyCache: lazy.NewProvider(loader.loadVault),
tokenVaultLazyCache: lazy.NewProvider(loader.loadTokenVault),
subscribers: events.NewSubscribers(),
endorsementServiceProvider: endorsementServiceProvider,
finalityTracer: tracerProvider.Tracer("finality_listener", tracing.WithMetricsOpts(tracing.MetricsOpts{
Expand Down Expand Up @@ -250,7 +250,7 @@ func (n *Network) Connect(ns string) ([]token2.ServiceOption, error) {
NewTokenRWSetProcessor(
n.Name(),
ns,
utils.NewLazyGetter[*tokens2.Tokens](func() (*tokens2.Tokens, error) {
lazy.NewGetter[*tokens2.Tokens](func() (*tokens2.Tokens, error) {
return n.tokensProvider.Tokens(tmsID)
}).Get,
func() *token2.ManagementServiceProvider {
Expand Down
10 changes: 5 additions & 5 deletions token/services/network/orion/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-smart-client/platform/orion"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/events"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/services/network/common/rws/keys"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/network/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault"
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
Expand All @@ -48,8 +48,8 @@ type Network struct {
filterProvider common2.TransactionFilterProvider[*common2.AcceptTxInDBsFilter]
finalityTracer trace.Tracer

vaultLazyCache utils.LazyProvider[string, driver.Vault]
tokenVaultLazyCache utils.LazyProvider[string, driver.TokenVault]
vaultLazyCache lazy.Provider[string, driver.Vault]
tokenVaultLazyCache lazy.Provider[string, driver.TokenVault]
subscribers *events.Subscribers
dbManager *DBManager
}
Expand Down Expand Up @@ -78,8 +78,8 @@ func NewNetwork(
n: n,
viewManager: viewManager,
tmsProvider: tmsProvider,
vaultLazyCache: utils.NewLazyProvider(loader.loadVault),
tokenVaultLazyCache: utils.NewLazyProvider(loader.loadTokenVault),
vaultLazyCache: lazy.NewProvider(loader.loadVault),
tokenVaultLazyCache: lazy.NewProvider(loader.loadTokenVault),
subscribers: events.NewSubscribers(), ledger: &ledger{network: n.Name(), viewManager: viewManager, dbManager: dbManager},
finalityTracer: tracerProvider.Tracer("finality_listener", tracing.WithMetricsOpts(tracing.MetricsOpts{
Namespace: "tokensdk_orion",
Expand Down
6 changes: 3 additions & 3 deletions token/services/selector/sherdlock/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package sherdlock
import (
"time"

lazy2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/types/transaction"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
Expand All @@ -33,7 +33,7 @@ type tokenSelectorUnlocker interface {
}

type manager struct {
selectorCache utils.LazyProvider[transaction.ID, tokenSelectorUnlocker]
selectorCache lazy2.Provider[transaction.ID, tokenSelectorUnlocker]
locker Locker
evictionDelay time.Duration
cleanupPeriod time.Duration
Expand All @@ -56,7 +56,7 @@ func NewManager(
m := &manager{
locker: locker,
evictionDelay: evictionDelay,
selectorCache: utils.NewLazyProvider(func(txID transaction.ID) (tokenSelectorUnlocker, error) {
selectorCache: lazy2.NewProvider(func(txID transaction.ID) (tokenSelectorUnlocker, error) {
return NewSherdSelector(txID, fetcher, locker, precision, backoff), nil
}),
cleanupPeriod: cleanupPeriod,
Expand Down
6 changes: 3 additions & 3 deletions token/services/selector/sherdlock/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ package sherdlock
import (
"time"

lazy2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokendb"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokenlockdb"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
"github.com/pkg/errors"
)

Expand All @@ -24,7 +24,7 @@ const (
)

type SelectorService struct {
managerLazyCache utils.LazyProvider[*token.ManagementService, token.SelectorManager]
managerLazyCache lazy2.Provider[*token.ManagementService, token.SelectorManager]
}

func NewService(tokenDBManager *tokendb.Manager, tokenLockDBManager *tokenlockdb.Manager, metricsProvider metrics.Provider) *SelectorService {
Expand All @@ -34,7 +34,7 @@ func NewService(tokenDBManager *tokendb.Manager, tokenLockDBManager *tokenlockdb
m: newMetrics(metricsProvider),
}
return &SelectorService{
managerLazyCache: utils.NewLazyProviderWithKeyMapper(key, loader.load),
managerLazyCache: lazy2.NewProviderWithKeyMapper(key, loader.load),
}
}

Expand Down
6 changes: 3 additions & 3 deletions token/services/selector/simple/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"context"
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/lazy"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
)
Expand All @@ -30,7 +30,7 @@ type LockerProvider interface {
}

type SelectorService struct {
managerLazyCache utils.LazyProvider[*token.ManagementService, token.SelectorManager]
managerLazyCache lazy.Provider[*token.ManagementService, token.SelectorManager]
}

func NewService(lockerProvider LockerProvider) *SelectorService {
Expand All @@ -41,7 +41,7 @@ func NewService(lockerProvider LockerProvider) *SelectorService {
requestCertification: true,
}
return &SelectorService{
managerLazyCache: utils.NewLazyProviderWithKeyMapper(key, loader.load),
managerLazyCache: lazy.NewProviderWithKeyMapper(key, loader.load),
}
}

Expand Down
31 changes: 0 additions & 31 deletions token/services/utils/lazygetter.go

This file was deleted.

Loading

0 comments on commit e312123

Please sign in to comment.