Class: Sigma::Contract

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/contract.rb

Overview

Defines the contract (script) that will be guarding box contents

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



18
19
20
# File 'lib/sigma/contract.rb', line 18

def pointer
  @pointer
end

Class Method Details

.compile_from_string(source) ⇒ Contract

Compiles a contract from ErgoScript source code

Parameters:

  • source (String)

Returns:



41
42
43
44
45
46
47
# File 'lib/sigma/contract.rb', line 41

def self.compile_from_string(source)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_contract_compile(source, pointer)
  Util.check_error!(error)
  
  init(pointer)
end

.from_ergo_tree(ergo_tree) ⇒ Contract

Create a new contract from an ErgoTree

Parameters:

Returns:



31
32
33
34
35
36
# File 'lib/sigma/contract.rb', line 31

def self.from_ergo_tree(ergo_tree)
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_contract_new(ergo_tree.pointer, pointer)

  init(pointer) 
end

.pay_to_address(address) ⇒ Contract

Create new contract that allow spending of the guarded box by a given recipient (Address)

Parameters:

Returns:



52
53
54
55
56
57
58
# File 'lib/sigma/contract.rb', line 52

def self.pay_to_address(address)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_contract_pay_to_address(address.pointer, pointer)
  Util.check_error!(error)

  init(pointer)
end

.with_raw_pointer(contract_pointer) ⇒ Contract

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing Contract Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



24
25
26
# File 'lib/sigma/contract.rb', line 24

def self.with_raw_pointer(contract_pointer)
  init(contract_pointer)
end

Instance Method Details

#==(contract_two) ⇒ bool

Equality check for two Contracts

Parameters:

Returns:

  • (bool)


71
72
73
# File 'lib/sigma/contract.rb', line 71

def ==(contract_two)
  ergo_lib_contract_eq(self.pointer, contract_two.pointer)
end

#get_ergo_treeErgoTree

Get the ErgoTree of the contract

Returns:



62
63
64
65
66
# File 'lib/sigma/contract.rb', line 62

def get_ergo_tree
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_contract_ergo_tree(self.pointer, pointer)
  Sigma::ErgoTree.with_raw_pointer(pointer)
end