Documentation
¶
Index ¶
- func ArrayFromAssetPropList(a []AssetProp) []map[string]interface{}
- func ArrayFromAssetTypeList(assetTypes []AssetType) (array []map[string]interface{})
- func CheckDataType(dataType string, newTypesList []interface{}) errors.ICCError
- func CheckValue(value interface{}, required bool, expectedType, fieldName string) (interface{}, errors.ICCError)
- func CustomDataTypes(m map[string]DataType) error
- func DataTypeMap() map[string]DataType
- func GenerateKey(asset map[string]interface{}) (string, errors.ICCError)
- func GetAssetAdminsDynamicAssetType() []string
- func GetAssetListUpdateTime() time.Time
- func GetEnabledDynamicAssetType() bool
- func InitAssetList(l []AssetType)
- func InitDynamicAssetTypeConfig(c DynamicAssetType)
- func PutNewRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
- func PutRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
- func ReplaceAssetList(l []AssetType)
- func RestoreAssetList(stub *sw.StubWrapper, init bool) errors.ICCError
- func SetAssetListUpdateTime(t time.Time)
- func StartupCheck() errors.ICCError
- func StoreAssetList(stub *sw.StubWrapper) errors.ICCError
- func UpdateAssetList(l []AssetType)
- func UpdateRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
- type Asset
- func (a Asset) CheckWriters(stub *sw.StubWrapper) errors.ICCError
- func (a *Asset) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (a *Asset) Delete(stub *sw.StubWrapper) ([]byte, errors.ICCError)
- func (a *Asset) DeleteCascade(stub *sw.StubWrapper) ([]byte, errors.ICCError)
- func (a *Asset) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError)
- func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError)
- func (a Asset) GetProp(propTag string) interface{}
- func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)
- func (a Asset) IsPrivate() bool
- func (a Asset) IsReferenced(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (a Asset) JSON() []byte
- func (a Asset) Key() string
- func (a *Asset) Put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)
- func (a *Asset) PutNew(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)
- func (a Asset) Referrers(stub *sw.StubWrapper, assetTypeFilter ...string) ([]Key, errors.ICCError)
- func (a Asset) Refs() ([]Key, errors.ICCError)
- func (a *Asset) SetProp(propTag string, value interface{}) errors.ICCError
- func (a Asset) String() string
- func (a Asset) Type() *AssetType
- func (a Asset) TypeTag() string
- func (a *Asset) UnmarshalJSON(jsonData []byte) error
- func (a *Asset) Update(stub *sw.StubWrapper, update map[string]interface{}) (map[string]interface{}, errors.ICCError)
- func (a Asset) ValidateProps() errors.ICCError
- type AssetProp
- func AssetPropFromMap(m map[string]interface{}) AssetProp
- func AssetPropListFromArray(a []interface{}) []AssetProp
- func BuildAssetProp(propMap map[string]interface{}, newTypesList []interface{}) (AssetProp, errors.ICCError)
- func HandlePropUpdate(assetProps AssetProp, propMap map[string]interface{}) (AssetProp, errors.ICCError)
- type AssetType
- func AssetTypeFromMap(m map[string]interface{}) AssetType
- func AssetTypeList() []AssetType
- func AssetTypeListFromArray(array []interface{}) (assetTypes []AssetType)
- func FetchAssetType(assetTypeTag string) *AssetType
- func GetListAssetType() AssetType
- func RemoveAssetType(tag string, l []AssetType) []AssetType
- func ReplaceAssetType(assetType AssetType, l []AssetType) []AssetType
- type DataType
- type DynamicAssetType
- type HistoryResponse
- type Key
- func (k *Key) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (k *Key) Delete(stub *sw.StubWrapper) ([]byte, errors.ICCError)
- func (k *Key) DeleteCascade(stub *sw.StubWrapper) ([]byte, errors.ICCError)
- func (k *Key) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (k *Key) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError)
- func (k *Key) GetBytes(stub *sw.StubWrapper) ([]byte, errors.ICCError)
- func (k *Key) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError)
- func (k *Key) GetMap(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)
- func (k *Key) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)
- func (k Key) IsPrivate() bool
- func (k Key) IsReferenced(stub *sw.StubWrapper) (bool, errors.ICCError)
- func (k Key) JSON() []byte
- func (k Key) Key() string
- func (k Key) Referrers(stub *sw.StubWrapper, assetTypeFilter ...string) ([]Key, errors.ICCError)
- func (k Key) Refs(stub *sw.StubWrapper) ([]Key, errors.ICCError)
- func (k Key) String() string
- func (k Key) Type() *AssetType
- func (k Key) TypeTag() string
- func (k *Key) UnmarshalJSON(jsonData []byte) error
- func (k *Key) Update(stub *sw.StubWrapper, update map[string]interface{}) (map[string]interface{}, errors.ICCError)
- type SearchResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayFromAssetPropList ¶ added in v0.8.0
ArrayFromAssetPropList converts an array of AssetProp to an array of map[string]interface
func ArrayFromAssetTypeList ¶ added in v0.8.0
ArrayFromAssetTypeList converts an array of AssetType to an array of map[string]interface
func CheckDataType ¶ added in v0.8.0
CheckDataType verifies if dataType is valid among the ones availiable in the chaincode
func CheckValue ¶ added in v0.8.0
func CheckValue(value interface{}, required bool, expectedType, fieldName string) (interface{}, errors.ICCError)
CheckValue verifies if parameter value is of the expected type
func CustomDataTypes ¶
CustomDataTypes allows cc developer to inject custom primitive data types
func DataTypeMap ¶
DataTypeMap returns a copy of the primitive data type map
func GenerateKey ¶
GenerateKey implements the logic to generate an asset's unique key. It validates the assets properties and generates a hash with this values. Based around SHA1 hash function
func GetAssetAdminsDynamicAssetType ¶ added in v0.8.0
func GetAssetAdminsDynamicAssetType() []string
GetAssetAdminsDynamicAssetType returns the value of the AssetAdmins field
func GetAssetListUpdateTime ¶ added in v0.8.0
GetAssetListUpdateTime returns the last time the asset list was updated
func GetEnabledDynamicAssetType ¶ added in v0.8.0
func GetEnabledDynamicAssetType() bool
GetEnabledDynamicAssetType returns the value of the Enabled field
func InitAssetList ¶
func InitAssetList(l []AssetType)
InitAssetList appends custom assets to assetTypeList to avoid initialization loop.
func InitDynamicAssetTypeConfig ¶ added in v0.8.0
func InitDynamicAssetTypeConfig(c DynamicAssetType)
InitDynamicAssetTypeConfig initilizes the dynamicAssetTypeConfig variable
func PutNewRecursive ¶
func PutNewRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
PutNewRecursive inserts asset and all its subassets in blockchain This method is experimental and might not work as intended. Use with caution. It returns conflict error only if root asset exists. If one of the subassets already exist in ledger, it is not updated.
func PutRecursive ¶
func PutRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
PutRecursive inserts asset and all its subassets in blockchain. This method is experimental and might not work as intended. Use with caution.
func ReplaceAssetList ¶ added in v0.8.0
func ReplaceAssetList(l []AssetType)
ReplaceAssetList replace assetTypeList to for a new one
func RestoreAssetList ¶ added in v0.8.0
func RestoreAssetList(stub *sw.StubWrapper, init bool) errors.ICCError
RestoreAssetList restores the assetList from the blockchain
func SetAssetListUpdateTime ¶ added in v0.8.0
SetAssetListUpdateTime sets the last time the asset list was updated
func StartupCheck ¶
StartupCheck verifies if asset definitions are properly coded, returning an error if they're not
func StoreAssetList ¶ added in v0.8.0
func StoreAssetList(stub *sw.StubWrapper) errors.ICCError
StoreAssetList stores the current assetList on the blockchain
func UpdateAssetList ¶ added in v0.8.0
func UpdateAssetList(l []AssetType)
UpdateAssetList updates the assetTypeList variable on runtime
func UpdateRecursive ¶ added in v0.7.3
func UpdateRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError)
UpdateRecursive updates asset and all its subassets in blockchain. It checks if root asset and subassets exist, if not, it returns error. This method is experimental and might not work as intended. Use with caution.
Types ¶
type Asset ¶
type Asset map[string]interface{}
Asset implements the json.Unmarshaler interface and is the base object in cc-tools network. It is a generic map that stores information about a specific ledger asset. It is also used as the base interface to perform operations on the blockchain.
func NewAsset ¶
NewAsset constructs Asset object from a map of properties. It ensures every asset property is properly formatted and computes the asset's identifying key on the ledger, storing it in the property "@key".
func (Asset) CheckWriters ¶
func (a Asset) CheckWriters(stub *sw.StubWrapper) errors.ICCError
CheckWriters checks if tx creator is allowed to write asset.
func (*Asset) CommittedInLedger ¶ added in v0.7.2
CommittedInLedger checks if asset currently has a state committed in ledger.
func (*Asset) Delete ¶
Delete erases asset from world state and checks for all necessary permissions. An asset cannot be deleted if any other asset references it.
func (*Asset) DeleteCascade ¶
DeleteCascade erases asset and recursively erases those which reference it. This method is experimental and might not work as intended. Use with caution.
func (*Asset) ExistsInLedger ¶
ExistsInLedger checks if asset currently has a state.
func (*Asset) GetCommitted ¶ added in v0.7.1
GetCommitted fetches asset entry from ledger.
func (*Asset) GetRecursive ¶
GetRecursive reads asset from ledger and resolves all references
func (Asset) IsPrivate ¶
IsPrivate returns true if the Asset's asset type belongs to a private collection.
func (Asset) IsReferenced ¶
IsReferenced checks if the asset is referenced by another asset.
func (Asset) Referrers ¶ added in v0.7.2
Referrers returns an array of Keys of all the assets pointing to asset. assetTypeFilter can be used to filter the results by asset type.
func (Asset) Refs ¶
Refs returns an array of Keys containing the reference keys for all present subAssets. The referenced keys are fetched based on current asset configuration.
func (*Asset) SetProp ¶
SetProp sets the prop value with proper validation. It does not update the asset in the ledger.
func (*Asset) UnmarshalJSON ¶
UnmarshalJSON parses JSON-encoded data and returns an Asset object pointer
func (*Asset) Update ¶
func (a *Asset) Update(stub *sw.StubWrapper, update map[string]interface{}) (map[string]interface{}, errors.ICCError)
Update receives a map[string]interface{} with key/vals to update the asset value in the world state.
func (Asset) ValidateProps ¶
ValidateProps checks if all props are compliant to format
type AssetProp ¶
type AssetProp struct { // Tag is the string used to reference the prop in the Asset map Tag string `json:"tag"` // Label is the pretty property name for front-end rendering Label string `json:"label"` // Description is a simple explanation describing the meaning of the property. Description string `json:"description"` // IsKey defines if the property is a Primary Key. At least one of the Asset's // properties must have this set as true. IsKey bool `json:"isKey"` // Required defines if the NewAsset function should fail if property is undefined. // If IsKey is set as true, this value is ignored. (primary key is always required) Required bool `json:"required"` // ReadOnly means property can only be set during Asset creation. ReadOnly bool `json:"readOnly"` // DefaultValue is the default property value in case it is not defined when parsing asset. DefaultValue interface{} `json:"defaultValue,omitempty"` // DataType can assume the following values: // Primary types: "string", "number", "integer", "boolean", "datetime" // Special types: // -><assetType>: the specific asset type key (reference) as defined by <assetType> in the assets packages // []<type>: an array of elements specified by <type> as any of the above valid types DataType string `json:"dataType"` // Writers is an array of orgs that specify who can write in the asset // and accepts either basic strings for exact matches // eg. []string{'org1MSP', 'org2MSP'} // or regular expressions // eg. []string{`$org\dMSP`} and cc-tools will // check for a match with regular expression `org\dMSP` Writers []string `json:"writers"` // Validate is a function called when validating property format. Validate func(interface{}) error `json:"-"` }
AssetProp describes properties of each asset attribute
func AssetPropFromMap ¶ added in v0.8.0
AssetPropFromMap converts a map[string]interface{} to an AssetProp
func AssetPropListFromArray ¶ added in v0.8.0
func AssetPropListFromArray(a []interface{}) []AssetProp
AssetPropListFromArray converts an array of map[string]interface to an array of AssetProp
func BuildAssetProp ¶ added in v0.8.0
func BuildAssetProp(propMap map[string]interface{}, newTypesList []interface{}) (AssetProp, errors.ICCError)
BuildAssetProp builds an AssetProp from an object with the required fields
type AssetType ¶
type AssetType struct { // Tag is how the asset type will be referenced in the "@assetType" metaproperty. Tag string `json:"tag"` // Label is the pretty asset type name for front-end rendering Label string `json:"label"` // Description is a simple explanation describing the meaning of the asset type. Description string `json:"description"` // Props receives an array of assetProps, defining the asset's properties. Props []AssetProp `json:"props"` // Readers is an array that specifies which organizations can read the asset. // Must be coherent with private data collections configuration. // Accepts either basic strings for exact matches // eg. []string{'org1MSP', 'org2MSP'} // or regular expressions // eg. []string{`$org\dMSP`} and cc-tools will // check for a match with regular expression `org\dMSP` Readers []string `json:"readers,omitempty"` // Validate is a function called when validating asset as a whole. Validate func(Asset) error `json:"-"` // Dynamic is a flag that indicates if the asset type is dynamic. Dynamic bool `json:"dynamic,omitempty"` }
AssetType is a list of all asset properties
func AssetTypeFromMap ¶ added in v0.8.0
AssetTypeFromMap returns an asset type from a map representation.
func AssetTypeList ¶
func AssetTypeList() []AssetType
AssetTypeList returns a copy of the assetTypeList variable.
func AssetTypeListFromArray ¶ added in v0.8.0
func AssetTypeListFromArray(array []interface{}) (assetTypes []AssetType)
AssetTypeListFromArray converts an array of map[string]interface to an array of AssetType
func FetchAssetType ¶
FetchAssetType returns a pointer to the AssetType object or nil if asset type is not found.
func GetListAssetType ¶ added in v0.8.0
func GetListAssetType() AssetType
GetListAssetType returns the Dynamic AssetType meta type
func RemoveAssetType ¶ added in v0.8.0
RemoveAssetType removes an asset type from an AssetType List and returns the new list
func ReplaceAssetType ¶ added in v0.8.0
ReplaceAssetType replaces an asset type from an AssetType List with an updated version and returns the new list This function does not automatically update the assetTypeList variable
func (AssetType) GetPropDef ¶
GetPropDef fetches the propDef with tag propTag.
func (AssetType) Keys ¶
Keys returns a list of asset properties which are defined as primary keys. (IsKey == true)
type DataType ¶
type DataType struct { // AcceptedFormats is a list of "core" types that can be accepted (string, number, integer, boolean, datetime) AcceptedFormats []string `json:"acceptedFormats"` // Description is a simple text describing the data type Description string `json:"description,omitempty"` // DropDownValues is a set of predetermined values to be used in a dropdown menu on frontend rendering DropDownValues map[string]interface{} `json:"DropDownValues"` // Parse is called to check if the input value is valid, make necessary // conversions and returns a string representation of the value Parse func(interface{}) (string, interface{}, errors.ICCError) `json:"-"` }
DataType is the struct defining a primitive data type.
func FetchDataType ¶
FetchDataType returns a pointer to the DataType object or nil if asset type is not found.
type DynamicAssetType ¶ added in v0.8.0
type DynamicAssetType struct { // Enabled defines whether the Dynamic AssetTypes feature is active Enabled bool `json:"enabled"` // AssetAdmins is an array that specifies which organizations can operate the Dynamic AssetTyper feature. // Accepts either basic strings for exact matches // eg. []string{'org1MSP', 'org2MSP'} // or regular expressions // eg. []string{`$org\dMSP`} and cc-tools will // check for a match with regular expression `org\dMSP` AssetAdmins []string `json:"assetAdmins"` }
DynamicAssetType is the configuration for the Dynamic AssetTypes
type HistoryResponse ¶ added in v0.9.0
type HistoryResponse struct { Result []map[string]interface{} `json:"result"` Metadata *pb.QueryResponseMetadata `json:"metadata"` }
func History ¶ added in v0.9.0
func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, errors.ICCError)
type Key ¶
type Key map[string]interface{}
Key stores the information for retrieving an Asset from the ledger. Instead of having every asset property mapped such as the Asset type, Key only has the properties needed for fetching the full Asset.
func NewKey ¶
NewKey constructs Key object from a map of properties. The map must contain the `@assetType` entry and either all the key properties of the asset (`IsKey == true`) or the `@key` property. Either way, the Key object returned contains only the `@assetType` and `@key` entries.
func (*Key) CommittedInLedger ¶ added in v0.7.2
CommittedInLedger checks if asset referenced by a key object currently has a state committed in ledger.
func (*Key) Delete ¶ added in v0.7.1
Delete erases asset from world state and checks for all necessary permissions. An asset cannot be deleted if any other asset references it.
func (*Key) DeleteCascade ¶ added in v0.7.1
DeleteCascade erases asset and recursively erases those which reference it. This method is experimental and might not work as intended. Use with caution.
func (*Key) ExistsInLedger ¶
ExistsInLedger checks if asset referenced by a key object currently has a state.
func (*Key) GetCommitted ¶ added in v0.7.1
GetCommitted fetches asset entry from ledger.
func (*Key) GetRecursive ¶
GetRecursive reads asset from ledger and resolves all references
func (Key) IsReferenced ¶ added in v0.7.2
IsReferenced checks if the asset is referenced by another asset.
func (Key) Referrers ¶ added in v0.7.2
Referrers returns an array of Keys of all the assets pointing to key. assetTypeFilter can be used to filter the results by asset type.
func (Key) Refs ¶
Refs returns an array of Keys containing the reference keys for all present subAssets. The referenced keys are fetched from current asset state on ledger.
func (*Key) UnmarshalJSON ¶
UnmarshalJSON parses JSON-encoded data and returns a Key object pointer
type SearchResponse ¶ added in v0.7.2
type SearchResponse struct { Result []map[string]interface{} `json:"result"` Metadata *pb.QueryResponseMetadata `json:"metadata"` }
func Search ¶ added in v0.7.2
func Search(stub *sw.StubWrapper, request map[string]interface{}, privateCollection string, resolve bool) (*SearchResponse, errors.ICCError)
Source Files
¶
- asset.go
- assetList.go
- assetListFuncs.go
- assetProp.go
- assetType.go
- checkWriters.go
- clean.go
- dataType.go
- delete.go
- dynamicAssetType.go
- dynamicAssetTypeConfig.go
- dynamicAssetTypeFuncs.go
- existsInLedger.go
- generateKey.go
- get.go
- getProp.go
- history.go
- key.go
- put.go
- references.go
- search.go
- setProp.go
- startupCheck.go
- update.go
- validateProp.go
- validateProps.go