Documentation ¶
Overview ¶
Package schema defines a module for defining on-chain schema definitions. The rationale for on-chain schema definitions is that a blockchain can enforce schema definition rules that force backwards compatibility. Specifically if a schema property or class is defined to have one meaning at one point, that same identifier can't be redefined with an incompatible meaning in the future. Having consensus around the meaning of schema identifiers provides a basis for which applications developers can safely write interoperable apps that don't break arbitrarily. In addition to providing this basis for consistency, the schema module also aims to provide clear pathways for upgrading schemas and defining schemas which mix and match different parts of other schemas in order to facilitate a new generation of interoperable apps and data, most importantly within the ecological domain.
Index ¶
- Constants
- Variables
- func NewHandler(keeper Keeper) sdk.Handler
- func NewOnChainSchemaResolver(keeper Keeper, ctx sdk.Context) graph.SchemaResolver
- func NewProperty(propertyDefinition PropertyDefinition, uri *url.URL) graph.Property
- func PropertyKey(id graph.PropertyID) []byte
- func PropertyURLKey(url string) []byte
- func RegisterCodec(cdc *codec.Codec)
- type Keeper
- func (keeper Keeper) DefineProperty(ctx sdk.Context, def PropertyDefinition) (id graph.PropertyID, uri *url.URL, err sdk.Error)
- func (keeper Keeper) GetLastPropertyID(ctx sdk.Context) graph.PropertyID
- func (keeper Keeper) GetPropertyDefinition(ctx sdk.Context, id graph.PropertyID) (prop PropertyDefinition, found bool)
- func (keeper Keeper) GetPropertyID(ctx sdk.Context, propertyURL string) graph.PropertyID
- type PropertyDefinition
- func (prop PropertyDefinition) GetSignBytes() []byte
- func (prop PropertyDefinition) GetSigners() []sdk.AccAddress
- func (PropertyDefinition) Route() string
- func (prop PropertyDefinition) String() string
- func (PropertyDefinition) Type() string
- func (prop PropertyDefinition) URI() *url.URL
- func (prop PropertyDefinition) ValidateBasic() sdk.Error
Constants ¶
const PropertyNameRegex = "^[a-z][a-zA-Z0-9_]*$"
PropertyNameRegex defines the valid characters for property names. Only lowercase ascii letters are allowed, property names must start with a letter and can otherwise also contain numbers and underscores. Snake case is preferred as a number of sources point suggest it has enhanced readability as opposed to camel case
Variables ¶
var (
LastPropertyIDKey = []byte("_/next-property-id")
)
Functions ¶
func NewHandler ¶
NewHandler returns a handler for "schema" type messages.
func NewOnChainSchemaResolver ¶
func NewOnChainSchemaResolver(keeper Keeper, ctx sdk.Context) graph.SchemaResolver
func NewProperty ¶
func NewProperty(propertyDefinition PropertyDefinition, uri *url.URL) graph.Property
NewProperty wraps a PropertyDefinition as a Property TODO move this to the schema module
func PropertyKey ¶
func PropertyKey(id graph.PropertyID) []byte
PropertyKey returns the store key for the given graph.PropertyID that points to its PropertyDefinition
func PropertyURLKey ¶
PropertyURLKey returns the store key for the given property URL that points to its graph.PropertyID
func RegisterCodec ¶
RegisterCodec registers concrete types on the Amino codec
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper is the schema module keeper
func (Keeper) DefineProperty ¶
func (keeper Keeper) DefineProperty(ctx sdk.Context, def PropertyDefinition) (id graph.PropertyID, uri *url.URL, err sdk.Error)
DefineProperty defines a property within the state store return the property's id and URL if it was defined successfully or else an error
func (Keeper) GetLastPropertyID ¶
func (keeper Keeper) GetLastPropertyID(ctx sdk.Context) graph.PropertyID
func (Keeper) GetPropertyDefinition ¶
func (keeper Keeper) GetPropertyDefinition(ctx sdk.Context, id graph.PropertyID) (prop PropertyDefinition, found bool)
GetProperty returns a PropertyDefinition given a graph.PropertyID if one exists
func (Keeper) GetPropertyID ¶
GetPropertyID returns the ID for a property URL if one exists, the graph.PropertyID 0 indicates no property with this URL is defined
type PropertyDefinition ¶
type PropertyDefinition struct { // Creator is the entity that defined this property Creator sdk.AccAddress `json:"creator"` // Name is the human-readable name of the property within the creator's namespace of properties Name string `json:"name"` // Many indicates whether or not this property can be assigned more than once to a given node/object. If it is // false, then the property can only be assigned once for a given node/object Arity graph.Arity `json:"arity:omitempty"` // PropertyType indicates the data type of the property PropertyType graph.PropertyType `json:"type,omitempty"` }
PropertyDefinition defines the schema for a property
func (PropertyDefinition) GetSignBytes ¶
func (prop PropertyDefinition) GetSignBytes() []byte
GetSignBytes returns the bytes over which to sign
func (PropertyDefinition) GetSigners ¶
func (prop PropertyDefinition) GetSigners() []sdk.AccAddress
GetSigners returns the addresses which must sign the message
func (PropertyDefinition) Route ¶
func (PropertyDefinition) Route() string
Route returns the route of the message
func (PropertyDefinition) String ¶
func (prop PropertyDefinition) String() string
func (PropertyDefinition) Type ¶
func (PropertyDefinition) Type() string
Type returns the type of the message
func (PropertyDefinition) URI ¶
func (prop PropertyDefinition) URI() *url.URL
URL returns the URL of the property
func (PropertyDefinition) ValidateBasic ¶
func (prop PropertyDefinition) ValidateBasic() sdk.Error
ValidateBasic ensures that Creator and Name are non-empty and the PropertyType is valid