View Source BitcoinLib.Script.Runner (BitcoinLib v0.4.3)

Script execution outcomes are based on this https://learnmeabitcoin.com/technical/script#what-makes-a-script-valid

Link to this section Summary

Functions

Executes a script and returns the resulting stack upon successful execution, or an error message

Executes a script and returns a boolean result upon successful execution, or an error message

Link to this section Functions

@spec execute(list(), list()) :: {:ok, list()} | {:error, binary()}

Executes a script and returns the resulting stack upon successful execution, or an error message

examples

Examples

iex> opcodes = [%BitcoinLib.Script.Opcodes.Stack.Dup{},
...>   %BitcoinLib.Script.Opcodes.Crypto.Hash160{},
...>   %BitcoinLib.Script.Opcodes.Data{value: <<0x842c9a57d0580a45cb91912b63ced8866c8f7b28::160>>},
...>   %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
...>   %BitcoinLib.Script.Opcodes.Crypto.CheckSig{script: <<0x76a914842c9a57d0580a45cb91912b63ced8866c8f7b2888ac::200>>}
...> ]
...> stack = [
...>   <<0x0253df833b37c1690234118d29fcff7c9f2f7ecc044d5b0ca6f1de76952f3f6463::264>>,
...>   <<0x3044022053646a4c2ea586024baa2c640246694e168da673ba96526aa82fc40e9508e993022056872566b2c39fd6a95613558278987acfb084fbdc8d3f2ef8d50ca58d570f05::560>>
...> ]
...> BitcoinLib.Script.Runner.execute(opcodes, stack)
{:ok, [1]}
Link to this function

validate(opcodes, stack)

View Source
@spec validate(list(), list()) :: {:ok, boolean()} | {:error, binary()}

Executes a script and returns a boolean result upon successful execution, or an error message

examples

Examples

iex> opcodes = [%BitcoinLib.Script.Opcodes.Stack.Dup{},
...>   %BitcoinLib.Script.Opcodes.Crypto.Hash160{},
...>   %BitcoinLib.Script.Opcodes.Data{value: <<0x842c9a57d0580a45cb91912b63ced8866c8f7b28::160>>},
...>   %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
...>   %BitcoinLib.Script.Opcodes.Crypto.CheckSig{script: <<0x76a914842c9a57d0580a45cb91912b63ced8866c8f7b2888ac::200>>}
...> ]
...> stack = [
...>   <<0x0253df833b37c1690234118d29fcff7c9f2f7ecc044d5b0ca6f1de76952f3f6463::264>>,
...>   <<0x3044022053646a4c2ea586024baa2c640246694e168da673ba96526aa82fc40e9508e993022056872566b2c39fd6a95613558278987acfb084fbdc8d3f2ef8d50ca58d570f05::560>>
...> ]
...> BitcoinLib.Script.Runner.validate(opcodes, stack)
{:ok, true}