Class: Stellar::Transaction

Inherits:
XDR::Struct
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.account_merge(attributes = {}) ⇒ Object



54
55
56
# File 'lib/stellar/transaction.rb', line 54

def self.(attributes={})
  make :account_merge, attributes
end

.allow_trust(attributes = {}) ⇒ Object



48
49
50
# File 'lib/stellar/transaction.rb', line 48

def self.allow_trust(attributes={})
  make :allow_trust, attributes
end

.change_trust(attributes = {}) ⇒ Object



24
25
26
# File 'lib/stellar/transaction.rb', line 24

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.(attributes={})
  make :create_account, attributes
end

.create_passive_offer(attributes = {}) ⇒ Object



36
37
38
# File 'lib/stellar/transaction.rb', line 36

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.

Parameters:

  • attributes={}
    type
    description

Returns:

Raises:

  • (ArgumentError)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/stellar/transaction.rb', line 98

def self.(attributes={})
    = attributes[:account]
  sequence = attributes[:sequence]
  fee      = attributes[:fee]

  raise ArgumentError, "Bad :account" unless .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. = .
    result.apply_defaults
  end
end

.inflation(attributes = {}) ⇒ Object



60
61
62
# File 'lib/stellar/transaction.rb', line 60

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.

Parameters:

  • operation_type (Symbol)

    the operation to use

  • attributes={}
    Hash

    attributes to use for both the transaction and the operation

Returns:

See Also:



82
83
84
85
86
# File 'lib/stellar/transaction.rb', line 82

def self.make(operation_type, attributes={})
  (attributes).tap do |result|
    result.operations << Operation.send(operation_type, attributes)
  end
end

.manage_data(attributes = {}) ⇒ Object



66
67
68
# File 'lib/stellar/transaction.rb', line 66

def self.manage_data(attributes={})
  make :manage_data, attributes
end

.manage_offer(attributes = {}) ⇒ Object

See Also:

  • Operation.create_offer


30
31
32
# File 'lib/stellar/transaction.rb', line 30

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

See Also:



6
7
8
# File 'lib/stellar/transaction.rb', line 6

def self.payment(attributes={})
  make :payment, attributes
end

.set_options(attributes = {}) ⇒ Object



42
43
44
# File 'lib/stellar/transaction.rb', line 42

def self.set_options(attributes={})
  make :set_options, attributes
end

Instance Method Details

#apply_defaultsObject



170
171
172
173
174
175
# File 'lib/stellar/transaction.rb', line 170

def apply_defaults
  self.operations ||= []
  self.fee        ||= 100
  self.memo       ||= Memo.new(:memo_none)
  self.ext        ||= Stellar::Transaction::Ext.new 0
end

#hashObject



124
125
126
# File 'lib/stellar/transaction.rb', line 124

def hash
  Digest::SHA256.digest(signature_base)
end

#merge(other) ⇒ Object



149
150
151
152
153
# File 'lib/stellar/transaction.rb', line 149

def merge(other)
  cloned = Marshal.load Marshal.dump(self)
  cloned.operations += other.to_operations
  cloned
end

#sign(key_pair) ⇒ Object



116
117
118
# File 'lib/stellar/transaction.rb', line 116

def sign(key_pair)
  key_pair.sign(hash)
end

#sign_decorated(key_pair) ⇒ Object



120
121
122
# File 'lib/stellar/transaction.rb', line 120

def sign_decorated(key_pair)
  key_pair.sign_decorated(hash)
end

#signature_baseObject

Returns the string of bytes that, when hashed, provide the value which should be signed to create a valid stellar transaciton signature



130
131
132
# File 'lib/stellar/transaction.rb', line 130

def signature_base
  signature_base_prefix + to_xdr
end

#signature_base_prefixObject



134
135
136
137
138
# File 'lib/stellar/transaction.rb', line 134

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



140
141
142
143
144
145
146
147
# File 'lib/stellar/transaction.rb', line 140

def to_envelope(*key_pairs)
  signatures = (key_pairs || []).map(&method(:sign_decorated))

  TransactionEnvelope.new({
    :signatures => signatures,
    :tx => self
  })
end

#to_operationsArray<Operation>

Extracts the operations from this single transaction, setting the source account on the extracted operations.

Useful for merging transactions.

Returns:



163
164
165
166
167
168
# File 'lib/stellar/transaction.rb', line 163

def to_operations
  cloned = Marshal.load Marshal.dump(operations)
  operations.each do |op|
    op. = self.
  end
end