stellar-lib 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d7007ba8eef347cae51d9b2b837102dcf062a03
4
+ data.tar.gz: 9f40405bbc3dd18ade31e55898c13f7501b560d9
5
+ SHA512:
6
+ metadata.gz: 9c313acc7f1ef594a54ae7d19caa7a1dd8ae0375c00433c6bb88a416f6ca1d4e9a11215f2b15870c1292e0de0ab936f72b3cd44fd4fc046432816a3e68165855
7
+ data.tar.gz: ecdd99fb7be686ef77deb400c93a45794ac55f9cb53c1d647027ba230c51d31e87928656bb09529df92ea4379c2558a3da2a29e0adf35705ce87a92b3c6a111c
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.5
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - jruby-1.7.9
8
+ - jruby-head
9
+ script: LD_LIBRARY_PATH=lib bundle exec rake travis
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: jruby-head
13
+ notifications:
14
+ slack:
15
+ secure: D1gWWsjE9i9XLRM6Bfw2pu3tTPW025iqjhgwE3KNw1QwP2TrehbCwRpjVR4rrnaju9FhYqM0+eT4rFc9g6itBPf2pfN1WziVf/CVJORYTzR9HbLL1rMOaWhEv4x/+Uwu0kxQon9ThnM9w6XjjD1+NoBfGn4Lcgc/OgmUGw1jAvQ=
@@ -0,0 +1,7 @@
1
+ --output-dir doc/generated
2
+ --protected
3
+ --no-private
4
+ --embed-mixin ClassMethods
5
+ lib/**/*.rb
6
+ -
7
+ doc/*.md
@@ -0,0 +1,48 @@
1
+ # How to contribute
2
+
3
+ Your contributions to the Stellar network will help improve the world’s financial
4
+ infrastructure, faster.
5
+
6
+ We want to make it as easy as possible to contribute changes that
7
+ help the Stellar network grow and thrive. There are a few guidelines that we
8
+ ask contributors to follow so that we can merge your changes quickly.
9
+
10
+ ## Getting Started
11
+
12
+ * Create a GitHub issue for your contribution, assuming one does not already exist.
13
+ * Clearly describe the issue including steps to reproduce if it is a bug.
14
+ * Fork the repository on GitHub
15
+
16
+ ## Making Changes
17
+
18
+ * Create a topic branch from where you want to base your work.
19
+ * This is usually the master branch.
20
+ * Please avoid working directly on the `master` branch.
21
+ * Make sure you have added the necessary tests for your changes, and make sure all tests pass.
22
+
23
+ ## Submitting Changes
24
+
25
+ * <a href="https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form">Sign the Contributor License Agreement</a>
26
+ * Push your changes to a topic branch in your fork of the repository.
27
+ * Submit a pull request to the corresponding repository in the Stellar organization.
28
+ * Include a descriptive [commit message](https://github.com/erlang/otp/wiki/Writing-good-commit-messages).
29
+ * Changes contributed via pull request should focus on a single issue at a time.
30
+ * Rebase your local changes against the master branch. Resolve any conflicts that arise.
31
+
32
+ At this point you're waiting on us. We like to at least comment on pull requests within three
33
+ business days. We may suggest some changes or improvements or alternatives.
34
+
35
+ # Additional Resources
36
+
37
+ * [Bug tracker (Github)](https://github.com/stellar/ruby-stellar-lib/issues)
38
+ * <a href="https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form">Contributor License Agreement</a>
39
+ * #stellar-dev IRC channel on freenode.org and Slack chat on stellar-public.slack.com
40
+
41
+
42
+ This document is inspired by:
43
+
44
+ https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md
45
+
46
+ https://github.com/thoughtbot/factory_girl_rails/blob/master/CONTRIBUTING.md
47
+
48
+ https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem "xdr", git: "git@github.com:stellar/ruby-xdr.git"
6
+ # gem "xdr", path: "../ruby-xdr"
7
+
8
+ # gem "stellar-base", git: "git@github.com:stellar/ruby-stellar-base.git"
9
+ # gem "stellar-base", path: "../ruby-stellar-base"
10
+
11
+ group :development do
12
+ gem "pry"
13
+ end
14
+
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2015 Stellar Development Foundation
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,55 @@
1
+ # Ruby Stellar
2
+
3
+ [![Build Status](https://travis-ci.org/stellar/ruby-stellar-lib.svg)](https://travis-ci.org/stellar/ruby-stellar-lib)
4
+ [![Code Climate](https://codeclimate.com/github/stellar/ruby-stellar-lib/badges/gpa.svg)](https://codeclimate.com/github/stellar/ruby-stellar-lib)
5
+
6
+ *STATUS: this library is very early and incomplete. The examples provided do not work, yet*
7
+
8
+ This library helps you to integrate your application into the [Stellar network](http://stellar.org).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'stellar'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install stellar
25
+
26
+ Also requires libsodium. Installable via `brew install libsodium` on OS X.
27
+
28
+ ## Usage
29
+
30
+ See [examples](examples).
31
+
32
+ A simple payment from the root account to some random accounts
33
+
34
+ ```ruby
35
+ require 'stellar'
36
+
37
+ account = Stellar::Account.master
38
+ client = Stellar::Client.default_testnet()
39
+ recipient = Stellar::Account.random
40
+
41
+ client.send_payment({
42
+ from: account,
43
+ to: recipient,
44
+ amount: Stellar::Amount.new(100_000000)
45
+ })
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Sign the [Contributor License Agreement](https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form)
51
+ 2. Fork it ( https://github.com/stellar/ruby-stellar-lib/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ Bundler.setup
3
+
4
+ require "rbnacl/rake_tasks"
5
+
6
+ Dir["tasks/**/*.rake"].each{|f| load f}
@@ -0,0 +1,37 @@
1
+ require 'stellar'
2
+
3
+ # Reference an account from a secret seed
4
+ account = Stellar::Account.from_seed("s3fu5vCMrfYouKuk2uB1gCD7EsuuBKY9M4qmnniQMBFMWR6Gaqm")
5
+
6
+ # Further options
7
+ #
8
+ # Make a random account
9
+ #
10
+ # account = Stellar::Account.random()
11
+ #
12
+ # Reference an account (unauthenticated) from an address
13
+ #
14
+ # account = Stellar::Account.from_address("gjgPNE2GpySt5iYZaFFo1svCJ4gbHwXxUy8DDqeYTDK6UzsPTs")
15
+ #
16
+ # Reference an account (unauthenticated) from a federation name
17
+ #
18
+ # account = Stellar::Account.lookup("nullstyle") # defaults to stellar.org
19
+ # account = Stellar::Account.lookup("nullstyle@stellar.org")
20
+ #
21
+
22
+ # create a connection to the stellar network
23
+ client = Stellar::Client.default_testnet()
24
+
25
+ # Further options
26
+ #
27
+ # Connect to the live network (when it is created)
28
+ #
29
+ # client = Stellar::Client.default
30
+ #
31
+ # Connect to a specific horizon host
32
+ #
33
+ # client = Stellar::Client.new(host: "127.0.0.1")
34
+
35
+ # Get our friendly friendbot to
36
+ # fund your new account
37
+ response = client.friendbot(account) # => #<OK>
@@ -0,0 +1,15 @@
1
+ require 'stellar'
2
+
3
+ account = Stellar::Account.from_seed("s3fu5vCMrfYouKuk2uB1gCD7EsuuBKY9M4qmnniQMBFMWR6Gaqm")
4
+ client = Stellar::Client.default_testnet()
5
+
6
+ # create a random recipients
7
+ recipient = Stellar::Account.random
8
+
9
+ # make a payment
10
+ client.send_payment({
11
+ from: account,
12
+ to: recipient,
13
+ amount: Stellar::Amount.new(100_000000)
14
+ }) # => #<OK>
15
+
@@ -0,0 +1,23 @@
1
+ require 'stellar'
2
+
3
+ account = Stellar::Account.from_seed("s3fu5vCMrfYouKuk2uB1gCD7EsuuBKY9M4qmnniQMBFMWR6Gaqm")
4
+ client = Stellar::Client.default_testnet()
5
+
6
+ # load the first page of transactions
7
+ transactions = client.transactions({
8
+ account: account,
9
+ order: :chronological
10
+ }) # => #<TransactionPage count=50 [...]>
11
+
12
+ # TransactionPage implements Enumerable...
13
+ transactions.first # => #<Stellar::Transaction ...>
14
+ transactions.each{|tx| p tx}
15
+ transactions.take(3) # => [...]
16
+
17
+ # ...but also has methods to advance pages
18
+ newer_transactions = transactions.next_page
19
+ older_transactions = transactions.prev_page # => []
20
+
21
+ # we can also just advance the current page in place
22
+ transactions.next_page!
23
+ transactions.prev_page!
@@ -0,0 +1,12 @@
1
+ require 'stellar'
2
+
3
+ account = Stellar::Account.from_seed("s3fu5vCMrfYouKuk2uB1gCD7EsuuBKY9M4qmnniQMBFMWR6Gaqm")
4
+ client = Stellar::Client.default_testnet()
5
+
6
+ issuer = Stellar::Account.lookup("issuer@haste.co.nz"))
7
+ currency = Stellar::Currency.iso4217("USD", issuer)
8
+
9
+ client.trust({
10
+ account: account
11
+ currency: currency
12
+ })
@@ -0,0 +1,13 @@
1
+ require 'stellar'
2
+
3
+ account = Stellar::Account.from_seed("s3fu5vCMrfYouKuk2uB1gCD7EsuuBKY9M4qmnniQMBFMWR6Gaqm")
4
+ client = Stellar::Client.default_testnet()
5
+
6
+ issuer = Stellar::Account.lookup("issuer@haste.co.nz"))
7
+ currency = Stellar::Currency.iso4217("USD", issuer)
8
+
9
+ client.send({
10
+ from: account,
11
+ to: recipient,
12
+ amount: Stellar::Amount.new(100, currency, issuer)
13
+ }) # => #<OK>
@@ -0,0 +1,19 @@
1
+ require 'stellar-base'
2
+ require 'contracts'
3
+
4
+ module Stellar
5
+
6
+ autoload :Account
7
+ autoload :AccountInfo
8
+ autoload :Amount
9
+ autoload :Client
10
+
11
+ module Horizon
12
+ extend ActiveSupport::Autoload
13
+
14
+ autoload :Problem
15
+ autoload :Result
16
+ end
17
+
18
+ autoload :TransactionPage
19
+ end
@@ -0,0 +1,38 @@
1
+ module Stellar
2
+ class Account
3
+ include Contracts
4
+
5
+ delegate :address, to: :keypair
6
+
7
+ def self.random
8
+ keypair = Stellar::KeyPair.random
9
+ new(keypair)
10
+ end
11
+
12
+ def self.from_seed(seed)
13
+ keypair = Stellar::KeyPair.from_seed(seed)
14
+ new(keypair)
15
+ end
16
+
17
+ def self.from_address(address)
18
+ keypair = Stellar::KeyPair.from_address(address)
19
+ new(keypair)
20
+ end
21
+
22
+ def self.lookup(federated_name)
23
+ raise NotImplementedError
24
+ end
25
+
26
+ def self.master
27
+ keypair = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
28
+ new(keypair)
29
+ end
30
+
31
+ attr_reader :keypair
32
+
33
+ Contract Stellar::KeyPair => Any
34
+ def initialize(keypair)
35
+ @keypair = keypair
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ module Stellar
2
+ class Amount
3
+ include Contracts
4
+
5
+ attr_reader :amount
6
+ attr_reader :currency
7
+
8
+ Contract Pos, Currency => Any
9
+ def initialize(amount, currency=Stellar::Currency.native())
10
+ # TODO: how are we going to handle decimal considerations?
11
+
12
+ @amount = amount
13
+ @currency = currency
14
+ end
15
+
16
+
17
+ Contract None => Or[
18
+ [:iso4217, String, KeyPair, Pos],
19
+ [:native, Pos],
20
+ ]
21
+ def to_payment
22
+ case currency.type
23
+ when CurrencyType.native
24
+ [:native, amount]
25
+ when CurrencyType.iso4217
26
+ keypair = KeyPair.from_public_key(currency.issuer)
27
+ [:iso4217, currency, keypair, amount]
28
+ else
29
+ raise "Unknown currency type: #{currency.type}"
30
+ end
31
+ end
32
+
33
+ def inspect
34
+ "#<Stellar::Amount #{currency}(#{amount})>"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,94 @@
1
+ require 'hyperclient'
2
+
3
+ module Stellar
4
+ class Client
5
+ include Contracts
6
+
7
+ def self.default(options={})
8
+ new options.merge({
9
+ horizon: "https://horizon.stellar.org"
10
+ })
11
+ end
12
+
13
+ def self.default_testnet(options={})
14
+ new options.merge({
15
+ horizon: "https://horizon-testnet.stellar.org",
16
+ friendbot: "https://horizon-testnet.stellar.org",
17
+ })
18
+ end
19
+
20
+ def self.localhost(options={})
21
+ new options.merge({
22
+ horizon: "http://127.0.0.1:3000", #TODO: figure out a real port
23
+ })
24
+ end
25
+
26
+ attr_reader :horizon
27
+
28
+ Contract ({horizon: String}) => Any
29
+ def initialize(options)
30
+ @options = options
31
+ @horizon = Hyperclient.new(options[:horizon]) do |client|
32
+ client.faraday_block = lambda do |conn|
33
+ conn.use Faraday::Response::RaiseError
34
+ conn.use FaradayMiddleware::FollowRedirects
35
+ conn.request :url_encoded
36
+ conn.response :hal_json, content_type: /\bjson$/
37
+ conn.adapter :excon
38
+ end
39
+ client.headers = {
40
+ 'Accept' => 'application/hal+json,application/problem+json,application/json'
41
+ }
42
+ end
43
+ end
44
+
45
+ def friendbot(account)
46
+ raise NotImplementedError
47
+ end
48
+
49
+ # Contract Stellar::Account => Stellar::AccountInfo
50
+ Contract Stellar::Account => Any
51
+ def account_info(account)
52
+ address = account.address
53
+ @horizon.account(address:address)
54
+ end
55
+
56
+ Contract ({
57
+ from: Stellar::Account,
58
+ to: Stellar::Account,
59
+ amount: Stellar::Amount
60
+ }) => Any
61
+ def send_payment(options={})
62
+ from = options[:from]
63
+ sequence = options[:sequence] || (account_info(from).sequence + 1)
64
+
65
+ payment = Stellar::Transaction.payment({
66
+ account: from.keypair,
67
+ destination: options[:to].keypair,
68
+ sequence: sequence,
69
+ amount: options[:amount].to_payment,
70
+ })
71
+
72
+ envelope_hex = payment.to_envelope(from.keypair).to_xdr(:hex)
73
+ @horizon.transactions._post(tx: envelope_hex)
74
+ end
75
+
76
+ Contract ({
77
+ account: Maybe[Stellar::Account],
78
+ limit: Maybe[Pos]
79
+ }) => TransactionPage
80
+ def transactions(options={})
81
+ args = options.slice(:limit)
82
+
83
+ resource = if options[:account]
84
+ args = args.merge(address: options[:account].address)
85
+ @horizon.account_transactions(args)
86
+ else
87
+ @horizon.transactions(args)
88
+ end
89
+
90
+ TransactionPage.new(resource)
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,47 @@
1
+ module Stellar
2
+ module Horizon
3
+ class Problem
4
+ include Contracts
5
+
6
+ def initialize(attributes)
7
+ @attributes = attributes.reverse_merge({
8
+ type: "about:blank",
9
+ title: "Unknown Error",
10
+ status: 500,
11
+ })
12
+
13
+ @meta = @attributes.except!(:type, :title, :status, :detail, :instance)
14
+ end
15
+
16
+ Contract None => String
17
+ def type
18
+ @attributes[:type]
19
+ end
20
+
21
+ Contract None => String
22
+ def title
23
+ @attributes[:title]
24
+ end
25
+
26
+ Contract None => Num
27
+ def status
28
+ @attributes[:status]
29
+ end
30
+
31
+ Contract None => String
32
+ def detail
33
+ @attributes[:detail]
34
+ end
35
+
36
+ Contract None => String
37
+ def instance
38
+ @attributes[:instance]
39
+ end
40
+
41
+ Contract None => HashOf[String, Any]
42
+ def meta
43
+ @attributes[:instance]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ module Stellar
2
+ class TransactionPage
3
+ include Contracts
4
+ include Enumerable
5
+
6
+ Contract Hyperclient::Link => Any
7
+ def initialize(resource)
8
+ @resource = resource
9
+ end
10
+
11
+ def each
12
+ @resource.records.each do |tx|
13
+ yield tx if block_given?
14
+ end
15
+ end
16
+
17
+ Contract None => TransactionPage
18
+ def next_page
19
+ self.class.new(@resource.next)
20
+ end
21
+
22
+ def next_page!
23
+ @resource = @resource.next
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Stellar
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stellar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stellar-lib"
8
+ spec.version = Stellar::VERSION
9
+ spec.authors = ["Scott Fleckenstein"]
10
+ spec.email = ["scott@stellar.org"]
11
+ spec.summary = %q{Stellar client library}
12
+ spec.homepage = "http://github.com/stellar/ruby-stellar-lib"
13
+ spec.license = "Apache 2.0"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "stellar-base", "= 0.0.5"
21
+ spec.add_dependency "hyperclient", "~> 0.7.0"
22
+ spec.add_dependency "excon", "~> 0.44.4"
23
+ spec.add_dependency "contracts", "~> 0.7"
24
+ spec.add_dependency "activesupport", "~> 4"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.1"
29
+ spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "simplecov"
31
+ spec.add_development_dependency "yard"
32
+
33
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe Stellar::Client, ".localhost" do
4
+ subject{ Stellar::Client.localhost }
5
+
6
+ it{ should be_a(Stellar::Client) }
7
+ end
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ require 'pry'
8
+ require 'stellar'
9
+
10
+ SPEC_ROOT = File.dirname(__FILE__)
11
+
12
+ Dir["#{SPEC_ROOT}/support/**/*.rb"].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :be_base58_check do |version_byte|
2
+ match do |actual|
3
+ begin
4
+ Stellar::Util::Base58.stellar.check_decode(version_byte, actual)
5
+ rescue ArgumentError
6
+ false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :eq_bytes do |expected|
2
+ match do |actual|
3
+ expected.force_encoding("ASCII-8BIT") == actual.force_encoding("ASCII-8BIT")
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :have_length do |length|
2
+ match do |actual|
3
+ actual.length == length
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
5
+ rescue LoadError
6
+ end
@@ -0,0 +1,9 @@
1
+ file "lib/libsodium.so" => :build_libsodium do
2
+ cp $LIBSODIUM_PATH, "lib/libsodium.so"
3
+ end
4
+
5
+ task "ci:sodium" => "lib/libsodium.so"
6
+
7
+ task :travis => %w(ci:sodium spec)
8
+
9
+ CLEAN.add "lib/libsodium.*"
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stellar-lib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Scott Fleckenstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stellar-base
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: hyperclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: excon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.44.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.44.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: contracts
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - scott@stellar.org
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".travis.yml"
176
+ - ".yardopts"
177
+ - CONTRIBUTING.md
178
+ - Gemfile
179
+ - Guardfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - examples/01_get_funded.rb
184
+ - examples/02_payment.rb
185
+ - examples/03_transaction_history.rb
186
+ - examples/04_setting_trust.rb
187
+ - examples/05_fiat_payment.rb
188
+ - lib/stellar.rb
189
+ - lib/stellar/account.rb
190
+ - lib/stellar/amount.rb
191
+ - lib/stellar/client.rb
192
+ - lib/stellar/horizon/problem.rb
193
+ - lib/stellar/transaction_page.rb
194
+ - lib/stellar/version.rb
195
+ - ruby-stellar-lib.gemspec
196
+ - spec/lib/stellar/client_spec.rb
197
+ - spec/spec_helper.rb
198
+ - spec/support/matchers/be_base58_check.rb
199
+ - spec/support/matchers/eq_bytes.rb
200
+ - spec/support/matchers/have_length.rb
201
+ - tasks/rspec.rake
202
+ - tasks/travis.rake
203
+ homepage: http://github.com/stellar/ruby-stellar-lib
204
+ licenses:
205
+ - Apache 2.0
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubyforge_project:
223
+ rubygems_version: 2.2.2
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: Stellar client library
227
+ test_files:
228
+ - spec/lib/stellar/client_spec.rb
229
+ - spec/spec_helper.rb
230
+ - spec/support/matchers/be_base58_check.rb
231
+ - spec/support/matchers/eq_bytes.rb
232
+ - spec/support/matchers/have_length.rb
233
+ has_rdoc: