manifest

package
v0.0.0-...-886a677 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// MethodInit is a name for default initialization method.
	MethodInit = "_initialize"

	// MethodDeploy is a name for default method called during contract deployment.
	MethodDeploy = "_deploy"

	// MethodVerify is a name for default verification method.
	MethodVerify = "verify"

	// MethodOnNEP17Payment is the name of the method which is called when contract receives NEP-17 tokens.
	MethodOnNEP17Payment = "onNEP17Payment"

	// MethodOnNEP11Payment is the name of the method which is called when contract receives NEP-11 tokens.
	MethodOnNEP11Payment = "onNEP11Payment"
)
View Source
const (
	// MaxManifestSize is the max length for a valid contract manifest.
	MaxManifestSize = math.MaxUint16

	// NEP11StandardName represents the name of NEP-11 smartcontract standard.
	NEP11StandardName = "NEP-11"
	// NEP17StandardName represents the name of NEP-17 smartcontract standard.
	NEP17StandardName = "NEP-17"
	// NEP11Payable represents the name of contract interface which can receive NEP-11 tokens.
	NEP11Payable = "NEP-11-Payable"
	// NEP17Payable represents the name of contract interface which can receive NEP-17 tokens.
	NEP17Payable = "NEP-17-Payable"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ABI

type ABI struct {
	Methods []Method `json:"methods"`
	Events  []Event  `json:"events"`
}

ABI represents a contract application binary interface.

func (*ABI) FromStackItem

func (a *ABI) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to ABI.

func (*ABI) GetEvent

func (a *ABI) GetEvent(name string) *Event

GetEvent returns the event with the specified name.

func (*ABI) GetMethod

func (a *ABI) GetMethod(name string, paramCount int) *Method

GetMethod returns methods with the specified name.

func (*ABI) IsValid

func (a *ABI) IsValid() error

IsValid checks ABI consistency and correctness.

func (*ABI) ToStackItem

func (a *ABI) ToStackItem() stackitem.Item

ToStackItem converts ABI to stackitem.Item.

type Event

type Event struct {
	Name       string      `json:"name"`
	Parameters []Parameter `json:"parameters"`
}

Event is a description of a single event.

func (*Event) CheckCompliance

func (e *Event) CheckCompliance(items []stackitem.Item) error

CheckCompliance checks compliance of the given array of items with the current event.

func (*Event) FromStackItem

func (e *Event) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Event.

func (*Event) IsValid

func (e *Event) IsValid() error

IsValid checks Event consistency and correctness.

func (*Event) ToStackItem

func (e *Event) ToStackItem() stackitem.Item

ToStackItem converts Event to stackitem.Item.

type Group

type Group struct {
	PublicKey *keys.PublicKey `json:"pubkey"`
	Signature []byte          `json:"signature"`
}

Group represents a group of smartcontracts identified by a public key. Every SC in a group must provide signature of its hash to prove it belongs to the group.

func (*Group) FromStackItem

func (g *Group) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Group.

func (*Group) IsValid

func (g *Group) IsValid(h util.Uint160) error

IsValid checks whether the group's signature corresponds to the given hash.

func (*Group) MarshalJSON

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Group) ToStackItem

func (g *Group) ToStackItem() stackitem.Item

ToStackItem converts Group to stackitem.Item.

func (*Group) UnmarshalJSON

func (g *Group) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Groups

type Groups []Group

Groups is just an array of Group.

func (Groups) AreValid

func (g Groups) AreValid(h util.Uint160) error

AreValid checks for groups correctness and uniqueness. If the contract hash is empty, then hash-related checks are omitted.

func (Groups) Contains

func (g Groups) Contains(k *keys.PublicKey) bool

type Manifest

type Manifest struct {
	// Name is a contract's name.
	Name string `json:"name"`
	// ABI is a contract's ABI.
	ABI ABI `json:"abi"`
	// Features is a set of contract features. Currently unused.
	Features json.RawMessage `json:"features"`
	// Groups is a set of groups to which a contract belongs.
	Groups      []Group      `json:"groups"`
	Permissions []Permission `json:"permissions"`
	// SupportedStandards is a list of standards supported by the contract.
	SupportedStandards []string `json:"supportedstandards"`
	// Trusts is a set of hashes to a which contract trusts.
	Trusts WildPermissionDescs `json:"trusts"`
	// Extra is an implementation-defined user data.
	Extra json.RawMessage `json:"extra"`
}

Manifest represens contract metadata.

func DefaultManifest

func DefaultManifest(name string) *Manifest

DefaultManifest returns the default contract manifest.

func NewManifest

func NewManifest(name string) *Manifest

NewManifest returns a new manifest with necessary fields initialized.

func (*Manifest) CanCall

func (m *Manifest) CanCall(hash util.Uint160, toCall *Manifest, method string) bool

CanCall returns true if the current contract is allowed to call the method of another contract with the specified hash.

func (*Manifest) FromStackItem

func (m *Manifest) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Manifest.

func (*Manifest) IsStandardSupported

func (m *Manifest) IsStandardSupported(standard string) bool

IsStandardSupported denotes whether the specified standard is supported by the contract.

func (*Manifest) IsValid

func (m *Manifest) IsValid(hash util.Uint160, checkSize bool) error

IsValid checks manifest internal consistency and correctness, one of the checks is for group signature correctness, contract hash is passed for it. If hash is empty, then hash-related checks are omitted.

func (*Manifest) ToStackItem

func (m *Manifest) ToStackItem() (stackitem.Item, error)

ToStackItem converts Manifest to stackitem.Item.

type Method

type Method struct {
	Name       string                  `json:"name"`
	Offset     int                     `json:"offset"`
	Parameters []Parameter             `json:"parameters"`
	ReturnType smartcontract.ParamType `json:"returntype"`
	Safe       bool                    `json:"safe"`
}

Method represents method's metadata.

func (*Method) FromStackItem

func (m *Method) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Method.

func (*Method) IsValid

func (m *Method) IsValid() error

IsValid checks Method consistency and correctness.

func (*Method) ToStackItem

func (m *Method) ToStackItem() stackitem.Item

ToStackItem converts Method to stackitem.Item.

type Parameter

type Parameter struct {
	Name string                  `json:"name"`
	Type smartcontract.ParamType `json:"type"`
}

Parameter represents smartcontract's parameter's definition.

func NewParameter

func NewParameter(name string, typ smartcontract.ParamType) Parameter

NewParameter returns a new parameter of the specified name and type.

func (*Parameter) FromStackItem

func (p *Parameter) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Parameter.

func (*Parameter) IsValid

func (p *Parameter) IsValid() error

IsValid checks Parameter consistency and correctness.

func (*Parameter) ToStackItem

func (p *Parameter) ToStackItem() stackitem.Item

ToStackItem converts Parameter to stackitem.Item.

type Parameters

type Parameters []Parameter

Parameters is just an array of Parameter.

func (Parameters) AreValid

func (p Parameters) AreValid() error

AreValid checks all parameters for validity and consistency.

type Permission

type Permission struct {
	Contract PermissionDesc `json:"contract"`
	Methods  WildStrings    `json:"methods"`
}

Permission describes which contracts may be invoked and which methods are called.

func NewPermission

func NewPermission(typ PermissionType, args ...any) *Permission

NewPermission returns a new permission of the given type.

func (*Permission) FromStackItem

func (p *Permission) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to Permission.

func (*Permission) IsAllowed

func (p *Permission) IsAllowed(hash util.Uint160, m *Manifest, method string) bool

IsAllowed checks if the method is allowed to be executed.

func (*Permission) IsValid

func (p *Permission) IsValid() error

IsValid checks if Permission is correct.

func (*Permission) ToStackItem

func (p *Permission) ToStackItem() stackitem.Item

ToStackItem converts Permission to stackitem.Item.

func (*Permission) UnmarshalJSON

func (p *Permission) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type PermissionDesc

type PermissionDesc struct {
	Type  PermissionType
	Value any
}

PermissionDesc is a permission descriptor.

func (*PermissionDesc) Equals

func (d *PermissionDesc) Equals(v PermissionDesc) bool

Equals returns true if both PermissionDesc values are the same.

func (*PermissionDesc) FromStackItem

func (d *PermissionDesc) FromStackItem(item stackitem.Item) error

FromStackItem converts stackitem.Item to PermissionDesc.

func (*PermissionDesc) Group

func (d *PermissionDesc) Group() *keys.PublicKey

Group returns group's public key for group-permission.

func (*PermissionDesc) Hash

func (d *PermissionDesc) Hash() util.Uint160

Hash returns hash for hash-permission.

func (*PermissionDesc) Less

func (d *PermissionDesc) Less(d1 PermissionDesc) bool

Less returns true if this value is less than the given PermissionDesc value.

func (*PermissionDesc) MarshalJSON

func (d *PermissionDesc) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*PermissionDesc) ToStackItem

func (d *PermissionDesc) ToStackItem() stackitem.Item

ToStackItem converts PermissionDesc to stackitem.Item.

func (*PermissionDesc) UnmarshalJSON

func (d *PermissionDesc) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type PermissionType

type PermissionType uint8

PermissionType represents permission type.

const (
	// PermissionWildcard allows everything.
	PermissionWildcard PermissionType = 0
	// PermissionHash restricts called contracts based on hash.
	PermissionHash PermissionType = 1
	// PermissionGroup restricts called contracts based on public key.
	PermissionGroup PermissionType = 2
)

type Permissions

type Permissions []Permission

Permissions is just an array of Permission.

func (Permissions) AreValid

func (ps Permissions) AreValid() error

AreValid checks each Permission and ensures there are no duplicates.

type WildPermissionDescs

type WildPermissionDescs struct {
	Value []PermissionDesc
}

WildPermissionDescs represents a PermissionDescriptor set which can be a wildcard.

func (*WildPermissionDescs) Add

Add adds v to the container.

func (*WildPermissionDescs) Contains

func (c *WildPermissionDescs) Contains(v PermissionDesc) bool

Contains checks if v is in the container.

func (*WildPermissionDescs) IsWildcard

func (c *WildPermissionDescs) IsWildcard() bool

IsWildcard returns true iff the container is a wildcard.

func (WildPermissionDescs) MarshalJSON

func (c WildPermissionDescs) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*WildPermissionDescs) Restrict

func (c *WildPermissionDescs) Restrict()

Restrict transforms the container into an empty one.

func (*WildPermissionDescs) UnmarshalJSON

func (c *WildPermissionDescs) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WildStrings

type WildStrings struct {
	Value []string
}

WildStrings represents a string set which can be a wildcard.

func (*WildStrings) Add

func (c *WildStrings) Add(v string)

Add adds v to the container.

func (*WildStrings) Contains

func (c *WildStrings) Contains(v string) bool

Contains checks if v is in the container.

func (*WildStrings) IsWildcard

func (c *WildStrings) IsWildcard() bool

IsWildcard returns true iff the container is a wildcard.

func (WildStrings) MarshalJSON

func (c WildStrings) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*WildStrings) Restrict

func (c *WildStrings) Restrict()

Restrict transforms the container into an empty one.

func (*WildStrings) UnmarshalJSON

func (c *WildStrings) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Directories

Path Synopsis
Package standard contains interfaces for well-defined standards and a function for checking if an arbitrary manifest complies with them.
Package standard contains interfaces for well-defined standards and a function for checking if an arbitrary manifest complies with them.

Jump to

Keyboard shortcuts

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