stellar-base 0.25.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -31
  3. data/README.md +3 -3
  4. data/generated/stellar/account_flags.rb +9 -4
  5. data/generated/stellar/account_merge_result.rb +1 -1
  6. data/generated/stellar/allow_trust_op.rb +3 -18
  7. data/generated/stellar/asset_code.rb +30 -0
  8. data/generated/stellar/begin_sponsoring_future_reserves_result.rb +2 -1
  9. data/generated/stellar/claimable_balance_entry/ext.rb +4 -0
  10. data/generated/stellar/claimable_balance_entry.rb +2 -0
  11. data/generated/stellar/claimable_balance_entry_extension_v1/ext.rb +24 -0
  12. data/generated/stellar/claimable_balance_entry_extension_v1.rb +30 -0
  13. data/generated/stellar/claimable_balance_flags.rb +22 -0
  14. data/generated/stellar/clawback_claimable_balance_op.rb +18 -0
  15. data/generated/stellar/clawback_claimable_balance_result.rb +26 -0
  16. data/generated/stellar/clawback_claimable_balance_result_code.rb +29 -0
  17. data/generated/stellar/clawback_op.rb +22 -0
  18. data/generated/stellar/clawback_result.rb +25 -0
  19. data/generated/stellar/clawback_result_code.rb +31 -0
  20. data/generated/stellar/create_passive_sell_offer_op.rb +1 -1
  21. data/generated/stellar/end_sponsoring_future_reserves_result.rb +2 -1
  22. data/generated/stellar/operation/body.rb +12 -0
  23. data/generated/stellar/operation.rb +6 -0
  24. data/generated/stellar/operation_id/id.rb +2 -2
  25. data/generated/stellar/operation_id.rb +1 -1
  26. data/generated/stellar/operation_result/tr.rb +12 -0
  27. data/generated/stellar/operation_result.rb +6 -0
  28. data/generated/stellar/operation_type.rb +7 -1
  29. data/generated/stellar/payment_result_code.rb +1 -1
  30. data/generated/stellar/revoke_sponsorship_op.rb +1 -2
  31. data/generated/stellar/set_options_result_code.rb +14 -11
  32. data/generated/stellar/set_trust_line_flags_op.rb +25 -0
  33. data/generated/stellar/set_trust_line_flags_result.rb +25 -0
  34. data/generated/stellar/set_trust_line_flags_result_code.rb +31 -0
  35. data/generated/stellar/transaction_result_code.rb +1 -1
  36. data/generated/stellar/trust_line_flags.rb +5 -1
  37. data/generated/stellar-base-generated.rb +15 -0
  38. data/lib/stellar/account.rb +59 -0
  39. data/lib/stellar/compat.rb +6 -3
  40. data/lib/stellar/concerns/transaction.rb +4 -2
  41. data/lib/stellar/dsl.rb +23 -0
  42. data/lib/stellar/operation.rb +85 -16
  43. data/lib/stellar/transaction_builder.rb +20 -7
  44. data/lib/stellar/trust_line_flags.rb +53 -0
  45. data/lib/stellar/util/strkey.rb +15 -7
  46. data/lib/stellar/version.rb +3 -0
  47. data/lib/stellar-base.rb +3 -2
  48. metadata +28 -12
  49. data/generated/stellar/allow_trust_op/asset.rb +0 -33
  50. data/lib/stellar/base/version.rb +0 -5
@@ -0,0 +1,53 @@
1
+ module Stellar
2
+ class TrustLineFlags
3
+ # Converts an array of Stellar::TrustLineFlags members into
4
+ # an integers suitable for use in in a SetTrustLineFlagsOp.
5
+ #
6
+ # @param flags [Array<Stellar::TrustLineFlags>] the flags to combine
7
+ #
8
+ # @return [Fixnum] the combined result
9
+ def self.make_mask(flags)
10
+ normalize(flags).map(&:value).inject(&:|) || 0
11
+ end
12
+
13
+ # Converts an integer used in SetTrustLineFlagsOp on the set/clear flag options
14
+ # into an array of Stellar::TrustLineFlags members
15
+ #
16
+ # @param combined [Fixnum]
17
+ # @return [Array<Stellar::AccountFlags>]
18
+ def self.parse_mask(combined)
19
+ members.values.select { |m| (m.value & combined) != 0 }
20
+ end
21
+
22
+ # Converts each element of the input array to Stellar::TrustLineFlags instance.
23
+ #
24
+ # @param [Array<Stellar::TrustLineFlags,Symbol,#to_s>] input
25
+ # @return [Array<Stellar::TrustLineFlags>]
26
+ # @raise [TypeError] if any element of the input cannot be converted
27
+ def self.normalize(input)
28
+ input.map do |val|
29
+ case val
30
+ when Stellar::TrustLineFlags
31
+ val
32
+ when ->(_) { members.key?(val.to_s) }
33
+ from_name(val.to_s)
34
+ when ->(_) { members.key?("#{val}_flag") }
35
+ from_name("#{val}_flag")
36
+ else
37
+ raise TypeError, "unknown trustline flag: #{val}"
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.set_clear_masks(flags)
43
+ set_flags = []
44
+ clear_flags = []
45
+
46
+ Hash(flags).each do |flag, value|
47
+ value.present? ? set_flags.push(flag) : clear_flags.push(flag)
48
+ end
49
+
50
+ {set_flags: make_mask(set_flags), clear_flags: make_mask(clear_flags)}
51
+ end
52
+ end
53
+ end
@@ -8,7 +8,8 @@ module Stellar
8
8
  account_id: [6 << 3].pack("C"), # Base32-encodes to 'G...'
9
9
  seed: [18 << 3].pack("C"), # Base32-encodes to 'S...'
10
10
  pre_auth_tx: [19 << 3].pack("C"), # Base32-encodes to 'T...'
11
- hash_x: [23 << 3].pack("C") # Base32-encodes to 'X...'
11
+ hash_x: [23 << 3].pack("C"), # Base32-encodes to 'X...'
12
+ muxed: [12 << 3].pack("C") # Base32-encodes to 'M...'
12
13
  }
13
14
 
14
15
  def self.check_encode(version, byte_str)
@@ -25,13 +26,11 @@ module Stellar
25
26
  # @param muxed_account [Stellar::MuxedAccount] account
26
27
  # @return [String] "G.."-like address
27
28
  def self.encode_muxed_account(muxed_account)
28
- ed25519 = if muxed_account.switch == Stellar::CryptoKeyType.key_type_ed25519
29
- muxed_account.ed25519!
29
+ if muxed_account.ed25519
30
+ check_encode(:account_id, muxed_account.ed25519)
30
31
  else
31
- muxed_account.med25519!.ed25519
32
+ check_encode(:muxed, muxed_account.med25519!.ed25519 + [muxed_account.med25519!.id].pack("Q>"))
32
33
  end
33
-
34
- check_encode(:account_id, ed25519)
35
34
  end
36
35
 
37
36
  # Returns a Stellar::MuxedAccount, forcing the ed25519 discriminant
@@ -39,7 +38,16 @@ module Stellar
39
38
  # @param strkey [String] address string to decode
40
39
  # @return [Stellar::MuxedAccount] MuxedAccount with ed25519 discriminant
41
40
  def self.decode_muxed_account(strkey)
42
- Stellar::MuxedAccount.new(:key_type_ed25519, check_decode(:account_id, strkey))
41
+ case strkey
42
+ when /^G[0-9A-Z]{55}$/
43
+ ed25519 = check_decode(:account_id, strkey)
44
+ Stellar::MuxedAccount.ed25519(ed25519)
45
+ when /^M[0-9A-Z]{68}$/
46
+ payload = check_decode(:muxed, strkey)
47
+ Stellar::MuxedAccount.med25519(ed25519: payload[0, 32], id: payload[32, 8].unpack1("Q>"))
48
+ else
49
+ raise "cannot decode MuxedAccount from #{strkey}"
50
+ end
43
51
  end
44
52
 
45
53
  def self.check_decode(expected_version, str)
@@ -0,0 +1,3 @@
1
+ module Stellar
2
+ VERSION = "0.29.0".freeze
3
+ end
data/lib/stellar-base.rb CHANGED
@@ -16,14 +16,14 @@ silence_warnings do
16
16
  end
17
17
  Stellar.load_all!
18
18
 
19
- require_relative "stellar/base/version"
20
- Stellar::VERSION = Stellar::Base::VERSION
19
+ require_relative "stellar/version"
21
20
 
22
21
  Stellar::ONE = 1_0000000
23
22
  Stellar::Deprecation = ActiveSupport::Deprecation.new("next release", "stellar-base")
24
23
 
25
24
  # extensions onto the generated files must be loaded manually, below
26
25
 
26
+ require_relative "./stellar/account"
27
27
  require_relative "./stellar/account_flags"
28
28
  require_relative "./stellar/asset"
29
29
  require_relative "./stellar/claim_predicate"
@@ -35,6 +35,7 @@ require_relative "./stellar/path_payment_strict_receive_result"
35
35
  require_relative "./stellar/price"
36
36
  require_relative "./stellar/signer_key"
37
37
  require_relative "./stellar/thresholds"
38
+ require_relative "./stellar/trust_line_flags"
38
39
 
39
40
  require_relative "./stellar/concerns/transaction"
40
41
  require_relative "./stellar/fee_bump_transaction"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-10-30 00:00:00.000000000 Z
13
+ date: 2021-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -168,9 +168,9 @@ dependencies:
168
168
  - - "~>"
169
169
  - !ruby/object:Gem::Version
170
170
  version: '1.3'
171
- description: "The stellar-base library is the lowest-level stellar helper library.
172
- It consists of classes to read, write, \nhash, and sign the xdr structures that
173
- are used in stellar-core.\n"
171
+ description: |
172
+ The stellar-base library is the lowest-level stellar helper library. It consists of classes to read, write,
173
+ hash, and sign the xdr structures that are used in stellar-core.
174
174
  email:
175
175
  executables: []
176
176
  extensions: []
@@ -193,12 +193,12 @@ files:
193
193
  - generated/stellar/account_merge_result.rb
194
194
  - generated/stellar/account_merge_result_code.rb
195
195
  - generated/stellar/allow_trust_op.rb
196
- - generated/stellar/allow_trust_op/asset.rb
197
196
  - generated/stellar/allow_trust_result.rb
198
197
  - generated/stellar/allow_trust_result_code.rb
199
198
  - generated/stellar/asset.rb
200
199
  - generated/stellar/asset/alpha_num12.rb
201
200
  - generated/stellar/asset/alpha_num4.rb
201
+ - generated/stellar/asset_code.rb
202
202
  - generated/stellar/asset_type.rb
203
203
  - generated/stellar/auth.rb
204
204
  - generated/stellar/auth_cert.rb
@@ -225,11 +225,20 @@ files:
225
225
  - generated/stellar/claim_predicate_type.rb
226
226
  - generated/stellar/claimable_balance_entry.rb
227
227
  - generated/stellar/claimable_balance_entry/ext.rb
228
+ - generated/stellar/claimable_balance_entry_extension_v1.rb
229
+ - generated/stellar/claimable_balance_entry_extension_v1/ext.rb
230
+ - generated/stellar/claimable_balance_flags.rb
228
231
  - generated/stellar/claimable_balance_id.rb
229
232
  - generated/stellar/claimable_balance_id_type.rb
230
233
  - generated/stellar/claimant.rb
231
234
  - generated/stellar/claimant/v0.rb
232
235
  - generated/stellar/claimant_type.rb
236
+ - generated/stellar/clawback_claimable_balance_op.rb
237
+ - generated/stellar/clawback_claimable_balance_result.rb
238
+ - generated/stellar/clawback_claimable_balance_result_code.rb
239
+ - generated/stellar/clawback_op.rb
240
+ - generated/stellar/clawback_result.rb
241
+ - generated/stellar/clawback_result_code.rb
233
242
  - generated/stellar/create_account_op.rb
234
243
  - generated/stellar/create_account_result.rb
235
244
  - generated/stellar/create_account_result_code.rb
@@ -355,6 +364,9 @@ files:
355
364
  - generated/stellar/set_options_op.rb
356
365
  - generated/stellar/set_options_result.rb
357
366
  - generated/stellar/set_options_result_code.rb
367
+ - generated/stellar/set_trust_line_flags_op.rb
368
+ - generated/stellar/set_trust_line_flags_result.rb
369
+ - generated/stellar/set_trust_line_flags_result_code.rb
358
370
  - generated/stellar/signed_survey_request_message.rb
359
371
  - generated/stellar/signed_survey_response_message.rb
360
372
  - generated/stellar/signer.rb
@@ -403,10 +415,10 @@ files:
403
415
  - generated/stellar/trust_line_flags.rb
404
416
  - generated/stellar/upgrade_entry_meta.rb
405
417
  - lib/stellar-base.rb
418
+ - lib/stellar/account.rb
406
419
  - lib/stellar/account_flags.rb
407
420
  - lib/stellar/asset.rb
408
421
  - lib/stellar/base.rb
409
- - lib/stellar/base/version.rb
410
422
  - lib/stellar/claim_predicate.rb
411
423
  - lib/stellar/compat.rb
412
424
  - lib/stellar/concerns/transaction.rb
@@ -428,15 +440,19 @@ files:
428
440
  - lib/stellar/transaction_builder.rb
429
441
  - lib/stellar/transaction_envelope.rb
430
442
  - lib/stellar/transaction_v0.rb
443
+ - lib/stellar/trust_line_flags.rb
431
444
  - lib/stellar/util/strkey.rb
432
- homepage: https://github.com/astroband/ruby-stellar-sdk/tree/master/base
445
+ - lib/stellar/version.rb
446
+ homepage: https://github.com/astroband/ruby-stellar-sdk
433
447
  licenses:
434
448
  - Apache-2.0
435
449
  metadata:
450
+ bug_tracker_uri: https://github.com/astroband/ruby-stellar-sdk/issues
451
+ changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.29.0/base/CHANGELOG.md
452
+ documentation_uri: https://rubydoc.info/gems/stellar-base/0.29.0/
436
453
  github_repo: ssh://github.com/astroband/ruby-stellar-sdk
437
- documentation_uri: https://rubydoc.info/gems/stellar-base/0.25.0/
438
- changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.25.0/base/CHANGELOG.md
439
- source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.25.0/base
454
+ homepage_uri: https://github.com/astroband/ruby-stellar-sdk/tree/main/base
455
+ source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.29.0/base
440
456
  post_install_message:
441
457
  rdoc_options: []
442
458
  require_paths:
@@ -453,7 +469,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
469
  - !ruby/object:Gem::Version
454
470
  version: '0'
455
471
  requirements: []
456
- rubygems_version: 3.2.0.rc.2
472
+ rubygems_version: 3.1.4
457
473
  signing_key:
458
474
  specification_version: 4
459
475
  summary: 'Stellar client library: XDR'
@@ -1,33 +0,0 @@
1
- # This code was automatically generated using xdrgen
2
- # DO NOT EDIT or your changes may be overwritten
3
-
4
- require 'xdr'
5
-
6
- # === xdr source ============================================================
7
- #
8
- # union switch (AssetType type)
9
- # {
10
- # // ASSET_TYPE_NATIVE is not allowed
11
- # case ASSET_TYPE_CREDIT_ALPHANUM4:
12
- # AssetCode4 assetCode4;
13
- #
14
- # case ASSET_TYPE_CREDIT_ALPHANUM12:
15
- # AssetCode12 assetCode12;
16
- #
17
- # // add other asset types here in the future
18
- # }
19
- #
20
- # ===========================================================================
21
- module Stellar
22
- class AllowTrustOp
23
- class Asset < XDR::Union
24
- switch_on AssetType, :type
25
-
26
- switch :asset_type_credit_alphanum4, :asset_code4
27
- switch :asset_type_credit_alphanum12, :asset_code12
28
-
29
- attribute :asset_code4, AssetCode4
30
- attribute :asset_code12, AssetCode12
31
- end
32
- end
33
- end
@@ -1,5 +0,0 @@
1
- module Stellar
2
- module Base
3
- VERSION = "0.25.0"
4
- end
5
- end