Sha256: c315c1954d1761e159c868c01e288a6b10ed137f213c4a36ada2312173867582

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

Contents

module Stellar
  class Amount
    attr_reader :amount
    attr_reader :asset

    # @param [Fixnum] amount
    # @param [Stellar::Asset] asset
    def initialize(amount, asset = Stellar::Asset.native)
      # TODO: how are we going to handle decimal considerations?

      @amount = amount
      @asset = asset
    end

    # @return [Array(Symbol, Fixnum)] in case of a native asset
    # @return [Array(Symbol, String, Stellar::KeyPair, Fixnum)] in case of alphanum asset
    def to_payment
      case asset.type
      when AssetType.asset_type_native
        [:native, amount]
      when AssetType.asset_type_credit_alphanum4
        keypair = KeyPair.from_public_key(asset.issuer.value)
        [:alphanum4, asset.code, keypair, amount]
      when AssetType.asset_type_credit_alphanum12
        keypair = KeyPair.from_public_key(asset.issuer.value)
        [:alphanum12, asset.code, keypair, amount]
      else
        raise "Unknown asset type: #{asset.type}"
      end
    end

    def inspect
      "#<Stellar::Amount #{asset}(#{amount})>"
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
stellar-base-0.32.0 lib/stellar/amount.rb
stellar-base-0.31.0 lib/stellar/amount.rb
stellar-base-0.30.0 lib/stellar/amount.rb
stellar-sdk-0.29.0 lib/stellar/amount.rb
stellar-sdk-0.28.0 lib/stellar/amount.rb
stellar-sdk-0.27.0 lib/stellar/amount.rb
stellar-sdk-0.26.0 lib/stellar/amount.rb
stellar-sdk-0.25.0 lib/stellar/amount.rb
stellar-sdk-0.24.0 lib/stellar/amount.rb
stellar-sdk-0.24.0.pre.1 lib/stellar/amount.rb
stellar-sdk-0.23.1 lib/stellar/amount.rb
stellar-sdk-0.23.0 lib/stellar/amount.rb
stellar-sdk-0.23.0.rc2 lib/stellar/amount.rb
stellar-sdk-0.9.0.rc1 lib/stellar/amount.rb
stellar-sdk-0.9.0.pre2 lib/stellar/amount.rb