open-core 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +8 -0
  5. data/CONTRIBUTING.md +48 -0
  6. data/Gemfile +15 -0
  7. data/Guardfile +5 -0
  8. data/LICENSE.txt +202 -0
  9. data/README.md +83 -0
  10. data/Rakefile +4 -0
  11. data/examples/create_account.rb +26 -0
  12. data/examples/low_level_transaction_post.rb +46 -0
  13. data/examples/mid_level_transaction_post.rb +33 -0
  14. data/examples/non_native_payment.rb +60 -0
  15. data/examples/offer.rb +75 -0
  16. data/examples/transaction_merge.rb +23 -0
  17. data/generated/stellar-base-generated.rb +134 -0
  18. data/generated/stellar/account_entry.rb +53 -0
  19. data/generated/stellar/account_entry/ext.rb +24 -0
  20. data/generated/stellar/account_flags.rb +27 -0
  21. data/generated/stellar/account_merge_result.rb +26 -0
  22. data/generated/stellar/account_merge_result_code.rb +30 -0
  23. data/generated/stellar/allow_trust_op.rb +38 -0
  24. data/generated/stellar/allow_trust_op/asset.rb +33 -0
  25. data/generated/stellar/allow_trust_result.rb +25 -0
  26. data/generated/stellar/allow_trust_result_code.rb +31 -0
  27. data/generated/stellar/asset.rb +47 -0
  28. data/generated/stellar/asset/alpha_num12.rb +22 -0
  29. data/generated/stellar/asset/alpha_num4.rb +22 -0
  30. data/generated/stellar/asset_type.rb +24 -0
  31. data/generated/stellar/bucket_entry.rb +28 -0
  32. data/generated/stellar/bucket_entry_type.rb +22 -0
  33. data/generated/stellar/change_trust_op.rb +22 -0
  34. data/generated/stellar/change_trust_result.rb +25 -0
  35. data/generated/stellar/change_trust_result_code.rb +30 -0
  36. data/generated/stellar/claim_offer_atom.rb +33 -0
  37. data/generated/stellar/create_account_op.rb +20 -0
  38. data/generated/stellar/create_account_result.rb +25 -0
  39. data/generated/stellar/create_account_result_code.rb +32 -0
  40. data/generated/stellar/create_passive_offer_op.rb +24 -0
  41. data/generated/stellar/crypto_key_type.rb +20 -0
  42. data/generated/stellar/decorated_signature.rb +20 -0
  43. data/generated/stellar/dont_have.rb +20 -0
  44. data/generated/stellar/envelope_type.rb +22 -0
  45. data/generated/stellar/error.rb +20 -0
  46. data/generated/stellar/hello.rb +26 -0
  47. data/generated/stellar/inflation_payout.rb +20 -0
  48. data/generated/stellar/inflation_result.rb +26 -0
  49. data/generated/stellar/inflation_result_code.rb +24 -0
  50. data/generated/stellar/ledger_entry.rb +44 -0
  51. data/generated/stellar/ledger_entry/data.rb +33 -0
  52. data/generated/stellar/ledger_entry/ext.rb +24 -0
  53. data/generated/stellar/ledger_entry_change.rb +31 -0
  54. data/generated/stellar/ledger_entry_change_type.rb +24 -0
  55. data/generated/stellar/ledger_entry_type.rb +24 -0
  56. data/generated/stellar/ledger_header.rb +65 -0
  57. data/generated/stellar/ledger_header/ext.rb +24 -0
  58. data/generated/stellar/ledger_header_history_entry.rb +33 -0
  59. data/generated/stellar/ledger_header_history_entry/ext.rb +24 -0
  60. data/generated/stellar/ledger_key.rb +50 -0
  61. data/generated/stellar/ledger_key/account.rb +20 -0
  62. data/generated/stellar/ledger_key/offer.rb +22 -0
  63. data/generated/stellar/ledger_key/trust_line.rb +22 -0
  64. data/generated/stellar/ledger_upgrade.rb +27 -0
  65. data/generated/stellar/ledger_upgrade_type.rb +22 -0
  66. data/generated/stellar/manage_offer_effect.rb +24 -0
  67. data/generated/stellar/manage_offer_op.rb +28 -0
  68. data/generated/stellar/manage_offer_result.rb +26 -0
  69. data/generated/stellar/manage_offer_result_code.rb +48 -0
  70. data/generated/stellar/manage_offer_success_result.rb +34 -0
  71. data/generated/stellar/manage_offer_success_result/offer.rb +30 -0
  72. data/generated/stellar/memo.rb +38 -0
  73. data/generated/stellar/memo_type.rb +28 -0
  74. data/generated/stellar/message_type.rb +45 -0
  75. data/generated/stellar/offer_entry.rb +49 -0
  76. data/generated/stellar/offer_entry/ext.rb +24 -0
  77. data/generated/stellar/offer_entry_flags.rb +21 -0
  78. data/generated/stellar/operation.rb +51 -0
  79. data/generated/stellar/operation/body.rb +60 -0
  80. data/generated/stellar/operation_meta.rb +18 -0
  81. data/generated/stellar/operation_result.rb +53 -0
  82. data/generated/stellar/operation_result/tr.rb +61 -0
  83. data/generated/stellar/operation_result_code.rb +25 -0
  84. data/generated/stellar/operation_type.rb +38 -0
  85. data/generated/stellar/path_payment_op.rb +32 -0
  86. data/generated/stellar/path_payment_result.rb +34 -0
  87. data/generated/stellar/path_payment_result/success.rb +22 -0
  88. data/generated/stellar/path_payment_result_code.rb +45 -0
  89. data/generated/stellar/payment_op.rb +22 -0
  90. data/generated/stellar/payment_result.rb +25 -0
  91. data/generated/stellar/payment_result_code.rb +39 -0
  92. data/generated/stellar/peer_address.rb +22 -0
  93. data/generated/stellar/price.rb +20 -0
  94. data/generated/stellar/public_key.rb +23 -0
  95. data/generated/stellar/scp_ballot.rb +20 -0
  96. data/generated/stellar/scp_envelope.rb +20 -0
  97. data/generated/stellar/scp_nomination.rb +22 -0
  98. data/generated/stellar/scp_quorum_set.rb +22 -0
  99. data/generated/stellar/scp_statement.rb +59 -0
  100. data/generated/stellar/scp_statement/pledges.rb +64 -0
  101. data/generated/stellar/scp_statement/pledges/confirm.rb +28 -0
  102. data/generated/stellar/scp_statement/pledges/externalize.rb +28 -0
  103. data/generated/stellar/scp_statement/pledges/prepare.rb +32 -0
  104. data/generated/stellar/scp_statement_type.rb +26 -0
  105. data/generated/stellar/set_options_op.rb +41 -0
  106. data/generated/stellar/set_options_result.rb +25 -0
  107. data/generated/stellar/set_options_result_code.rb +38 -0
  108. data/generated/stellar/signer.rb +20 -0
  109. data/generated/stellar/simple_payment_result.rb +22 -0
  110. data/generated/stellar/stellar_message.rb +66 -0
  111. data/generated/stellar/stellar_value.rb +40 -0
  112. data/generated/stellar/stellar_value/ext.rb +24 -0
  113. data/generated/stellar/threshold_indexes.rb +26 -0
  114. data/generated/stellar/time_bounds.rb +20 -0
  115. data/generated/stellar/transaction.rb +50 -0
  116. data/generated/stellar/transaction/ext.rb +24 -0
  117. data/generated/stellar/transaction_envelope.rb +20 -0
  118. data/generated/stellar/transaction_history_entry.rb +33 -0
  119. data/generated/stellar/transaction_history_entry/ext.rb +24 -0
  120. data/generated/stellar/transaction_history_result_entry.rb +33 -0
  121. data/generated/stellar/transaction_history_result_entry/ext.rb +24 -0
  122. data/generated/stellar/transaction_meta.rb +31 -0
  123. data/generated/stellar/transaction_meta/v0.rb +22 -0
  124. data/generated/stellar/transaction_result.rb +43 -0
  125. data/generated/stellar/transaction_result/ext.rb +24 -0
  126. data/generated/stellar/transaction_result/result.rb +30 -0
  127. data/generated/stellar/transaction_result_code.rb +45 -0
  128. data/generated/stellar/transaction_result_pair.rb +20 -0
  129. data/generated/stellar/transaction_result_set.rb +18 -0
  130. data/generated/stellar/transaction_set.rb +20 -0
  131. data/generated/stellar/trust_line_entry.rb +41 -0
  132. data/generated/stellar/trust_line_entry/ext.rb +24 -0
  133. data/generated/stellar/trust_line_flags.rb +21 -0
  134. data/lib/stellar-base.rb +32 -0
  135. data/lib/stellar/account_flags.rb +28 -0
  136. data/lib/stellar/asset.rb +69 -0
  137. data/lib/stellar/base.rb +1 -0
  138. data/lib/stellar/base/version.rb +5 -0
  139. data/lib/stellar/convert.rb +32 -0
  140. data/lib/stellar/key_pair.rb +112 -0
  141. data/lib/stellar/networks.rb +45 -0
  142. data/lib/stellar/operation.rb +304 -0
  143. data/lib/stellar/path_payment_result.rb +17 -0
  144. data/lib/stellar/price.rb +32 -0
  145. data/lib/stellar/thresholds.rb +39 -0
  146. data/lib/stellar/transaction.rb +170 -0
  147. data/lib/stellar/transaction_envelope.rb +32 -0
  148. data/lib/stellar/util/continued_fraction.rb +96 -0
  149. data/lib/stellar/util/strkey.rb +43 -0
  150. data/open-core.gemspec +37 -0
  151. data/spec/lib/stellar/account_flags_spec.rb +19 -0
  152. data/spec/lib/stellar/asset_spec.rb +45 -0
  153. data/spec/lib/stellar/convert_spec.rb +61 -0
  154. data/spec/lib/stellar/key_pair_spec.rb +238 -0
  155. data/spec/lib/stellar/networks_spec.rb +77 -0
  156. data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
  157. data/spec/lib/stellar/price_spec.rb +34 -0
  158. data/spec/lib/stellar/thresholds_spec.rb +62 -0
  159. data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
  160. data/spec/lib/stellar/transaction_spec.rb +54 -0
  161. data/spec/lib/stellar/util/strkey_spec.rb +46 -0
  162. data/spec/spec_helper.rb +16 -0
  163. data/spec/support/matchers/be_strkey.rb +9 -0
  164. data/spec/support/matchers/eq_bytes.rb +5 -0
  165. data/spec/support/matchers/have_length.rb +5 -0
  166. data/tasks/rspec.rake +6 -0
  167. data/tasks/travis.rake +1 -0
  168. data/tasks/xdr.rake +50 -0
  169. data/xdr/Stellar-SCP.x +87 -0
  170. data/xdr/Stellar-ledger-entries.x +222 -0
  171. data/xdr/Stellar-ledger.x +231 -0
  172. data/xdr/Stellar-overlay.x +87 -0
  173. data/xdr/Stellar-transaction.x +670 -0
  174. data/xdr/Stellar-types.x +34 -0
  175. metadata +444 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d95acb6ef46fdd6756e27777994df139a087db01
4
+ data.tar.gz: 1de820367f8156cd4bf6123f6e2f9326392fcab5
5
+ SHA512:
6
+ metadata.gz: 612b8b220e827e616c313769bdcbc65bf4f07624f0412c5e4df91072e8971123c4760b06d2ef4b8a101ee751a6d5a296e898de55bec82bf87b0392df4c88fc95
7
+ data.tar.gz: 2a807330ae99bc5499524d4d169aa20022ab702cd181d78632c8721f40029ee03e8bda8f71651cd085c387ca28b7029b680665b06c7d8840e17b1e4ea884e636
@@ -0,0 +1,15 @@
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
15
+ .DS_Store
@@ -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.20
8
+ - jruby-head
9
+ script: bundle exec rake travis
10
+ notifications:
11
+ slack:
12
+ secure: V/6a8KFe067uukrbCJA2R1HPO4xy0YSQ1pwmHVRi5StX+yl+lYsWWJdjdBdT0j3iJBYyPRqU4bQYck+OloxtELnrHCX+OkodxcxW8W/ACc914iIf0FyY9pnusK7ck2awmt4Iuf94YPgi0XTm1aCcm+f0yU7wiIVFpftoXSk1EDY=
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-head
@@ -0,0 +1,8 @@
1
+ --output-dir doc/generated
2
+ --protected
3
+ --no-private
4
+ --embed-mixin ClassMethods
5
+ lib/**/*.rb
6
+ generated/**/*.rb
7
+ -
8
+ 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-base/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,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem "xdr", git: "https://github.com/stellar/ruby-xdr.git"
6
+ # gem "xdr", path: "../ruby-xdr"
7
+
8
+ group :development do
9
+ gem "xdrgen", git: "https://github.com/stellar/xdrgen.git"
10
+ # gem "xdrgen", path: "../xdrgen"
11
+ gem "pry"
12
+ gem "faraday"
13
+ gem "faraday_middleware"
14
+ end
15
+
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'bundle exec 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,83 @@
1
+ # Stellar::Base
2
+
3
+ [![Build Status](https://travis-ci.org/stellar/ruby-stellar-base.svg)](https://travis-ci.org/stellar/ruby-stellar-base)
4
+ [![Code Climate](https://codeclimate.com/github/stellar/ruby-stellar-base/badges/gpa.svg)](https://codeclimate.com/github/stellar/ruby-stellar-base)
5
+
6
+ The stellar-base library is the lowest-level stellar helper library. It consists of classes
7
+ to read, write, hash, and sign the xdr structures that are used in stellard.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'stellar-base'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install stellar-base
24
+
25
+ Also requires libsodium. Installable via `brew install libsodium` on OS X.
26
+
27
+ ## Supported Ruby Versions
28
+
29
+ Please see [travis.yml](.travis.yml) for what versions of ruby are currently tested by our continuous integration system. Any ruby in that list is officially supported.
30
+
31
+ ### JRuby
32
+
33
+ It seems as though jruby is particularly slow when it comes to BigDecimal math; the source behind this slowness has not been investigated, but it is something to be aware of.
34
+
35
+ ## Usage
36
+
37
+ [Examples are here](examples)
38
+
39
+ In addition to the code generated from the XDR definition files (see [ruby-xdr](https://github.com/stellar/ruby-xdr) for example usage), this library also provides some stellar specific features. Let's look at some of them.
40
+
41
+ We wrap rbnacl with `Stellar::KeyPair`, providing some stellar specific functionality as seen below:
42
+
43
+ ```ruby
44
+
45
+ # Create a keypair from a stellar secret seed
46
+ signer = Stellar::KeyPair.from_seed("SCBASSEX34FJNIPLUYQPSMZHHYXXQNWOOV42XYZFXM6EGYX2DPIZVIA3")
47
+
48
+ # Create a keypair from a stellar address
49
+ verifier = Stellar::KeyPair.from_address("GBQWWBFLRP3BXD2RI2FH7XNNU2MKIYVUI7QXUAIVG34JY6MQGXVUO3RX")
50
+
51
+ # Produce a stellar compliant "decorated signature" that is compliant with stellar transactions
52
+
53
+ signer.sign_decorated("Hello world!") # => #<Stellar::DecoratedSignature ...>
54
+
55
+ ```
56
+
57
+ This library also provides an impementation of Stellar's "StrKey" encoding (RFC-4648 Base32 + CCITT-XModem CRC16):
58
+
59
+ ```ruby
60
+
61
+ Stellar::Util::StrCheck.check_encode(:account_id, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF") # => "GD777777777764TU"
62
+ Stellar::Util::StrCheck.check_encode(:seed, "\x00\x00\x00\x00\x00\x00\x39") # => "SAAAAAAAAAADST3H"
63
+
64
+ # To prevent interpretation mistakes, you must pass the expected version byte
65
+ # when decoding a check_encoded value
66
+
67
+ encoded = Stellar::Util::StrCheck.check_encode(:account_id, "\x61\x6b\x04\xab\x8b\xf6\x1b")
68
+ Stellar::Util::StrCheck.check_decode(:account_id, encoded) # => "\x61\x6b\x04\xab\x8b\xf6\x1b"
69
+ Stellar::Util::StrCheck.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version: :account_id
70
+
71
+ ```
72
+
73
+ ## Updating Generated Code
74
+
75
+ The generated code of this library must be refreshed each time the Stellar network's protocol is updated. To perform this task, run `rake xdr:update`, which will download the latest `.x` files into the `xdr` folder and will run `xdrgen` to regenerate the built ruby code.
76
+
77
+ ## Caveats
78
+
79
+ The current integration of user-written code with auto-generated classes is to put it nicely, weird. We intend to segregate the auto-generated code into its own namespace and refrain from monkey patching them. This will happen before 1.0, and hopefully will happen soon.
80
+
81
+ ## Contributing
82
+
83
+ Please [see CONTRIBUTING.md for details](CONTRIBUTING.md).
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ Bundler.setup
3
+
4
+ Dir["tasks/**/*.rake"].each{|f| load f}
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'stellar-base'
5
+ require 'faraday'
6
+ require 'faraday_middleware'
7
+
8
+ $server = Faraday.new(url: "http://localhost:39132") do |conn|
9
+ conn.response :json
10
+ conn.adapter Faraday.default_adapter
11
+ end
12
+
13
+ master = Stellar::KeyPair.master
14
+ destination = Stellar::KeyPair.random
15
+
16
+ tx = Stellar::Transaction.create_account({
17
+ account: master,
18
+ destination: destination,
19
+ sequence: 1,
20
+ starting_balance: 50 * Stellar::ONE
21
+ })
22
+
23
+ b64 = tx.to_envelope(master).to_xdr(:base64)
24
+
25
+ result = $server.get('tx', blob: b64)
26
+ p result.body
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is an example of using the raw xdr objects to post a transaction
4
+ # notice that we must manually hash/sign the structures and we must manually
5
+ # fill out all the fields.
6
+ #
7
+ # Look at mid_level_transaction_post.rb to see a friendlier form
8
+
9
+ require 'rbnacl'
10
+ require 'stellar-base'
11
+ require 'faraday'
12
+ require 'digest/sha2'
13
+
14
+ master = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")
15
+ destination = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")
16
+
17
+ tx = Stellar::Transaction.new
18
+ tx.account = master.verify_key.to_bytes
19
+ tx.fee = 1000
20
+ tx.seq_num = 1
21
+
22
+ payment = Stellar::PaymentOp.new
23
+ payment.destination = destination.verify_key.to_bytes
24
+ payment.asset = Stellar::Asset.new(:native)
25
+ payment.amount = 200 * Stellar::ONE
26
+
27
+ op = Stellar::Operation.new
28
+ op.body = Stellar::Operation::Body.new(:payment, payment)
29
+
30
+ tx.operations = [op]
31
+
32
+ raw = tx.to_xdr
33
+ tx_hash = Digest::SHA256.digest raw
34
+ signature = master.sign(tx_hash)
35
+
36
+ env = Stellar::TransactionEnvelope.new
37
+ env.tx = tx
38
+ env.signatures = [Stellar::DecoratedSignature.new({
39
+ hint:master.verify_key.to_bytes[0...4],
40
+ signature:signature
41
+ })]
42
+
43
+ env_hex = env.to_xdr.unpack("H*").first
44
+
45
+ result = Faraday.get('http://localhost:39132/tx', blob: env_hex)
46
+ puts result.body