config

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const BatchPrefix = "batchTransactions"

BatchPrefix is a prefix for batched transactions

Variables

View Source
var (
	ErrAdminEmpty            = errors.New("'admin' address is empty")
	ErrIssuerEmpty           = errors.New("'issuer' address is empty")
	ErrFeeSetterEmpty        = errors.New("'fee-setter' address is empty")
	ErrFeeAddressSetterEmpty = errors.New("'fee-address-setter' address is empty")
)

positional args specific errors

View Source
var ErrCfgBytesEmpty = errors.New("config bytes is empty")

Functions

func Configure added in v0.0.3

func Configure(contract Configurator, rawCfg []byte) error

Configure sets up the contract configuration for the given ContractConfigurable instance.

This function attempts to perform the following steps: 1. If the ContractConfigurable instance implements the StubGetSetter interface, it sets the ChaincodeStub. 2. If the configuration bytes (cfgBytes) are nil, the function returns nil immediately. 3. It parses the configuration bytes into a ContractConfig instance. 4. If the ContractConfig instance has nil options, it initializes them. 5. It applies the parsed ContractConfig to the ContractConfigurable instance. 6. If the ContractConfigurable instance implements the TokenConfigurable interface, it parses and applies the TokenConfig. 7. If the ContractConfigurable instance implements the ExternalConfigurable interface, it applies the external configuration directly.

Parameters: - cc: The ContractConfigurable instance to be configured. - stub: The ChaincodeStubInterface instance used for the contract. - cfgBytes: A byte slice containing the configuration data.

Returns: - error: Returns an error if any step of the configuration process fails.

Example:

err := config.Configure(myContract, myStub, configBytes)
if err != nil {
    log.Fatalf("Failed to configure contract: %v", err)
}

func FromArgsWithAdmin

func FromArgsWithAdmin(symbol string, args []string) (*proto.Config, error)

FromArgsWithAdmin configures the proto.Config with an admin address. Args: [platformSKI (deprecated), robotSKI, adminAddress]

func FromArgsWithIssuerAndAdmin

func FromArgsWithIssuerAndAdmin(symbol string, args []string) (*proto.Config, error)

FromArgsWithIssuerAndAdmin configures the proto.Config with an issuer and admin address. Args: [platformSKI (deprecated), robotSKI, issuerAddress, adminAddress]

func FromArgsWithIssuerAndFeeSetter

func FromArgsWithIssuerAndFeeSetter(symbol string, args []string) (*proto.Config, error)

FromArgsWithIssuerAndFeeSetter configures the proto.Config with an issuer and fee setter address. Args: [platformSKI (deprecated), robotSKI, issuerAddress, feeSetter]

func FromArgsWithIssuerFeeSetterAndFeeAddressSetter

func FromArgsWithIssuerFeeSetterAndFeeAddressSetter(symbol string, args []string) (*proto.Config, error)

FromArgsWithIssuerFeeSetterAndFeeAddressSetter configures the proto.Config with an issuer, fee setter, and fee admin setter address. Args: [platformSKI (deprecated), robotSKI, issuerAddress, feeSetter, feeAddressSetter]

func FromBytes

func FromBytes(cfgBytes []byte) (*proto.Config, error)

FromBytes parses the provided byte slice containing JSON-encoded configuration and returns a pointer to a proto.Config struct.

func FromInitArgs deprecated

func FromInitArgs(channel string, args []string) ([]byte, error)

Deprecated: added only for backward compatibility. FromInitArgs parses positional initialization arguments and generates JSON-config of []byte type. Accepts the channel name (chaincode) and the list of positional initialization parameters. Only needed to maintain backward compatibility. Marked for deletion after all deploy tools will be switched to JSON-config initialization of chaincodes.

func IsJSON

func IsJSON(args []string) bool

IsJSON checks if the provided arguments represent a valid JSON configuration.

The function returns true if there is exactly one argument in the initialization args slice, and if the content of that argument is a valid JSON.

func Load

func Load(stub shim.ChaincodeStubInterface) ([]byte, error)

Load retrieves and returns the raw configuration data from the state using the provided State interface.

The function returns the configuration data as a byte slice and nil error if successful.

If there is an error while loading the data from the state, an error is returned with additional information about the error.

If the retrieved configuration data is empty, the function returns an ErrCfgBytesEmpty error.

func Save

func Save(stub shim.ChaincodeStubInterface, cfgBytes []byte) error

Save saves configuration data to the state using the provided State interface.

If the provided cfgBytes slice is empty, the function returns an ErrCfgBytesEmpty error.

If there is an error while saving the data to the state, an error is returned with additional information about the error.

func Validate added in v0.0.3

func Validate(contract Configurator, rawCfg []byte) error

Validate validates the contract configuration for the given ContractConfigurable instance.

This function attempts to perform the following steps: 1. If the contract implements the Configurator interface, it validates the contract configuration. 2. If the contract implements the TokenConfigurator interface, it validates the token configuration. 3. If the contract implements the ExternalConfigurator interface, it validates the external configuration.

Parameters: - contract: The Base instance to be validated. - rawCfg: A byte slice containing the configuration data.

Returns: - error: Returns an error if any step of the validation process fails.

Example:

err := contract.Validate(myContract, configBytes)
if err != nil {
    log.Fatalf("Failed to validate contract: %v", err)
}

Types

type ConfigMapper added in v0.0.3

type ConfigMapper interface {
	// MapConfig maps the provided arguments to a proto.Config instance.
	MapConfig(args []string) (*proto.Config, error)
}

ConfigMapper defines a method for mapping Init arguments to a Config instance.

type ConfigMapperFunc added in v0.0.3

type ConfigMapperFunc func(args []string) (*proto.Config, error)

ConfigMapperFunc is a function type that implements the ConfigMapper interface.

func (ConfigMapperFunc) MapConfig added in v0.0.3

func (c ConfigMapperFunc) MapConfig(args []string) (*proto.Config, error)

MapConfig calls the underlying function to map the provided arguments to a proto.Config instance.

type Configurator added in v0.0.3

type Configurator interface {
	// ValidateConfig validates the provided contract configuration data.
	ValidateConfig(config []byte) error

	// ApplyContractConfig applies the provided contract configuration.
	ApplyContractConfig(config *proto.ContractConfig) error

	// ContractConfig retrieves the current contract configuration.
	ContractConfig() *proto.ContractConfig
}

Configurator defines methods for validating, applying, and retrieving contract configuration.

type ExternalConfigurator added in v0.0.3

type ExternalConfigurator interface {
	// ValidateExtConfig validates the provided external configuration data.
	ValidateExtConfig(cfgBytes []byte) error

	// ApplyExtConfig applies the provided external configuration to the chaincode.
	ApplyExtConfig(cfgBytes []byte) error
}

ExternalConfigurator defines methods for validating and applying external configuration.

type TokenConfigurator added in v0.0.3

type TokenConfigurator interface {
	// ValidateTokenConfig validates the provided token configuration data.
	ValidateTokenConfig(config []byte) error

	// ApplyTokenConfig applies the provided token configuration.
	ApplyTokenConfig(config *proto.TokenConfig) error

	// TokenConfig retrieves the current token configuration.
	TokenConfig() *proto.TokenConfig
}

TokenConfigurator defines methods for validating, applying, and retrieving token configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL