Documentation ¶
Index ¶
- func Configure(contract Base, stub shim.ChaincodeStubInterface, rawCfg []byte) error
- func ValidateConfig(contract Base, rawCfg []byte) error
- type Base
- type ConfigMapper
- type ConfigMapperFunc
- type Configurator
- type ExternalConfigurator
- type Function
- type Method
- type MethodType
- type Router
- type StubGetSetter
- type TokenConfigurator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure(contract Base, stub shim.ChaincodeStubInterface, 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 := contract.Configure(myContract, myStub, configBytes) if err != nil { log.Fatalf("Failed to configure contract: %v", err) }
func ValidateConfig ¶
ValidateConfig 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.ValidateConfig(myContract, configBytes) if err != nil { log.Fatalf("Failed to validate contract: %v", err) }
Types ¶
type Base ¶
type Base interface { ID() string // ID retrieves the unique identifier for the contract. Configurator StubGetSetter }
Base is the minimal interface required for a contract to execute within the system.
type ConfigMapper ¶
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 ¶
ConfigMapperFunc is a function type that implements the ConfigMapper interface.
type Configurator ¶
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 ¶
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 Method ¶
type Method struct { Type MethodType // The type of the method. ChaincodeFunc Function // The name of the chaincode function being called. MethodName string // The actual method name to be invoked. RequiresAuth bool // Indicates if the method requires authentication. ReturnsError bool // Indicates if the method returns an error. NumArgs int // Number of arguments the method takes (excluding the receiver). NumReturns int // Number of return values the method has. }
Method represents an endpoint of a contract.
type MethodType ¶
type MethodType int
MethodType represents the type of a method in the contract.
const ( MethodTypeTransaction MethodType = iota // Tx-prefixed transaction when using reflectx.Router. MethodTypeInvoke // NBTx-prefixed transaction when using reflectx.Router. MethodTypeQuery // Query-prefixed transaction when using reflectx.Router. )
Constants representing the different types of methods.
type Router ¶
type Router interface { // Check validates the provided arguments for the specified method. // It returns an error if the validation fails. Check(method string, args ...string) error // Invoke calls the specified method with the provided arguments. // It returns a slice of return values and an error if the invocation fails. Invoke(method string, args ...string) ([]any, error) // Methods retrieves a map of all available methods, keyed by their chaincode function names. Methods() map[Function]Method }
Router defines the interface for managing contract methods and routing calls.
type StubGetSetter ¶
type StubGetSetter interface { // GetStub retrieves the current ChaincodeStubInterface. GetStub() shim.ChaincodeStubInterface // SetStub sets the provided ChaincodeStubInterface. SetStub(shim.ChaincodeStubInterface) }
StubGetSetter defines methods for getting and setting the ChaincodeStubInterface.
type TokenConfigurator ¶
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.