@@ -7,9 +7,19 @@ SPDX-License-Identifier: Apache-2.0
77package config
88
99import (
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 {
7080func (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+ }
0 commit comments