module Digitalbits::Concerns::Transaction

Public Instance Methods

apply_defaults() click to toggle source
# File lib/digitalbits/concerns/transaction.rb, line 43
def apply_defaults
  self.operations ||= []
  self.fee ||= 100
  self.memo ||= Digitalbits::Memo.new(:memo_none)
  self.ext ||= Digitalbits::Transaction::Ext.new 0
end
hash() click to toggle source
# File lib/digitalbits/concerns/transaction.rb, line 17
def hash
  Digest::SHA256.digest(signature_base)
end
merge(other) click to toggle source
# File lib/digitalbits/concerns/transaction.rb, line 21
def merge(other)
  cloned = from_xdr(to_xdr)
  cloned.operations += other.to_operations
  cloned
end
sign(key_pair) click to toggle source
# File lib/digitalbits/concerns/transaction.rb, line 9
def sign(key_pair)
  key_pair.sign(hash)
end
sign_decorated(key_pair) click to toggle source
# File lib/digitalbits/concerns/transaction.rb, line 13
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 digitalbits transaction signature

# File lib/digitalbits/concerns/transaction.rb, line 5
def signature_base
  signature_base_prefix + to_xdr
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/digitalbits/concerns/transaction.rb, line 34
def to_operations
  codec = XDR::VarArray[Digitalbits::Operation]
  ops = respond_to?(:operations) ? operations : inner_tx.value.tx.operations
  cloned = codec.from_xdr(codec.to_xdr(ops))
  cloned.each do |op|
    op.source_account ||= source_account
  end
end