class Stellar::Client
Attributes
horizon[R]
Public Class Methods
default(options={})
click to toggle source
# File lib/stellar/client.rb, line 7 def self.default(options={}) new options.merge({ horizon: "https://horizon.stellar.org" }) end
default_testnet(options={})
click to toggle source
# File lib/stellar/client.rb, line 13 def self.default_testnet(options={}) new options.merge({ horizon: "https://horizon-testnet.stellar.org", friendbot: "https://horizon-testnet.stellar.org", }) end
localhost(options={})
click to toggle source
# File lib/stellar/client.rb, line 20 def self.localhost(options={}) new options.merge({ horizon: "http://127.0.0.1:3000", #TODO: figure out a real port }) end
new(options)
click to toggle source
# File lib/stellar/client.rb, line 29 def initialize(options) @options = options @horizon = Hyperclient.new(options[:horizon]) do |client| client.faraday_block = lambda do |conn| conn.use Faraday::Response::RaiseError conn.use FaradayMiddleware::FollowRedirects conn.request :url_encoded conn.response :hal_json, content_type: /\bjson$/ conn.adapter :excon end client.headers = { 'Accept' => 'application/hal+json,application/problem+json,application/json' } end end
Public Instance Methods
account_info(account)
click to toggle source
# File lib/stellar/client.rb, line 51 def account_info(account) address = account.address @horizon.account(address:address) end
friendbot(account)
click to toggle source
# File lib/stellar/client.rb, line 45 def friendbot(account) raise NotImplementedError end
send_payment(options={})
click to toggle source
# File lib/stellar/client.rb, line 61 def send_payment(options={}) from = options[:from] sequence = options[:sequence] || (account_info(from).sequence + 1) payment = Stellar::Transaction.payment({ account: from.keypair, destination: options[:to].keypair, sequence: sequence, amount: options[:amount].to_payment, }) envelope_hex = payment.to_envelope(from.keypair).to_xdr(:hex) @horizon.transactions._post(tx: envelope_hex) end
transactions(options={})
click to toggle source
# File lib/stellar/client.rb, line 80 def transactions(options={}) args = options.slice(:limit) resource = if options[:account] args = args.merge(address: options[:account].address) @horizon.account_transactions(args) else @horizon.transactions(args) end TransactionPage.new(resource) end