Sha256: bbcd62c07caa88789ce60093580b484b88d0f70502673cde1864e53bef42f056

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Stellar
  class Amount
    include Contracts

    attr_reader :amount
    attr_reader :asset

    Contract Pos, Asset => Any
    def initialize(amount, asset=Stellar::Asset.native())
      # TODO: how are we going to handle decimal considerations?
      
      @amount = amount
      @asset  = asset
    end


    Contract None => Or[
      [Or[:credit_alphanum4, :credit_alphanum12], String, KeyPair, Pos],
      [:native, Pos],
    ]
    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)
        [:credit_alphanum4, asset, keypair, amount]
      when AssetType.asset_type_credit_alphanum12
        keypair = KeyPair.from_public_key(asset.issuer)
        [:credit_alphanum12, asset, keypair, amount]
      else
        raise "Unknown asset type: #{asset.type}"
      end
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stellar-sdk-0.2.0 lib/stellar/amount.rb