Documentation
¶
Index ¶
- Constants
- Variables
- func AllowedTypedContractImportsDescription() string
- func BuildExpr(schema ContractSchema, typ TypeRef, sv SnapshotValue) (gno.Expr, error)
- func BuildLiteral(schema ContractSchema, typ TypeRef, sv SnapshotValue) (string, error)
- func CaptureSnapshot(pkg *gno.PackageValue, store gno.Store, schema ContractSchema) ([]byte, error)
- func ClassifyGnoExecutionPanic(scope string, r any, gasMeter gstore.GasMeter) base.OperationProcessReasonError
- func CombineNativeResolvers(resolvers ...gno.NativeResolver) gno.NativeResolver
- func ContractCallDataTotalBytes(callData map[string]string) int
- func GetAccountStateFunc(addr string, encs encoder.Encoders, getStateFunc base.GetStateFunc) (bool, error)
- func GnoStdlibMemPackages() ([]*gnostd.MemPackage, error)
- func GnoStdlibMemPackagesForContract(sourceCode string) ([]*gnostd.MemPackage, error)
- func HostABIMemPackages() []*gnostd.MemPackage
- func IsAllowedTypedContractImport(path string) bool
- func IsSupportedScalarType(typ TypeRef) bool
- func MitumChainMemPackage() *gnostd.MemPackage
- func MitumNativeResolver(pkgPath string, name gno.Name) func(m *gno.Machine)
- func NewGnoGasMeter(limit int64) gstore.GasMeter
- func NewPersistedContractSchema(sourceCode string, schema ContractSchema) contracttypes.PersistedContractSchema
- func QueryValueToJSONCompatible(schema ContractSchema, typ TypeRef, qv QueryValue) (interface{}, error)
- func RestoreSnapshot(m *gno.Machine, pkg *gno.PackageValue, snapshot []byte, schema ContractSchema) error
- func ValidateContractCallDataLimits(name string, callData map[string]string) error
- func ValidateContractCallItemsLimits(name string, items []ExecuteCallItem) error
- func ValidateSnapshotLimits(doc SnapshotDoc, snapshotBytes []byte) error
- type AccountReader
- type AllowedImportKind
- type AllowedImportSpec
- type BalanceReader
- type ComplexityRules
- type ContextRules
- type ContractEngine
- type ContractReader
- type ContractSchema
- func (s ContractSchema) FindFunction(name string) (FunctionSchema, bool)
- func (s ContractSchema) ResolveType(t TypeRef) TypeRef
- func (s ContractSchema) SupportsScalarOnlyType(t TypeRef) bool
- func (s ContractSchema) ValidatePersistentGlobalType(binding PersistentBindingSchema) error
- func (s ContractSchema) ValidateQueryArgType(typ TypeRef, subject string) error
- func (s ContractSchema) ValidateQueryResultType(typ TypeRef, subject string) error
- func (s ContractSchema) ValidateWriteArgType(typ TypeRef, subject string) error
- type ExecuteCallItem
- type ExecuteRequest
- type ExecuteResult
- type ExecutionContext
- type FunctionSchema
- func (fn FunctionSchema) IsContextCallable() bool
- func (fn FunctionSchema) IsQueryContextCallable() bool
- func (fn FunctionSchema) IsSingleErrorResult() bool
- func (fn FunctionSchema) IsTypedABIShape() bool
- func (fn FunctionSchema) IsTypedInitializeShape() bool
- func (fn FunctionSchema) IsTypedQueryShape() bool
- func (fn FunctionSchema) IsTypedWriteShape() bool
- func (fn FunctionSchema) IsWriteContextCallable() bool
- func (fn FunctionSchema) UsesLegacyContractContext() bool
- type GnoExecutionLimits
- type ImportRules
- type InputRules
- type InvocationMode
- type LifecycleRules
- type ParamSchema
- type PersistentBindingSchema
- type QueryField
- type QueryMapEntry
- type QueryRequest
- type QueryResult
- type QueryRules
- type QueryValue
- type ResultSchema
- type ScalarRules
- type SchemaMode
- type SchemaRuleset
- type SchemaShapeKind
- type SnapshotBinding
- type SnapshotDoc
- type SnapshotField
- type SnapshotMapEntry
- type SnapshotStats
- type SnapshotValue
- type SourceRules
- type StateAccountReader
- type StateBalanceReader
- type StateContractReader
- type StateRules
- type StructField
- type TypeKind
- type TypeRef
- type TypeRegistry
Constants ¶
const ( MaxContractCallDataEntries = 64 MaxContractCallDataKeyBytes = 128 MaxContractCallDataValueBytes = 16 * 1024 MaxContractCallDataTotalBytes = 64 * 1024 MaxContractCallItems = 16 MaxContractCallItemsTotalBytes = 64 * 1024 )
const ( GnoWriteGasLimit = int64(5_000_000) GnoQueryGasLimit = int64(1_000_000) GnoWriteMaxAllocBytes = int64(8 << 20) GnoQueryMaxAllocBytes = int64(4 << 20) )
Query gas is a read-only resource cap, not a transaction billing budget. It is intentionally smaller than write/register/call execution gas.
const ( GnoSnapshotCodecName = "gno-snapshot-json-v1" GnoSnapshotVersion = uint64(1) )
const ( MaxContractSnapshotBytes = 256 * 1024 MaxContractSnapshotMapEntries = 256 MaxContractSnapshotSliceItems = 256 MaxContractSnapshotNodes = 8 * 1024 )
const ( ScalarOnlySupportDescription = "current Gno typed ABI v1 supports only scalar types: string, bool, int, int64, uint64" FlatStructGlobalSupportDescription = "" /* 353-byte string literal not displayed */ MapGlobalSupportDescription = "" /* 342-byte string literal not displayed */ SliceSupportDescription = "" /* 310-byte string literal not displayed */ QueryResultSupportDescription = "" /* 308-byte string literal not displayed */ WriteArgSupportDescription = "current Gno write ABI v1 supports only scalar parameters: string, bool, int, int64, uint64" QueryArgSupportDescription = "current Gno query ABI v1 supports only scalar parameters: string, bool, int, int64, uint64" )
const ( MaxContractSchemaImports = 16 MaxContractSchemaFunctions = 128 MaxContractSchemaPersistentGlobals = 128 MaxContractSchemaStructs = 64 MaxContractSchemaStructFields = 64 MaxContractSchemaTypeNestingDepth = 16 MaxContractSchemaNodes = 4096 )
const ( // CurrentSchemaRulesetVersion names the current context-split typed Gno // ABI as the canonical baseline. The earlier ContractContext draft was // internal design-convergence work, not a durable external compatibility // line, so this baseline intentionally remains v1 instead of preserving a // legacy-style v2 name. CurrentSchemaRulesetVersion = "typed-gno-ruleset-v1" MaxTypedContractSourceBytes = 256 * 1024 )
const (
MitumChainPackageName = "chain"
)
const MitumChainPackagePath = "mitum/chain"
Variables ¶
var AllowedTypedContractImports = allowedTypedContractImportPaths()
AllowedTypedContractImports is a compatibility snapshot of the current policy. Validation reads the canonical import specs directly.
Functions ¶
func AllowedTypedContractImportsDescription ¶
func AllowedTypedContractImportsDescription() string
func BuildExpr ¶
func BuildExpr(schema ContractSchema, typ TypeRef, sv SnapshotValue) (gno.Expr, error)
func BuildLiteral ¶
func BuildLiteral(schema ContractSchema, typ TypeRef, sv SnapshotValue) (string, error)
func CaptureSnapshot ¶
func CaptureSnapshot(pkg *gno.PackageValue, store gno.Store, schema ContractSchema) ([]byte, error)
func CombineNativeResolvers ¶
func CombineNativeResolvers(resolvers ...gno.NativeResolver) gno.NativeResolver
func GetAccountStateFunc ¶
func GnoStdlibMemPackages ¶
func GnoStdlibMemPackages() ([]*gnostd.MemPackage, error)
GnoStdlibMemPackages returns the Gno source packages needed by the allowed contract stdlib imports. The Gno source is vendored under gno_stdlib and embedded into the binary, so runtime execution does not depend on GNOROOT, GOMODCACHE, or a local github.com/gnolang/gno checkout.
Internal dependencies are loaded to execute allowed packages, but are not added to the contract import allowlist.
func GnoStdlibMemPackagesForContract ¶
func GnoStdlibMemPackagesForContract(sourceCode string) ([]*gnostd.MemPackage, error)
GnoStdlibMemPackagesForContract returns only directly imported allowed stdlib packages and their internal dependencies. This keeps contracts which import no stdlib from paying package initialization cost for unused code.
func HostABIMemPackages ¶
func HostABIMemPackages() []*gnostd.MemPackage
func IsSupportedScalarType ¶
func MitumChainMemPackage ¶
func MitumChainMemPackage() *gnostd.MemPackage
func MitumNativeResolver ¶
func NewGnoGasMeter ¶
func NewPersistedContractSchema ¶
func NewPersistedContractSchema( sourceCode string, schema ContractSchema, ) contracttypes.PersistedContractSchema
func QueryValueToJSONCompatible ¶
func QueryValueToJSONCompatible(schema ContractSchema, typ TypeRef, qv QueryValue) (interface{}, error)
func RestoreSnapshot ¶
func RestoreSnapshot(m *gno.Machine, pkg *gno.PackageValue, snapshot []byte, schema ContractSchema) error
func ValidateContractCallItemsLimits ¶
func ValidateContractCallItemsLimits(name string, items []ExecuteCallItem) error
func ValidateSnapshotLimits ¶
func ValidateSnapshotLimits(doc SnapshotDoc, snapshotBytes []byte) error
Types ¶
type AccountReader ¶
type AllowedImportKind ¶
type AllowedImportKind string
const ( AllowedImportHostABI AllowedImportKind = "hostabi" AllowedImportStdlib AllowedImportKind = "stdlib" )
type AllowedImportSpec ¶
type AllowedImportSpec struct {
Path string
Kind AllowedImportKind
}
func AllowedTypedContractImportSpecs ¶
func AllowedTypedContractImportSpecs() []AllowedImportSpec
AllowedTypedContractImportSpecs returns the canonical contract-facing import policy. Schema admission and runtime package registration must derive from this list so an admitted import cannot silently lose runtime support.
type BalanceReader ¶
type ComplexityRules ¶
type ContextRules ¶
type ContextRules struct {
WriteContextType string
QueryContextType string
LegacyContractContextType string
LegacyContractContextAllowed bool
QueryContextSenderAllowed bool
QuerySenderCallDataKeyParsed bool
QueryContextCurrentHeightAllowed bool
WriteContextCurrentHeightAllowed bool
ChainCurrentHeightNativeAllowed bool
WriteContextBlockTimeAllowed bool
QueryContextBlockTimeAllowed bool
}
type ContractEngine ¶
type ContractEngine interface {
ValidateContract(sourceCode string) (ContractSchema, base.OperationProcessReasonError)
ExecuteContract(
encs encoder.Encoders,
getStateFunc base.GetStateFunc,
req ExecuteRequest,
) (ExecuteResult, base.OperationProcessReasonError)
QueryContract(
encs encoder.Encoders,
getStateFunc base.GetStateFunc,
req QueryRequest,
) (QueryResult, base.OperationProcessReasonError)
}
func NewGnoEngine ¶
func NewGnoEngine() ContractEngine
type ContractReader ¶
type ContractSchema ¶
type ContractSchema struct {
PackageName string
Mode SchemaMode
Types TypeRegistry
PersistentGlobals []PersistentBindingSchema
Functions []FunctionSchema
}
func AnalyzeContractSchema ¶
func AnalyzeContractSchema(sourceCode string) (ContractSchema, error)
func RuntimeSchemaFromPersisted ¶
func RuntimeSchemaFromPersisted( sourceCode string, persisted *contracttypes.PersistedContractSchema, ) (ContractSchema, bool)
func (ContractSchema) FindFunction ¶
func (s ContractSchema) FindFunction(name string) (FunctionSchema, bool)
func (ContractSchema) ResolveType ¶
func (s ContractSchema) ResolveType(t TypeRef) TypeRef
func (ContractSchema) SupportsScalarOnlyType ¶
func (s ContractSchema) SupportsScalarOnlyType(t TypeRef) bool
func (ContractSchema) ValidatePersistentGlobalType ¶
func (s ContractSchema) ValidatePersistentGlobalType(binding PersistentBindingSchema) error
func (ContractSchema) ValidateQueryArgType ¶
func (s ContractSchema) ValidateQueryArgType(typ TypeRef, subject string) error
func (ContractSchema) ValidateQueryResultType ¶
func (s ContractSchema) ValidateQueryResultType(typ TypeRef, subject string) error
func (ContractSchema) ValidateWriteArgType ¶
func (s ContractSchema) ValidateWriteArgType(typ TypeRef, subject string) error
type ExecuteCallItem ¶
type ExecuteRequest ¶
type ExecuteRequest struct {
Mode InvocationMode
Contract base.Address
Sender base.Address
Height base.Height
BlockTime int64
ContractCode string
Schema *ContractSchema
// Function and CallData are kept as a legacy single-call bridge. New call
// execution should normalize through CallItems; register should use InitData.
Function string
CallData map[string]string
CallItems []ExecuteCallItem
InitData map[string]string
}
type ExecuteResult ¶
type ExecuteResult struct {
Engine state.RuntimeEngine
StateMerges []base.StateMergeValue
}
type ExecutionContext ¶
type ExecutionContext struct {
Sender base.Address
Contract base.Address
Height base.Height
CurrentHeight base.Height
ReadOnly bool
AccountReader AccountReader
ContractReader ContractReader
BalanceReader BalanceReader
}
func NewExecutionContext ¶
func (*ExecutionContext) Validate ¶
func (ctx *ExecutionContext) Validate() error
type FunctionSchema ¶
type FunctionSchema struct {
Name string
Exported bool
Params []ParamSchema
Results []ResultSchema
}
func (FunctionSchema) IsContextCallable ¶
func (fn FunctionSchema) IsContextCallable() bool
func (FunctionSchema) IsQueryContextCallable ¶
func (fn FunctionSchema) IsQueryContextCallable() bool
func (FunctionSchema) IsSingleErrorResult ¶
func (fn FunctionSchema) IsSingleErrorResult() bool
func (FunctionSchema) IsTypedABIShape ¶
func (fn FunctionSchema) IsTypedABIShape() bool
func (FunctionSchema) IsTypedInitializeShape ¶
func (fn FunctionSchema) IsTypedInitializeShape() bool
func (FunctionSchema) IsTypedQueryShape ¶
func (fn FunctionSchema) IsTypedQueryShape() bool
func (FunctionSchema) IsTypedWriteShape ¶
func (fn FunctionSchema) IsTypedWriteShape() bool
func (FunctionSchema) IsWriteContextCallable ¶
func (fn FunctionSchema) IsWriteContextCallable() bool
func (FunctionSchema) UsesLegacyContractContext ¶
func (fn FunctionSchema) UsesLegacyContractContext() bool
type GnoExecutionLimits ¶
func QueryGnoExecutionLimits ¶
func QueryGnoExecutionLimits() GnoExecutionLimits
func WriteGnoExecutionLimits ¶
func WriteGnoExecutionLimits() GnoExecutionLimits
type ImportRules ¶
type ImportRules struct {
AllowedImports []string
}
type InputRules ¶
type InputRules struct {
CompositeInputAllowed bool
}
type InvocationMode ¶
type InvocationMode string
const ( InvocationModeRegister InvocationMode = "register" InvocationModeCall InvocationMode = "call" )
type LifecycleRules ¶
type ParamSchema ¶
type PersistentBindingSchema ¶
type QueryField ¶
type QueryField struct {
Name string `json:"name"`
Value QueryValue `json:"value"`
}
type QueryMapEntry ¶
type QueryMapEntry struct {
Key string `json:"key"`
Value QueryValue `json:"value"`
}
type QueryRequest ¶
type QueryResult ¶
type QueryResult struct {
Engine state.RuntimeEngine
Result interface{}
Ok *bool
}
type QueryRules ¶
type QueryRules struct {
TopLevelResultKinds []SchemaShapeKind
NestedStructFieldKinds []SchemaShapeKind
SliceElementKinds []SchemaShapeKind
MapKeyScalarKinds []string
MapValueKinds []SchemaShapeKind
SingleResultAllowed bool
BoolPresenceResultAllowed bool
BoolPresenceResultValueKinds []SchemaShapeKind
BoolPresenceSecondResultScalarKind string
EmbeddedFieldsAllowed bool
NamedStructAllowed bool
NestedNamedStructAllowed bool
AnonymousResultStructAllowed bool
AnonymousNestedStructFieldsAllowed bool
RecursiveNamedStructsAllowed bool
TopLevelMapAllowed bool
NestedMapAllowed bool
MapStringScalarAllowed bool
MapStringNamedStructAllowed bool
AnonymousStructMapValuesAllowed bool
MapValueSlicesAllowed bool
MapValueMapsAllowed bool
TopLevelSliceAllowed bool
NestedSliceAllowed bool
SliceScalarAllowed bool
SliceNamedStructAllowed bool
AnonymousStructSliceElementsAllowed bool
SliceElementSlicesAllowed bool
SliceElementMapsAllowed bool
}
type QueryValue ¶
type QueryValue struct {
Kind string `json:"kind"`
Scalar string `json:"scalar,omitempty"`
Fields []QueryField `json:"fields,omitempty"`
Entries []QueryMapEntry `json:"entries,omitempty"`
Items []QueryValue `json:"items,omitempty"`
IsNil bool `json:"is_nil,omitempty"`
}
func ExtractQueryValue ¶
func ExtractQueryValue(schema ContractSchema, typ TypeRef, tv gno.TypedValue, store gno.Store) (QueryValue, error)
type ResultSchema ¶
type ResultSchema struct {
Type TypeRef
}
type ScalarRules ¶
type ScalarRules struct {
AllowedKinds []string
}
type SchemaMode ¶
type SchemaMode string
const (
SchemaModeTypedArgs SchemaMode = "typed-snapshot-v1"
)
type SchemaRuleset ¶
type SchemaRuleset struct {
// Version tracks the semantic contract-schema policy bundle.
// It is distinct from the snapshot codec version and any future
// serialized schema metadata format version.
//
// Bump this version when accepted/rejected schema meaning changes:
// package/source rules, import allowlist, scalar kinds, input/state/query
// shapes, lifecycle semantics, complexity limits, or struct/map/slice
// constraints. Do not bump for support text wording, error wording,
// test-only hooks, or implementation refactors that preserve the same
// schema acceptance policy. During pre-external design convergence, prefer
// redefining the canonical baseline over carrying legacy-preserving version
// increments without a concrete compatibility reason.
Version string
SourceRules SourceRules
ImportRules ImportRules
ScalarRules ScalarRules
ContextRules ContextRules
InputRules InputRules
StateRules StateRules
QueryRules QueryRules
LifecycleRules LifecycleRules
ComplexityRules ComplexityRules
}
func CurrentSchemaRuleset ¶
func CurrentSchemaRuleset() SchemaRuleset
type SchemaShapeKind ¶
type SchemaShapeKind string
const ( SchemaShapeScalar SchemaShapeKind = "scalar" SchemaShapeNamedStruct SchemaShapeKind = "named-struct" SchemaShapeMap SchemaShapeKind = "map" SchemaShapeSlice SchemaShapeKind = "slice" SchemaShapeAnonymousStruct SchemaShapeKind = "anonymous-struct" )
type SnapshotBinding ¶
type SnapshotBinding struct {
Name string `json:"name"`
Value SnapshotValue `json:"value"`
}
type SnapshotDoc ¶
type SnapshotDoc struct {
Version uint64 `json:"version"`
Bindings []SnapshotBinding `json:"bindings"`
}
type SnapshotField ¶
type SnapshotField struct {
Name string `json:"name"`
Value SnapshotValue `json:"value"`
}
type SnapshotMapEntry ¶
type SnapshotMapEntry struct {
Key string `json:"key"`
Value SnapshotValue `json:"value"`
}
type SnapshotStats ¶
type SnapshotStats struct {
Bytes int
Bindings int
MapEntries int
SliceItems int
StructNodes int
Nodes int
}
func SnapshotStatsForDoc ¶
func SnapshotStatsForDoc(doc SnapshotDoc, snapshotBytes []byte) SnapshotStats
type SnapshotValue ¶
type SnapshotValue struct {
Kind string `json:"kind"`
Scalar string `json:"scalar,omitempty"`
Fields []SnapshotField `json:"fields,omitempty"`
Entries []SnapshotMapEntry `json:"entries,omitempty"`
Items []SnapshotValue `json:"items,omitempty"`
IsNil bool `json:"is_nil,omitempty"`
}
func ExtractSnapshotValue ¶
func ExtractSnapshotValue(schema ContractSchema, typ TypeRef, tv gno.TypedValue) (SnapshotValue, error)
type SourceRules ¶
type StateAccountReader ¶
type StateAccountReader struct {
// contains filtered or unexported fields
}
func NewStateAccountReader ¶
func NewStateAccountReader( encs encoder.Encoders, getStateFunc base.GetStateFunc, ) StateAccountReader
func (StateAccountReader) AccountExists ¶
func (r StateAccountReader) AccountExists(addr string) (bool, error)
type StateBalanceReader ¶
type StateBalanceReader struct {
// contains filtered or unexported fields
}
func NewStateBalanceReader ¶
func NewStateBalanceReader( encs encoder.Encoders, getStateFunc base.GetStateFunc, ) StateBalanceReader
type StateContractReader ¶
type StateContractReader struct {
// contains filtered or unexported fields
}
func NewStateContractReader ¶
func NewStateContractReader( encs encoder.Encoders, getStateFunc base.GetStateFunc, ) StateContractReader
func (StateContractReader) IsContractAccount ¶
func (r StateContractReader) IsContractAccount(addr string) (bool, error)
type StateRules ¶
type StateRules struct {
TopLevelPersistentGlobalKinds []SchemaShapeKind
NestedStructFieldKinds []SchemaShapeKind
SliceElementKinds []SchemaShapeKind
MapKeyScalarKinds []string
MapValueKinds []SchemaShapeKind
ExplicitPersistentGlobalTypeRequired bool
EmbeddedFieldsAllowed bool
NamedStructAllowed bool
NestedNamedStructAllowed bool
AnonymousNestedStructFieldsAllowed bool
RecursiveNamedStructsAllowed bool
TopLevelMapAllowed bool
NestedMapAllowed bool
MapStringScalarAllowed bool
MapStringNamedStructAllowed bool
AnonymousStructMapValuesAllowed bool
MapValueSlicesAllowed bool
MapValueMapsAllowed bool
TopLevelSliceAllowed bool
NestedSliceAllowed bool
SliceScalarAllowed bool
SliceNamedStructAllowed bool
AnonymousStructSliceElementsAllowed bool
SliceElementSlicesAllowed bool
SliceElementMapsAllowed bool
}
type StructField ¶
type TypeRef ¶
type TypeRef struct {
Kind TypeKind
Raw string
Scalar string
Name string
Key *TypeRef
Elem *TypeRef
Fields []StructField
}
func (TypeRef) NormalizedString ¶
type TypeRegistry ¶
func NewTypeRegistry ¶
func NewTypeRegistry() TypeRegistry
Source Files
¶
- call_data_limits.go
- engine.go
- gno_call_arg.go
- gno_engine.go
- gno_execution_context.go
- gno_hostabi_package.go
- gno_limits.go
- gno_native_gas.go
- gno_native_resolver.go
- gno_package_load_error.go
- gno_query.go
- gno_query_value.go
- gno_snapshot_codec.go
- gno_snapshot_limits.go
- gno_stdlib_package.go
- import_policy.go
- schema.go
- schema_analyzer.go
- schema_cache.go
- schema_complexity.go
- schema_metadata.go
- schema_ruleset.go
- state_readers.go