Documentation ¶
Index ¶
- Constants
- Variables
- func AddDocs(stub shim.ChaincodeStubInterface, rawDocs string) error
- func CheckSign(stub shim.ChaincodeStubInterface, fn string, args []string, auth []string) (*types.Address, string, error)
- func DeleteDoc(stub shim.ChaincodeStubInterface, docID string) error
- func Logger() *logging.Logger
- type BaseContract
- func (bc *BaseContract) AllowedBalanceAdd(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) AllowedBalanceBurnLocked(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) AllowedBalanceGet(token string, address *types.Address) (*big.Int, error)
- func (bc *BaseContract) AllowedBalanceGetAll(address *types.Address) (map[string]string, error)
- func (bc *BaseContract) AllowedBalanceLock(token string, address *types.Address, amount *big.Int) error
- func (bc *BaseContract) AllowedBalanceSub(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) AllowedBalanceTransfer(token string, from *types.Address, to *types.Address, amount *big.Int, ...) error
- func (bc *BaseContract) AllowedBalanceTransferLocked(token string, from *types.Address, to *types.Address, amount *big.Int, ...) error
- func (bc *BaseContract) AllowedBalanceUnLock(token string, address *types.Address, amount *big.Int) error
- func (bc *BaseContract) AllowedIndustrialBalanceAdd(address *types.Address, industrialAssets []*pb.Asset, reason string) error
- func (bc *BaseContract) AllowedIndustrialBalanceSub(address *types.Address, industrialAssets []*pb.Asset, reason string) error
- func (bc *BaseContract) AllowedIndustrialBalanceTransfer(from *types.Address, to *types.Address, industrialAssets []*pb.Asset, ...) error
- func (bc *BaseContract) ApplyContractConfig(config *pb.ContractConfig) error
- func (bc *BaseContract) ContractConfig() *pb.ContractConfig
- func (bc *BaseContract) GetID() string
- func (bc *BaseContract) GetMethods(bci BaseContractInterface) []string
- func (bc *BaseContract) GetStub() shim.ChaincodeStubInterface
- func (bc *BaseContract) GetTraceContext() telemetry.TraceContext
- func (bc *BaseContract) IndustrialBalanceAdd(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) IndustrialBalanceBurnLocked(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) IndustrialBalanceGet(address *types.Address) (map[string]string, error)
- func (bc *BaseContract) IndustrialBalanceGetLocked(address *types.Address) (map[string]string, error)
- func (bc *BaseContract) IndustrialBalanceLock(token string, address *types.Address, amount *big.Int) error
- func (bc *BaseContract) IndustrialBalanceSub(token string, address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) IndustrialBalanceTransfer(token string, from *types.Address, to *types.Address, amount *big.Int, ...) error
- func (bc *BaseContract) IndustrialBalanceTransferLocked(token string, from *types.Address, to *types.Address, amount *big.Int, ...) error
- func (bc *BaseContract) IndustrialBalanceUnLock(token string, address *types.Address, amount *big.Int) error
- func (bc *BaseContract) NBTxCommitCCTransferFrom(id string) error
- func (bc *BaseContract) NBTxDeleteCCTransferFrom(id string) error
- func (bc *BaseContract) NBTxDeleteCCTransferTo(id string) error
- func (bc *BaseContract) NBTxHealthCheckNb(_ *types.Sender) error
- func (bc *BaseContract) QueryBuildInfo() (*debug.BuildInfo, error)
- func (bc *BaseContract) QueryChannelTransferFrom(id string) (*pb.CCTransfer, error)
- func (bc *BaseContract) QueryChannelTransferTo(id string) (*pb.CCTransfer, error)
- func (bc *BaseContract) QueryChannelTransfersFrom(pageSize int64, bookmark string) (*pb.CCTransfers, error)
- func (bc *BaseContract) QueryCoreChaincodeIDName() (string, error)
- func (bc *BaseContract) QueryGetLockedAllowedBalance(lockID string) (*proto.AllowedBalanceLock, error)
- func (bc *BaseContract) QueryGetLockedTokenBalance(lockID string) (*proto.TokenBalanceLock, error)
- func (bc *BaseContract) QueryGetNonce(owner *types.Address) (string, error)
- func (bc *BaseContract) QueryGroupBalanceOf(address *types.Address) (map[string]string, error)
- func (bc *BaseContract) QueryMultiSwapGet(swapID string) (*proto.MultiSwap, error)
- func (bc *BaseContract) QueryNameOfFiles() ([]string, error)
- func (bc *BaseContract) QuerySrcFile(name string) (string, error)
- func (bc *BaseContract) QuerySrcPartFile(name string, start int, end int) (string, error)
- func (bc *BaseContract) QuerySwapGet(swapID string) (*proto.Swap, error)
- func (bc *BaseContract) QuerySystemEnv() (map[string]string, error)
- func (bc *BaseContract) TokenBalanceAdd(address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) TokenBalanceAddWithTicker(address *types.Address, amount *big.Int, ticker string, reason string) error
- func (bc *BaseContract) TokenBalanceBurnLocked(address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) TokenBalanceGet(address *types.Address) (*big.Int, error)
- func (bc *BaseContract) TokenBalanceGetLocked(address *types.Address) (*big.Int, error)
- func (bc *BaseContract) TokenBalanceLock(address *types.Address, amount *big.Int) error
- func (bc *BaseContract) TokenBalanceSub(address *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) TokenBalanceSubWithTicker(address *types.Address, amount *big.Int, ticker string, reason string) error
- func (bc *BaseContract) TokenBalanceTransfer(from *types.Address, to *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) TokenBalanceTransferLocked(from *types.Address, to *types.Address, amount *big.Int, reason string) error
- func (bc *BaseContract) TokenBalanceUnlock(address *types.Address, amount *big.Int) error
- func (bc *BaseContract) TracingHandler() *telemetry.TracingHandler
- func (bc *BaseContract) TxCancelCCTransferFrom(id string) error
- func (bc *BaseContract) TxChannelTransferByAdmin(sender *types.Sender, idTransfer string, to string, idUser *types.Address, ...) (string, error)
- func (bc *BaseContract) TxChannelTransferByCustomer(sender *types.Sender, idTransfer string, to string, token string, ...) (string, error)
- func (bc *BaseContract) TxCreateCCTransferTo(dataIn string) (string, error)
- func (bc *BaseContract) TxHealthCheck(_ *types.Sender) error
- func (bc *BaseContract) TxLockAllowedBalance(sender *types.Sender, req *proto.BalanceLockRequest) error
- func (bc *BaseContract) TxLockTokenBalance(sender *types.Sender, req *proto.BalanceLockRequest) error
- func (bc *BaseContract) TxMultiSwapBegin(sender *types.Sender, token string, multiSwapAssets types.MultiSwapAssets, ...) (string, error)
- func (bc *BaseContract) TxMultiSwapCancel(sender *types.Sender, swapID string) error
- func (bc *BaseContract) TxSwapBegin(sender *types.Sender, token string, contractTo string, amount *big.Int, ...) (string, error)
- func (bc *BaseContract) TxSwapCancel(_ *types.Sender, swapID string) error
- func (bc *BaseContract) TxUnlockAllowedBalance(sender *types.Sender, req *proto.BalanceLockRequest) error
- func (bc *BaseContract) TxUnlockTokenBalance(sender *types.Sender, req *proto.BalanceLockRequest) error
- func (bc *BaseContract) ValidateConfig(config []byte) error
- type BaseContractInterface
- type ChainCode
- func (cc *ChainCode) BatchHandler(traceCtx telemetry.TraceContext, stub shim.ChaincodeStubInterface, ...) peer.Response
- func (cc *ChainCode) Init(stub shim.ChaincodeStubInterface) peer.Response
- func (cc *ChainCode) Invoke(stub shim.ChaincodeStubInterface) (r peer.Response)
- func (cc *ChainCode) Start() error
- func (cc *ChainCode) ValidateTxID(stub shim.ChaincodeStubInterface) error
- type ChaincodeOption
- type ContractConfigurable
- type ContractMethods
- type Doc
- type ExternalConfigurable
- type Fn
- type In
- type TLS
- type TokenConfigurable
- type TxResponse
Constants ¶
const ( // CreateFrom - Channel transference creation From CreateFrom typeOperation = iota // CreateTo - Channel transference creation To CreateTo // CancelFrom - cancellation in the From CancelFrom )
const ( CreateIndex = "createIndex" SetIndexCreatedFlag = "setIndexCreatedFlag" BatchExecute = "batchExecute" SwapDone = "swapDone" MultiSwapDone = "multiSwapDone" CreateCCTransferTo = "createCCTransferTo" DeleteCCTransferTo = "deleteCCTransferTo" CommitCCTransferFrom = "commitCCTransferFrom" CancelCCTransferFrom = "cancelCCTransferFrom" DeleteCCTransferFrom = "deleteCCTransferFrom" )
const ( // BalanceTokenLockedEvent - event on token balance locked BalanceTokenLockedEvent = "BalanceTokenLocked" // BalanceTokenUnlockedEvent - event on token balance unlocked BalanceTokenUnlockedEvent = "BalanceTokenUnlocked" // BalanceAllowedLockedEvent - event on allowed balance locked BalanceAllowedLockedEvent = "BalanceAllowedLocked" // BalanceAllowedUnlockedEvent - event on allowed balance unlocked BalanceAllowedUnlockedEvent = "BalanceAllowedUnlocked" )
const DocsKey = "documents"
DocsKey is a key for documents
const (
// ErrMethodNotImplemented is the error message for not implemented methods
ErrMethodNotImplemented = "method is not implemented for query"
)
const (
LenTimeInMilliseconds = 13
)
const StateKeyNonce byte = 42 // hex: 2a
Variables ¶
var ( ErrSwapDisabled = errors.New("swap is disabled") ErrMultiSwapDisabled = errors.New("multi-swap is disabled") )
var ( // ErrBigIntFromString - error on big int from string ErrBigIntFromString = errors.New("big int from string") // ErrPlatformAdminOnly - error on platform admin only ErrPlatformAdminOnly = errors.New("platform admin only") // ErrEmptyLockID - error on empty lock id ErrEmptyLockID = errors.New("empty lock id") // ErrReason - error on reason ErrReason = errors.New("empty reason") // ErrLockNotExists - error on lock not exists ErrLockNotExists = errors.New("lock not exists") // ErrAddressRequired - error on address required ErrAddressRequired = errors.New("address required") // ErrAmountRequired - error on amount required ErrAmountRequired = errors.New("amount required") // ErrTokenTickerRequired - error on token ticker required ErrTokenTickerRequired = errors.New("token ticker required") // ErrAlreadyExist - error on already exist ErrAlreadyExist = errors.New("lock already exist") // ErrInsufficientFunds - error on insufficient funds ErrInsufficientFunds = errors.New("insufficient balance") ErrAdminNotSet = errors.New("admin is not set in contract config") )
var ErrMethodAlreadyDefined = errors.New("pure method has already defined")
Functions ¶
func AddDocs ¶
func AddDocs(stub shim.ChaincodeStubInterface, rawDocs string) error
AddDocs adds documents to the ledger
func CheckSign ¶
func CheckSign( stub shim.ChaincodeStubInterface, fn string, args []string, auth []string, ) (*types.Address, string, error)
CheckSign exists fo backward compatibility
Types ¶
type BaseContract ¶
type BaseContract struct {
// contains filtered or unexported fields
}
BaseContract is a base contract for all contracts
func (*BaseContract) AllowedBalanceAdd ¶
func (*BaseContract) AllowedBalanceBurnLocked ¶
func (*BaseContract) AllowedBalanceGet ¶
func (*BaseContract) AllowedBalanceGetAll ¶
func (*BaseContract) AllowedBalanceLock ¶
func (*BaseContract) AllowedBalanceSub ¶
func (*BaseContract) AllowedBalanceTransfer ¶
func (*BaseContract) AllowedBalanceTransferLocked ¶
func (*BaseContract) AllowedBalanceUnLock ¶
func (*BaseContract) AllowedIndustrialBalanceAdd ¶
func (*BaseContract) AllowedIndustrialBalanceSub ¶
func (*BaseContract) AllowedIndustrialBalanceTransfer ¶
func (*BaseContract) ApplyContractConfig ¶
func (bc *BaseContract) ApplyContractConfig(config *pb.ContractConfig) error
func (*BaseContract) ContractConfig ¶
func (bc *BaseContract) ContractConfig() *pb.ContractConfig
func (*BaseContract) GetID ¶
func (bc *BaseContract) GetID() string
func (*BaseContract) GetMethods ¶
func (bc *BaseContract) GetMethods(bci BaseContractInterface) []string
GetMethods returns list of methods
func (*BaseContract) GetStub ¶
func (bc *BaseContract) GetStub() shim.ChaincodeStubInterface
GetStub returns stub
func (*BaseContract) GetTraceContext ¶
func (bc *BaseContract) GetTraceContext() telemetry.TraceContext
GetTraceContext returns trace context. Using for call methods only
func (*BaseContract) IndustrialBalanceAdd ¶
func (*BaseContract) IndustrialBalanceBurnLocked ¶
func (*BaseContract) IndustrialBalanceGet ¶
func (*BaseContract) IndustrialBalanceGetLocked ¶
func (*BaseContract) IndustrialBalanceLock ¶
func (*BaseContract) IndustrialBalanceSub ¶
func (*BaseContract) IndustrialBalanceTransfer ¶
func (*BaseContract) IndustrialBalanceTransferLocked ¶
func (*BaseContract) IndustrialBalanceUnLock ¶
func (*BaseContract) NBTxCommitCCTransferFrom ¶
func (bc *BaseContract) NBTxCommitCCTransferFrom(id string) error
NBTxCommitCCTransferFrom - transaction writes the commit flag in the transfer in the From channel. Executed after successful creation of a mating part in the channel To (TxCreateCCTransferTo) This transaction is sent only by the channel-transfer service with a "robot" certificate
func (*BaseContract) NBTxDeleteCCTransferFrom ¶
func (bc *BaseContract) NBTxDeleteCCTransferFrom(id string) error
NBTxDeleteCCTransferFrom - transaction deletes the transfer record in the channel From. Performed after successful removal in the canal To (NBTxDeleteCCTransferTo) This transaction is sent only by the channel-transfer service with a "robot" certificate
func (*BaseContract) NBTxDeleteCCTransferTo ¶
func (bc *BaseContract) NBTxDeleteCCTransferTo(id string) error
NBTxDeleteCCTransferTo - transaction deletes transfer record in channel To. Executed after a successful commit in the From channel (NBTxCommitCCTransferFrom) This transaction is sent only by the channel-transfer service with a "robot" certificate
func (*BaseContract) NBTxHealthCheckNb ¶
func (bc *BaseContract) NBTxHealthCheckNb(_ *types.Sender) error
NBTxHealthCheckNb - the same but not batched
func (*BaseContract) QueryBuildInfo ¶
func (bc *BaseContract) QueryBuildInfo() (*debug.BuildInfo, error)
QueryBuildInfo returns debug.BuildInfo struct with build information, stored in binary file or error if it is occurs
func (*BaseContract) QueryChannelTransferFrom ¶
func (bc *BaseContract) QueryChannelTransferFrom(id string) (*pb.CCTransfer, error)
QueryChannelTransferFrom - receiving a transfer record from the channel From
func (*BaseContract) QueryChannelTransferTo ¶
func (bc *BaseContract) QueryChannelTransferTo(id string) (*pb.CCTransfer, error)
QueryChannelTransferTo - receiving a transfer record from the channel To
func (*BaseContract) QueryChannelTransfersFrom ¶
func (bc *BaseContract) QueryChannelTransfersFrom(pageSize int64, bookmark string) (*pb.CCTransfers, error)
QueryChannelTransfersFrom - getting all transfer records from the channel From You can receive them in parts (chunks)
func (*BaseContract) QueryCoreChaincodeIDName ¶
func (bc *BaseContract) QueryCoreChaincodeIDName() (string, error)
QueryCoreChaincodeIDName returns CORE_CHAINCODE_ID_NAME
func (*BaseContract) QueryGetLockedAllowedBalance ¶
func (bc *BaseContract) QueryGetLockedAllowedBalance( lockID string, ) (*proto.AllowedBalanceLock, error)
QueryGetLockedAllowedBalance - returns the existing blocking of the allowedbalance AllowedBalanceLock
func (*BaseContract) QueryGetLockedTokenBalance ¶
func (bc *BaseContract) QueryGetLockedTokenBalance( lockID string, ) (*proto.TokenBalanceLock, error)
QueryGetLockedTokenBalance - returns an existing balance token lock TokenBalanceLock
func (*BaseContract) QueryGetNonce ¶
func (bc *BaseContract) QueryGetNonce(owner *types.Address) (string, error)
func (*BaseContract) QueryGroupBalanceOf ¶
QueryGroupBalanceOf - returns balance of the token for user address
func (*BaseContract) QueryMultiSwapGet ¶
func (bc *BaseContract) QueryMultiSwapGet(swapID string) (*proto.MultiSwap, error)
QueryMultiSwapGet - returns multiswap by id
func (*BaseContract) QueryNameOfFiles ¶
func (bc *BaseContract) QueryNameOfFiles() ([]string, error)
QueryNameOfFiles returns list path/name of embed files
func (*BaseContract) QuerySrcFile ¶
func (bc *BaseContract) QuerySrcFile(name string) (string, error)
QuerySrcFile returns file
func (*BaseContract) QuerySrcPartFile ¶
QuerySrcPartFile returns part of file start - include end - exclude
func (*BaseContract) QuerySwapGet ¶
func (bc *BaseContract) QuerySwapGet(swapID string) (*proto.Swap, error)
QuerySwapGet returns swap by id
func (*BaseContract) QuerySystemEnv ¶
func (bc *BaseContract) QuerySystemEnv() (map[string]string, error)
QuerySystemEnv returns system environment
func (*BaseContract) TokenBalanceAdd ¶
func (*BaseContract) TokenBalanceAddWithTicker ¶
func (bc *BaseContract) TokenBalanceAddWithTicker( address *types.Address, amount *big.Int, ticker string, reason string, ) error
TokenBalanceAddWithTicker adds a specified amount of tokens to an account's balance while recording the transaction in the ledger.
Parameters: - address: The address of the account to add tokens to. - amount: The amount of tokens to add. - ticker: The token ticker symbol, e.g., OTF, FIAT, CURUSD, FRA_<barID>, BA_<barID>. - reason: The reason for adding tokens.
Returns: - An error if the operation fails.
func (*BaseContract) TokenBalanceBurnLocked ¶
func (*BaseContract) TokenBalanceGet ¶
func (*BaseContract) TokenBalanceGetLocked ¶
func (*BaseContract) TokenBalanceLock ¶
func (*BaseContract) TokenBalanceSub ¶
func (*BaseContract) TokenBalanceSubWithTicker ¶
func (bc *BaseContract) TokenBalanceSubWithTicker( address *types.Address, amount *big.Int, ticker string, reason string, ) error
TokenBalanceSubWithTicker subtracts a specified amount of tokens from an account's balance with accounting for different tickers. It records the transaction in the ledger.
Parameters: - address: The address of the account to subtract tokens from. - amount: The amount of tokens to subtract. - ticker: The token ticker symbol, e.g., OTF, FIAT, CURUSD, FRA_<barID>, BA_<barID>. - reason: The reason for subtracting tokens.
Returns: - An error if the operation fails.
func (*BaseContract) TokenBalanceTransfer ¶
func (*BaseContract) TokenBalanceTransferLocked ¶
func (*BaseContract) TokenBalanceUnlock ¶
func (*BaseContract) TracingHandler ¶
func (bc *BaseContract) TracingHandler() *telemetry.TracingHandler
TracingHandler returns base contract tracingHandler
func (*BaseContract) TxCancelCCTransferFrom ¶
func (bc *BaseContract) TxCancelCCTransferFrom(id string) error
TxCancelCCTransferFrom - transaction cancels (deletes) the transfer record in the From channel returns balances to the user. If the service cannot create a response part in the "To" channel within some timeout, it is required to cancel the transfer. After TxChannelTransferByAdmin or TxChannelTransferByCustomer This transaction is sent only by the channel-transfer service with a "robot" certificate
func (*BaseContract) TxChannelTransferByAdmin ¶
func (bc *BaseContract) TxChannelTransferByAdmin( sender *types.Sender, idTransfer string, to string, idUser *types.Address, token string, amount *big.Int, ) (string, error)
TxChannelTransferByAdmin - transaction initiating transfer between channels. Signed by the channel admin (site). The tokens are transferred from idUser to the same user. After the checks, a transfer record is created and the user's balances are reduced.
func (*BaseContract) TxChannelTransferByCustomer ¶
func (bc *BaseContract) TxChannelTransferByCustomer( sender *types.Sender, idTransfer string, to string, token string, amount *big.Int, ) (string, error)
TxChannelTransferByCustomer - transaction initiating transfer between channels. The owner of tokens signs. Tokens are transferred to themselveselves. After the checks, a transfer record is created and the user's balances are reduced.
func (*BaseContract) TxCreateCCTransferTo ¶
func (bc *BaseContract) TxCreateCCTransferTo(dataIn string) (string, error)
TxCreateCCTransferTo - transaction creates a transfer (already with commit sign) in the channel To and increases the user's balances. The transaction must be executed after the initiating transfer transaction (TxChannelTransferByAdmin or TxChannelTransferByCustomer). This transaction is sent only by the channel-transfer service with a "robot" certificate
func (*BaseContract) TxHealthCheck ¶
func (bc *BaseContract) TxHealthCheck(_ *types.Sender) error
TxHealthCheck can be called by an administrator of the contract for checking if the business logic of the chaincode is still alive.
func (*BaseContract) TxLockAllowedBalance ¶
func (bc *BaseContract) TxLockAllowedBalance( sender *types.Sender, req *proto.BalanceLockRequest, ) error
TxLockAllowedBalance - blocks tokens on the user's allowedbalance method calls the chaincode admin, the input is a BalanceLockRequest
func (*BaseContract) TxLockTokenBalance ¶
func (bc *BaseContract) TxLockTokenBalance( sender *types.Sender, req *proto.BalanceLockRequest, ) error
TxLockTokenBalance - blocks tokens on the user's token balance method is called by the chaincode admin, the input is BalanceLockRequest
func (*BaseContract) TxMultiSwapBegin ¶
func (bc *BaseContract) TxMultiSwapBegin(sender *types.Sender, token string, multiSwapAssets types.MultiSwapAssets, contractTo string, hash types.Hex) (string, error)
TxMultiSwapBegin - creates multiswap
func (*BaseContract) TxMultiSwapCancel ¶
func (bc *BaseContract) TxMultiSwapCancel(sender *types.Sender, swapID string) error
TxMultiSwapCancel - cancels multiswap
func (*BaseContract) TxSwapBegin ¶
func (bc *BaseContract) TxSwapBegin( sender *types.Sender, token string, contractTo string, amount *big.Int, hash types.Hex, ) (string, error)
TxSwapBegin creates swap
func (*BaseContract) TxSwapCancel ¶
func (bc *BaseContract) TxSwapCancel(_ *types.Sender, swapID string) error
TxSwapCancel cancels swap
func (*BaseContract) TxUnlockAllowedBalance ¶
func (bc *BaseContract) TxUnlockAllowedBalance( sender *types.Sender, req *proto.BalanceLockRequest, ) error
TxUnlockAllowedBalance - unblocks (fully or partially) tokens on the user's allowedbalance method calls the chaincode admin, the input is a BalanceLockRequest
func (*BaseContract) TxUnlockTokenBalance ¶
func (bc *BaseContract) TxUnlockTokenBalance( sender *types.Sender, req *proto.BalanceLockRequest, ) error
TxUnlockTokenBalance - unblocks (fully or partially) tokens on the user's token balance method is called by the chaincode admin, the input is BalanceLockRequest
func (*BaseContract) ValidateConfig ¶
func (bc *BaseContract) ValidateConfig(config []byte) error
type BaseContractInterface ¶
type BaseContractInterface interface { GetStub() shim.ChaincodeStubInterface GetID() string TokenBalanceTransfer(from *types.Address, to *types.Address, amount *big.Int, reason string) error AllowedBalanceTransfer(token string, from *types.Address, to *types.Address, amount *big.Int, reason string) error TokenBalanceGet(address *types.Address) (*big.Int, error) TokenBalanceAdd(address *types.Address, amount *big.Int, reason string) error TokenBalanceSub(address *types.Address, amount *big.Int, reason string) error TokenBalanceAddWithTicker(address *types.Address, amount *big.Int, ticker string, reason string) error TokenBalanceSubWithTicker(address *types.Address, amount *big.Int, ticker string, reason string) error AllowedBalanceGet(token string, address *types.Address) (*big.Int, error) AllowedBalanceAdd(token string, address *types.Address, amount *big.Int, reason string) error AllowedBalanceSub(token string, address *types.Address, amount *big.Int, reason string) error AllowedBalanceGetAll(address *types.Address) (map[string]string, error) IndustrialBalanceGet(address *types.Address) (map[string]string, error) IndustrialBalanceTransfer(token string, from *types.Address, to *types.Address, amount *big.Int, reason string) error IndustrialBalanceAdd(token string, address *types.Address, amount *big.Int, reason string) error IndustrialBalanceSub(token string, address *types.Address, amount *big.Int, reason string) error AllowedIndustrialBalanceAdd(address *types.Address, industrialAssets []*pb.Asset, reason string) error AllowedIndustrialBalanceSub(address *types.Address, industrialAssets []*pb.Asset, reason string) error AllowedIndustrialBalanceTransfer(from *types.Address, to *types.Address, industrialAssets []*pb.Asset, reason string) error GetTraceContext() telemetry.TraceContext TracingHandler() *telemetry.TracingHandler ContractConfigurable // contains filtered or unexported methods }
BaseContractInterface represents BaseContract interface
type ChainCode ¶
type ChainCode struct {
// contains filtered or unexported fields
}
ChainCode defines the structure for a chaincode instance, with methods, configuration, and options for transaction processing.
func NewCC ¶
func NewCC( cc BaseContractInterface, chOptions ...ChaincodeOption, ) (*ChainCode, error)
NewCC creates a new instance of ChainCode with the given contract interface and configurable options. It initializes the ChainCode instance with the provided BaseContractInterface and applies advanced configuration settings through a combination of ChaincodeOption functions and environmental variables.
The environmental variables are checked first to configure TLS settings, which takes precedence over the settings provided by the ChaincodeOption functions. The function will configure TLS if the respective environment variables contain the necessary information. These variables are:
- CHAINCODE_TLS_KEY or CHAINCODE_TLS_KEY_FILE: For the private key in PEM format or file path. - CHAINCODE_TLS_CERT or CHAINCODE_TLS_CERT_FILE: For the public key certificate in PEM format or file path. - CHAINCODE_TLS_CLIENT_CA_CERTS or CHAINCODE_TLS_CLIENT_CA_CERTS_FILE: For the client CA certificates in PEM format or file path.
If the environment variables do not provide the TLS configuration, the function will fall back to the configuration provided by ChaincodeOption functions, such as WithTLS or WithTLSFromFiles. If neither are provided, the TLS feature will remain disabled in the chaincode configuration.
Args: cc: The BaseContractInterface which encapsulates the contract logic that the ChainCode will execute.
options: ContractOptions is a pointer to the configuration settings that will be applied to the chaincode. The settings within options allow for fine-tuned control of the chaincode's behavior, such as transaction TTL, batching prefixes, and swap behavior. If this parameter is not needed, it can be omitted or set to nil.
chOptions: A variadic number of ChaincodeOption function types which are used to apply specific configurations to the chaincodeOptions structure. These options may include configurations that can be overridden by environmental variables, particularly for TLS.
Returns: A pointer to a ChainCode instance and an error. An error is non-nil if there is a failure in applying the provided ChaincodeOption functions, or if there is an issue with reading and processing the environmental variables for the TLS configuration.
Example usage:
tlsConfig := &core.TLS{ /* ... */ } cc, err := core.NewCC(contract, contractOptions, core.WithTLS(tlsConfig)) if err != nil { // Handle error }
In the above example, tlsConfig provided by WithTLS will be overridden if the corresponding environmental variables for TLS configuration are set.
func (*ChainCode) BatchHandler ¶
func (cc *ChainCode) BatchHandler( traceCtx telemetry.TraceContext, stub shim.ChaincodeStubInterface, funcName string, fn *Fn, args []string, ) peer.Response
BatchHandler handles the batching logic for chaincode invocations.
Args: stub: The shim.ChaincodeStubInterface containing the context of the call. funcName: The name of the chaincode function to be executed. fn: A pointer to the chaincode function to be executed. args: A slice of arguments to pass to the function.
Returns: - A success response if the batching is successful. - An error response if there is any failure in authentication, preparation, or saving to batch.
func (*ChainCode) Init ¶
func (cc *ChainCode) Init(stub shim.ChaincodeStubInterface) peer.Response
Init is called during chaincode instantiation to initialize any data. Note that upgrade also calls this function to reset or to migrate data.
Args: stub: The shim.ChaincodeStubInterface containing the context of the call.
Returns: - A success response if initialization succeeds. - An error response if it fails to get the creator or to initialize the chaincode.
func (*ChainCode) Invoke ¶
func (cc *ChainCode) Invoke(stub shim.ChaincodeStubInterface) (r peer.Response)
Invoke is called to update or query the ledger in a proposal transaction. Given the function name, it delegates the execution to the respective handler.
Args: stub: The shim.ChaincodeStubInterface containing the context of the call.
Returns: - A response from the executed handler. - An error response if any validations fail or the required method is not found.
func (*ChainCode) Start ¶
Start begins the chaincode execution based on the environment configuration. It decides whether to start the chaincode in the default mode or as a server based on the CHAINCODE_EXEC_MODE environment variable. In server mode, it requires the CHAINCODE_ID to be set and uses CHAINCODE_SERVER_PORT for the port or defaults to a predefined port if not set. It returns an error if the necessary environment variables are not set or if the chaincode fails to start.
func (*ChainCode) ValidateTxID ¶
func (cc *ChainCode) ValidateTxID(stub shim.ChaincodeStubInterface) error
ValidateTxID validates the transaction ID to ensure it is correctly formatted.
Args: stub: The shim.ChaincodeStubInterface to access the transaction ID.
Returns: - nil if the transaction ID is valid. - An error if the transaction ID is not valid hexadecimal.
type ChaincodeOption ¶
type ChaincodeOption func(opts *chaincodeOptions) error
ChaincodeOption represents a function that applies configuration options to a chaincodeOptions object.
opts: A pointer to a chaincodeOptions object that the function will modify.
error: The function returns an error if applying the option fails.
func WithSrcFS ¶
func WithSrcFS(fs *embed.FS) ChaincodeOption
WithSrcFS is a ChaincodeOption that specifies the source file system to be used by the ChainCode.
fs: A pointer to an embedded file system containing the chaincode files.
It returns a ChaincodeOption that sets the SrcFs field in the chaincodeOptions.
func WithTLS ¶
func WithTLS(tls *TLS) ChaincodeOption
WithTLS is a ChaincodeOption that specifies the TLS configuration for the ChainCode.
tls: A pointer to a TLS structure containing the TLS certificates and keys.
It returns a ChaincodeOption that sets the TLS field in the chaincodeOptions.
func WithTLSFromFiles ¶
func WithTLSFromFiles(keyPath, certPath, clientCACertPath string) (ChaincodeOption, error)
WithTLSFromFiles returns a ChaincodeOption that sets the TLS configuration for the ChainCode from provided file paths. It reads the specified files and uses their contents to configure TLS for the chaincode.
keyPath: A string representing the file path to the TLS private key.
certPath: A string representing the file path to the TLS public certificate.
clientCACertPath: An optional string representing the file path to the client CA certificate. If no client CA certificate is needed, this can be left empty.
It returns a ChaincodeOption or an error if reading any of the files fails.
Example:
tlsOpt, err := core.WithTLSFromFiles("tls/key.pem", "tls/cert.pem", "tls/ca.pem") if err != nil { log.Fatalf("Error configuring TLS: %v", err) } cc, err := core.NewCC(contractInstance, contractOptions, tlsOpt) if err != nil { log.Fatalf("Error creating new chaincode instance: %v", err) }
This example sets up the chaincode TLS configuration using the key, certificate, and CA certificate files located in the "tls" directory. After obtaining the ChaincodeOption from WithTLSFromFiles, it is passed to NewCC to create a new instance of ChainCode with TLS enabled.
type ContractConfigurable ¶
type ContractConfigurable interface { ValidateConfig(config []byte) error ApplyContractConfig(config *pb.ContractConfig) error ContractConfig() *pb.ContractConfig }
type ContractMethods ¶
type Doc ¶
Doc json struct
func DocumentsList ¶
func DocumentsList(stub shim.ChaincodeStubInterface) ([]Doc, error)
DocumentsList returns list of documents
type ExternalConfigurable ¶
type ExternalConfigurable interface { // ValidateExtConfig validates the provided external configuration data. // It takes a byte slice containing the external configuration data, typically in a // specific format, and returns an error if the validation fails. The error should // provide information about the validation failure. ValidateExtConfig(cfgBytes []byte) error // ApplyExtConfig applies the provided external configuration to the chaincode. // It takes a byte slice containing the external configuration data and returns an error // if applying the configuration fails. The error should provide information about the failure. ApplyExtConfig(cfgBytes []byte) error }
ExternalConfigurable is an interface that defines methods for validating and applying external configuration. This interface should be implemented in chaincode to initialize some extended chaincode attributes on Init() call. ValidateExtConfig function called in shim.Chaincode.Init function, verify that config is OK. ApplyExtConfig function called each time shim.Chaincode.Invoke called. It loads configuration from state and apply to chaincode.
type In ¶
type In struct {
// contains filtered or unexported fields
}
In is a struct for input parameters
type TLS ¶
type TLS struct { Key []byte // Private key for TLS authentication. Cert []byte // Public certificate for TLS authentication. ClientCACerts []byte // Optional client CA certificates for verifying connecting peers. }
TLS holds the key and certificate data for TLS communication, as well as client CA certificates for peer verification if needed.
type TokenConfigurable ¶
type TokenConfigurable interface { // ValidateTokenConfig validates the provided token configuration data. // It takes a byte slice containing JSON-encoded token configuration and returns an error // if the validation fails. The error should provide information about the validation failure. // // The implementation of this method may include unmarshalling the JSON-encoded data and // invoking specific validation logic on the deserialized token configuration. ValidateTokenConfig(config []byte) error // ApplyTokenConfig applies the provided token configuration to the implementing object. // It takes a pointer to a proto.TokenConfig struct and returns an error if applying the // configuration fails. The error should provide information about the failure. // // The implementation of this method may include setting various properties of the implementing // object based on the values in the provided token configuration. ApplyTokenConfig(config *proto.TokenConfig) error // TokenConfig retrieves the current token configuration from the implementing object. // It returns a pointer to a proto.TokenConfig struct representing the current configuration. // // The implementation of this method should return the current state of the token configuration // stored within the object. TokenConfig() *proto.TokenConfig }
TokenConfigurable is an interface that defines methods for validating, applying, and retrieving token configuration.