Class: Sigma::Transaction
- Inherits:
-
Object
- Object
- Sigma::Transaction
- 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
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create_from_json(json) ⇒ Transaction
Parse from JSON.
-
.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.
-
.with_raw_pointer(pointer) ⇒ Transaction
Takes ownership of an existing Transaction Pointer.
Instance Method Summary collapse
-
#get_data_inputs ⇒ DataInputs
Get data inputs.
-
#get_inputs ⇒ Inputs
Get inputs.
-
#get_output_candidates ⇒ ErgoBoxCandidates
Get output candidates.
-
#get_outputs ⇒ ErgoBoxes
Get outputs.
-
#get_tx_id ⇒ TxId
Get transaction id.
-
#to_json ⇒ String
JSON representation as text (compatible with Ergo Node/Explorer API, numbers are encoded as numbers).
-
#to_json_eip12 ⇒ Object
JSON representation according to EIP-12.
Instance Attribute Details
#pointer ⇒ Object
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
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
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
A user of sigma_rb generally does not need to call this function
Takes ownership of an existing Transaction Pointer.
57 58 59 |
# File 'lib/sigma/transaction.rb', line 57 def self.with_raw_pointer(pointer) init(pointer) end |
Instance Method Details
#get_data_inputs ⇒ DataInputs
Get data inputs
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_inputs ⇒ Inputs
Get inputs
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_candidates ⇒ ErgoBoxCandidates
Get output candidates
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_outputs ⇒ ErgoBoxes
Get outputs
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_id ⇒ TxId
Get transaction id
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_json ⇒ String
JSON representation as text (compatible with Ergo Node/Explorer API, numbers are encoded as numbers)
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_eip12 ⇒ Object
JSON representation according to EIP-12
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 |