Class: Stellar::Client
- Inherits:
-
Object
- Object
- Stellar::Client
- Includes:
- Contracts
- Defined in:
- lib/stellar/client.rb
Instance Attribute Summary collapse
-
#horizon ⇒ Object
readonly
Returns the value of attribute horizon.
Class Method Summary collapse
- .default(options = {}) ⇒ Object
- .default_testnet(options = {}) ⇒ Object
- .localhost(options = {}) ⇒ Object
Instance Method Summary collapse
- #account_info(account) ⇒ Object
- #friendbot(account) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #send_payment(options = {}) ⇒ Object
- #transactions(options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stellar/client.rb', line 29 def initialize() @options = @horizon = Hyperclient.new([: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 |
Instance Attribute Details
#horizon ⇒ Object (readonly)
Returns the value of attribute horizon.
26 27 28 |
# File 'lib/stellar/client.rb', line 26 def horizon @horizon end |
Class Method Details
.default(options = {}) ⇒ Object
7 8 9 10 11 |
# File 'lib/stellar/client.rb', line 7 def self.default(={}) new .merge({ horizon: "https://horizon.stellar.org" }) end |
.default_testnet(options = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/stellar/client.rb', line 13 def self.default_testnet(={}) new .merge({ horizon: "https://horizon-testnet.stellar.org", friendbot: "https://horizon-testnet.stellar.org", }) end |
.localhost(options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/stellar/client.rb', line 20 def self.localhost(={}) new .merge({ horizon: "http://127.0.0.1:3000", #TODO: figure out a real port }) end |
Instance Method Details
#account_info(account) ⇒ Object
51 52 53 54 |
# File 'lib/stellar/client.rb', line 51 def account_info(account) address = account.address @horizon.account(address:address) end |
#friendbot(account) ⇒ Object
45 46 47 |
# File 'lib/stellar/client.rb', line 45 def friendbot(account) raise NotImplementedError end |
#send_payment(options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/stellar/client.rb', line 61 def send_payment(={}) from = [:from] sequence = [:sequence] || (account_info(from).sequence + 1) payment = Stellar::Transaction.payment({ account: from.keypair, destination: [:to].keypair, sequence: sequence, amount: [:amount].to_payment, }) envelope_hex = payment.to_envelope(from.keypair).to_xdr(:hex) @horizon.transactions._post(tx: envelope_hex) end |
#transactions(options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/stellar/client.rb', line 80 def transactions(={}) args = .slice(:limit) resource = if [:account] args = args.merge(address: [:account].address) @horizon.account_transactions(args) else @horizon.transactions(args) end TransactionPage.new(resource) end |