assets

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

func StartupCheck() errors.ICCError

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

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) ([]Key, errors.ICCError)

Referrers returns an array of Keys of all the assets pointing to asset.

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

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

func FetchAssetType(assetTypeTag string) *AssetType

FetchAssetType returns a pointer to the AssetType object or nil if asset type is not found.

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

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 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) ([]Key, errors.ICCError)

Referrers returns an array of Keys of all the assets pointing to key.

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