Operate v0.1.0-beta.1 Operate View Source
Load and run Operate programs (known as "tapes") from the BSV blockchain.
Operate is an extensible Bitcoin meta programming protocol. It offers a way of constructing Turing Complete programs encapsulated in Bitcoin transactions that can be be used to process data, perform calculations and operations, and return any kind of result.
Installation
The package is bundled with libsecp256k1
NIF bindings. libtool
, automake
and autogen
are required in order for the package to compile.
The package can be installed by adding operate
to your list of dependencies
in mix.exs
.
The most recent luerl
package published on hex.pm
is based on Lua 5.2
which may not be compatible with all Ops. It is recommended to override the
luerl
dependency with the latest development version to benefit from Lua 5.3.
def deps do
[
{:operate, "~> 0.1.0-beta.1"},
{:luerl, github: "rvirding/luerl", branch: "develop", override: true}
]
end
Quick start
The agent can be used straight away without starting any processes. This will run without caching so should only be used for testing and kicking the tyres.
{:ok, tape} = Operate.load_tape(txid)
{:ok, tape} = Operate.run_tape(tape)
tape.result
See load_tape/2
and run_tape/2
.
Process supervision
To enable caching the agent should be started as part of your applications process supervision tree.
children = [
{Operate, [
cache: Operate.Cache.ConCache,
]},
{ConCache, [
name: :operate,
ttl_check_interval: :timer.minutes(1),
global_ttl: :timer.minutes(10),
touch_on_read: true
]}
]
Supervisor.start_link(children, strategy: :one_for_one)
Configuration
Operate can be configured with the following options. Additionally, any of
these options can be passed to load_tape/2
and run_tape/2
to override
the configuration.
:tape_adapter
- The adapter module used to fetch the tape transaction.:op_adaapter
- The adapter module used to fetch the tape's Ops.:cache
- The cache module used for caching tapes and Ops.:extensions
- A list of extension modules to extend the VM state.:aliases
- A map of references to alias functions to alternative references.:strict
- Setfalse
to disable strict mode and ignore missing and/or erring functions.
The default configuration:
tape_adapter: Operate.Adapter.Bob,
op_adapter: Operate.Adapter.OpApi,
cache: Operate.Cache.NoCache,
extensions: [],
aliases: %{},
strict: true
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Gets Operate's current VM state and config.
Loads a tape from the given txid.
As load_tape/2
, but returns the tape or raises an exception.
Runs the given tape executing each of the tape's cells and returns the
modified and complete Operate.Tape.t/0
in an :ok
/ :error
tuple pair.
As run_tape/2
, but returns the tape or raises an exception.
Starts an Operate agent process with the given options merged with the default config.
Returns the current version number.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
get_state(options \\ [])
View Sourceget_state(keyword()) :: {Operate.VM.t(), map()}
Gets Operate's current VM state and config.
If a process has already been started then the existing VM and config is returned. Alternatively a new VM state is initiated and the default config returned. In either case any configuration option can be overridden.
Returns a tuple pair containing the VM state and a configuration map.
load_tape(txid, options \\ [])
View Sourceload_tape(String.t(), keyword()) :: {:ok, Operate.Tape.t()} | {:error, String.t()}
Loads a tape from the given txid.
Fetchs the tape transaction output as well as all of the required functions,
and returns a Operate.Tape.t/0
ready for execution in an :ok
/ :error
tuple pair.
If an Operate agent process has already been started the existing config will be used. Otherwise a default config will be used. Any configuration option can be overridden.
Options
Refer to the list of accepted configuration options.
load_tape!(txid, options \\ [])
View Sourceload_tape!(String.t(), keyword()) :: Operate.Tape.t()
As load_tape/2
, but returns the tape or raises an exception.
run_tape(tape, options \\ [])
View Sourcerun_tape(Operate.Tape.t(), keyword()) :: {:ok, Operate.Tape.t()} | {:error, Operate.Tape.t()}
Runs the given tape executing each of the tape's cells and returns the
modified and complete Operate.Tape.t/0
in an :ok
/ :error
tuple pair.
If an Operate agent process has already been started the existing VM state and config will be used. Otherwise a new state and default config will be used. Any configuration option can be overridden.
Options
The accepted options are:
:extensions
- A list of extension modules to extend the VM state.:strict
- Strict mode (defaultstrue
). Disable to force the tape to ignore missing and/or erroring cells.:state
- Speficy a state which the tape begins execution with (defaults tonil
).:vm
- Pass an already initiated VM state in which to run the tape.
run_tape!(tape, options \\ [])
View Sourcerun_tape!(Operate.Tape.t(), keyword()) :: Operate.Tape.t()
As run_tape/2
, but returns the tape or raises an exception.
Starts an Operate agent process with the given options merged with the default config.
Options
Refer to the list of accepted configuration options.
Returns the current version number.