Class: Stellar::Transaction
- Inherits:
-
XDR::Struct
- Object
- XDR::Struct
- Stellar::Transaction
- Defined in:
- lib/stellar/transaction.rb,
generated/stellar/transaction.rb
Class Method Summary collapse
- .account_merge(attributes = {}) ⇒ Object
- .allow_trust(attributes = {}) ⇒ Object
- .change_trust(attributes = {}) ⇒ Object
- .create_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.
- .payment(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
- #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
36 37 38 |
# File 'lib/stellar/transaction.rb', line 36 def self.account_merge(attributes={}) make :account_merge, attributes end |
.allow_trust(attributes = {}) ⇒ Object
30 31 32 |
# File 'lib/stellar/transaction.rb', line 30 def self.allow_trust(attributes={}) make :allow_trust, attributes end |
.change_trust(attributes = {}) ⇒ Object
12 13 14 |
# File 'lib/stellar/transaction.rb', line 12 def self.change_trust(attributes={}) make :change_trust, attributes end |
.create_offer(attributes = {}) ⇒ Object
18 19 20 |
# File 'lib/stellar/transaction.rb', line 18 def self.create_offer(attributes={}) make :create_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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/stellar/transaction.rb', line 74 def self.for_account(attributes={}) account = attributes[:account] sequence = attributes[:sequence] max_fee = attributes[:max_fee] raise ArgumentError, "Bad :account" unless account.is_a?(KeyPair) && account.sign? raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer) raise ArgumentError, "Bad :max_fee #{sequence}" if max_fee.present? && !max_fee.is_a?(Integer) new.tap do |result| result.seq_num = sequence result.max_fee = max_fee result.source_account = account.public_key result.apply_defaults end end |
.inflation(attributes = {}) ⇒ Object
42 43 44 |
# File 'lib/stellar/transaction.rb', line 42 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.
58 59 60 61 62 |
# File 'lib/stellar/transaction.rb', line 58 def self.make(operation_type, attributes={}) for_account(attributes).tap do |result| result.operations << Operation.send(operation_type, attributes) end end |
.payment(attributes = {}) ⇒ Object
6 7 8 |
# File 'lib/stellar/transaction.rb', line 6 def self.payment(attributes={}) make :payment, attributes end |
.set_options(attributes = {}) ⇒ Object
24 25 26 |
# File 'lib/stellar/transaction.rb', line 24 def self.(attributes={}) make :set_options, attributes end |
Instance Method Details
#apply_defaults ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/stellar/transaction.rb', line 133 def apply_defaults self.operations ||= [] self.max_fee ||= 10 self.min_ledger ||= 0 self.max_ledger ||= 2**32 - 1 self.memo ||= Memo.new(:memo_type_none) end |
#hash ⇒ Object
99 100 101 |
# File 'lib/stellar/transaction.rb', line 99 def hash Digest::SHA256.digest(to_xdr) end |
#merge(other) ⇒ Object
112 113 114 115 116 |
# File 'lib/stellar/transaction.rb', line 112 def merge(other) cloned = Marshal.load Marshal.dump(self) cloned.operations += other.to_operations cloned end |
#sign(key_pair) ⇒ Object
91 92 93 |
# File 'lib/stellar/transaction.rb', line 91 def sign(key_pair) key_pair.sign(hash) end |
#sign_decorated(key_pair) ⇒ Object
95 96 97 |
# File 'lib/stellar/transaction.rb', line 95 def sign_decorated(key_pair) key_pair.sign_decorated(hash) end |
#to_envelope(*key_pairs) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/stellar/transaction.rb', line 103 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.
126 127 128 129 130 131 |
# File 'lib/stellar/transaction.rb', line 126 def to_operations cloned = Marshal.load Marshal.dump(operations) operations.each do |op| op.source_account = self.source_account end end |