Class: RippleRest::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/ripple-rest/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accountAccount

Returns:


105
106
107
# File 'lib/ripple-rest/helpers.rb', line 105

def 
  @account
end

Instance Method Details

#[](hash) ⇒ Payment

Returns an individual payment.

Parameters:

  • hash (String)

    Payment hash or client resource ID

Returns:

Raises:


112
113
114
115
# File 'lib/ripple-rest/helpers.rb', line 112

def [] hash
  Payment.new RippleRest
    .get("v1/accounts/#{.address}/payments/#{hash}")["payment"]
end

#create(destination_account, destination_amount) ⇒ Payment

Create a Payment object with some field filled.

Returns:


139
140
141
142
143
144
145
# File 'lib/ripple-rest/helpers.rb', line 139

def create , destination_amount
  payment = Payment.new
  payment. = 
  payment. = .to_s
  payment.destination_amount = Amount.from_string(destination_amount)
  payment
end

#find_path(destination_account, destination_amount, source_currencies = nil) ⇒ Array<Payment>

Query `rippled` for possible payment “paths” through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency.

Parameters:

  • destination_account (String, Account)

    destination account

  • destination_amount (String, Amount)

    destination amount

  • source_currencies (Array<String>) (defaults to: nil)

    an array of source currencies that can be used to constrain the results returned (e.g. `[“XRP”, “USD+r…”, “BTC+r…”]`) Currencies can be denoted by their currency code (e.g. USD) or by their currency code and issuer (e.g. `USD+r…`). If no issuer is specified for a currency other than XRP, the results will be limited to the specified currencies but any issuer for that currency will do.

Returns:

Raises:


124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ripple-rest/helpers.rb', line 124

def find_path , destination_amount, source_currencies = nil
  uri = "v1/accounts/#{.address}/payments/paths/#{.to_s}/#{destination_amount.to_s}"
  
  if source_currencies
    cur = source_currencies.join(",")
    uri += "?source_currencies=#{cur}"
  end
  
  RippleRest.get(uri)["payments"].map(&Payment.method(:new)).each do |i|
    i. = 
  end
end

#query(options = {}) ⇒ Array<Payment>

Browse historical payments in bulk.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :source_account (String, Account)

    If specified, limit the results to payments initiated by a particular account

  • :destination_account (String, Account)

    If specified, limit the results to payments made to a particular account

  • :exclude_failed (Boolean)

    if set to true, this will return only payment that were successfully validated and written into the Ripple Ledger

  • :start_ledger (String)

    If earliest_first is set to true this will be the index number of the earliest ledger queried, or the most recent one if earliest_first is set to false. Defaults to the first ledger the rippled has in its complete ledger. An error will be returned if this value is outside the rippled's complete ledger set

  • :end_ledger (String)

    If earliest_first is set to true this will be the index number of the most recent ledger queried, or the earliest one if earliest_first is set to false. Defaults to the last ledger the rippled has in its complete ledger. An error will be returned if this value is outside the rippled's complete ledger set

  • :earliest_first (Boolean)

    Determines the order in which the results should be displayed. Defaults to true

  • :results_per_page (Fixnum)

    Limits the number of resources displayed per page. Defaults to 20

  • :page (Fixnum)

    The page to be displayed. If there are fewer than the results_per_page number displayed, this indicates that this is the last page

Returns:

Raises:


159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ripple-rest/helpers.rb', line 159

def query options = {}
  qs = ""
  if options && options.size > 0
    qs = "?" + options.map { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
  end
  
  uri = "v1/accounts/#{.address}/payments#{qs}"
  
  RippleRest.get(uri)["payments"].map do |i|
    payment = Payment.new(i["payment"])
    payment.client_resource_id = i["client_resource_id"]
    payment
  end
end