stellar-base 0.18.0 → 0.23.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +5 -5
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/README.md +2 -3
  4. data/generated/stellar-base-generated.rb +45 -8
  5. data/generated/stellar/allow_trust_op.rb +5 -4
  6. data/generated/stellar/allow_trust_op/asset.rb +4 -4
  7. data/generated/stellar/asset.rb +2 -2
  8. data/generated/stellar/asset/alpha_num12.rb +2 -2
  9. data/generated/stellar/asset/alpha_num4.rb +2 -2
  10. data/generated/stellar/authenticated_message.rb +4 -4
  11. data/generated/stellar/authenticated_message/v0.rb +4 -4
  12. data/generated/stellar/bucket_entry.rb +6 -0
  13. data/generated/stellar/bucket_entry_type.rb +8 -2
  14. data/generated/stellar/bucket_metadata.rb +32 -0
  15. data/generated/stellar/bucket_metadata/ext.rb +24 -0
  16. data/generated/stellar/claim_offer_atom.rb +2 -2
  17. data/generated/stellar/{create_passive_offer_op.rb → create_passive_sell_offer_op.rb} +2 -2
  18. data/generated/stellar/crypto_key_type.rb +8 -4
  19. data/generated/stellar/curve25519_public.rb +1 -1
  20. data/generated/stellar/curve25519_secret.rb +1 -1
  21. data/generated/stellar/envelope_type.rb +10 -4
  22. data/generated/stellar/fee_bump_transaction.rb +39 -0
  23. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  24. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  25. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  26. data/generated/stellar/hmac_sha256_key.rb +1 -1
  27. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  28. data/generated/stellar/inner_transaction_result.rb +56 -0
  29. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  30. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  31. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  32. data/generated/stellar/ledger_close_meta.rb +23 -0
  33. data/generated/stellar/ledger_close_meta_v0.rb +35 -0
  34. data/generated/stellar/ledger_close_value_signature.rb +20 -0
  35. data/generated/stellar/ledger_key.rb +1 -1
  36. data/generated/stellar/ledger_key/offer.rb +2 -2
  37. data/generated/stellar/manage_buy_offer_op.rb +29 -0
  38. data/generated/stellar/{manage_offer_result.rb → manage_buy_offer_result.rb} +5 -5
  39. data/generated/stellar/manage_buy_offer_result_code.rb +51 -0
  40. data/generated/stellar/{manage_offer_op.rb → manage_sell_offer_op.rb} +4 -4
  41. data/generated/stellar/manage_sell_offer_result.rb +26 -0
  42. data/generated/stellar/manage_sell_offer_result_code.rb +54 -0
  43. data/generated/stellar/message_type.rb +6 -1
  44. data/generated/stellar/muxed_account.rb +35 -0
  45. data/generated/stellar/muxed_account/med25519.rb +22 -0
  46. data/generated/stellar/offer_entry.rb +2 -2
  47. data/generated/stellar/operation.rb +13 -9
  48. data/generated/stellar/operation/body.rb +37 -29
  49. data/generated/stellar/operation_result.rb +10 -6
  50. data/generated/stellar/operation_result/tr.rb +38 -30
  51. data/generated/stellar/operation_result_code.rb +11 -7
  52. data/generated/stellar/operation_type.rb +20 -16
  53. data/generated/stellar/{path_payment_op.rb → path_payment_strict_receive_op.rb} +6 -6
  54. data/generated/stellar/path_payment_strict_receive_result.rb +38 -0
  55. data/generated/stellar/path_payment_strict_receive_result/success.rb +22 -0
  56. data/generated/stellar/path_payment_strict_receive_result_code.rb +56 -0
  57. data/generated/stellar/path_payment_strict_send_op.rb +32 -0
  58. data/generated/stellar/{path_payment_result.rb → path_payment_strict_send_result.rb} +7 -7
  59. data/generated/stellar/{path_payment_result → path_payment_strict_send_result}/success.rb +1 -1
  60. data/generated/stellar/path_payment_strict_send_result_code.rb +55 -0
  61. data/generated/stellar/payment_op.rb +4 -4
  62. data/generated/stellar/peer_stats.rb +48 -0
  63. data/generated/stellar/signed_survey_request_message.rb +20 -0
  64. data/generated/stellar/signed_survey_response_message.rb +20 -0
  65. data/generated/stellar/signer.rb +1 -1
  66. data/generated/stellar/stellar_message.rb +22 -12
  67. data/generated/stellar/stellar_value.rb +7 -5
  68. data/generated/stellar/stellar_value/ext.rb +8 -4
  69. data/generated/stellar/stellar_value_type.rb +22 -0
  70. data/generated/stellar/survey_message_command_type.rb +20 -0
  71. data/generated/stellar/survey_request_message.rb +26 -0
  72. data/generated/stellar/survey_response_body.rb +23 -0
  73. data/generated/stellar/survey_response_message.rb +26 -0
  74. data/generated/stellar/time_bounds.rb +4 -4
  75. data/generated/stellar/topology_response_body.rb +25 -0
  76. data/generated/stellar/transaction.rb +4 -4
  77. data/generated/stellar/transaction_envelope.rb +17 -8
  78. data/generated/stellar/transaction_meta.rb +4 -0
  79. data/generated/stellar/transaction_meta_v1.rb +1 -1
  80. data/generated/stellar/transaction_meta_v2.rb +24 -0
  81. data/generated/stellar/transaction_result.rb +3 -0
  82. data/generated/stellar/transaction_result/result.rb +9 -3
  83. data/generated/stellar/transaction_result_code.rb +21 -14
  84. data/generated/stellar/transaction_result_meta.rb +22 -0
  85. data/generated/stellar/transaction_signature_payload.rb +3 -1
  86. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  87. data/generated/stellar/transaction_v0.rb +39 -0
  88. data/generated/stellar/transaction_v0/ext.rb +24 -0
  89. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  90. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  91. data/generated/stellar/trust_line_flags.rb +6 -2
  92. data/generated/stellar/upgrade_entry_meta.rb +20 -0
  93. data/lib/stellar-base.rb +28 -23
  94. data/lib/stellar/account_flags.rb +2 -4
  95. data/lib/stellar/asset.rb +6 -6
  96. data/lib/stellar/base.rb +1 -1
  97. data/lib/stellar/compat.rb +21 -0
  98. data/lib/stellar/concerns/transaction.rb +49 -0
  99. data/lib/stellar/convert.rb +2 -2
  100. data/lib/stellar/factories.rb +1 -3
  101. data/lib/stellar/fee_bump_transaction.rb +21 -0
  102. data/lib/stellar/key_pair.rb +9 -6
  103. data/lib/stellar/networks.rb +5 -7
  104. data/lib/stellar/operation.rb +428 -317
  105. data/lib/stellar/{path_payment_result.rb → path_payment_strict_receive_result.rb} +2 -3
  106. data/lib/stellar/price.rb +2 -4
  107. data/lib/stellar/signer_key.rb +4 -8
  108. data/lib/stellar/thresholds.rb +5 -7
  109. data/lib/stellar/transaction.rb +154 -169
  110. data/lib/stellar/transaction_builder.rb +149 -0
  111. data/lib/stellar/transaction_envelope.rb +40 -8
  112. data/lib/stellar/transaction_v0.rb +39 -0
  113. data/lib/stellar/util/continued_fraction.rb +19 -19
  114. data/lib/stellar/util/strkey.rb +39 -14
  115. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  116. metadata +69 -211
  117. data/.gitignore +0 -17
  118. data/.travis.yml +0 -14
  119. data/.yardopts +0 -8
  120. data/CHANGELOG.md +0 -120
  121. data/CONTRIBUTING.md +0 -48
  122. data/Gemfile +0 -15
  123. data/Guardfile +0 -5
  124. data/Rakefile +0 -4
  125. data/examples/create_account.rb +0 -26
  126. data/examples/low_level_transaction_post.rb +0 -46
  127. data/examples/mid_level_transaction_post.rb +0 -33
  128. data/examples/non_native_payment.rb +0 -60
  129. data/examples/offer.rb +0 -75
  130. data/examples/transaction_merge.rb +0 -23
  131. data/generated/stellar/manage_offer_result_code.rb +0 -50
  132. data/generated/stellar/path_payment_result_code.rb +0 -47
  133. data/ruby-stellar-base.gemspec +0 -34
  134. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  135. data/spec/lib/stellar/asset_spec.rb +0 -45
  136. data/spec/lib/stellar/convert_spec.rb +0 -61
  137. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  138. data/spec/lib/stellar/networks_spec.rb +0 -77
  139. data/spec/lib/stellar/operation_spec.rb +0 -71
  140. data/spec/lib/stellar/path_payment_result_spec.rb +0 -95
  141. data/spec/lib/stellar/price_spec.rb +0 -34
  142. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  143. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  144. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  145. data/spec/lib/stellar/transaction_spec.rb +0 -100
  146. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  147. data/spec/spec_helper.rb +0 -16
  148. data/spec/support/matchers/be_strkey.rb +0 -9
  149. data/spec/support/matchers/eq_bytes.rb +0 -5
  150. data/spec/support/matchers/have_length.rb +0 -5
  151. data/tasks/rspec.rake +0 -6
  152. data/tasks/travis.rake +0 -1
  153. data/tasks/xdr.rake +0 -50
  154. data/xdr/Stellar-SCP.x +0 -86
  155. data/xdr/Stellar-ledger-entries.x +0 -288
  156. data/xdr/Stellar-ledger.x +0 -283
  157. data/xdr/Stellar-overlay.x +0 -146
  158. data/xdr/Stellar-transaction.x +0 -777
  159. data/xdr/Stellar-types.x +0 -81
@@ -1,6 +1,6 @@
1
1
  module Stellar
2
2
  class Asset
3
- TYPES = %i(native alphanum4 alphanum12)
3
+ TYPES = %i[native alphanum4 alphanum12]
4
4
 
5
5
  def self.native
6
6
  new(:asset_type_native)
@@ -9,14 +9,14 @@ module Stellar
9
9
  def self.alphanum4(code, issuer)
10
10
  raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
11
11
  code = normalize_code(code, 4)
12
- an = AlphaNum4.new({asset_code:code, issuer:issuer.account_id})
12
+ an = AlphaNum4.new({asset_code: code, issuer: issuer.account_id})
13
13
  new(:asset_type_credit_alphanum4, an)
14
14
  end
15
15
 
16
16
  def self.alphanum12(code, issuer)
17
17
  raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
18
18
  code = normalize_code(code, 12)
19
- an = AlphaNum12.new({asset_code:code, issuer:issuer.account_id})
19
+ an = AlphaNum12.new({asset_code: code, issuer: issuer.account_id})
20
20
  new(:asset_type_credit_alphanum12, an)
21
21
  end
22
22
 
@@ -36,8 +36,8 @@ module Stellar
36
36
  end
37
37
 
38
38
  def inspect
39
- label = switch.to_s
40
- "#<Stellar::Asset #{to_s}>"
39
+ # label = switch.to_s
40
+ "#<Stellar::Asset #{self}>"
41
41
  end
42
42
 
43
43
  def code
@@ -50,7 +50,7 @@ module Stellar
50
50
  raise "#{switch} assets do not have a code"
51
51
  end
52
52
  end
53
-
53
+
54
54
  def issuer
55
55
  case switch
56
56
  when AssetType.asset_type_credit_alphanum4
@@ -1 +1 @@
1
- require "stellar-base"
1
+ require "stellar-base"
@@ -0,0 +1,21 @@
1
+ require "active_support/deprecation"
2
+
3
+ Stellar::Deprecation ||= ActiveSupport::Deprecation.new("next release", "stellar-base")
4
+
5
+ class << Stellar::Operation
6
+ alias manage_offer manage_sell_offer
7
+ alias create_passive_offer create_passive_sell_offer
8
+
9
+ deprecate deprecator: Stellar::Deprecation,
10
+ manage_offer: :manage_sell_offer,
11
+ create_passive_offer: :create_passive_sell_offer
12
+ end
13
+
14
+ class << Stellar::Transaction
15
+ alias manage_offer manage_sell_offer
16
+ alias create_passive_offer create_passive_sell_offer
17
+
18
+ deprecate deprecator: Stellar::Deprecation,
19
+ manage_offer: :manage_sell_offer,
20
+ create_passive_offer: :create_passive_sell_offer
21
+ end
@@ -0,0 +1,49 @@
1
+ module Stellar::Concerns
2
+ module Transaction
3
+ # Returns the string of bytes that, when hashed, provide the value which
4
+ # should be signed to create a valid stellar transaction signature
5
+ def signature_base
6
+ signature_base_prefix + to_xdr
7
+ end
8
+
9
+ def sign(key_pair)
10
+ key_pair.sign(hash)
11
+ end
12
+
13
+ def sign_decorated(key_pair)
14
+ key_pair.sign_decorated(hash)
15
+ end
16
+
17
+ def hash
18
+ Digest::SHA256.digest(signature_base)
19
+ end
20
+
21
+ def merge(other)
22
+ cloned = Marshal.load Marshal.dump(self)
23
+ cloned.operations += other.to_operations
24
+ cloned
25
+ end
26
+
27
+ #
28
+ # Extracts the operations from this single transaction,
29
+ # setting the source account on the extracted operations.
30
+ #
31
+ # Useful for merging transactions.
32
+ #
33
+ # @return [Array<Operation>] the operations
34
+ def to_operations
35
+ # FIXME: what was the purpose of this?
36
+ # cloned = Marshal.load Marshal.dump(operations)
37
+ operations.each do |op|
38
+ op.source_account ||= source_account
39
+ end
40
+ end
41
+
42
+ def apply_defaults
43
+ self.operations ||= []
44
+ self.fee ||= 100
45
+ self.memo ||= Stellar::Memo.new(:memo_none)
46
+ self.ext ||= Stellar::Transaction::Ext.new 0
47
+ end
48
+ end
49
+ end
@@ -3,10 +3,10 @@ module Stellar
3
3
  # Generic format conversion module
4
4
  #
5
5
  module Convert
6
- require 'base64'
6
+ require "base64"
7
7
 
8
8
  def to_hex(string)
9
- string.unpack("H*").first
9
+ string.unpack1("H*")
10
10
  end
11
11
 
12
12
  def from_hex(hex_string)
@@ -1,5 +1,4 @@
1
1
  FactoryBot.define do
2
-
3
2
  factory :stellar_ledger, class: Hyperclient::Resource do
4
3
  initialize_with { new(attributes.stringify_keys, nil, nil) }
5
4
 
@@ -39,7 +38,7 @@ FactoryBot.define do
39
38
  fee_meta_xdr { "AAAAAgAAAAMAAAABAAAAAAAAAAABlHJijueOuScU0i0DkJY8JNkn6gCZmUhuiR+sLaqcIQ3gtrOnZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAAAAAAABlHJijueOuScU0i0DkJY8JNkn6gCZmUhuiR+sLaqcIQ3gtrOnY/7UAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA==" }
40
39
  memo_type { "text" }
41
40
  signatures do
42
- [ "SsKlst02jsaBp35vXlI300Qbz39+HbwwNDX/gfM+MwaG/dFF7bgqpkKsDAsh/qJDiN3NOW695IZB9Mj+JAsHBA==" ]
41
+ ["SsKlst02jsaBp35vXlI300Qbz39+HbwwNDX/gfM+MwaG/dFF7bgqpkKsDAsh/qJDiN3NOW695IZB9Mj+JAsHBA=="]
43
42
  end
44
43
  end
45
44
 
@@ -57,5 +56,4 @@ FactoryBot.define do
57
56
  funder { "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7" }
58
57
  account { "GALPCCZN4YXA3YMJHKL6CVIECKPLJJCTVMSNYWBTKJW4K5HQLYLDMZTB" }
59
58
  end
60
-
61
59
  end
@@ -0,0 +1,21 @@
1
+ module Stellar
2
+ class FeeBumpTransaction
3
+ include Stellar::Concerns::Transaction
4
+
5
+ def to_envelope(*key_pairs)
6
+ signatures = (key_pairs || []).map(&method(:sign_decorated))
7
+
8
+ TransactionEnvelope.fee_bump(signatures: signatures, tx: self)
9
+ end
10
+
11
+ def signature_base_prefix
12
+ val = Stellar::EnvelopeType.envelope_type_tx_v0
13
+
14
+ Stellar.current_network_id + Stellar::EnvelopeType.to_xdr(val)
15
+ end
16
+
17
+ def source_account
18
+ source_account_ed25519
19
+ end
20
+ end
21
+ end
@@ -36,7 +36,7 @@ module Stellar
36
36
  from_raw_seed(Stellar.current_network_id)
37
37
  end
38
38
 
39
- def initialize(public_key, secret_key=nil)
39
+ def initialize(public_key, secret_key = nil)
40
40
  @public_key = public_key
41
41
  @secret_key = secret_key
42
42
  end
@@ -45,6 +45,10 @@ module Stellar
45
45
  Stellar::AccountID.new :public_key_type_ed25519, raw_public_key
46
46
  end
47
47
 
48
+ def muxed_account
49
+ Stellar::MuxedAccount.new :key_type_ed25519, raw_public_key
50
+ end
51
+
48
52
  def public_key
49
53
  Stellar::PublicKey.new :public_key_type_ed25519, raw_public_key
50
54
  end
@@ -81,9 +85,9 @@ module Stellar
81
85
 
82
86
  def seed
83
87
  raise "no private key" if @secret_key.nil?
84
- #TODO: improve the error class above
88
+ # TODO: improve the error class above
85
89
  seed_bytes = raw_seed
86
- encoder = Util::StrKey.check_encode(:seed, seed_bytes)
90
+ Util::StrKey.check_encode(:seed, seed_bytes)
87
91
  end
88
92
 
89
93
  def sign?
@@ -92,14 +96,14 @@ module Stellar
92
96
 
93
97
  def sign(message)
94
98
  raise "no private key" if @secret_key.nil?
95
- #TODO: improve the error class above
99
+ # TODO: improve the error class above
96
100
  @secret_key.sign(message)
97
101
  end
98
102
 
99
103
  def sign_decorated(message)
100
104
  raw_signature = sign(message)
101
105
  Stellar::DecoratedSignature.new({
102
- hint: signature_hint,
106
+ hint: signature_hint,
103
107
  signature: raw_signature
104
108
  })
105
109
  end
@@ -111,6 +115,5 @@ module Stellar
111
115
  rescue RbNaCl::BadSignatureError
112
116
  false
113
117
  end
114
-
115
118
  end
116
119
  end
@@ -1,10 +1,8 @@
1
1
  module Stellar
2
2
  # Provides a container for well-known network passphrases, such as the main network and SDF test network
3
3
  module Networks
4
-
5
- PUBLIC = "Public Global Stellar Network ; September 2015"
4
+ PUBLIC = "Public Global Stellar Network ; September 2015"
6
5
  TESTNET = "Test SDF Network ; September 2015"
7
-
8
6
  end
9
7
 
10
8
  # Configures the default stellar network passphrase for the current process. Unless otherwise
@@ -23,15 +21,15 @@ module Stellar
23
21
  # Returns the passphrase for the currently-configured network, as set by Stellar.default_network
24
22
  # or Stellar.on_network
25
23
  def self.current_network
26
- Thread.current["stellar_network_passphrase"] ||
27
- @default_network ||
28
- Stellar::Networks::TESTNET
24
+ Thread.current["stellar_network_passphrase"] ||
25
+ @default_network ||
26
+ Stellar::Networks::TESTNET
29
27
  end
30
28
 
31
29
  # Returns the id for the currently configured network, suitable for use in generating
32
30
  # a signature base string or making the root account's keypair.
33
31
  def self.current_network_id
34
- Digest::SHA256.digest(self.current_network)
32
+ Digest::SHA256.digest(current_network)
35
33
  end
36
34
 
37
35
  # Executes the provided block in the context of the provided network.
@@ -1,367 +1,478 @@
1
- require 'bigdecimal'
1
+ require "bigdecimal"
2
2
 
3
3
  module Stellar
4
4
  class Operation
5
-
6
5
  MAX_INT64 = 2**63 - 1
7
6
 
8
- #
9
- # Construct a new Stellar::Operation from the provided
10
- # source account and body
11
- #
12
- # @param [Hash] attributes the attributes to create the operation with
13
- # @option attributes [Stellar::KeyPair] :source_account
14
- # @option attributes [Stellar::Operation::Body] :body
15
- #
16
- # @return [Stellar::Operation] the built operation
17
- def self.make(attributes={})
18
- source_account = attributes[:source_account]
19
- body = Stellar::Operation::Body.new(*attributes[:body])
20
-
21
- op = Stellar::Operation.new(body:body)
22
-
23
- if source_account
24
- raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair)
25
- op.source_account = source_account.account_id
7
+ class << self
8
+ #
9
+ # Construct a new Stellar::Operation from the provided
10
+ # source account and body
11
+ #
12
+ # @param [Hash] attributes the attributes to create the operation with
13
+ # @option attributes [Stellar::KeyPair] :source_account
14
+ # @option attributes [Stellar::Operation::Body] :body
15
+ #
16
+ # @return [Stellar::Operation] the built operation
17
+ def make(attributes = {})
18
+ source_account = attributes[:source_account]
19
+ body = Stellar::Operation::Body.new(*attributes[:body])
20
+
21
+ op = Stellar::Operation.new(body: body)
22
+
23
+ if source_account
24
+ raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair)
25
+ op.source_account = source_account.muxed_account
26
+ end
27
+
28
+ op
26
29
  end
27
30
 
28
- return op
29
- end
31
+ #
32
+ # Helper method to create a valid PaymentOp, wrapped
33
+ # in the necessary XDR structs to be included within a
34
+ # transactions `operations` array.
35
+ #
36
+ # @see Stellar::Asset
37
+ #
38
+ # @param [Hash] attributes the attributes to create the operation with
39
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
40
+ # @option attributes [Array] :amount the amount to pay
41
+ # @return [Stellar::Operation] the built operation, containing a
42
+ # Stellar::PaymentOp body
43
+ def payment(attributes = {})
44
+ destination = attributes[:destination]
45
+ asset, amount = get_asset_amount(attributes[:amount])
46
+
47
+ raise ArgumentError unless destination.is_a?(KeyPair)
48
+
49
+ op = PaymentOp.new
50
+ op.asset = asset
51
+ op.amount = amount
52
+ op.destination = destination.muxed_account
53
+
54
+ make(attributes.merge({
55
+ body: [:payment, op]
56
+ }))
57
+ end
30
58
 
59
+ #
60
+ # Helper method to create a valid PathPaymentStrictReceiveOp, wrapped
61
+ # in the necessary XDR structs to be included within a
62
+ # transactions `operations` array.
63
+ #
64
+ # @deprecated Please use Operation.path_payment_strict_receive
65
+ #
66
+ # @see Stellar::Asset
67
+ #
68
+ # @param [Hash] attributes the attributes to create the operation with
69
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
70
+ # @option attributes [Array] :amount the destination asset and the amount to pay
71
+ # @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
72
+ # @option attributes [Array<Stellar::Asset>] :path the payment path to use
73
+ #
74
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
75
+ #
76
+ def path_payment(attributes = {})
77
+ path_payment_strict_receive(attributes)
78
+ end
31
79
 
32
- #
33
- # Helper method to create a valid PaymentOp, wrapped
34
- # in the necessary XDR structs to be included within a
35
- # transactions `operations` array.
36
- #
37
- # @see Stellar::Asset
38
- #
39
- # @param [Hash] attributes the attributes to create the operation with
40
- # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
41
- # @option attributes [Array] :amount the amount to pay
42
- # @return [Stellar::Operation] the built operation, containing a
43
- # Stellar::PaymentOp body
44
- def self.payment(attributes={})
45
- destination = attributes[:destination]
46
- asset, amount = extract_amount(attributes[:amount])
47
-
48
- raise ArgumentError unless destination.is_a?(KeyPair)
49
-
50
-
51
- op = PaymentOp.new
52
- op.asset = asset
53
- op.amount = amount
54
- op.destination = destination.account_id
55
-
56
- return make(attributes.merge({
57
- body:[:payment, op]
58
- }))
59
- end
80
+ #
81
+ # Helper method to create a valid PathPaymentStrictReceiveOp, wrapped
82
+ # in the necessary XDR structs to be included within a
83
+ # transactions `operations` array.
84
+ #
85
+ # @see Stellar::Asset
86
+ #
87
+ # @param [Hash] attributes the attributes to create the operation with
88
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
89
+ # @option attributes [Array] :amount the destination asset and the amount to pay
90
+ # @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
91
+ # @option attributes [Array<Stellar::Asset>] :path the payment path to use
92
+ #
93
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
94
+ #
95
+ def path_payment_strict_receive(attributes = {})
96
+ destination = attributes[:destination]
97
+ asset, amount = get_asset_amount(attributes[:amount])
98
+ send_asset, send_max = get_asset_amount(attributes[:with])
99
+ path = (attributes[:path] || []).map { |p|
100
+ p.is_a?(Array) ? Stellar::Asset.send(*p) : p
101
+ }
102
+
103
+ raise ArgumentError unless destination.is_a?(KeyPair)
104
+
105
+ op = PathPaymentStrictReceiveOp.new
106
+ op.send_asset = send_asset
107
+ op.send_max = send_max
108
+ op.destination = destination.muxed_account
109
+ op.dest_asset = asset
110
+ op.dest_amount = amount
111
+ op.path = path
112
+
113
+ make(attributes.merge({
114
+ body: [:path_payment_strict_receive, op]
115
+ }))
116
+ end
60
117
 
61
- #
62
- # Helper method to create a valid PathPaymentOp, wrapped
63
- # in the necessary XDR structs to be included within a
64
- # transactions `operations` array.
65
- #
66
- # @see Stellar::Asset
67
- #
68
- # @param [Hash] attributes the attributes to create the operation with
69
- # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
70
- # @option attributes [Array] :amount the amount to pay
71
- # @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
72
- # @option attributes [Array<Stellar::Asset>] :path the payment path to use
73
- #
74
- # @return [Stellar::Operation] the built operation, containing a
75
- # Stellar::PaymentOp body
76
- def self.path_payment(attributes={})
77
- destination = attributes[:destination]
78
- asset, amount = extract_amount(attributes[:amount])
79
- send_asset, send_max = extract_amount(attributes[:with])
80
- path = (attributes[:path] || []).map{|p| Stellar::Asset.send(*p)}
81
-
82
- raise ArgumentError unless destination.is_a?(KeyPair)
83
-
84
- op = PathPaymentOp.new
85
- op.send_asset = send_asset
86
- op.send_max = send_max
87
- op.destination = destination.account_id
88
- op.dest_asset = asset
89
- op.dest_amount = amount
90
- op.path = path
91
-
92
- return make(attributes.merge({
93
- body:[:path_payment, op]
94
- }))
95
- end
118
+ #
119
+ # Helper method to create a valid PathPaymentStrictSendOp, wrapped
120
+ # in the necessary XDR structs to be included within a
121
+ # transactions `operations` array.
122
+ #
123
+ # @see Stellar::Asset
124
+ #
125
+ # @param [Hash] attributes the attributes to create the operation with
126
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
127
+ # @option attributes [Array] :amount the destination asset and the minimum amount of destination asset to be received
128
+ # @option attributes [Array] :with the source asset and amount to pay with
129
+ # @option attributes [Array<Stellar::Asset>] :path the payment path to use
130
+ #
131
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
132
+ #
133
+ def path_payment_strict_send(attributes = {})
134
+ destination = attributes[:destination]
135
+ asset, dest_min = get_asset_amount(attributes[:amount])
136
+ send_asset, send_amount = get_asset_amount(attributes[:with])
137
+ path = (attributes[:path] || []).map { |p|
138
+ p.is_a?(Array) ? Stellar::Asset.send(*p) : p
139
+ }
140
+
141
+ raise ArgumentError unless destination.is_a?(KeyPair)
142
+
143
+ op = PathPaymentStrictSendOp.new
144
+ op.send_asset = send_asset
145
+ op.send_amount = send_amount
146
+ op.destination = destination.muxed_account
147
+ op.dest_asset = asset
148
+ op.dest_min = dest_min
149
+ op.path = path
150
+
151
+ make(attributes.merge({
152
+ body: [:path_payment_strict_send, op]
153
+ }))
154
+ end
96
155
 
97
- def self.create_account(attributes={})
98
- destination = attributes[:destination]
99
- starting_balance = interpret_amount(attributes[:starting_balance])
156
+ def create_account(attributes = {})
157
+ destination = attributes[:destination]
158
+ starting_balance = interpret_amount(attributes[:starting_balance])
100
159
 
101
- raise ArgumentError unless destination.is_a?(KeyPair)
160
+ raise ArgumentError unless destination.is_a?(KeyPair)
102
161
 
103
- op = CreateAccountOp.new()
104
- op.destination = destination.account_id
105
- op.starting_balance = starting_balance
162
+ op = CreateAccountOp.new
163
+ op.destination = destination.account_id
164
+ op.starting_balance = starting_balance
106
165
 
107
- return make(attributes.merge({
108
- body:[:create_account, op]
109
- }))
110
- end
166
+ make(attributes.merge({
167
+ body: [:create_account, op]
168
+ }))
169
+ end
111
170
 
112
- #
113
- # Helper method to create a valid ChangeTrustOp, wrapped
114
- # in the necessary XDR structs to be included within a
115
- # transactions `operations` array.
116
- #
117
- # @param [Hash] attributes the attributes to create the operation with
118
- # @option attributes [Stellar::Asset] :line the asset to trust
119
- # @option attributes [Fixnum] :limit the maximum amount to trust, defaults to max int64,
120
- # if the limit is set to 0 it deletes the trustline.
121
- #
122
- # @return [Stellar::Operation] the built operation, containing a
123
- # Stellar::ChangeTrustOp body
124
- def self.change_trust(attributes={})
125
- line = attributes[:line]
126
- if !line.is_a?(Asset)
127
- if !Asset::TYPES.include?(line[0])
128
- fail ArgumentError, "must be one of #{Asset::TYPES}"
171
+ #
172
+ # Helper method to create a valid ChangeTrustOp, wrapped
173
+ # in the necessary XDR structs to be included within a
174
+ # transactions `operations` array.
175
+ #
176
+ # @param [Hash] attributes the attributes to create the operation with
177
+ # @option attributes [Stellar::Asset] :line the asset to trust
178
+ # @option attributes [Fixnum] :limit the maximum amount to trust, defaults to max int64,
179
+ # if the limit is set to 0 it deletes the trustline.
180
+ #
181
+ # @return [Stellar::Operation] the built operation, containing a
182
+ # Stellar::ChangeTrustOp body
183
+ def change_trust(attributes = {})
184
+ line = attributes[:line]
185
+ unless line.is_a?(Asset)
186
+ unless Asset::TYPES.include?(line[0])
187
+ fail ArgumentError, "must be one of #{Asset::TYPES}"
188
+ end
189
+ line = Asset.send(*line)
129
190
  end
130
- line = Asset.send(*line)
131
- end
132
191
 
133
- limit = attributes.key?(:limit) ? interpret_amount(attributes[:limit]) : MAX_INT64
192
+ limit = attributes.key?(:limit) ? interpret_amount(attributes[:limit]) : MAX_INT64
134
193
 
135
- raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer)
194
+ raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer)
136
195
 
137
- op = ChangeTrustOp.new(line: line, limit: limit)
196
+ op = ChangeTrustOp.new(line: line, limit: limit)
138
197
 
139
- return make(attributes.merge({
140
- body:[:change_trust, op]
141
- }))
142
- end
198
+ make(attributes.merge({
199
+ body: [:change_trust, op]
200
+ }))
201
+ end
143
202
 
144
- def self.manage_offer(attributes={})
145
- buying = Asset.send(*attributes[:buying])
146
- selling = Asset.send(*attributes[:selling])
147
- amount = interpret_amount(attributes[:amount])
148
- offer_id = attributes[:offer_id] || 0
149
- price = interpret_price(attributes[:price])
150
-
151
- op = ManageOfferOp.new({
152
- buying: buying,
153
- selling: selling,
154
- amount: amount,
155
- price: price,
156
- offer_id: offer_id
157
- })
158
-
159
- return make(attributes.merge({
160
- body:[:manage_offer, op]
161
- }))
162
- end
203
+ def manage_sell_offer(attributes = {})
204
+ buying = attributes[:buying]
205
+ if buying.is_a?(Array)
206
+ buying = Asset.send(*buying)
207
+ end
208
+ selling = attributes[:selling]
209
+ if selling.is_a?(Array)
210
+ selling = Asset.send(*selling)
211
+ end
212
+ amount = interpret_amount(attributes[:amount])
213
+ offer_id = attributes[:offer_id] || 0
214
+ price = interpret_price(attributes[:price])
215
+
216
+ op = ManageSellOfferOp.new({
217
+ buying: buying,
218
+ selling: selling,
219
+ amount: amount,
220
+ price: price,
221
+ offer_id: offer_id
222
+ })
223
+
224
+ make(attributes.merge({
225
+ body: [:manage_sell_offer, op]
226
+ }))
227
+ end
163
228
 
164
- def self.create_passive_offer(attributes={})
165
- buying = Asset.send(*attributes[:buying])
166
- selling = Asset.send(*attributes[:selling])
167
- amount = interpret_amount(attributes[:amount])
168
- price = interpret_price(attributes[:price])
169
-
170
- op = CreatePassiveOfferOp.new({
171
- buying: buying,
172
- selling: selling,
173
- amount: amount,
174
- price: price,
175
- })
176
-
177
- return make(attributes.merge({
178
- body:[:create_passive_offer, op]
179
- }))
180
- end
229
+ def manage_buy_offer(attributes = {})
230
+ buying = attributes[:buying]
231
+ if buying.is_a?(Array)
232
+ buying = Asset.send(*buying)
233
+ end
234
+ selling = attributes[:selling]
235
+ if selling.is_a?(Array)
236
+ selling = Asset.send(*selling)
237
+ end
238
+ amount = interpret_amount(attributes[:amount])
239
+ offer_id = attributes[:offer_id] || 0
240
+ price = interpret_price(attributes[:price])
241
+
242
+ op = ManageBuyOfferOp.new({
243
+ buying: buying,
244
+ selling: selling,
245
+ amount: amount,
246
+ price: price,
247
+ offer_id: offer_id
248
+ })
249
+
250
+ make(attributes.merge({
251
+ body: [:manage_buy_offer, op]
252
+ }))
253
+ end
254
+
255
+ def create_passive_sell_offer(attributes = {})
256
+ buying = attributes[:buying]
257
+ if buying.is_a?(Array)
258
+ buying = Asset.send(*buying)
259
+ end
260
+ selling = attributes[:selling]
261
+ if selling.is_a?(Array)
262
+ selling = Asset.send(*selling)
263
+ end
264
+ amount = interpret_amount(attributes[:amount])
265
+ price = interpret_price(attributes[:price])
266
+
267
+ op = CreatePassiveSellOfferOp.new({
268
+ buying: buying,
269
+ selling: selling,
270
+ amount: amount,
271
+ price: price
272
+ })
273
+
274
+ make(attributes.merge({
275
+ body: [:create_passive_sell_offer, op]
276
+ }))
277
+ end
278
+
279
+ #
280
+ # Helper method to create a valid SetOptionsOp, wrapped
281
+ # in the necessary XDR structs to be included within a
282
+ # transactions `operations` array.
283
+ #
284
+ # @param [Hash] attributes the attributes to create the operation with
285
+ # @option attributes [Stellar::KeyPair] :inflation_dest
286
+ # @option attributes [Array<Stellar::AccountFlags>] :set flags to set
287
+ # @option attributes [Array<Stellar::AccountFlags>] :clear flags to clear
288
+ # @option attributes [String] :thresholds
289
+ # @option attributes [Stellar::Signer] :signer
290
+ #
291
+ # @return [Stellar::Operation] the built operation, containing a
292
+ # Stellar::SetOptionsOp body
293
+ def set_options(attributes = {})
294
+ op = SetOptionsOp.new
295
+ op.set_flags = Stellar::AccountFlags.make_mask attributes[:set]
296
+ op.clear_flags = Stellar::AccountFlags.make_mask attributes[:clear]
297
+ op.master_weight = attributes[:master_weight]
298
+ op.low_threshold = attributes[:low_threshold]
299
+ op.med_threshold = attributes[:med_threshold]
300
+ op.high_threshold = attributes[:high_threshold]
301
+
302
+ op.signer = attributes[:signer]
303
+ op.home_domain = attributes[:home_domain]
304
+
305
+ inflation_dest = attributes[:inflation_dest]
306
+ if inflation_dest
307
+ raise ArgumentError, "Bad :inflation_dest" unless inflation_dest.is_a?(Stellar::KeyPair)
308
+ op.inflation_dest = inflation_dest.account_id
309
+ end
181
310
 
182
- #
183
- # Helper method to create a valid SetOptionsOp, wrapped
184
- # in the necessary XDR structs to be included within a
185
- # transactions `operations` array.
186
- #
187
- # @param [Hash] attributes the attributes to create the operation with
188
- # @option attributes [Stellar::KeyPair] :inflation_dest
189
- # @option attributes [Array<Stellar::AccountFlags>] :set flags to set
190
- # @option attributes [Array<Stellar::AccountFlags>] :clear flags to clear
191
- # @option attributes [String] :thresholds
192
- # @option attributes [Stellar::Signer] :signer
193
- #
194
- # @return [Stellar::Operation] the built operation, containing a
195
- # Stellar::SetOptionsOp body
196
- def self.set_options(attributes={})
197
- op = SetOptionsOp.new()
198
- op.set_flags = Stellar::AccountFlags.make_mask attributes[:set]
199
- op.clear_flags = Stellar::AccountFlags.make_mask attributes[:clear]
200
- op.master_weight = attributes[:master_weight]
201
- op.low_threshold = attributes[:low_threshold]
202
- op.med_threshold = attributes[:med_threshold]
203
- op.high_threshold = attributes[:high_threshold]
204
-
205
- op.signer = attributes[:signer]
206
- op.home_domain = attributes[:home_domain]
207
-
208
-
209
- inflation_dest = attributes[:inflation_dest]
210
- if inflation_dest
211
- raise ArgumentError, "Bad :inflation_dest" unless inflation_dest.is_a?(Stellar::KeyPair)
212
- op.inflation_dest = inflation_dest.account_id
311
+ make(attributes.merge({
312
+ body: [:set_options, op]
313
+ }))
213
314
  end
214
315
 
316
+ #
317
+ # Helper method to create a valid AllowTrustOp, wrapped
318
+ # in the necessary XDR structs to be included within a
319
+ # transactions `operations` array.
320
+ #
321
+ # @param [Hash] attributes the attributes to create the operation with
322
+ # @option attributes [Stellar::KeyPair] :trustor
323
+ # @option attributes [Stellar::Asset] :asset
324
+ # @option attributes [Symbol, Boolean] :authorize :full, maintain_liabilities or :none
325
+ #
326
+ # @return [Stellar::Operation] the built operation, containing a
327
+ # Stellar::AllowTrustOp body
328
+ def allow_trust(attributes = {})
329
+ op = AllowTrustOp.new
330
+
331
+ trustor = attributes[:trustor]
332
+ authorize = attributes[:authorize]
333
+ asset = attributes[:asset]
334
+ if asset.is_a?(Array)
335
+ asset = Asset.send(*asset)
336
+ end
215
337
 
216
- return make(attributes.merge({
217
- body:[:set_options, op]
218
- }))
219
- end
338
+ raise ArgumentError, "Bad :trustor" unless trustor.is_a?(Stellar::KeyPair)
220
339
 
221
- #
222
- # Helper method to create a valid AllowTrustOp, wrapped
223
- # in the necessary XDR structs to be included within a
224
- # transactions `operations` array.
225
- #
226
- # @param [Hash] attributes the attributes to create the operation with
227
- # @option attributes [Stellar::KeyPair] :trustor
228
- # @option attributes [Stellar::Asset] :asset
229
- #
230
- # @return [Stellar::Operation] the built operation, containing a
231
- # Stellar::AllowTrustOp body
232
- def self.allow_trust(attributes={})
233
- op = AllowTrustOp.new()
234
-
235
- trustor = attributes[:trustor]
236
- authorize = attributes[:authorize]
237
- asset = Asset.send(*attributes[:asset])
238
-
239
- raise ArgumentError, "Bad :trustor" unless trustor.is_a?(Stellar::KeyPair)
240
- raise ArgumentError, "Bad :authorize" unless authorize == !!authorize # check boolean
241
- raise ArgumentError, "Bad :asset" unless asset.type == Stellar::AssetType.asset_type_credit_alphanum4
242
-
243
- atc = AllowTrustOp::Asset.new(:asset_type_credit_alphanum4, asset.code)
244
-
245
- op.trustor = trustor.account_id
246
- op.authorize = authorize
247
- op.asset = atc
248
-
249
- return make(attributes.merge({
250
- body:[:allow_trust, op]
251
- }))
252
- end
340
+ op.authorize = case authorize
341
+ when :none, false then 0 # we handle booleans here for the backward compatibility
342
+ when :full, true then TrustLineFlags.authorized_flag.value
343
+ when :maintain_liabilities then TrustLineFlags.authorized_to_maintain_liabilities_flag.value
344
+ else
345
+ raise ArgumentError, "Bad :authorize, supported values: :full, :maintain_liabilities, :none"
346
+ end
253
347
 
254
- #
255
- # Helper method to create an account merge operation
256
- #
257
- # @param [Hash] attributes the attributes to create the operation with
258
- # @option attributes [Stellar::KeyPair] :destination
259
- #
260
- # @return [Stellar::Operation] the built operation
261
- def self.account_merge(attributes={})
262
- destination = attributes[:destination]
263
-
264
- raise ArgumentError, "Bad :destination" unless destination.is_a?(KeyPair)
265
-
266
- # TODO: add source_account support
267
- return make(attributes.merge({
268
- body:[:account_merge, destination.account_id]
269
- }))
270
- end
348
+ raise ArgumentError, "Bad :asset" unless asset.type == Stellar::AssetType.asset_type_credit_alphanum4
271
349
 
272
- #
273
- # Helper method to create an inflation operation
274
- #
275
- # @param [Hash] attributes the attributes to create the operation with
276
- # @option attributes [Integer] :sequence
277
- #
278
- # @return [Stellar::Operation] the built operation
279
- def self.inflation(attributes={})
280
- sequence = attributes[:sequence]
281
-
282
- raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer)
283
-
284
- # TODO: add source_account support
285
- return make(attributes.merge({
286
- body:[:inflation]
287
- }))
288
- end
350
+ atc = AllowTrustOp::Asset.new(:asset_type_credit_alphanum4, asset.code)
289
351
 
290
- #
291
- # Helper method to create an manage data operation
292
- #
293
- # @param [Hash] attributes the attributes to create the operation with
294
- # @option attributes [Integer] :sequence
295
- #
296
- # @return [Stellar::Operation] the built operation
297
- def self.manage_data(attributes={})
298
- op = ManageDataOp.new()
352
+ op.trustor = trustor.account_id
353
+ op.asset = atc
299
354
 
300
- name = attributes[:name]
301
- value = attributes[:value]
355
+ make(attributes.merge({
356
+ body: [:allow_trust, op]
357
+ }))
358
+ end
302
359
 
303
- raise ArgumentError, "Invalid :name" unless name.is_a?(String)
304
- raise ArgumentError, ":name too long" unless name.bytesize <= 64
360
+ #
361
+ # Helper method to create an account merge operation
362
+ #
363
+ # @param [Hash] attributes the attributes to create the operation with
364
+ # @option attributes [Stellar::KeyPair] :destination
365
+ #
366
+ # @return [Stellar::Operation] the built operation
367
+ def account_merge(attributes = {})
368
+ destination = attributes[:destination]
369
+
370
+ raise ArgumentError, "Bad :destination" unless destination.is_a?(KeyPair)
371
+
372
+ # TODO: add source_account support
373
+ make(attributes.merge({
374
+ body: [:account_merge, destination.muxed_account]
375
+ }))
376
+ end
305
377
 
306
- if value.present?
307
- raise ArgumentError, ":value too long" unless value.bytesize <= 64
378
+ #
379
+ # Helper method to create an inflation operation
380
+ #
381
+ # @param [Hash] attributes the attributes to create the operation with
382
+ # @option attributes [Integer] :sequence
383
+ #
384
+ # @return [Stellar::Operation] the built operation
385
+ def inflation(attributes = {})
386
+ sequence = attributes[:sequence]
387
+
388
+ raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer)
389
+
390
+ # TODO: add source_account support
391
+ make(attributes.merge({
392
+ body: [:inflation]
393
+ }))
308
394
  end
309
395
 
310
- op.data_name = name
311
- op.data_value = value
396
+ #
397
+ # Helper method to create an manage data operation
398
+ #
399
+ # @param [Hash] attributes the attributes to create the operation with
400
+ # @option attributes [Integer] :sequence
401
+ #
402
+ # @return [Stellar::Operation] the built operation
403
+ def manage_data(attributes = {})
404
+ op = ManageDataOp.new
312
405
 
313
- return make(attributes.merge({
314
- body:[:manage_data, op]
315
- }))
316
- end
406
+ name = attributes[:name]
407
+ value = attributes[:value]
408
+
409
+ raise ArgumentError, "Invalid :name" unless name.is_a?(String)
410
+ raise ArgumentError, ":name too long" unless name.bytesize <= 64
317
411
 
318
- def self.bump_sequence(attributes={})
319
- op = BumpSequenceOp.new()
412
+ if value.present?
413
+ raise ArgumentError, ":value too long" unless value.bytesize <= 64
414
+ end
320
415
 
321
- bump_to = attributes[:bump_to]
416
+ op.data_name = name
417
+ op.data_value = value
322
418
 
323
- raise ArgumentError, ":bump_to too big" unless bump_to <= MAX_INT64
419
+ make(attributes.merge({
420
+ body: [:manage_data, op]
421
+ }))
422
+ end
324
423
 
325
- op.bump_to = bump_to
424
+ def bump_sequence(attributes = {})
425
+ op = BumpSequenceOp.new
326
426
 
327
- return make(attributes.merge({
328
- body:[:bump_sequence, op]
329
- }))
330
- end
427
+ bump_to = attributes[:bump_to]
331
428
 
332
- private
333
- def self.extract_amount(a)
334
- amount = interpret_amount(a.last)
335
- asset = Stellar::Asset.send(*a[0...-1])
429
+ raise ArgumentError, ":bump_to too big" unless bump_to <= MAX_INT64
336
430
 
337
- return asset, amount
338
- end
431
+ op.bump_to = bump_to
339
432
 
340
- def self.interpret_amount(amount)
341
- case amount
342
- when String
343
- (BigDecimal.new(amount) * Stellar::ONE).floor
344
- when Integer
345
- amount * Stellar::ONE
346
- when Numeric
347
- (amount * Stellar::ONE).floor
348
- else
349
- raise ArgumentError, "Invalid amount type: #{amount.class}. Must be String or Numeric"
433
+ make(attributes.merge({
434
+ body: [:bump_sequence, op]
435
+ }))
350
436
  end
351
- end
352
437
 
438
+ private
439
+
440
+ def get_asset_amount(values)
441
+ amount = interpret_amount(values.last)
442
+ asset = if values[0].is_a?(Stellar::Asset)
443
+ values.first
444
+ else
445
+ Stellar::Asset.send(*values[0...-1])
446
+ end
353
447
 
354
- def self.interpret_price(price)
355
- case price
356
- when String
357
- bd = BigDecimal.new(price)
358
- Price.from_f(bd)
359
- when Numeric
360
- Price.from_f(price)
361
- when Stellar::Price
362
- price
363
- else
364
- raise ArgumentError, "Invalid price type: #{price.class}. Must be String, Numeric, or Stellar::Price"
448
+ [asset, amount]
449
+ end
450
+
451
+ def interpret_amount(amount)
452
+ case amount
453
+ when String
454
+ (BigDecimal(amount) * Stellar::ONE).floor
455
+ when Integer
456
+ amount * Stellar::ONE
457
+ when Numeric
458
+ (amount * Stellar::ONE).floor
459
+ else
460
+ raise ArgumentError, "Invalid amount type: #{amount.class}. Must be String or Numeric"
461
+ end
462
+ end
463
+
464
+ def interpret_price(price)
465
+ case price
466
+ when String
467
+ bd = BigDecimal(price)
468
+ Price.from_f(bd)
469
+ when Numeric
470
+ Price.from_f(price)
471
+ when Stellar::Price
472
+ price
473
+ else
474
+ raise ArgumentError, "Invalid price type: #{price.class}. Must be String, Numeric, or Stellar::Price"
475
+ end
365
476
  end
366
477
  end
367
478
  end