Skip to content

Commit

Permalink
renamed several types for clarity
Browse files Browse the repository at this point in the history
- renamed Logic to LogicDriver
- renamed CtxDriver to StateDriver, ContextStateKind to StateKind and ContextStateMatrix to StateMatrix
- renamed EnvDriver to EnvironmentDriver
- renamed CryptoDriver to CryptographyDriver
- renamed IxnDriver to InteractionDriver and IxnType to InteractionType
- renamed ReferenceVal to ReferenceValue
- renamed FetchCryptoDriver function to FetchCryptographyDriver
  • Loading branch information
sarvalabs-manish committed Sep 24, 2023
1 parent 1dae462 commit c257b97
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 247 deletions.
7 changes: 3 additions & 4 deletions callsite.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"gopkg.in/yaml.v3"
)

// Callsite represents a callable point in a Logic.
// It can be resolved from a string identifier
// with the GetCallsite method on Logic
// Callsite represents a callable point in a LogicDriver.
// It can be resolved from a string identifier with the GetCallsite method on LogicDriver
type Callsite struct {
Ptr ElementPtr
Kind CallsiteKind
}

// CallsiteKind represents the type of callable point in a Logic.
// CallsiteKind represents the type of callable point in a LogicDriver.
type CallsiteKind int

const (
Expand Down
143 changes: 0 additions & 143 deletions context.go

This file was deleted.

9 changes: 5 additions & 4 deletions drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/sarvalabs/go-polo"
)

// EnvDriver represents a driver for environmental information.
// EnvironmentDriver represents a driver for environmental information.
// It describes information about the execution context such
// as the consensus cluster ID or execution timestamp.
type EnvDriver interface {
type EnvironmentDriver interface {
Timestamp() int64
ClusterID() string
}
Expand All @@ -22,6 +22,7 @@ type EnvDriver interface {
// the pointers being vertices and their relationship being directional edges.
type DependencyDriver interface {
fmt.Stringer

json.Marshaler
json.Unmarshaler

Expand All @@ -38,10 +39,10 @@ type DependencyDriver interface {
Dependencies(uint64) []uint64
}

// CryptoDriver represents an interface for cryptographic operations.
// CryptographyDriver represents an interface for cryptographic operations.
// It can be used to validate signature formats and verify them for a public key.
// This interfaces allows us to pass the capabilities of go-moi's crypto package to different engine runtimes.
type CryptoDriver interface {
type CryptographyDriver interface {
ValidateSignature(sig []byte) bool
VerifySignature(data, sig, pub []byte) (bool, error)
}
10 changes: 5 additions & 5 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ type CallEncoder interface {
DecodeOutputs([]byte) (map[string]any, error)
}

// ReferenceVal is a reference identifier
// ReferenceValue is a reference identifier
// that resolves to an encodable value
type ReferenceVal string
type ReferenceValue string

func (ref ReferenceVal) String() string {
func (ref ReferenceValue) String() string {
return "ref<" + string(ref) + ">"
}

// ReferenceProvider resolves a ReferenceVal into
// an encodable value confirming the resolution
type ReferenceProvider interface {
GetReference(ReferenceVal) (any, bool)
GetReference(ReferenceValue) (any, bool)
}

// EncodeValues encodes a value into a bytes, recursively resolving any internal type data.
Expand Down Expand Up @@ -102,7 +102,7 @@ func EncodeValues(value any, references ReferenceProvider) ([]byte, error) {
return polorizer.Bytes(), nil

// Reference Type
case ReferenceVal:
case ReferenceValue:
// If no reference provider is given, error
if references == nil {
return nil, errors.New("encountered reference value without a ref provider")
Expand Down
8 changes: 4 additions & 4 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

type mockRefProvider map[string]any

func (m mockRefProvider) GetReference(ref ReferenceVal) (any, bool) {
func (m mockRefProvider) GetReference(ref ReferenceValue) (any, bool) {
val, ok := m[string(ref)]

return val, ok
}

func TestReferenceVal_String(t *testing.T) {
ref := ReferenceVal("foo")
ref := ReferenceValue("foo")
assert.Equal(t, "ref<foo>", ref.String())
}

Expand All @@ -42,14 +42,14 @@ func TestEncodeValues(t *testing.T) {
},
{
name: "encode reference",
input: ReferenceVal("myref"),
input: ReferenceValue("myref"),
refs: &mockRefProvider{"myref": 100},
output: []byte{0x03, 0x64},
err: "",
},
{
name: "encode reference without provider",
input: ReferenceVal("myref"),
input: ReferenceValue("myref"),
output: nil,
err: "encountered reference value without a ref provider",
},
Expand Down
39 changes: 19 additions & 20 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,55 @@ type EngineFuel = uint64

// Engine is an execution engine interface with a specific EngineKind.
// A new Engine instance can be spawned from an EngineRuntime with its
// SpawnEngine method an is bound to a specific Logic and EnvDriver.
// SpawnEngine method and is bound to a specific LogicDriver and EnvironmentDriver.
//
// An Engine can be used to perform calls on its Logic with an IxnDriver
// and some optional participants with their CtxDriver objects.
// An Engine can be used to perform calls on its LogicDriver with an InteractionDriver
// and some optional participants with their StateDriver objects.
type Engine interface {
// Kind returns the kind of engine
Kind() EngineKind

// Call calls a logical callsite on the Engine's Logic.
// The callsite and input calldata are provided in the given IxnDriver.
// Optionally accepts some participant CtxDriver objects based on the interaction type.
Call(context.Context, IxnDriver, ...CtxDriver) (CallResult, error)
// Call calls a logical callsite on the Engine's LogicDriver.
// The callsite and input calldata are provided in the given InteractionDriver.
// Optionally accepts some participant StateDriver objects based on the interaction type.
Call(context.Context, InteractionDriver, ...StateDriver) (CallResult, error)
}

// EngineRuntime is an interface that defines an engine runtime.

// EngineRuntime is the base definition for execution engine runtime. It is
// used for runtime level behavioural capabilities rather for logic execution.
//
// This can include:
// - Compiling Manifest objects for the runtime into a Logic
// - Spawning execution Engine instances 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
// - Decoding DependencyDriver and ErrorResult objects for the runtime
// - Compiling Manifest objects for the runtime into a LogicDriver
// - Spawning execution Engine instances 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
// - Decoding DependencyDriver and ErrorResult objects for the runtime
type EngineRuntime interface {
// Kind returns the kind of engine that the factory can produce
Kind() EngineKind
// Version returns the semver version string of the engine runtime
Version() string

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

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

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

// GetElementGenerator returns a generator function for an element schema with the
// given ElementKind. Returns false, if no such element is defined by the runtime
GetElementGenerator(ElementKind) (ManifestElementGenerator, bool)

// GetCallEncoder returns a CallEncoder object for a given
// callsite element pointer from a LogicDriver object
GetCallEncoder(*Callsite, Logic) (CallEncoder, error)
GetCallEncoder(*Callsite, LogicDriver) (CallEncoder, error)

// DecodeDependencyDriver decodes the given bytes of the given
// encoding into a DepDriver that is supported by the engine runtime
Expand Down
18 changes: 9 additions & 9 deletions interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package engineio

import "math/big"

// IxnType is an interface that describes the different kinds of
// interactions available on go-moi. Each IxnType has a unique ID
// and a string representation. It is implemented by common.IxType.
type IxnType interface {
// InteractionType is an interface that describes the different kinds
// of interactions available on go-moi. Each InteractionType has a unique
// ID and a string representation. It is implemented by common.IxType.
type InteractionType interface {
IxnID() int
String() string
}

// IxnDriver represents a driver for interaction information.
// It describes the callsite and input calldata for execution calls along
// with other information such as the Interaction's fuel parameters or transfer funds.
type IxnDriver interface {
IxnType() IxnType
// InteractionDriver represents a driver for interaction information.
// It describes the callsite and input calldata for execution calls along with
// other information such as the Interaction's fuel parameters or transfer funds.
type InteractionDriver interface {
InteractionType() InteractionType

FuelPrice() *big.Int
FuelLimit() uint64
Expand Down
Loading

0 comments on commit c257b97

Please sign in to comment.