class Stellar::Transaction

Public Class Methods

account_merge(attributes={}) click to toggle source

@see Stellar::Operation.account_merge

# File lib/stellar/transaction.rb, line 54
def self.account_merge(attributes={})
  make :account_merge, attributes
end
allow_trust(attributes={}) click to toggle source

@see Stellar::Operation.allow_trust

# File lib/stellar/transaction.rb, line 48
def self.allow_trust(attributes={})
  make :allow_trust, attributes
end
change_trust(attributes={}) click to toggle source

@see Stellar::Operation.change_trust

# File lib/stellar/transaction.rb, line 24
def self.change_trust(attributes={})
  make :change_trust, attributes
end
create_account(attributes={}) click to toggle source

@see Stellar::Operation.create_account

# File lib/stellar/transaction.rb, line 18
def self.create_account(attributes={})
  make :create_account, attributes
end
create_passive_offer(attributes={}) click to toggle source

@see Stellar::Operation.create_passive_offer

# File lib/stellar/transaction.rb, line 36
def self.create_passive_offer(attributes={})
  make :create_passive_offer, attributes
end
for_account(attributes={}) click to toggle source

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.

@param attributes={} [type] [description]

@return [Stellar::Transaction] the resulting skeleton

# File lib/stellar/transaction.rb, line 92
def self.for_account(attributes={})
  account  = attributes[:account]
  sequence = attributes[:sequence]
  fee      = attributes[: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 :fee #{sequence}" if fee.present? && !fee.is_a?(Integer)

  new.tap do |result|
    result.seq_num        = sequence
    result.fee            = fee
    result.source_account = account.account_id
    result.apply_defaults
  end
end
inflation(attributes={}) click to toggle source

@see Stellar::Operation.inflation

# File lib/stellar/transaction.rb, line 60
def self.inflation(attributes={})
  make :inflation, attributes
end
make(operation_type, attributes={}) click to toggle source

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.

@see Stellar::Operation

@param operation_type [Symbol] the operation to use @param attributes={} [Hash] attributes to use for both the transaction and the operation

@return [Stellar::Transaction] the resulting transaction

# File lib/stellar/transaction.rb, line 76
def self.make(operation_type, attributes={})
  for_account(attributes).tap do |result|
    result.operations << Operation.send(operation_type, attributes)
  end
end
manage_offer(attributes={}) click to toggle source

@see Stellar::Operation.create_offer

# File lib/stellar/transaction.rb, line 30
def self.manage_offer(attributes={})
  make :manage_offer, attributes
end
path_payment(attributes={}) click to toggle source

@see Stellar::Operation.path_payment

# File lib/stellar/transaction.rb, line 12
def self.path_payment(attributes={})
  make :path_payment, attributes
end
payment(attributes={}) click to toggle source

@see Stellar::Operation.payment

# File lib/stellar/transaction.rb, line 6
def self.payment(attributes={})
  make :payment, attributes
end
set_options(attributes={}) click to toggle source

@see Stellar::Operation.set_options

# File lib/stellar/transaction.rb, line 42
def self.set_options(attributes={})
  make :set_options, attributes
end

Public Instance Methods

apply_defaults() click to toggle source
# File lib/stellar/transaction.rb, line 163
def apply_defaults
  self.operations ||= []
  self.fee        ||= 10
  self.memo       ||= Memo.new(:memo_none)
  self.ext        ||= Stellar::Transaction::Ext.new 0
end
hash() click to toggle source
# File lib/stellar/transaction.rb, line 117
def hash
  Digest::SHA256.digest(signature_base)
end
merge(other) click to toggle source
# File lib/stellar/transaction.rb, line 142
def merge(other)
  cloned = Marshal.load Marshal.dump(self)
  cloned.operations += other.to_operations
  cloned
end
sign(key_pair) click to toggle source
# File lib/stellar/transaction.rb, line 109
def sign(key_pair)
  key_pair.sign(hash)
end
sign_decorated(key_pair) click to toggle source
# File lib/stellar/transaction.rb, line 113
def sign_decorated(key_pair)
  key_pair.sign_decorated(hash)
end
signature_base() click to toggle source

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

# File lib/stellar/transaction.rb, line 123
def signature_base
  signature_base_prefix + to_xdr
end
signature_base_prefix() click to toggle source
# File lib/stellar/transaction.rb, line 127
def signature_base_prefix
  val = Stellar::EnvelopeType.envelope_type_tx

  Stellar::EnvelopeType.to_xdr(val)
end
to_envelope(*key_pairs) click to toggle source
# File lib/stellar/transaction.rb, line 133
def to_envelope(*key_pairs)
  signatures = key_pairs.map(&method(:sign_decorated))

  TransactionEnvelope.new({
    :signatures => signatures,
    :tx => self
  })
end
to_operations() click to toggle source

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

Useful for merging transactions.

@return [Array<Operation>] the operations

# File lib/stellar/transaction.rb, line 156
def to_operations
  cloned = Marshal.load Marshal.dump(operations)
  operations.each do |op|
    op.source_account = self.source_account
  end
end