astroband/ruby-stellar-sdk

View on GitHub
base/lib/stellar/path_payment_strict_receive_result.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module Stellar
  class PathPaymentStrictReceiveResult
    # send_amount returns the actual amount paid for the corresponding
    # PathPaymentOp to this result.
    #
    def send_amount
      s = success!
      return s.last.amount if s.offers.blank?

      source_asset = s.offers.first.asset_bought
      source_offers = s.offers.take_while { |o| o.asset_bought == source_asset }

      source_offers.map(&:amount_bought).sum
    end
  end
end