stellar-base 0.22.0 → 0.23.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/README.md +2 -3
  4. data/generated/stellar-base-generated.rb +10 -1
  5. data/generated/stellar/allow_trust_op.rb +3 -2
  6. data/generated/stellar/authenticated_message.rb +4 -4
  7. data/generated/stellar/authenticated_message/v0.rb +4 -4
  8. data/generated/stellar/change_trust_result_code.rb +1 -1
  9. data/generated/stellar/crypto_key_type.rb +8 -4
  10. data/generated/stellar/curve25519_public.rb +1 -1
  11. data/generated/stellar/curve25519_secret.rb +1 -1
  12. data/generated/stellar/envelope_type.rb +9 -5
  13. data/generated/stellar/fee_bump_transaction.rb +39 -0
  14. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  15. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  16. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  17. data/generated/stellar/hmac_sha256_key.rb +1 -1
  18. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  19. data/generated/stellar/inner_transaction_result.rb +56 -0
  20. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  21. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  22. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  23. data/generated/stellar/ledger_close_meta.rb +1 -1
  24. data/generated/stellar/manage_buy_offer_result_code.rb +5 -4
  25. data/generated/stellar/manage_sell_offer_result_code.rb +12 -8
  26. data/generated/stellar/muxed_account.rb +35 -0
  27. data/generated/stellar/muxed_account/med25519.rb +22 -0
  28. data/generated/stellar/operation.rb +3 -3
  29. data/generated/stellar/operation/body.rb +2 -2
  30. data/generated/stellar/operation_result.rb +1 -1
  31. data/generated/stellar/operation_result/tr.rb +1 -1
  32. data/generated/stellar/operation_result_code.rb +3 -3
  33. data/generated/stellar/path_payment_strict_receive_op.rb +4 -4
  34. data/generated/stellar/path_payment_strict_receive_result_code.rb +21 -12
  35. data/generated/stellar/path_payment_strict_send_op.rb +6 -6
  36. data/generated/stellar/path_payment_strict_send_result_code.rb +20 -12
  37. data/generated/stellar/payment_op.rb +4 -4
  38. data/generated/stellar/survey_response_body.rb +2 -2
  39. data/generated/stellar/transaction.rb +2 -2
  40. data/generated/stellar/transaction_envelope.rb +17 -8
  41. data/generated/stellar/transaction_result.rb +3 -0
  42. data/generated/stellar/transaction_result/result.rb +9 -3
  43. data/generated/stellar/transaction_result_code.rb +21 -14
  44. data/generated/stellar/transaction_signature_payload.rb +3 -1
  45. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  46. data/generated/stellar/transaction_v0.rb +39 -0
  47. data/generated/stellar/transaction_v0/ext.rb +24 -0
  48. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  49. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  50. data/generated/stellar/trust_line_flags.rb +6 -2
  51. data/lib/stellar-base.rb +27 -25
  52. data/lib/stellar/account_flags.rb +2 -4
  53. data/lib/stellar/asset.rb +6 -6
  54. data/lib/stellar/base.rb +1 -1
  55. data/lib/stellar/{base/compat.rb → compat.rb} +6 -7
  56. data/lib/stellar/concerns/transaction.rb +49 -0
  57. data/lib/stellar/convert.rb +2 -2
  58. data/lib/stellar/factories.rb +1 -3
  59. data/lib/stellar/fee_bump_transaction.rb +21 -0
  60. data/lib/stellar/key_pair.rb +9 -6
  61. data/lib/stellar/networks.rb +5 -7
  62. data/lib/stellar/operation.rb +421 -416
  63. data/lib/stellar/path_payment_strict_receive_result.rb +1 -2
  64. data/lib/stellar/price.rb +2 -4
  65. data/lib/stellar/signer_key.rb +4 -8
  66. data/lib/stellar/thresholds.rb +5 -7
  67. data/lib/stellar/transaction.rb +154 -198
  68. data/lib/stellar/transaction_builder.rb +66 -23
  69. data/lib/stellar/transaction_envelope.rb +40 -8
  70. data/lib/stellar/transaction_v0.rb +39 -0
  71. data/lib/stellar/util/continued_fraction.rb +19 -19
  72. data/lib/stellar/util/strkey.rb +39 -14
  73. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  74. metadata +33 -203
  75. data/.gitignore +0 -17
  76. data/.travis.yml +0 -16
  77. data/.yardopts +0 -8
  78. data/CHANGELOG.md +0 -149
  79. data/CONTRIBUTING.md +0 -48
  80. data/Gemfile +0 -9
  81. data/Guardfile +0 -5
  82. data/Rakefile +0 -4
  83. data/examples/allow_trust.rb +0 -51
  84. data/examples/create_account.rb +0 -26
  85. data/examples/low_level_transaction_post.rb +0 -46
  86. data/examples/mid_level_transaction_post.rb +0 -33
  87. data/examples/non_native_payment.rb +0 -60
  88. data/examples/offer.rb +0 -75
  89. data/examples/transaction_merge.rb +0 -23
  90. data/ruby-stellar-base.gemspec +0 -34
  91. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  92. data/spec/lib/stellar/asset_spec.rb +0 -45
  93. data/spec/lib/stellar/convert_spec.rb +0 -61
  94. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  95. data/spec/lib/stellar/networks_spec.rb +0 -77
  96. data/spec/lib/stellar/operation_spec.rb +0 -131
  97. data/spec/lib/stellar/path_payment_strict_receive_result_spec.rb +0 -95
  98. data/spec/lib/stellar/price_spec.rb +0 -34
  99. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  100. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  101. data/spec/lib/stellar/transaction_builder_spec.rb +0 -263
  102. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  103. data/spec/lib/stellar/transaction_spec.rb +0 -132
  104. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  105. data/spec/spec_helper.rb +0 -16
  106. data/spec/support/matchers/be_strkey.rb +0 -9
  107. data/spec/support/matchers/eq_bytes.rb +0 -5
  108. data/spec/support/matchers/have_length.rb +0 -5
  109. data/tasks/rspec.rake +0 -6
  110. data/tasks/travis.rake +0 -1
  111. data/tasks/xdr.rake +0 -45
  112. data/xdr/Stellar-SCP.x +0 -86
  113. data/xdr/Stellar-ledger-entries.x +0 -295
  114. data/xdr/Stellar-ledger.x +0 -372
  115. data/xdr/Stellar-overlay.x +0 -229
  116. data/xdr/Stellar-transaction.x +0 -901
  117. data/xdr/Stellar-types.x +0 -81
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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
- /.vscode
15
- mkmf.log
16
- .DS_Store
17
- .idea
@@ -1,16 +0,0 @@
1
- dist: xenial
2
- language: ruby
3
- rvm:
4
- - 2.5
5
- - 2.6
6
- cache: bundler
7
- addons:
8
- apt:
9
- packages:
10
- - libsodium-dev
11
- before_install:
12
- - gem update --system && gem install --no-document bundler
13
- script: bundle exec rake travis
14
- notifications:
15
- slack:
16
- secure: V/6a8KFe067uukrbCJA2R1HPO4xy0YSQ1pwmHVRi5StX+yl+lYsWWJdjdBdT0j3iJBYyPRqU4bQYck+OloxtELnrHCX+OkodxcxW8W/ACc914iIf0FyY9pnusK7ck2awmt4Iuf94YPgi0XTm1aCcm+f0yU7wiIVFpftoXSk1EDY=
data/.yardopts DELETED
@@ -1,8 +0,0 @@
1
- --output-dir doc/generated
2
- --protected
3
- --no-private
4
- --embed-mixin ClassMethods
5
- lib/**/*.rb
6
- generated/**/*.rb
7
- -
8
- doc/*.md
@@ -1,149 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this
4
- file. This project adheres to [Semantic Versioning](http://semver.org/).
5
-
6
- As this project is pre 1.0, breaking changes may happen for minor version
7
- bumps. A breaking change will get clearly notified in this log.
8
-
9
- ## [0.22.0](https://github.com/stellar/ruby-stellar-base/compare/v0.21.0...v0.22.0) - 2020-03-26
10
- ### Added
11
- - Add TransactionBuilder ([#54](https://github.com/stellar/ruby-stellar-base/issues/54))
12
-
13
- ### Changed
14
- - Regenerate XDR files ([#57](https://github.com/stellar/ruby-stellar-base/issues/57))
15
- - Allow asset objects to be passed instead of list of parameters ([#59](https://github.com/stellar/ruby-stellar-base/issues/59))
16
-
17
- ## [0.21.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.20.0...v0.21.0) - 2019-10-04
18
- ### Changed
19
- - [Stellar Protocol 12 compatibility](https://github.com/bloom-solutions/ruby-stellar-base/pull/51).
20
- - XDR changes for path payment
21
- - constant renames, which may cause breaking changes if referred to directly
22
-
23
- ## [0.20.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.19.0...v0.20.0) - 2019-05-22
24
- ### Added
25
- - Stellar Protocol 11 compatibility (#48)
26
- - XDR changes for [CAP-0006 Buy Offers](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0006.md)
27
- - XDR changes for [CAP-0020 Bucket Initial Entries](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0020.md)
28
- - Add `manage_buy_offer`, `manage_sell_offer` and `create_passive_sell_offer` factory methods to `Stellar::Transaction` and `Stellar::Operation`
29
-
30
- ### Changed
31
- - Deprecate `manage_offer` and `create_passive_offer` factory methods in `Stellar::Transaction` and `Stellar::Operation`
32
- - Add an option to pass the exact stellar-core revision into `xdr:update` Rake task
33
-
34
- ## [0.19.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.18.0...v0.19.0)
35
- ### Changed
36
- - Loosen ActiveSupport to >= 5.0.0
37
-
38
- ## [0.18.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.17.0...v0.18.0)
39
- ### Added
40
- - Update XDR definitions for stellar-core v10.0.0 (introduces Liabilities and other changes to support asset-backed offers as per [CAP-0003 Specification](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0003.md#specification))
41
- - Add factories for ledger, transaction, operation.
42
-
43
- ### Changed
44
- - Use rbnacl instead of rbnacl-libsodium (the latter has been [deprecated](https://github.com/crypto-rb/rbnacl-libsodium/issues/29))
45
-
46
- ## [0.17.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.16.0...v0.17.0)
47
- ### Fixed
48
- - Rename `Stellar::SignerKey#onetime_signer` helper to `Stellar::SignerKey#hash_x`, add preimage validations
49
-
50
- ## [0.16.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.15.0...v0.16.0)
51
- ### Added
52
- - Create co-signers conveniently using helpers `ed25519(keypair)`, `preauthorized_transaction(tx)` and `onetime_signer(preimage)` from `Stellar::SignerKey` module
53
- - Merge two transactions with `Stellar::TransactionEnvelope#merge`
54
-
55
- ### Fixed
56
- - Source account overriding in Stellar::Transaction#to_operations
57
-
58
- ## [0.15.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.14.0...v0.15.0)
59
- ### Added
60
- - `Stellar::Operation.change_trust` can accept `Stellar::Asset` instance for `line`
61
-
62
- ### Fixed
63
- - Protect `Stellar::Operation.change_trust` against malicious arguments, in the event that developers pass this argument directly from user input
64
-
65
- ## [0.14.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.13.0...v0.14.0)
66
-
67
- ### Added
68
- - We now support the bump sequence operation with `Operation.bump_sequence`.
69
-
70
- ### Changed
71
- - Update XDR definitions for stellar-core 0.10.0 support
72
- - `Operation.change_trust` learned how to use a default for the `:limit` parameter
73
- - `StrKey` learned about new version bytes `pre_auth_tx` and `hash_x`
74
-
75
- ## [0.13.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.12.0...v0.13.0)
76
-
77
- ### Changed
78
- - Update XDR definitions for stellar-core 0.9.1 support
79
-
80
- ### Added
81
- - Added `#signer_key` helper to `KeyPair`
82
-
83
- ## [0.12.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.11.0...v0.12.0)
84
-
85
- ### Changed
86
- - Avoid modifying $LOAD_PATH to fix load order issues
87
- - Update XDR definitions for stellar-core 0.6 support
88
-
89
- ### Removed
90
-
91
- - BREAKING CHANGE: Removed support for JRuby.
92
-
93
- ## [0.11.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.10.0...v0.11.0)
94
-
95
- ### Added
96
- - Added support for `manage_data` operations
97
-
98
- ### Changed
99
- - `Stellar::Transaction#to_envelope` can now be used without arguments, returning a `Stellar::TransactionEnvelope` with zero signatures.
100
-
101
- ## [0.10.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.9.0...v0.10.0)
102
-
103
- - Added memo helpers to `Stellar::Transaction.for_account`, allowing any operation builder (such as `Stellar::Transaction.payment) to provide a custom memo using the `:memo` attribute.
104
-
105
- ## [0.9.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.8.0...v0.9.0)
106
-
107
- ### Changed
108
- - XDR Definitions have been updated to stellar-core commit eed89649c2060b8e9dacffe2cec4e8b258b32416
109
-
110
- ## [0.8.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.7.0...v0.8.0)
111
-
112
- ### Changed
113
- - BREAKING CHANGE: The default network for this library is now the stellar test network.
114
- To enable this library for the production network use `Stellar.default_network = Stellar::Networks::PUBLIC`
115
- at the head of your script or in your configuration function.
116
-
117
- ## [0.7.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.6.1...v0.7.0)
118
-
119
- ### Changed
120
-
121
- - Bump xdr dependency to 1.0.0
122
-
123
- ## [0.6.1](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.6.0...v0.6.1)
124
-
125
- ### Changed
126
-
127
- - Update default fee for transactions to new minimum of 100 stroops
128
-
129
-
130
- ## [0.6.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.5.0...v0.6.0)
131
-
132
- ### Changed
133
-
134
- - Update to latest xdr (stellar-core commit ad22bccafbbc14a358f05a989f7b95714dc9d4c6)
135
-
136
- ## [0.5.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.4.0...v0.5.0)
137
-
138
- ### Changed
139
-
140
- - Update to latest xdr
141
-
142
- ## [0.4.0](https://github.com/bloom-solutions/ruby-stellar-base/compare/v0.3.0...v0.4.0)
143
-
144
- ### Changed
145
- - BREAKING CHANGE: "Amounts", that is, input parameters that represent a
146
- certain amount of a given asset, such as the `:starting_balance` option for
147
- `Operation.create_account` are now interpreted using the convention of 7
148
- fixed-decimal places. For example, specifying a payment where the amount is
149
- `50` will result in a transaction with an amount set to `500000000`.
@@ -1,48 +0,0 @@
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/bloom-solutions/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 DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem "pry"
7
- gem "faraday"
8
- gem "faraday_middleware"
9
- end
data/Guardfile DELETED
@@ -1,5 +0,0 @@
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
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- require "bundler/gem_tasks"
2
- Bundler.setup
3
-
4
- Dir["tasks/**/*.rake"].each{|f| load f}
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rest-client'
4
- require 'stellar-base'
5
-
6
- # This is an example of using a higher level allow_trust operation.
7
- # This assumes that a stellar account is already created and a trustline
8
- # to an anchor's asset has been established.
9
-
10
- HUG_ASSET_CODE = 'HUG'
11
-
12
- def sequence_from_account(account)
13
- data = get_account_data(account)
14
- data['sequence'].to_i
15
- end
16
-
17
- def get_account_data(keypair, network_url)
18
- response = RestClient.get "#{network_url}/accounts/#{keypair.address}"
19
- JSON.parse(response.body)
20
- end
21
-
22
- def submit_transaction_operation(xdr_envelope, network_url)
23
- begin
24
- response = RestClient.post "#{network_url}/transactions", { tx: xdr_envelope }
25
- JSON.parse(response.body)
26
-
27
- rescue RestClient::ExceptionWithResponse => e
28
- # handle exceptions here
29
- end
30
- end
31
-
32
- def allow_trust(address, issuer_keypair)
33
- account = Stellar::KeyPair.from_address(address)
34
- current_sequence = sequence_from_account(issuer_keypair)
35
-
36
- tx = Stellar::Transaction.allow_trust({
37
- trustor: account,
38
- account: issuer_keypair,
39
- asset: [:alphanum4, HUG_ASSET_CODE, issuer_keypair],
40
- authorize: true,
41
- sequence: current_sequence + 1,
42
- })
43
-
44
- xdr_envelope = tx.to_envelope(issuer_keypair).to_xdr(:base64)
45
- submit_transaction_operation(xdr_envelope)
46
- end
47
-
48
- # Usage:
49
- # issuer_keypair must be a keypair from an anchor with both the public and
50
- # private key i.e type Stellar::KeyPair
51
- allow_trust("GCHOWITWOUNRUXGJWYUB4IMICZKROLHDRC2TJH5W324LBJVM4JUVXOZL", issuer_keypair)
@@ -1,26 +0,0 @@
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
21
- })
22
-
23
- b64 = tx.to_envelope(master).to_xdr(:base64)
24
- p b64
25
- result = $server.get('tx', blob: b64)
26
- p result.body
@@ -1,46 +0,0 @@
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
@@ -1,33 +0,0 @@
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]
28
- })
29
-
30
- b64 = tx.to_envelope(master).to_xdr(:base64)
31
-
32
- result = $server.get('tx', blob: b64)
33
- p result.body
@@ -1,60 +0,0 @@
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
- b64 = tx.to_envelope(key).to_xdr(:base64)
26
- response = $server.get('tx', blob: b64)
27
- raw = [response.body["result"]].pack("H*")
28
- p response.body
29
- end
30
-
31
- master = Stellar::KeyPair.master
32
- destination = Stellar::KeyPair.master
33
-
34
- submit master, Stellar::Transaction.payment({
35
- account: master,
36
- destination: destination,
37
- sequence: 1,
38
- amount: [:native, 2000]
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: [:alphanum4, "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: [:alphanum4, "USD\x00", master, 100]
60
- })