Class: Stellar::Transaction
- Inherits:
-
XDR::Struct
- Object
- XDR::Struct
- Stellar::Transaction
- Includes:
- XDR::Namespace
- Defined in:
- lib/stellar/transaction.rb,
generated/stellar/transaction.rb,
generated/stellar/transaction/ext.rb
Defined Under Namespace
Classes: Ext
Class Method Summary collapse
- .account_merge(attributes = {}) ⇒ Object
- .allow_trust(attributes = {}) ⇒ Object
- .change_trust(attributes = {}) ⇒ Object
- .create_account(attributes = {}) ⇒ Object
- .create_lot(attributes = {}) ⇒ Object
- .create_passive_offer(attributes = {}) ⇒ Object
-
.for_account(attributes = {}) ⇒ Stellar::Transaction
Helper method to create the skeleton of a transaction.
- .inflation(attributes = {}) ⇒ Object
-
.make(operation_type, attributes = {}) ⇒ Stellar::Transaction
Helper method to create a transaction with a single operation of the provided type.
- .manage_offer(attributes = {}) ⇒ Object
- .path_payment(attributes = {}) ⇒ Object
- .payment(attributes = {}) ⇒ Object
- .provide_proof(attributes = {}) ⇒ Object
- .register_participant(attributes = {}) ⇒ Object
- .set_options(attributes = {}) ⇒ Object
Instance Method Summary collapse
- #apply_defaults ⇒ Object
- #hash ⇒ Object
- #merge(other) ⇒ Object
- #sign(key_pair) ⇒ Object
- #sign_decorated(key_pair) ⇒ Object
-
#signature_base ⇒ Object
Returns the string of bytes that, when hashed, provide the value which should be signed to create a valid stellar transaciton signature.
- #signature_base_prefix ⇒ Object
- #to_envelope(*key_pairs) ⇒ Object
-
#to_operations ⇒ Array<Operation>
Extracts the operations from this single transaction, setting the source account on the extracted operations.
Class Method Details
.account_merge(attributes = {}) ⇒ Object
70 71 72 |
# File 'lib/stellar/transaction.rb', line 70 def self.account_merge(attributes={}) make :account_merge, attributes end |
.allow_trust(attributes = {}) ⇒ Object
64 65 66 |
# File 'lib/stellar/transaction.rb', line 64 def self.allow_trust(attributes={}) make :allow_trust, attributes end |
.change_trust(attributes = {}) ⇒ Object
40 41 42 |
# File 'lib/stellar/transaction.rb', line 40 def self.change_trust(attributes={}) make :change_trust, attributes end |
.create_account(attributes = {}) ⇒ Object
18 19 20 |
# File 'lib/stellar/transaction.rb', line 18 def self.create_account(attributes={}) make :create_account, attributes end |
.create_lot(attributes = {}) ⇒ Object
30 31 32 |
# File 'lib/stellar/transaction.rb', line 30 def self.create_lot(attributes={}) make :create_lot, attributes end |
.create_passive_offer(attributes = {}) ⇒ Object
52 53 54 |
# File 'lib/stellar/transaction.rb', line 52 def self.create_passive_offer(attributes={}) make :create_passive_offer, attributes end |
.for_account(attributes = {}) ⇒ Stellar::Transaction
Helper method to create the skeleton of a transaction. The resulting transaction will have its source account, sequence, fee, min ledger and max ledger set.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/stellar/transaction.rb', line 108 def self.for_account(attributes={}) account = attributes[:account] sequence = attributes[:sequence] fee = attributes[:fee] raise ArgumentError, "Bad :account" unless account.is_a?(KeyPair) raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer) raise ArgumentError, "Bad :fee #{sequence}" if fee.present? && !fee.is_a?(Integer) new.tap do |result| result.seq_num = sequence result.fee = fee result.memo = make_memo(attributes[:memo]) result.source_account = account.account_id result.apply_defaults end end |
.inflation(attributes = {}) ⇒ Object
76 77 78 |
# File 'lib/stellar/transaction.rb', line 76 def self.inflation(attributes={}) make :inflation, attributes end |
.make(operation_type, attributes = {}) ⇒ Stellar::Transaction
Helper method to create a transaction with a single operation of the provided type. See class methods on Stellar::Operation for available values for operation_type.
92 93 94 95 96 |
# File 'lib/stellar/transaction.rb', line 92 def self.make(operation_type, attributes={}) for_account(attributes).tap do |result| result.operations << Operation.send(operation_type, attributes) end end |
.manage_offer(attributes = {}) ⇒ Object
46 47 48 |
# File 'lib/stellar/transaction.rb', line 46 def self.manage_offer(attributes={}) make :manage_offer, attributes end |
.path_payment(attributes = {}) ⇒ Object
12 13 14 |
# File 'lib/stellar/transaction.rb', line 12 def self.path_payment(attributes={}) make :path_payment, attributes end |
.payment(attributes = {}) ⇒ Object
6 7 8 |
# File 'lib/stellar/transaction.rb', line 6 def self.payment(attributes={}) make :payment, attributes end |
.provide_proof(attributes = {}) ⇒ Object
24 25 26 |
# File 'lib/stellar/transaction.rb', line 24 def self.provide_proof(attributes={}) make :provide_proof, attributes end |
.register_participant(attributes = {}) ⇒ Object
34 35 36 |
# File 'lib/stellar/transaction.rb', line 34 def self.register_participant(attributes={}) make :register_participant, attributes end |
.set_options(attributes = {}) ⇒ Object
58 59 60 |
# File 'lib/stellar/transaction.rb', line 58 def self.(attributes={}) make :set_options, attributes end |
Instance Method Details
#apply_defaults ⇒ Object
179 180 181 182 183 184 |
# File 'lib/stellar/transaction.rb', line 179 def apply_defaults self.operations ||= [] self.fee ||= 100 self.memo ||= Memo.new(:memo_none) self.ext ||= Stellar::Transaction::Ext.new 0 end |
#hash ⇒ Object
134 135 136 |
# File 'lib/stellar/transaction.rb', line 134 def hash Digest::SHA256.digest(signature_base) end |
#merge(other) ⇒ Object
158 159 160 161 162 |
# File 'lib/stellar/transaction.rb', line 158 def merge(other) cloned = Marshal.load Marshal.dump(self) cloned.operations += other.to_operations cloned end |
#sign(key_pair) ⇒ Object
126 127 128 |
# File 'lib/stellar/transaction.rb', line 126 def sign(key_pair) key_pair.sign(hash) end |
#sign_decorated(key_pair) ⇒ Object
130 131 132 |
# File 'lib/stellar/transaction.rb', line 130 def sign_decorated(key_pair) key_pair.sign_decorated(hash) end |
#signature_base ⇒ Object
Returns the string of bytes that, when hashed, provide the value which should be signed to create a valid stellar transaciton signature
140 141 142 |
# File 'lib/stellar/transaction.rb', line 140 def signature_base signature_base_prefix + to_xdr end |
#signature_base_prefix ⇒ Object
144 145 146 147 148 |
# File 'lib/stellar/transaction.rb', line 144 def signature_base_prefix val = Stellar::EnvelopeType.envelope_type_tx Stellar.current_network_id + Stellar::EnvelopeType.to_xdr(val) end |
#to_envelope(*key_pairs) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/stellar/transaction.rb', line 150 def to_envelope(*key_pairs) signatures = key_pairs.map(&method(:sign_decorated)) TransactionEnvelope.new({ :signatures => signatures, :tx => self }) end |
#to_operations ⇒ Array<Operation>
Extracts the operations from this single transaction, setting the source account on the extracted operations.
Useful for merging transactions.
172 173 174 175 176 177 |
# File 'lib/stellar/transaction.rb', line 172 def to_operations cloned = Marshal.load Marshal.dump(operations) operations.each do |op| op.source_account = self.source_account end end |