Skip to content

Commit 20f2d32

Browse files
authored
extensions (#1221)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent c625899 commit 20f2d32

File tree

10 files changed

+71
-13
lines changed

10 files changed

+71
-13
lines changed

docs/core/extension/zkatdlog/nogh/v2/driver/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1111
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
1212
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/endpoint"
13+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/id"
1314
v2 "github.com/hyperledger-labs/fabric-token-sdk/docs/core/extension/zkatdlog/nogh/v2/setup"
1415
"github.com/hyperledger-labs/fabric-token-sdk/token/core"
1516
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common"
@@ -36,7 +37,7 @@ type Driver struct {
3637
tracerProvider trace.TracerProvider
3738
configService *config.Service
3839
storageProvider identity.StorageProvider
39-
identityProvider endpoint.IdentityService
40+
identityProvider *id.Provider
4041
endpointService *endpoint.Service
4142
networkProvider *network.Provider
4243
vaultProvider *vault.Provider
@@ -47,7 +48,7 @@ func NewDriver(
4748
tracerProvider trace.TracerProvider,
4849
configService *config.Service,
4950
storageProvider identity.StorageProvider,
50-
identityProvider endpoint.IdentityService,
51+
identityProvider *id.Provider,
5152
endpointService *endpoint.Service,
5253
networkProvider *network.Provider,
5354
vaultProvider *vault.Provider,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/gin-gonic/gin v1.10.0
1414
github.com/gobuffalo/packr/v2 v2.7.1
1515
github.com/hashicorp/go-uuid v1.0.3
16-
github.com/hyperledger-labs/fabric-smart-client v0.5.1
16+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39
1717
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0
1818
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5
1919
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
10711071
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
10721072
github.com/hyperledger-labs/SmartBFT v0.0.0-20250503203013-eb005eef8866 h1:Mu/6NJsfl9g3wM15Ue7hqPq4LtgYDoABh8MO4u8aW4g=
10731073
github.com/hyperledger-labs/SmartBFT v0.0.0-20250503203013-eb005eef8866/go.mod h1:9aNHNXsCVy/leGz2gpTC1eOL5QecxbSAGjqsLh4T1LM=
1074-
github.com/hyperledger-labs/fabric-smart-client v0.5.1 h1:NqZUToc+qkHscJNV7bQ4PpEqAqVcYuzpqDbziDXDoAc=
1075-
github.com/hyperledger-labs/fabric-smart-client v0.5.1/go.mod h1:ZL/HRmn79GeECtuQuc0rP5uzBAMyTzDKUbsUMMEuFW0=
1074+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39 h1:Dt5k7Zh7DNyVczaPBDNJnsGDGkSJGFQk2lYOcyD1QRE=
1075+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39/go.mod h1:ZL/HRmn79GeECtuQuc0rP5uzBAMyTzDKUbsUMMEuFW0=
10761076
github.com/hyperledger/aries-bbs-go v0.0.0-20240528084656-761671ea73bc h1:3Ykk6MtyfnlzMOQry9zkxsoLWpCWZwDPqehO/BJwArM=
10771077
github.com/hyperledger/aries-bbs-go v0.0.0-20240528084656-761671ea73bc/go.mod h1:Kofn6A6WWea1ZM8Rys5aBW9dszwJ7Ywa0kyyYL0TPYw=
10781078
github.com/hyperledger/fabric v1.4.0-rc1.0.20250510200036-435a7f1a780a h1:l9dE3iuE+mKj7K8Tcx904cF8zJpaNQONh3GNZdXnnyc=

token/core/fabtoken/v1/driver/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1111
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
1212
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/endpoint"
13+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/id"
1314
"github.com/hyperledger-labs/fabric-token-sdk/token/core"
1415
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common"
1516
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
@@ -34,7 +35,7 @@ type Driver struct {
3435
tracerProvider trace.TracerProvider
3536
configService *config.Service
3637
storageProvider identity.StorageProvider
37-
identityProvider endpoint.IdentityService
38+
identityProvider *id.Provider
3839
endpointService *endpoint.Service
3940
networkProvider *network.Provider
4041
vaultProvider *vault.Provider
@@ -45,7 +46,7 @@ func NewDriver(
4546
tracerProvider trace.TracerProvider,
4647
configService *config.Service,
4748
storageProvider identity.StorageProvider,
48-
identityProvider endpoint.IdentityService,
49+
identityProvider *id.Provider,
4950
endpointService *endpoint.Service,
5051
networkProvider *network.Provider,
5152
vaultProvider *vault.Provider,

token/core/zkatdlog/nogh/v1/driver/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1111
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
1212
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/endpoint"
13+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/id"
1314
"github.com/hyperledger-labs/fabric-token-sdk/docs/core/extension/zkatdlog/nogh/v2/setup"
1415
"github.com/hyperledger-labs/fabric-token-sdk/token/core"
1516
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common"
@@ -36,7 +37,7 @@ type Driver struct {
3637
tracerProvider trace.TracerProvider
3738
configService *config.Service
3839
storageProvider identity.StorageProvider
39-
identityProvider endpoint.IdentityService
40+
identityProvider *id.Provider
4041
endpointService *endpoint.Service
4142
networkProvider *network.Provider
4243
vaultProvider *vault.Provider
@@ -47,7 +48,7 @@ func NewDriver(
4748
tracerProvider trace.TracerProvider,
4849
configService *config.Service,
4950
storageProvider identity.StorageProvider,
50-
identityProvider endpoint.IdentityService,
51+
identityProvider *id.Provider,
5152
endpointService *endpoint.Service,
5253
networkProvider *network.Provider,
5354
vaultProvider *vault.Provider,

token/services/config/configuration.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ SPDX-License-Identifier: Apache-2.0
77
package config
88

99
import (
10+
"fmt"
11+
1012
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1113
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/config"
14+
"github.com/hyperledger-labs/fabric-token-sdk/token"
1215
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
16+
"gopkg.in/yaml.v2"
17+
)
18+
19+
const (
20+
Network = "network"
21+
Channel = "channel"
22+
Namespace = "namespace"
1323
)
1424

1525
// Configuration is the configuration of a given configuration
@@ -70,3 +80,33 @@ func (m *Configuration) GetBool(key string) bool {
7080
func (m *Configuration) IsSet(key string) bool {
7181
return m.cp.IsSet(config.Join(TMSPath, m.keyID, key))
7282
}
83+
84+
// Serialize serializes this configuration with the respect to the passed tms ID
85+
func (m *Configuration) Serialize(tmsID token.TMSID) ([]byte, error) {
86+
keyID := fmt.Sprintf("%s%s%s", tmsID.Network, tmsID.Channel, tmsID.Namespace)
87+
keys := map[string]any{}
88+
if err := m.cp.UnmarshalKey(config.Join(TMSPath, m.keyID), &keys); err != nil {
89+
return nil, errors.Wrapf(err, "failed unmarshalling key [%s]", config.Join(TMSPath, m.keyID))
90+
}
91+
keys[Network] = tmsID.Network
92+
keys[Channel] = tmsID.Channel
93+
keys[Namespace] = tmsID.Namespace
94+
c := &TMSConfig{
95+
Token: TokenConfig{
96+
TMS: map[string]map[string]any{
97+
keyID: keys,
98+
},
99+
},
100+
}
101+
return yaml.Marshal(c)
102+
}
103+
104+
// TMSConfig is the TMS configuration
105+
type TMSConfig struct {
106+
Token TokenConfig `yaml:"token"`
107+
}
108+
109+
// TokenConfig is used to serialize a TMS configuration
110+
type TokenConfig struct {
111+
TMS map[string]map[string]any `yaml:"tms" mapstructure:"tms"`
112+
}

token/services/config/service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var (
2323
TMSPath = config.Join(RootKey, TMSKey)
2424
VersionPath = config.Join(RootKey, "version")
2525
EnabledPath = config.Join(RootKey, "enabled")
26+
27+
// ErrConfigurationNotFound is returned when a configuration is not found
28+
ErrConfigurationNotFound = errors.Errorf("configuration not found")
2629
)
2730

2831
type Provider interface {
@@ -110,7 +113,7 @@ func (m *Service) ConfigurationFor(network, channel, namespace string) (*Configu
110113
}
111114
}
112115

113-
return nil, errors.Errorf("no token-sdk configuration for network %s, channel %s, namespace %s", network, channel, namespace)
116+
return nil, errors.Wrapf(ErrConfigurationNotFound, "no token-sdk configuration for network [%s], channel [%s], namespace [%s]", network, channel, namespace)
114117
}
115118

116119
// Configurations returns all configuration configurations.

token/services/config/service_test.go

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

1313
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/config"
14+
"github.com/hyperledger-labs/fabric-token-sdk/token"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617
)
@@ -30,6 +31,17 @@ func TestConfigurations(t *testing.T) {
3031
require.NoError(t, err)
3132
require.NoError(t, service.AddConfiguration(raw))
3233
checkConfigurations(t, service, 3)
34+
35+
configs, err := service.Configurations()
36+
require.NoError(t, err)
37+
raw, err = configs[0].Serialize(token.TMSID{
38+
Network: "new_network",
39+
Channel: "new_channel",
40+
Namespace: "new_namespace",
41+
})
42+
require.NoError(t, err)
43+
require.NoError(t, service.AddConfiguration(raw))
44+
checkConfigurations(t, service, 4)
3345
}
3446

3547
func checkConfigurations(t *testing.T, service *Service, expectedTMSs int) {

token/services/identity/storage/kvs/hashicorp/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/docker/docker v28.0.2+incompatible
99
github.com/docker/go-connections v0.5.0
1010
github.com/hashicorp/vault/api v1.16.0
11-
github.com/hyperledger-labs/fabric-smart-client v0.5.1
11+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39
1212
github.com/hyperledger-labs/fabric-token-sdk v0.4.1-0.20250528165839-032fb9265504
1313
github.com/stretchr/testify v1.10.0
1414
)

token/services/identity/storage/kvs/hashicorp/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
130130
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
131131
github.com/hashicorp/vault/api v1.16.0 h1:nbEYGJiAPGzT9U4oWgaaB0g+Rj8E59QuHKyA5LhwQN4=
132132
github.com/hashicorp/vault/api v1.16.0/go.mod h1:KhuUhzOD8lDSk29AtzNjgAu2kxRA9jL9NAbkFlqvkBA=
133-
github.com/hyperledger-labs/fabric-smart-client v0.5.1 h1:NqZUToc+qkHscJNV7bQ4PpEqAqVcYuzpqDbziDXDoAc=
134-
github.com/hyperledger-labs/fabric-smart-client v0.5.1/go.mod h1:ZL/HRmn79GeECtuQuc0rP5uzBAMyTzDKUbsUMMEuFW0=
133+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39 h1:Dt5k7Zh7DNyVczaPBDNJnsGDGkSJGFQk2lYOcyD1QRE=
134+
github.com/hyperledger-labs/fabric-smart-client v0.5.2-0.20250907063034-a38672e98d39/go.mod h1:ZL/HRmn79GeECtuQuc0rP5uzBAMyTzDKUbsUMMEuFW0=
135135
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 h1:B1Nt8hKb//KvgGRprk0h1t4lCnwhE9/ryb1WqfZbV+M=
136136
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
137137
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5 h1:RPWTL5wxAb+xDOrsCU3QYZP65305F8v3PaOyzdbPVMU=

0 commit comments

Comments
 (0)