Documentation
¶
Index ¶
- func CustomDataTypes(m map[string]DataType) error
- func DataTypeMap() map[string]DataType
- func GenerateKey(asset map[string]interface{}) (string, errors.ICCError)
- func InitAssetList(l []AssetType)
- 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 StartupCheck() errors.ICCError
- 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) ([]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
- type AssetType
- type DataType
- 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) ([]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 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 InitAssetList ¶
func InitAssetList(l []AssetType)
InitAssetList appends custom assets to assetTypeList to avoid initialization loop.
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 StartupCheck ¶
StartupCheck verifies if asset definitions are properly coded, returning an error if they're not
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.
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
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:"-"` }
AssetType is a list of all asset properties
func AssetTypeList ¶
func AssetTypeList() []AssetType
AssetTypeList returns a copy of the assetTypeList variable.
func FetchAssetType ¶
FetchAssetType returns a pointer to the AssetType object or nil if asset type is not found.
func (AssetType) GetPropDef ¶
GetPropDef fetches the propDef with tag propTag.
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 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.
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)