Class: Sigma::Transaction

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

Overview

ErgoTransaction is an atomic state transition operation. It destroys Boxes from the state and creates new ones. If transaction is spending boxes protected by some non-trivial scripts, its inputs should also contain proof of spending correctness - context extension (user-defined key-value map) and data inputs (links to existing boxes in the state) that may be used during script reduction to crypto, signatures that satisfies the remaining cryptographic protection of the script. Transactions are not encrypted, so it is possible to browse and view every transaction ever collected into a block.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



29
30
31
# File 'lib/sigma/transaction.rb', line 29

def pointer
  @pointer
end

Class Method Details

.create_from_json(json) ⇒ Transaction

Parse from JSON. Supports Ergo Node/Explorer API and box values and token amount encoded as strings

Parameters:

  • json (String)

Returns:



46
47
48
49
50
51
# File 'lib/sigma/transaction.rb', line 46

def self.create_from_json(json)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_tx_from_json(json, pointer)
  Util.check_error!(error)
  init(pointer)
end

.create_from_unsigned_tx(unsigned_tx:, proofs:) ⇒ Transaction

Create “Transaction“ from “UnsignedTransaction“ and an array of proofs in the same order as ‘UnsignedTransaction.inputs` with empty proof indicated with empty byte array

Parameters:

Returns:



36
37
38
39
40
41
# File 'lib/sigma/transaction.rb', line 36

def self.create_from_unsigned_tx(unsigned_tx:, proofs:)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_tx_from_unsigned_tx(unsigned_tx.pointer, proofs.pointer, pointer)
  Util.check_error!(error)
  init(pointer)
end

.with_raw_pointer(pointer) ⇒ Transaction

Note:

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

Takes ownership of an existing Transaction Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



57
58
59
# File 'lib/sigma/transaction.rb', line 57

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

Instance Method Details

#get_data_inputsDataInputs

Get data inputs

Returns:



79
80
81
82
83
# File 'lib/sigma/transaction.rb', line 79

def get_data_inputs
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_data_inputs(self.pointer, pointer)
  Sigma::DataInputs.with_raw_pointer(pointer)
end

#get_inputsInputs

Get inputs

Returns:



71
72
73
74
75
# File 'lib/sigma/transaction.rb', line 71

def get_inputs
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_inputs(self.pointer, pointer)
  Sigma::Inputs.with_raw_pointer(pointer)
end

#get_output_candidatesErgoBoxCandidates

Get output candidates

Returns:



87
88
89
90
91
# File 'lib/sigma/transaction.rb', line 87

def get_output_candidates
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_output_candidates(self.pointer, pointer)
  Sigma::ErgoBoxCandidates.with_raw_pointer(pointer)
end

#get_outputsErgoBoxes

Get outputs

Returns:



95
96
97
98
99
# File 'lib/sigma/transaction.rb', line 95

def get_outputs
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_outputs(self.pointer, pointer)
  Sigma::ErgoBoxes.with_raw_pointer(pointer)
end

#get_tx_idTxId

Get transaction id

Returns:



63
64
65
66
67
# File 'lib/sigma/transaction.rb', line 63

def get_tx_id
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_id(self.pointer, pointer)
  Sigma::TxId.with_raw_pointer(pointer)
end

#to_jsonString

JSON representation as text (compatible with Ergo Node/Explorer API, numbers are encoded as numbers)

Returns:

  • (String)


103
104
105
106
107
108
109
110
111
# File 'lib/sigma/transaction.rb', line 103

def to_json
  s_ptr = FFI::MemoryPointer.new(:pointer, 1)
  error = ergo_lib_tx_to_json(self.pointer, s_ptr)
  Util.check_error!(error)
  s_ptr = s_ptr.read_pointer()
  str = s_ptr.read_string().force_encoding('UTF-8')
  Util.ergo_lib_delete_string(s_ptr)
  str
end

#to_json_eip12Object

JSON representation according to EIP-12

See Also:



115
116
117
118
119
120
121
122
123
# File 'lib/sigma/transaction.rb', line 115

def to_json_eip12
  s_ptr = FFI::MemoryPointer.new(:pointer, 1)
  error = ergo_lib_tx_to_json_eip12(self.pointer, s_ptr)
  Util.check_error!(error)
  s_ptr = s_ptr.read_pointer()
  str = s_ptr.read_string().force_encoding('UTF-8')
  Util.ergo_lib_delete_string(s_ptr)
  str
end