assets

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayFromAssetPropList added in v0.8.0

func ArrayFromAssetPropList(a []AssetProp) []map[string]interface{}

ArrayFromAssetPropList converts an array of AssetProp to an array of map[string]interface

func ArrayFromAssetTypeList added in v0.8.0

func ArrayFromAssetTypeList(assetTypes []AssetType) (array []map[string]interface{})

ArrayFromAssetTypeList converts an array of AssetType to an array of map[string]interface

func CheckDataType added in v0.8.0

func CheckDataType(dataType string, newTypesList []interface{}) errors.ICCError

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

func CustomDataTypes(m map[string]DataType) error

CustomDataTypes allows cc developer to inject custom primitive data types

func DataTypeMap

func DataTypeMap() map[string]DataType

DataTypeMap returns a copy of the primitive data type map

func GenerateKey

func GenerateKey(asset map[string]interface{}) (string, errors.ICCError)

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

func GetAssetListUpdateTime() time.Time

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

func SetAssetListUpdateTime(t time.Time)

SetAssetListUpdateTime sets the last time the asset list was updated

func StartupCheck

func StartupCheck() errors.ICCError

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 GetMany added in v0.9.0

func GetMany(stub *sw.StubWrapper, keys []Key) ([]*Asset, errors.ICCError)

GetMany fetches assets entries from write set or ledger.

func NewAsset

func NewAsset(m map[string]interface{}) (a Asset, err errors.ICCError)

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

func (a *Asset) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)

CommittedInLedger checks if asset currently has a state committed in ledger.

func (*Asset) Delete

func (a *Asset) Delete(stub *sw.StubWrapper) ([]byte, errors.ICCError)

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

func (a *Asset) DeleteCascade(stub *sw.StubWrapper) ([]byte, errors.ICCError)

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

func (a *Asset) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)

ExistsInLedger checks if asset currently has a state.

func (*Asset) Get

func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError)

Get fetches asset entry from write set or ledger.

func (*Asset) GetCommitted added in v0.7.1

func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError)

GetCommitted fetches asset entry from ledger.

func (Asset) GetProp

func (a Asset) GetProp(propTag string) interface{}

GetProp returns the prop value. It returns nil if it doesn't exist.

func (*Asset) GetRecursive

func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)

GetRecursive reads asset from ledger and resolves all references

func (Asset) IsPrivate

func (a Asset) IsPrivate() bool

IsPrivate returns true if the Asset's asset type belongs to a private collection.

func (Asset) IsReferenced

func (a Asset) IsReferenced(stub *sw.StubWrapper) (bool, errors.ICCError)

IsReferenced checks if the asset is referenced by another asset.

func (Asset) JSON

func (a Asset) JSON() []byte

JSON returns the Asset in JSON format.

func (Asset) Key

func (a Asset) Key() string

Key returns the asset's unique identifying key in the ledger.

func (*Asset) Put

func (a *Asset) Put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)

Put inserts asset in blockchain

func (*Asset) PutNew

func (a *Asset) PutNew(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)

PutNew inserts asset in blockchain and returns error if asset exists.

func (Asset) Referrers added in v0.7.2

func (a Asset) Referrers(stub *sw.StubWrapper, assetTypeFilter ...string) ([]Key, errors.ICCError)

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

func (a Asset) Refs() ([]Key, errors.ICCError)

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

func (a *Asset) SetProp(propTag string, value interface{}) errors.ICCError

SetProp sets the prop value with proper validation. It does not update the asset in the ledger.

func (Asset) String

func (a Asset) String() string

String returns the Asset in stringified JSON format.

func (Asset) Type

func (a Asset) Type() *AssetType

Type return the AssetType object for the asset.

func (Asset) TypeTag

func (a Asset) TypeTag() string

TypeTag returns the @assetType attribute.

func (*Asset) UnmarshalJSON

func (a *Asset) UnmarshalJSON(jsonData []byte) error

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

func (a Asset) ValidateProps() errors.ICCError

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

func AssetPropFromMap(m map[string]interface{}) AssetProp

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

func HandlePropUpdate added in v0.8.0

func HandlePropUpdate(assetProps AssetProp, propMap map[string]interface{}) (AssetProp, errors.ICCError)

HandlePropUpdate updates an AssetProp with the values of the propMap

func (AssetProp) ToMap added in v0.8.0

func (p AssetProp) ToMap() map[string]interface{}

ToMap converts an AssetProp to a map[string]interface{}

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

func AssetTypeFromMap(m map[string]interface{}) AssetType

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

func FetchAssetType(assetTypeTag string) *AssetType

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

func RemoveAssetType(tag string, l []AssetType) []AssetType

RemoveAssetType removes an asset type from an AssetType List and returns the new list

func ReplaceAssetType added in v0.8.0

func ReplaceAssetType(assetType AssetType, l []AssetType) []AssetType

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

func (t AssetType) GetPropDef(propTag string) *AssetProp

GetPropDef fetches the propDef with tag propTag.

func (AssetType) HasProp

func (t AssetType) HasProp(propTag string) bool

HasProp returns true if asset type has a property with the given tag.

func (AssetType) IsPrivate

func (t AssetType) IsPrivate() bool

IsPrivate returns true if asset is in a private collection.

func (AssetType) Keys

func (t AssetType) Keys() (keys []AssetProp)

Keys returns a list of asset properties which are defined as primary keys. (IsKey == true)

func (AssetType) SubAssets

func (t AssetType) SubAssets() (subAssets []AssetProp)

SubAssets returns a list of asset properties which are subAssets (DataType is `->someAssetType`)

func (AssetType) ToMap added in v0.8.0

func (t AssetType) ToMap() map[string]interface{}

ToMap returns a map representation of the asset type.

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

func FetchDataType(dataTypeTag string) *DataType

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

func NewKey(m map[string]interface{}) (k Key, err errors.ICCError)

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

func (k *Key) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)

CommittedInLedger checks if asset referenced by a key object currently has a state committed in ledger.

func (*Key) Delete added in v0.7.1

func (k *Key) Delete(stub *sw.StubWrapper) ([]byte, errors.ICCError)

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

func (k *Key) DeleteCascade(stub *sw.StubWrapper) ([]byte, errors.ICCError)

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

func (k *Key) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError)

ExistsInLedger checks if asset referenced by a key object currently has a state.

func (*Key) Get

func (k *Key) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError)

Get fetches asset entry from write set or ledger.

func (*Key) GetBytes

func (k *Key) GetBytes(stub *sw.StubWrapper) ([]byte, errors.ICCError)

GetBytes reads the asset as bytes from ledger

func (*Key) GetCommitted added in v0.7.1

func (k *Key) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError)

GetCommitted fetches asset entry from ledger.

func (*Key) GetMap

func (k *Key) GetMap(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)

GetMap reads the asset as map from ledger

func (*Key) GetRecursive

func (k *Key) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError)

GetRecursive reads asset from ledger and resolves all references

func (Key) IsPrivate

func (k Key) IsPrivate() bool

IsPrivate returns true if asset type belongs to private collection

func (Key) IsReferenced added in v0.7.2

func (k Key) IsReferenced(stub *sw.StubWrapper) (bool, errors.ICCError)

IsReferenced checks if the asset is referenced by another asset.

func (Key) JSON

func (k Key) JSON() []byte

JSON returns the Asset in JSON format.

func (Key) Key

func (k Key) Key() string

Key returns the asset's unique identifying key in the ledger.

func (Key) Referrers added in v0.7.2

func (k Key) Referrers(stub *sw.StubWrapper, assetTypeFilter ...string) ([]Key, errors.ICCError)

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

func (k Key) Refs(stub *sw.StubWrapper) ([]Key, errors.ICCError)

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) String

func (k Key) String() string

String returns the Key in stringified JSON format.

func (Key) Type

func (k Key) Type() *AssetType

Type returns the AssetType configuration object for the asset

func (Key) TypeTag

func (k Key) TypeTag() string

TypeTag returns @assetType attribute

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(jsonData []byte) error

UnmarshalJSON parses JSON-encoded data and returns a Key object pointer

func (*Key) Update

func (k *Key) 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.

type SearchResponse added in v0.7.2

type SearchResponse struct {
	Result   []map[string]interface{}  `json:"result"`
	Metadata *pb.QueryResponseMetadata `json:"metadata"`
}
func Search(stub *sw.StubWrapper, request map[string]interface{}, privateCollection string, resolve bool) (*SearchResponse, errors.ICCError)

Jump to

Keyboard shortcuts

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