Skip to content

Commit

Permalink
fix docs and identifier imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvalabs-manish committed Dec 29, 2023
1 parent 3aa3cbd commit 26be2d0
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 55 deletions.
15 changes: 4 additions & 11 deletions common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package engineio

type (
// Hash is a 256-bit checksum digest
Hash = [32]byte
// Address is a 256-bit unique identifier for a participant.
Address = [32]byte
)

type (
// ElementKind is a type alias for an element kind string
ElementKind string
Expand Down Expand Up @@ -35,8 +28,8 @@ type Callsite interface {
type CallsiteKind int

const (
DeployerCallsite CallsiteKind = iota
EnlisterCallsite
InvokableCallsite
InteractableCallsite
CallsiteDeployer CallsiteKind = iota
CallsiteEnlister
CallsiteInvokable
CallsiteInteractable
)
21 changes: 16 additions & 5 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,46 @@ type CallEncoder interface {

// RuntimeEncoder is an interface that describes all encoding capabilities for a runtime
type RuntimeEncoder interface {
// Kind returns the kind of engine that the factory can produce
// Kind returns the kind of engine that the encoder works for
Kind() EngineKind

// EncodeValues encodes any given value into a byte representation suitable for the runtime.
// It also supports reference based encoding by accepting a ReferenceProvider
EncodeValues(any, ReferenceProvider) ([]byte, error)

// EncodeManifest encodes a Manifest with the given Encoding
EncodeManifest(Manifest, Encoding) ([]byte, error)
// DecodeManifest decodes a Manifest from some raw data of the given Encoding
DecodeManifest([]byte, Encoding) (Manifest, error)

// EncodeErrorResult encodes an ErrorResult into some
// byte representation suitable for the runtime
EncodeErrorResult(ErrorResult) ([]byte, error)
// DecodeErrorResult decodes the given bytes into an
// ErrorResult that is used by the engine runtime
// ErrorResult that is suitable for the engine runtime
DecodeErrorResult([]byte) (ErrorResult, error)
EncodeErrorResult(ErrorResult) ([]byte, error)

// EncodeDependencies encodes a DependencyDriver into the given encoding
EncodeDependencies(DependencyDriver, Encoding) ([]byte, error)
// DecodeDependencies decodes the given bytes of the given encoding
// into a DependencyDriver that is supported by the engine runtime
DecodeDependencies([]byte, Encoding) (DependencyDriver, error)
EncodeDependencies(DependencyDriver, Encoding) ([]byte, error)

// EncodeCallsite encodes a Callsite into the given encoding
EncodeCallsite(Callsite, Encoding) ([]byte, error)
// DecodeCallsite decodes a Callsite from the given encoding
DecodeCallsite([]byte, Encoding) (Callsite, error)

// EncodeClassdef encodes a Classdef into the given encoding
EncodeClassdef(Classdef, Encoding) ([]byte, error)
// DecodeClassdef decodes a Classdef from the given encoding
DecodeClassdef([]byte, Encoding) (Classdef, error)
}

// Reference is a reference identifier
// that resolves to an encodable value
type Reference interface {
String()
Identifier() string
}

// ReferenceProvider resolves a Reference into
Expand Down
24 changes: 12 additions & 12 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const (
// The canonical implementation is available at https://github.com/sarvalabs/go-pisa
PISA

// MERU is the EngineKind for a hypothetical engine runtime that works as a
// WASI (WebAssembly) based VM Runtime for MOI. No implementation exists yet.
// MERU is the EngineKind for a hypothetical engine runtime that works as a WASM
// environment that allows custom runtime implementations to run within it
MERU
)

Expand All @@ -42,15 +42,15 @@ type EngineInstance interface {
// used for runtime level behavioural capabilities rather for logic execution.
//
// This can include:
// - Compiling Manifest objects for the runtime into a Logic
// - Spawning execution EngineInstance for a specific Logic
// - Validating input calldata for a specific callsite on a Logic
// - Obtaining a calldata encoder for a specific callsite on a Logic
// - Compiling Manifest objects for the runtime into a LogicDriver
// - Spawning execution EngineInstance for a specific LogicDriver
// - Validating input calldata for a specific callsite on a LogicDriver
// - Obtaining a calldata encoder for a specific callsite on a LogicDriver
type EngineRuntime interface {
// RuntimeEncoder is an embedded interface for EngineRuntime, allowing
// the runtime to specify encoding/decoding rules for runtime specific
// types like Manifest, ErrorResult, DependencyDriver, etc.
// RuntimeEncoder
RuntimeEncoder

// Kind returns the kind of engine that the factory can produce
Kind() EngineKind
Expand All @@ -60,21 +60,21 @@ type EngineRuntime interface {
// GenerateRuntimeEncoder returns the RuntimeEncoder instance for the runtime
GenerateRuntimeEncoder() RuntimeEncoder
// GenerateCallEncoder returns a CallEncoder object for a
// given callsite element pointer from a Logic object
GenerateCallEncoder(Logic, Callsite) (CallEncoder, error)
// given callsite element pointer from a LogicDriver object
GenerateCallEncoder(LogicDriver, Callsite) (CallEncoder, error)

// SpawnInstance returns a new EngineInstance instance and initializes it with some
// EngineFuel, a Logic, the StateDriver associated with the logic and an EnvironmentDriver.
// EngineFuel, a LogicDriver, the StateDriver associated with the logic and an EnvironmentDriver.
// Will return an error if the Logic and its StateDriver do not match.
SpawnInstance(Logic, EngineFuel, StateDriver, EnvironmentDriver) (EngineInstance, error)
SpawnInstance(LogicDriver, EngineFuel, StateDriver, EnvironmentDriver) (EngineInstance, error)

// CompileManifest generates a LogicDescriptor from a Manifest, which can then be used to generate
// a Logic object. The fuel spent during compile is returned with any potential error.
CompileManifest(Manifest, EngineFuel) (LogicDescriptor, EngineFuel, error)

// ValidateCalldata verifies the calldata and callsite in an InteractionDriver.
// The Logic must describe a callsite which accepts the calldata.
ValidateCalldata(Logic, InteractionDriver) error
ValidateCalldata(LogicDriver, InteractionDriver) error
}

// registry is an in-memory registry of supported EngineRuntime instances.
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/sarvalabs/go-moi-engineio

go 1.20

require github.com/sarvalabs/go-moi-identifiers v0.1.0

require github.com/pkg/errors v0.9.1 // indirect
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/sarvalabs/go-moi-identifiers v0.1.0 h1:7JM/f+n4hvEFsaGQAvI8xLajkI6MamecSZLTPDtTEdg=
github.com/sarvalabs/go-moi-identifiers v0.1.0/go.mod h1:oui+KkrobvXej/S+qU6iaLunWRHtbxfvVnIWdbHEE6o=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
27 changes: 13 additions & 14 deletions logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ type LogicDriver interface {
LogicID() identifiers.LogicID
// Engine returns the EngineKind of the LogicDriver
Engine() EngineKind
// Manifest returns the hash of the logic's Manifest
Manifest() Hash
// ManifestHash returns the 256-bit digest hash of the logic's Manifest
ManifestHash() [32]byte

// IsSealed returns whether the state of the LogicDriver has been sealed
IsSealed() bool
// IsAssetLogic returns whether the LogicDriver is used for regulating an Asset
IsAssetLogic() bool
// IsInteractive returns whether the LogicDriver supports Interactable Callsites
IsInteractive() bool
// IsInteractable returns whether the LogicDriver supports Interactable Callsites
IsInteractable() bool

// PersistentState returns the pointer to the persistent state element
// with a confirmation that the LogicDriver defines a PersistentState
Expand All @@ -35,15 +33,16 @@ type LogicDriver interface {
// with a confirmation that the LogicDriver defines a EphemeralState
EphemeralState() (ElementPtr, bool)

// GetElementDeps returns the aggregated dependencies of an element pointer.
// The aggregation includes all sub-dependencies recursively.
GetElementDeps(ElementPtr) []ElementPtr
// GetElement returns the LogicElement for a given element pointer with confirmation of its existence.
GetElement(ElementPtr) (*LogicElement, bool)
// GetCallsite returns Callsite for a given string name with confirmation of its existence.
GetCallsite(string) (*Callsite, bool)
// GetClassdef returns class Datatype for a given string name with confirmation of its existence.
GetClassdef(string) (*Classdef, bool)

// GetElement returns the LogicElement for a given element pointer with confirmation of its existence.
GetElement(ElementPtr) (*LogicElement, bool)
// GetElementDeps returns the aggregated dependencies of an element pointer.
// The aggregation includes all sub-dependencies recursively.
GetElementDeps(ElementPtr) []ElementPtr
}

// LogicDescriptor is a container type returned by the CompileManifest method of EngineRuntime.
Expand All @@ -55,9 +54,9 @@ type LogicDriver interface {
type LogicDescriptor struct {
Engine EngineKind

ManifestRaw []byte
ManifestHash Hash
Interactable bool
ManifestData []byte
ManifestHash [32]byte
Interactable bool

States StateMatrix
Elements LogicElementTable
Expand Down
18 changes: 9 additions & 9 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package engineio
type Manifest interface {
// Kind returns the kind of engine of the Manifest
Kind() EngineKind
// Hash returns the 256-bit hash of the Manifest.
// Hash returns the 256-bit digest of the Manifest.
Hash() [32]byte
// Size returns the number of elements in the Manifest
Size() uint64
Expand All @@ -32,6 +32,14 @@ type Manifest interface {
GenerateCallEncoder(Callsite) (CallEncoder, error)
}

// ManifestHeader represents the header for a Manifest and describes its syntax form
// and engine specification. Useful for determining which engine to use to handle the
// Manifest. Every engine's manifest implementation must be able to decode into this header.
type ManifestHeader struct {
Syntax uint64 `yaml:"syntax" json:"syntax"`
Engine ManifestEngine `yaml:"engine" json:"engine"`
}

// ManifestEngine describes the engine specification in the Manifest
type ManifestEngine struct {
Kind EngineKind
Expand All @@ -51,11 +59,3 @@ type ManifestElement struct {
Kind ElementKind
Data any
}

// ManifestHeader represents the header for a Manifest and describes its syntax form
// and engine specification. Useful for determining which engine to use to handle the
// Manifest. Every engine's manifest implementation must be able to decode into this header.
type ManifestHeader struct {
Syntax uint64 `yaml:"syntax" json:"syntax"`
Engine ManifestEngine `yaml:"engine" json:"engine"`
}
4 changes: 2 additions & 2 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ type CallResult interface {
//
// It can be decoded from the raw data using the DecodeErrorResult method of EngineRuntime
type ErrorResult interface {
// Engine specifies the engine kind
// that generated the ErrorResult
// Engine specifies the engine kind that generated the ErrorResult
Engine() EngineKind
// String returns a string representation of ErrorResult
String() string
// Bytes returns the bytes representation of ErrorResult
Bytes() []byte
// Reverted returns whether the ErrorResult has a reversion flag
Reverted() bool
}
6 changes: 4 additions & 2 deletions state.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package engineio

import "github.com/sarvalabs/go-moi-identifiers"

// StateDriver represents an interface for accessing and manipulating state information of an account.
// It is bounded to a particular account and can only mutate within applicable portions
// of the state within the bounds of the logic's namespace
type StateDriver interface {
Address() Address
LogicID() LogicID
Address() identifiers.Address
LogicID() identifiers.LogicID

GetStorageEntry([]byte) ([]byte, bool)
SetStorageEntry([]byte, []byte) bool
Expand Down

0 comments on commit 26be2d0

Please sign in to comment.