stellar-base 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +15 -0
- data/.yardopts +8 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +202 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/examples/low_level_transaction_post.rb +53 -0
- data/examples/mid_level_transaction_post.rb +34 -0
- data/examples/non_native_payment.rb +60 -0
- data/generated/stellar/account_entry.rb +37 -0
- data/generated/stellar/account_flags.rb +20 -0
- data/generated/stellar/account_merge_result.rb +25 -0
- data/generated/stellar/account_merge_result_code.rb +30 -0
- data/generated/stellar/allow_trust_op/currency.rb +28 -0
- data/generated/stellar/allow_trust_op.rb +35 -0
- data/generated/stellar/allow_trust_result.rb +25 -0
- data/generated/stellar/allow_trust_result_code.rb +28 -0
- data/generated/stellar/bucket_entry.rb +28 -0
- data/generated/stellar/bucket_entry_type.rb +22 -0
- data/generated/stellar/change_trust_op.rb +22 -0
- data/generated/stellar/change_trust_result.rb +25 -0
- data/generated/stellar/change_trust_result_code.rb +28 -0
- data/generated/stellar/claim_offer_atom.rb +29 -0
- data/generated/stellar/create_offer_effect.rb +24 -0
- data/generated/stellar/create_offer_op.rb +28 -0
- data/generated/stellar/create_offer_result.rb +26 -0
- data/generated/stellar/create_offer_result_code.rb +45 -0
- data/generated/stellar/create_offer_success_result/offer.rb +30 -0
- data/generated/stellar/create_offer_success_result.rb +34 -0
- data/generated/stellar/currency.rb +29 -0
- data/generated/stellar/currency_type.rb +22 -0
- data/generated/stellar/decorated_signature.rb +20 -0
- data/generated/stellar/dont_have.rb +20 -0
- data/generated/stellar/error.rb +20 -0
- data/generated/stellar/hello.rb +24 -0
- data/generated/stellar/inflation_payout.rb +20 -0
- data/generated/stellar/inflation_result.rb +26 -0
- data/generated/stellar/inflation_result_code.rb +24 -0
- data/generated/stellar/iso_currency_issuer.rb +20 -0
- data/generated/stellar/ledger_entry.rb +33 -0
- data/generated/stellar/ledger_entry_type.rb +24 -0
- data/generated/stellar/ledger_header.rb +45 -0
- data/generated/stellar/ledger_header_history_entry.rb +20 -0
- data/generated/stellar/ledger_key/account.rb +20 -0
- data/generated/stellar/ledger_key/offer.rb +22 -0
- data/generated/stellar/ledger_key/trust_line.rb +22 -0
- data/generated/stellar/ledger_key.rb +50 -0
- data/generated/stellar/message_type.rb +45 -0
- data/generated/stellar/offer_entry.rb +34 -0
- data/generated/stellar/operation/body.rb +49 -0
- data/generated/stellar/operation.rb +45 -0
- data/generated/stellar/operation_result/tr.rb +49 -0
- data/generated/stellar/operation_result.rb +47 -0
- data/generated/stellar/operation_result_code.rb +25 -0
- data/generated/stellar/operation_type.rb +32 -0
- data/generated/stellar/payment_op.rb +35 -0
- data/generated/stellar/payment_result.rb +29 -0
- data/generated/stellar/payment_result_code.rb +41 -0
- data/generated/stellar/payment_success_multi_result.rb +20 -0
- data/generated/stellar/peer_address.rb +22 -0
- data/generated/stellar/price.rb +20 -0
- data/generated/stellar/scp_ballot.rb +20 -0
- data/generated/stellar/scp_envelope.rb +22 -0
- data/generated/stellar/scp_quorum_set.rb +20 -0
- data/generated/stellar/scp_statement/pledges/prepare.rb +24 -0
- data/generated/stellar/scp_statement/pledges.rb +40 -0
- data/generated/stellar/scp_statement.rb +42 -0
- data/generated/stellar/scp_statement_type.rb +26 -0
- data/generated/stellar/set_options_op.rb +31 -0
- data/generated/stellar/set_options_result.rb +25 -0
- data/generated/stellar/set_options_result_code.rb +28 -0
- data/generated/stellar/signer.rb +20 -0
- data/generated/stellar/simple_payment_result.rb +22 -0
- data/generated/stellar/stellar_ballot.rb +22 -0
- data/generated/stellar/stellar_ballot_value.rb +22 -0
- data/generated/stellar/stellar_message.rb +66 -0
- data/generated/stellar/transaction.rb +37 -0
- data/generated/stellar/transaction_envelope.rb +20 -0
- data/generated/stellar/transaction_history_entry.rb +20 -0
- data/generated/stellar/transaction_history_result_entry.rb +20 -0
- data/generated/stellar/transaction_meta.rb +18 -0
- data/generated/stellar/transaction_result/result.rb +30 -0
- data/generated/stellar/transaction_result.rb +33 -0
- data/generated/stellar/transaction_result_code.rb +46 -0
- data/generated/stellar/transaction_result_pair.rb +20 -0
- data/generated/stellar/transaction_result_set.rb +18 -0
- data/generated/stellar/transaction_set.rb +20 -0
- data/generated/stellar/trust_line_entry.rb +28 -0
- data/generated/stellar-base-generated.rb +160 -0
- data/lib/stellar/base/version.rb +5 -0
- data/lib/stellar/base.rb +1 -0
- data/lib/stellar/change_trust_op.rb +10 -0
- data/lib/stellar/currency.rb +28 -0
- data/lib/stellar/key_pair.rb +94 -0
- data/lib/stellar/payment_op.rb +38 -0
- data/lib/stellar/transaction.rb +72 -0
- data/lib/stellar/transaction_envelope.rb +32 -0
- data/lib/stellar/util/base58.rb +127 -0
- data/lib/stellar-base.rb +23 -0
- data/ruby-stellar-base.gemspec +34 -0
- data/spec/lib/stellar/key_pair_spec.rb +199 -0
- data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
- data/spec/lib/stellar/transaction_spec.rb +43 -0
- data/spec/lib/stellar/util/base58_spec.rb +74 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/matchers/be_base58_check.rb +9 -0
- data/spec/support/matchers/eq_bytes.rb +5 -0
- data/spec/support/matchers/have_length.rb +5 -0
- data/tasks/rspec.rake +6 -0
- data/tasks/travis.rake +9 -0
- data/tasks/xdr.rake +48 -0
- data/xdr/SCPXDR.x +61 -0
- data/xdr/Stellar-ledger-entries.x +105 -0
- data/xdr/Stellar-ledger.x +117 -0
- data/xdr/Stellar-overlay.x +100 -0
- data/xdr/Stellar-transaction.x +497 -0
- data/xdr/Stellar-types.x +53 -0
- data/xdr/StellarXDR.x +11 -0
- metadata +342 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e96c6ed22128b9697abddfe5d7af892a34998eef
|
4
|
+
data.tar.gz: fb6a8ef744c27cfe43fcc58958f3ec0b802b3671
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e4d7b0ed101c1522a5b319c098ea3c23134e6128d4ef88c392149cb4f9036367ab677da8ac3c7b4cb9da93b8c60223b89b696220508937e7598160dc82d589d
|
7
|
+
data.tar.gz: 9f1c3844cacd4a7baa49cc92add9ea973bed8448aa86149de5e44953a37898ba6f6da7d4c841e98b89b8dbec944cfaaec49d1dc0ac2ea4fe2fec8d5baa27d054
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -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
|
+
notifications:
|
11
|
+
slack:
|
12
|
+
secure: KM3guRjiX+LAjmALKtPvHBRbEaGdP2tjJOKymNDzl/+LpKME3sqkWnjNTyitgkpfmE66y7Dct9+NyNhzQfZ6iX0qN2i4sVr1WbGy90Duj+PyBf2t2juL0hIY3uQLBLt850TzlHgtTOQtTv0XsmpKLSa3bb00MHtD2TJ0zO66oc8=
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: jruby-head
|
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
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
|
+
group :development do
|
9
|
+
gem "xdrgen", git: "git@github.com:stellar/xdrgen.git"
|
10
|
+
# gem "xdrgen", path: "../xdrgen"
|
11
|
+
gem "pry"
|
12
|
+
gem "faraday"
|
13
|
+
gem "faraday_middleware"
|
14
|
+
end
|
15
|
+
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Stellar::Base
|
2
|
+
|
3
|
+
The stellar-base library is the lowest-level stellar helper library. It consists of classes
|
4
|
+
to read, write, hash, and sign the xdr structures that are used in stellard.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'stellar-base'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install stellar-base
|
21
|
+
|
22
|
+
Also requires libsodium. Installable via `brew install libsodium` on OS X.
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
[Examples are here](examples)
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
We wrap rbnacl with `Stellar::KeyPair`, providing some stellar specific functionality as seen below:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
|
34
|
+
# Create a keypair from a stellar secret seed
|
35
|
+
signer = Stellar::KeyPair.from_seed("s3tUdZbCmLoMdrZ6nhqztatMFaiD85P54oVj93g1NeSBwWQpTnE")
|
36
|
+
|
37
|
+
# Create a keypair from a stellar address
|
38
|
+
verifier = Stellar::KeyPair.from_address("gsTe6bDX54bPwtUAm2TER4shBF8nQNVtEvB8fmRkRoWvq3Y8XmY")
|
39
|
+
|
40
|
+
# Produce a stellar compliant "decorated signature" that is compliant with stellar transactions
|
41
|
+
|
42
|
+
signer.sign_decorated("Hello world!") # => #<Stellar::DecoratedSignature ...>
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
This library also provides an impementation of base58 and base58check encoding, with support for the bitcoin and stellar alphabets:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
b58 = Stellar::Util::Base58.stellar
|
50
|
+
|
51
|
+
encoded = b58.encode("\x00\x00\x00") # => "ggg"
|
52
|
+
b58.decode(encoded) # => "\x00\x00\x00"
|
53
|
+
|
54
|
+
# we can also use check encoding
|
55
|
+
|
56
|
+
b58.check_encode(:account_id, "\x00\x00\x00") # => "gggghbdQd2"
|
57
|
+
b58.check_encode(:seed, "\x00\x00\x00") # => "aX9UTew55Eh"
|
58
|
+
|
59
|
+
# To prevent interpretation mistakes, you must pass the expected version byte
|
60
|
+
# when decoding a check_encoded value
|
61
|
+
|
62
|
+
encoded = b58.check_encode(:account_id, "\x00\x00\x00")
|
63
|
+
b58.check_decode(:account_id, encoded) # => "\x00\x00\x00"
|
64
|
+
b58.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version: :account_id
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
## Caveats
|
69
|
+
|
70
|
+
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.
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Sign the [Contributor License Agreement](https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form)
|
75
|
+
2. Fork it ( https://github.com/stellar/ruby-stellar-base/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
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.max_fee = 1000
|
20
|
+
tx.seq_num = 1
|
21
|
+
tx.max_ledger = 1000
|
22
|
+
tx.min_ledger = 0
|
23
|
+
|
24
|
+
payment = Stellar::PaymentOp.new
|
25
|
+
payment.destination = destination.verify_key.to_bytes
|
26
|
+
payment.currency = Stellar::Currency.new(:native)
|
27
|
+
payment.path = []
|
28
|
+
payment.amount = 200_000000
|
29
|
+
payment.send_max = 200_000000
|
30
|
+
payment.source_memo = ""
|
31
|
+
payment.memo = ""
|
32
|
+
|
33
|
+
op = Stellar::Operation.new
|
34
|
+
op.body = Stellar::Operation::Body.new(:payment, payment)
|
35
|
+
|
36
|
+
tx.operations = [op]
|
37
|
+
|
38
|
+
raw = tx.to_xdr
|
39
|
+
tx_hash = Digest::SHA256.digest raw
|
40
|
+
signature = master.sign(tx_hash)
|
41
|
+
|
42
|
+
env = Stellar::TransactionEnvelope.new
|
43
|
+
env.tx = tx
|
44
|
+
env.signatures = [Stellar::DecoratedSignature.new({
|
45
|
+
hint:master.verify_key.to_bytes[0...4],
|
46
|
+
signature:signature
|
47
|
+
})]
|
48
|
+
|
49
|
+
env_hex = env.to_xdr.unpack("H*").first
|
50
|
+
|
51
|
+
result = Faraday.get('http://localhost:39132/tx', blob: env_hex)
|
52
|
+
puts result.body
|
53
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This is an example of using the higher level "payment" wrapper. Notice
|
4
|
+
# that we are using KeyPair instead of the raw rbnacl keys and that we need
|
5
|
+
# not build the entire heirarchy of xdr object manually.
|
6
|
+
#
|
7
|
+
# You can see where these helpers are defined in the files underneath /lib,
|
8
|
+
# which is where we extend the xdrgen generated source files with our higher
|
9
|
+
# level api.
|
10
|
+
|
11
|
+
require 'stellar-base'
|
12
|
+
require 'faraday'
|
13
|
+
require 'faraday_middleware'
|
14
|
+
|
15
|
+
$server = Faraday.new(url: "http://localhost:39132") do |conn|
|
16
|
+
conn.response :json
|
17
|
+
conn.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
|
20
|
+
master = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
|
21
|
+
destination = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
|
22
|
+
|
23
|
+
tx = Stellar::Transaction.payment({
|
24
|
+
account: master,
|
25
|
+
destination: destination,
|
26
|
+
sequence: 1,
|
27
|
+
amount: [:native, 20_000000]
|
28
|
+
})
|
29
|
+
|
30
|
+
hex = tx.to_envelope(master).to_xdr(:hex)
|
31
|
+
|
32
|
+
result = $server.get('tx', blob: hex)
|
33
|
+
raw = [result.body["result"]].pack("H*")
|
34
|
+
p Stellar::TransactionResult.from_xdr(raw)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This is an example of using the higher level "payment" wrapper. Notice
|
4
|
+
# that we are using KeyPair instead of the raw rbnacl keys and that we need
|
5
|
+
# not build the entire heirarchy of xdr object manually.
|
6
|
+
#
|
7
|
+
# You can see where these helpers are defined in the files underneath /lib,
|
8
|
+
# which is where we extend the xdrgen generated source files with our higher
|
9
|
+
# level api.
|
10
|
+
#
|
11
|
+
# NOTE: due to the way that sequence number for a new account are set, this
|
12
|
+
# example is pretty cumbersome to run. It is only used for illustrative purposes
|
13
|
+
# of the flow
|
14
|
+
|
15
|
+
require 'stellar-base'
|
16
|
+
require 'faraday'
|
17
|
+
require 'faraday_middleware'
|
18
|
+
|
19
|
+
$server = Faraday.new(url: "http://localhost:39132") do |conn|
|
20
|
+
conn.response :json
|
21
|
+
conn.adapter Faraday.default_adapter
|
22
|
+
end
|
23
|
+
|
24
|
+
def submit(key, tx)
|
25
|
+
hex = tx.to_envelope(key).to_xdr(:hex)
|
26
|
+
response = $server.get('tx', blob: hex)
|
27
|
+
raw = [response.body["result"]].pack("H*")
|
28
|
+
p Stellar::TransactionResult.from_xdr(raw)
|
29
|
+
end
|
30
|
+
|
31
|
+
master = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
|
32
|
+
destination = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
|
33
|
+
|
34
|
+
submit master, Stellar::Transaction.payment({
|
35
|
+
account: master,
|
36
|
+
destination: destination,
|
37
|
+
sequence: 1,
|
38
|
+
amount: [:native, 2000_000000]
|
39
|
+
})
|
40
|
+
|
41
|
+
# NOTE: after this step, you need to get the sequence number for destination
|
42
|
+
# Which is based off of the ledger sequence number it was funded in.
|
43
|
+
gets # pause to get the account's sequence from the hayashi db
|
44
|
+
|
45
|
+
destination_sequence = FILL_ME_IN
|
46
|
+
# destination_sequence = 17179869185
|
47
|
+
|
48
|
+
submit destination, Stellar::Transaction.change_trust({
|
49
|
+
account: destination,
|
50
|
+
sequence: destination_sequence,
|
51
|
+
line: [:iso4217, "USD\x00", master],
|
52
|
+
limit: 1000
|
53
|
+
})
|
54
|
+
|
55
|
+
submit master, Stellar::Transaction.payment({
|
56
|
+
account: master,
|
57
|
+
destination: destination,
|
58
|
+
sequence: 3,
|
59
|
+
amount: [:iso4217, "USD\x00", master, 100]
|
60
|
+
})
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Automatically generated on 2015-04-07T10:52:07-07:00
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct AccountEntry
|
9
|
+
# {
|
10
|
+
# AccountID accountID; // master public key for this account
|
11
|
+
# int64 balance; // in stroops
|
12
|
+
# SequenceNumber seqNum; // last sequence number used for this account
|
13
|
+
# uint32 numSubEntries; // number of sub-entries this account has
|
14
|
+
# // drives the reserve
|
15
|
+
# AccountID* inflationDest; // Account to vote during inflation
|
16
|
+
# uint32 flags; // see AccountFlags
|
17
|
+
#
|
18
|
+
# // fields used for signatures
|
19
|
+
# // thresholds stores unsigned bytes: [weight of master|low|medium|high]
|
20
|
+
# Thresholds thresholds;
|
21
|
+
#
|
22
|
+
# Signer signers<20>; // possible signers for this account
|
23
|
+
# };
|
24
|
+
#
|
25
|
+
# ===========================================================================
|
26
|
+
module Stellar
|
27
|
+
class AccountEntry < XDR::Struct
|
28
|
+
attribute :account_id, AccountID
|
29
|
+
attribute :balance, Int64
|
30
|
+
attribute :seq_num, SequenceNumber
|
31
|
+
attribute :num_sub_entries, Uint32
|
32
|
+
attribute :inflation_dest, XDR::Option[AccountID]
|
33
|
+
attribute :flags, Uint32
|
34
|
+
attribute :thresholds, Thresholds
|
35
|
+
attribute :signers, XDR::VarArray[Signer, 20]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Automatically generated on 2015-04-07T10:52:07-07:00
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# enum AccountFlags
|
9
|
+
# { // masks for each flag
|
10
|
+
# AUTH_REQUIRED_FLAG = 0x1
|
11
|
+
# };
|
12
|
+
#
|
13
|
+
# ===========================================================================
|
14
|
+
module Stellar
|
15
|
+
class AccountFlags < XDR::Enum
|
16
|
+
member :auth_required_flag, 1
|
17
|
+
|
18
|
+
seal
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Automatically generated on 2015-04-07T10:52:07-07:00
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union AccountMergeResult switch (AccountMergeResultCode code)
|
9
|
+
# {
|
10
|
+
# case ACCOUNT_MERGE_SUCCESS:
|
11
|
+
# void;
|
12
|
+
# default:
|
13
|
+
# void;
|
14
|
+
# };
|
15
|
+
#
|
16
|
+
# ===========================================================================
|
17
|
+
module Stellar
|
18
|
+
class AccountMergeResult < XDR::Union
|
19
|
+
switch_on AccountMergeResultCode, :code
|
20
|
+
|
21
|
+
switch :account_merge_success
|
22
|
+
switch :default
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Automatically generated on 2015-04-07T10:52:07-07:00
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# enum AccountMergeResultCode
|
9
|
+
# {
|
10
|
+
# // codes considered as "success" for the operation
|
11
|
+
# ACCOUNT_MERGE_SUCCESS = 0,
|
12
|
+
# // codes considered as "failure" for the operation
|
13
|
+
# ACCOUNT_MERGE_MALFORMED = 1, // can't merge onto itself
|
14
|
+
# ACCOUNT_MERGE_NO_ACCOUNT = 2, // destination does not exist
|
15
|
+
# ACCOUNT_MERGE_HAS_CREDIT = 3, // account has active trust lines
|
16
|
+
# ACCOUNT_MERGE_CREDIT_HELD = 4 // an issuer cannot be merged if used
|
17
|
+
# };
|
18
|
+
#
|
19
|
+
# ===========================================================================
|
20
|
+
module Stellar
|
21
|
+
class AccountMergeResultCode < XDR::Enum
|
22
|
+
member :account_merge_success, 0
|
23
|
+
member :account_merge_malformed, 1
|
24
|
+
member :account_merge_no_account, 2
|
25
|
+
member :account_merge_has_credit, 3
|
26
|
+
member :account_merge_credit_held, 4
|
27
|
+
|
28
|
+
seal
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Automatically generated on 2015-04-07T10:52:07-07:00
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (CurrencyType type)
|
9
|
+
# {
|
10
|
+
# // NATIVE is not allowed
|
11
|
+
# case ISO4217:
|
12
|
+
# opaque currencyCode[4];
|
13
|
+
#
|
14
|
+
# // add other currency types here in the future
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
# ===========================================================================
|
18
|
+
module Stellar
|
19
|
+
class AllowTrustOp
|
20
|
+
class Currency < XDR::Union
|
21
|
+
switch_on CurrencyType, :type
|
22
|
+
|
23
|
+
switch :iso4217, :currency_code
|
24
|
+
|
25
|
+
attribute :currency_code, XDR::Opaque[4]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|