stellar-base 0.23.1 → 0.24.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/generated/stellar-base-generated.rb +29 -1
  4. data/generated/stellar/account_entry.rb +3 -13
  5. data/generated/stellar/account_entry/ext.rb +2 -16
  6. data/generated/stellar/account_entry_extension_v1.rb +32 -0
  7. data/generated/stellar/account_entry_extension_v1/ext.rb +28 -0
  8. data/generated/stellar/account_entry_extension_v2.rb +34 -0
  9. data/generated/stellar/{account_entry/ext/v1 → account_entry_extension_v2}/ext.rb +8 -12
  10. data/generated/stellar/account_merge_result_code.rb +3 -1
  11. data/generated/stellar/begin_sponsoring_future_reserves_op.rb +18 -0
  12. data/generated/stellar/begin_sponsoring_future_reserves_result.rb +25 -0
  13. data/generated/stellar/begin_sponsoring_future_reserves_result_code.rb +29 -0
  14. data/generated/stellar/claim_claimable_balance_op.rb +18 -0
  15. data/generated/stellar/claim_claimable_balance_result.rb +25 -0
  16. data/generated/stellar/claim_claimable_balance_result_code.rb +31 -0
  17. data/generated/stellar/claim_predicate.rb +43 -0
  18. data/generated/stellar/claim_predicate_type.rb +30 -0
  19. data/generated/stellar/claimable_balance_entry.rb +44 -0
  20. data/generated/stellar/claimable_balance_entry/ext.rb +24 -0
  21. data/generated/stellar/claimable_balance_id.rb +23 -0
  22. data/generated/stellar/claimable_balance_id_type.rb +20 -0
  23. data/generated/stellar/claimant.rb +31 -0
  24. data/generated/stellar/claimant/v0.rb +22 -0
  25. data/generated/stellar/claimant_type.rb +20 -0
  26. data/generated/stellar/create_claimable_balance_op.rb +22 -0
  27. data/generated/stellar/create_claimable_balance_result.rb +27 -0
  28. data/generated/stellar/create_claimable_balance_result_code.rb +30 -0
  29. data/generated/stellar/end_sponsoring_future_reserves_result.rb +25 -0
  30. data/generated/stellar/end_sponsoring_future_reserves_result_code.rb +25 -0
  31. data/generated/stellar/envelope_type.rb +3 -1
  32. data/generated/stellar/inner_transaction_result.rb +2 -1
  33. data/generated/stellar/inner_transaction_result/result.rb +3 -1
  34. data/generated/stellar/ledger_entry.rb +4 -0
  35. data/generated/stellar/ledger_entry/data.rb +12 -8
  36. data/generated/stellar/ledger_entry/ext.rb +4 -0
  37. data/generated/stellar/ledger_entry_extension_v1.rb +30 -0
  38. data/generated/stellar/ledger_entry_extension_v1/ext.rb +24 -0
  39. data/generated/stellar/ledger_entry_type.rb +7 -5
  40. data/generated/stellar/ledger_key.rb +17 -8
  41. data/generated/stellar/ledger_key/claimable_balance.rb +20 -0
  42. data/generated/stellar/operation.rb +10 -0
  43. data/generated/stellar/operation/body.rb +45 -26
  44. data/generated/stellar/operation_id.rb +32 -0
  45. data/generated/stellar/operation_id/id.rb +24 -0
  46. data/generated/stellar/operation_result.rb +10 -0
  47. data/generated/stellar/operation_result/tr.rb +48 -28
  48. data/generated/stellar/operation_result_code.rb +3 -1
  49. data/generated/stellar/operation_type.rb +25 -15
  50. data/generated/stellar/path_payment_strict_receive_result.rb +2 -1
  51. data/generated/stellar/revoke_sponsorship_op.rb +36 -0
  52. data/generated/stellar/revoke_sponsorship_op/signer.rb +22 -0
  53. data/generated/stellar/revoke_sponsorship_result.rb +25 -0
  54. data/generated/stellar/revoke_sponsorship_result_code.rb +31 -0
  55. data/generated/stellar/revoke_sponsorship_type.rb +22 -0
  56. data/generated/stellar/transaction_result_code.rb +4 -2
  57. data/lib/stellar-base.rb +15 -5
  58. data/lib/stellar/account_flags.rb +1 -1
  59. data/lib/stellar/{version.rb → base/version.rb} +1 -1
  60. data/lib/stellar/claim_predicate.rb +198 -0
  61. data/lib/stellar/compat.rb +2 -11
  62. data/lib/stellar/dsl.rb +85 -0
  63. data/lib/stellar/ext/xdr.rb +49 -0
  64. data/lib/stellar/key_pair.rb +43 -35
  65. data/lib/stellar/ledger_key.rb +30 -0
  66. data/lib/stellar/networks.rb +12 -12
  67. data/lib/stellar/operation.rb +58 -1
  68. data/lib/stellar/price.rb +11 -2
  69. data/lib/stellar/transaction.rb +0 -168
  70. data/lib/stellar/transaction_builder.rb +28 -2
  71. data/lib/stellar/transaction_envelope.rb +3 -29
  72. data/lib/stellar/util/strkey.rb +6 -6
  73. metadata +162 -32
  74. data/generated/stellar/account_entry/ext/v1.rb +0 -34
  75. data/lib/stellar/util/continued_fraction.rb +0 -96
@@ -3,17 +3,8 @@ require "active_support/deprecation"
3
3
  Stellar::Deprecation ||= ActiveSupport::Deprecation.new("next release", "stellar-base")
4
4
 
5
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
6
+ alias_method :manage_offer, :manage_sell_offer
7
+ alias_method :create_passive_offer, :create_passive_sell_offer
17
8
 
18
9
  deprecate deprecator: Stellar::Deprecation,
19
10
  manage_offer: :manage_sell_offer,
@@ -0,0 +1,85 @@
1
+ module Stellar
2
+ module DSL
3
+ # Constructs a new ClaimPredicate using DSL
4
+ #
5
+ # @example fulfilled during [T+5min, T+60min] period, where T refers to claimable balance entry creation time
6
+ # Stellar::ClaimPredicate { before_relative_time(1.hour) & ~before_relative_time(5.minutes) }
7
+ #
8
+ # @example not fulfilled starting from today midnight until tomorrow midnight,
9
+ # Stellar::ClaimPredicate { before_absolute_time(Date.today.end_of_day) | ~before_absolute_time(Date.tomorrow.end_of_day) }
10
+ #
11
+ # @example always fulfilled
12
+ # Stellar::ClaimPredicate { }
13
+ def ClaimPredicate(&block)
14
+ return ClaimPredicate.unconditional unless block
15
+ ClaimPredicate.compose(&block)
16
+ end
17
+
18
+ def Claimant(destination, &block)
19
+ Claimant.new(
20
+ ClaimantType.claimant_type_v0,
21
+ Claimant::V0.new(
22
+ destination: KeyPair(destination).account_id,
23
+ predicate: ClaimPredicate(&block)
24
+ )
25
+ )
26
+ end
27
+
28
+ def Asset(subject = nil)
29
+ case subject
30
+ when Asset
31
+ subject
32
+ when nil, /^(XLM[-:])?native$/
33
+ Asset.native
34
+ when /^([0-9A-Z]{1,4})[-:](G[A-Z0-9]{55})$/
35
+ Asset.alphanum4($1, KeyPair($2))
36
+ when /^([0-9A-Z]{5,12})[-:](G[A-Z0-9]{55})$/
37
+ Asset.alphanum12($1, KeyPair($2))
38
+ else
39
+ raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Asset"
40
+ end
41
+ end
42
+
43
+ # Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.
44
+ # @param subject [String|Stellar::Account|Stellar::PublicKey|Stellar::SignerKey|Stellar::Keypair] subject.
45
+ # @return [Stellar::Keypair] Stellar::Keypair instance.
46
+ def KeyPair(subject = nil)
47
+ case subject
48
+ when ->(subj) { subj.respond_to?(:to_keypair) }
49
+ subject.to_keypair
50
+ when /G[A-Z0-9]{55}/
51
+ KeyPair.from_address(subject)
52
+ when /S[A-Z0-9]{55}/
53
+ KeyPair.from_seed(subject)
54
+ when PublicKey
55
+ KeyPair.from_public_key(subject.value)
56
+ when SignerKey
57
+ KeyPair.from_raw_seed(subject.value)
58
+ when nil
59
+ KeyPair.random
60
+ else
61
+ raise TypeError, "cannot convert #{subject.inspect} to Stellar::KeyPair"
62
+ end
63
+ end
64
+
65
+ # Provides conversion from different input types into the SignerKey to use in ManageData operation.
66
+ # @param input [String|zStellar::Account|Stellar::PublicKey|Stellar::SignerKey|Stellar::Keypair] subject.
67
+ # @return [Stellar::SignerKey] Stellar::Keypair instance.
68
+ def SignerKey(input = nil)
69
+ case input
70
+ when Transaction
71
+ SignerKey.pre_auth_tx(input.hash)
72
+ when /^[0-9A-Za-z+\/=]{44}$/
73
+ SignerKey.hash_x(Stellar::Convert.from_base64(input))
74
+ when /^[0-9a-f]{64}$/
75
+ SignerKey.hash_x(Stellar::Convert.from_hex(input))
76
+ when /^.{32}$/
77
+ SignerKey.hash_x(input)
78
+ else
79
+ SignerKey.ed25519(KeyPair(input))
80
+ end
81
+ end
82
+ end
83
+
84
+ extend DSL
85
+ end
@@ -0,0 +1,49 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "xdr"
3
+
4
+ # For every member of XDR::Enum define constant on the corresponding enum type class.
5
+ # Constant name is a member name stripped of the common prefix with enum type name.
6
+ XDR::DSL::Enum.redefine_method(:seal) do
7
+ names = [members.keys.first, name.demodulize.underscore + "_"].join(" ")
8
+ common_prefix = /\A(.*_).* \1.*\Z/.match(names)&.values_at(1)&.first
9
+ members.each do |name, value|
10
+ unless common_prefix.nil?
11
+ full_name, name = [name, name.delete_prefix(common_prefix)]
12
+ singleton_class.alias_method(name, full_name)
13
+ end
14
+ const_set(name.upcase, value)
15
+ end
16
+ self.sealed = true
17
+ end
18
+
19
+ XDR::DSL::Union.redefine_method(:switch) do |switch, arm = nil|
20
+ raise ArgumentError, "`switch_on` not defined yet" if switch_type.nil?
21
+
22
+ switch = normalize_switch_declaration(switch)
23
+ self.switches = switches.merge(switch => arm)
24
+
25
+ unless arm.nil?
26
+ define_singleton_method(arm) do |*args, **kwargs|
27
+ value_type = arms[arm]
28
+ value = if value_type.valid?(args.first)
29
+ args.first
30
+ elsif value_type.ancestors.include?(XDR::Struct)
31
+ value_type.new(kwargs)
32
+ elsif value_type.ancestors.include?(XDR::Union)
33
+ value_type.new(*args[0..1])
34
+ else
35
+ args.first
36
+ end
37
+ new(switch, value)
38
+ end
39
+ end
40
+ end
41
+
42
+ # XDR::Union generates an attribute method for each `arm`, but lacks the
43
+ # actual `attribute(attr)` method those generated methods delegate to.
44
+ # We follow the semantics of the bang variant `XDR::Union#attribute!` method,
45
+ # except that calls to `raise` are replaced with early returns of nil.
46
+ XDR::Union.define_method(:attribute) do |attr|
47
+ return unless @arm.to_s == attr
48
+ get
49
+ end
@@ -1,40 +1,44 @@
1
1
  module Stellar
2
2
  class KeyPair
3
- def self.from_seed(seed)
4
- seed_bytes = Util::StrKey.check_decode(:seed, seed)
5
- from_raw_seed seed_bytes
6
- end
7
-
8
- def self.from_raw_seed(seed_bytes)
9
- secret_key = RbNaCl::SigningKey.new(seed_bytes)
10
- public_key = secret_key.verify_key
11
- new(public_key, secret_key)
12
- end
13
-
14
- def self.from_public_key(pk_bytes)
15
- public_key = RbNaCl::VerifyKey.new(pk_bytes)
16
- new(public_key)
17
- end
18
-
19
- def self.from_address(address)
20
- pk_bytes = Util::StrKey.check_decode(:account_id, address)
21
- from_public_key(pk_bytes)
22
- end
23
-
24
- def self.random
25
- secret_key = RbNaCl::SigningKey.generate
26
- public_key = secret_key.verify_key
27
- new(public_key, secret_key)
28
- end
29
-
30
- def self.from_network_passphrase(passphrase)
31
- network_id = Digest::SHA256.digest(passphrase)
32
- from_raw_seed network_id
33
- end
34
-
35
- def self.master
36
- from_raw_seed(Stellar.current_network_id)
37
- end
3
+ module FactoryMethods
4
+ def from_seed(seed)
5
+ seed_bytes = Util::StrKey.check_decode(:seed, seed)
6
+ from_raw_seed seed_bytes
7
+ end
8
+
9
+ def from_raw_seed(seed_bytes)
10
+ secret_key = RbNaCl::SigningKey.new(seed_bytes)
11
+ public_key = secret_key.verify_key
12
+ new(public_key, secret_key)
13
+ end
14
+
15
+ def from_public_key(pk_bytes)
16
+ public_key = RbNaCl::VerifyKey.new(pk_bytes)
17
+ new(public_key)
18
+ end
19
+
20
+ def from_address(address)
21
+ pk_bytes = Util::StrKey.check_decode(:account_id, address)
22
+ from_public_key(pk_bytes)
23
+ end
24
+
25
+ def random
26
+ secret_key = RbNaCl::SigningKey.generate
27
+ public_key = secret_key.verify_key
28
+ new(public_key, secret_key)
29
+ end
30
+
31
+ def from_network_passphrase(passphrase)
32
+ network_id = Digest::SHA256.digest(passphrase)
33
+ from_raw_seed network_id
34
+ end
35
+
36
+ def master
37
+ from_raw_seed(Stellar.current_network_id)
38
+ end
39
+ end
40
+
41
+ extend FactoryMethods
38
42
 
39
43
  def initialize(public_key, secret_key = nil)
40
44
  @public_key = public_key
@@ -115,5 +119,9 @@ module Stellar
115
119
  rescue RbNaCl::BadSignatureError
116
120
  false
117
121
  end
122
+
123
+ def to_keypair
124
+ self
125
+ end
118
126
  end
119
127
  end
@@ -0,0 +1,30 @@
1
+ require "stellar/convert"
2
+ require "stellar/dsl"
3
+
4
+ module Stellar
5
+ class LedgerKey
6
+ class << self
7
+ def switch_for_arm(name)
8
+ (@switch_by_arm ||= switches.invert).fetch(name)
9
+ end
10
+
11
+ def from(account_id:, **options)
12
+ field, value = options.first
13
+ case field
14
+ when nil
15
+ account(account_id: Stellar.KeyPair(account_id).account_id)
16
+ when :balance_id
17
+ claimable_balance(balance_id: ClaimableBalanceID.v0(Stellar::Convert.from_hex(value.to_s)))
18
+ when :offer_id
19
+ offer(seller_id: account_id, offer_id: Integer(value))
20
+ when :data_name
21
+ data(account_id: account_id, data_name: value.to_s)
22
+ when :asset
23
+ trust_line(account_id: account_id, asset: Stellar.Asset(value))
24
+ else
25
+ raise ArgumentError, "unknown option #{field} (not in :asset, :offer_id, :data_name, :balance_id)"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -12,18 +12,18 @@ module Stellar
12
12
  # methods of specifying a network if you need two threads in the same process to communicate with
13
13
  # different networks
14
14
  #
15
- # @see Stellar.default_network
16
15
  # @see Stellar.on_network
17
- def self.default_network=(passphrase)
18
- @default_network = passphrase
19
- end
16
+ mattr_accessor :default_network, default: Networks::TESTNET
17
+
18
+ # Stellar network passphrase selected for current thread
19
+ #
20
+ # @see Stellar.current_network
21
+ # @see Stellar.on_network
22
+ thread_mattr_accessor :network
20
23
 
21
- # Returns the passphrase for the currently-configured network, as set by Stellar.default_network
22
- # or Stellar.on_network
24
+ # Returns the passphrase for the network currently active per-thread with a fallback to `Stellar.default_network`
23
25
  def self.current_network
24
- Thread.current["stellar_network_passphrase"] ||
25
- @default_network ||
26
- Stellar::Networks::TESTNET
26
+ network.presence || default_network
27
27
  end
28
28
 
29
29
  # Returns the id for the currently configured network, suitable for use in generating
@@ -34,10 +34,10 @@ module Stellar
34
34
 
35
35
  # Executes the provided block in the context of the provided network.
36
36
  def self.on_network(passphrase, &block)
37
- old = Thread.current["stellar_network_passphrase"]
38
- Thread.current["stellar_network_passphrase"] = passphrase
37
+ old = network
38
+ self.network = passphrase
39
39
  block.call
40
40
  ensure
41
- Thread.current["stellar_network_passphrase"] = old
41
+ self.network = old
42
42
  end
43
43
  end
@@ -168,7 +168,6 @@ module Stellar
168
168
  }))
169
169
  end
170
170
 
171
- #
172
171
  # Helper method to create a valid ChangeTrustOp, wrapped
173
172
  # in the necessary XDR structs to be included within a
174
173
  # transactions `operations` array.
@@ -200,6 +199,64 @@ module Stellar
200
199
  }))
201
200
  end
202
201
 
202
+ # Helper method to create a valid CreateClaimableBalanceOp, ready to be used
203
+ # within a transactions `operations` array.
204
+ #
205
+ # @see Stellar::DSL::Claimant
206
+ # @see https://github.com/astroband/ruby-stellar-sdk/tree/master/base/examples/claimable_balances.rb
207
+ #
208
+ # @param asset [Asset] the asset to transfer to a claimable balance
209
+ # @param amount [Fixnum] the amount of `asset` to put into a claimable balance
210
+ # @param claimants [Array<Claimant>] accounts authorized to claim the balance in the future
211
+ #
212
+ # @return [Operation] the built operation
213
+ def create_claimable_balance(asset:, amount:, claimants:, **attributes)
214
+ op = CreateClaimableBalanceOp.new(asset: asset, amount: amount, claimants: claimants)
215
+
216
+ make(attributes.merge(body: [:create_claimable_balance, op]))
217
+ end
218
+
219
+ # Helper method to create a valid CreateClaimableBalanceOp, ready to be used
220
+ # within a transactions `operations` array.
221
+ #
222
+ # @see Stellar::DSL::Claimant
223
+ # @see https://github.com/astroband/ruby-stellar-sdk/tree/master/base/examples/claimable_balances.rb
224
+ #
225
+ # @param balance_id [ClaimableBalanceID] unique ID of claimable balance
226
+ #
227
+ # @return [Operation] the built operation, containing a Stellar::ChangeTrustOp body
228
+ def claim_claimable_balance(balance_id:, **attributes)
229
+ op = ClaimClaimableBalanceOp.new(balance_id: balance_id)
230
+
231
+ make(attributes.merge(body: [:claim_claimable_balance, op]))
232
+ end
233
+
234
+ def begin_sponsoring_future_reserves(sponsored:, **attributes)
235
+ op = BeginSponsoringFutureReservesOp.new(
236
+ sponsored_id: Stellar.KeyPair(sponsored).account_id
237
+ )
238
+
239
+ make(attributes.merge(body: [:begin_sponsoring_future_reserves, op]))
240
+ end
241
+
242
+ def end_sponsoring_future_reserves(**attributes)
243
+ make(attributes.merge(body: [:end_sponsoring_future_reserves]))
244
+ end
245
+
246
+ # @param sponsored [#to_keypair] owner of sponsored entry
247
+ def revoke_sponsorship(sponsored:, **attributes)
248
+ key_fields = attributes.slice(:offer_id, :data_name, :balance_id, :asset, :signer)
249
+ raise ArgumentError, "conflicting attributes: #{key_fields.keys.join(", ")}" if key_fields.size > 1
250
+ account_id = Stellar.KeyPair(sponsored).account_id
251
+ key, value = key_fields.first
252
+ op = if key == :signer
253
+ RevokeSponsorshipOp.signer(account_id: account_id, signer_key: Stellar.SignerKey(value))
254
+ else
255
+ RevokeSponsorshipOp.ledger_key(LedgerKey.from(account_id: account_id, **key_fields))
256
+ end
257
+ make(attributes.merge(body: [:revoke_sponsorship, op]))
258
+ end
259
+
203
260
  def manage_sell_offer(attributes = {})
204
261
  buying = attributes[:buying]
205
262
  if buying.is_a?(Array)
@@ -4,7 +4,12 @@ module Stellar
4
4
  MAX_PRECISION = (2**31) - 1
5
5
 
6
6
  def self.from_f(number)
7
- best_r = Util::ContinuedFraction.best_r(number, MAX_PRECISION)
7
+ best_r = number.to_r.rationalize(1.0e-7)
8
+
9
+ if best_r.numerator > MAX_PRECISION || best_r.denominator > MAX_PRECISION
10
+ raise ArgumentError("Couldn't find price approximation")
11
+ end
12
+
8
13
  new({
9
14
  n: best_r.numerator,
10
15
  d: best_r.denominator
@@ -15,8 +20,12 @@ module Stellar
15
20
  self.class.new(n: d, d: n)
16
21
  end
17
22
 
23
+ def to_d
24
+ n.to_d / d
25
+ end
26
+
18
27
  def to_f
19
- n / d.to_f
28
+ n.to_f / d
20
29
  end
21
30
 
22
31
  def to_s
@@ -2,174 +2,6 @@ module Stellar
2
2
  class Transaction
3
3
  include Stellar::Concerns::Transaction
4
4
 
5
- class << self
6
- #
7
- # @see Stellar::Operation.payment
8
- def payment(attributes = {})
9
- make :payment, attributes
10
- end
11
-
12
- #
13
- # @see Stellar::Operation.path_payment
14
- def path_payment(attributes = {})
15
- make :path_payment, attributes
16
- end
17
-
18
- #
19
- # @see Stellar::Operation.path_payment_strict_receive
20
- def path_payment_strict_receive(attributes = {})
21
- make :path_payment_strict_receive, attributes
22
- end
23
-
24
- #
25
- # @see Stellar::Operation.path_payment_strict_send
26
- def path_payment_strict_send(attributes = {})
27
- make :path_payment_strict_send, attributes
28
- end
29
-
30
- #
31
- # @see Stellar::Operation.create_account
32
- def create_account(attributes = {})
33
- make :create_account, attributes
34
- end
35
-
36
- #
37
- # @see Stellar::Operation.change_trust
38
- def change_trust(attributes = {})
39
- make :change_trust, attributes
40
- end
41
-
42
- #
43
- # @see Stellar::Operation.manage_sell_offer
44
- def manage_sell_offer(attributes = {})
45
- make :manage_sell_offer, attributes
46
- end
47
-
48
- #
49
- # @see Stellar::Operation.manage_buy_offer
50
- def manage_buy_offer(attributes = {})
51
- make :manage_buy_offer, attributes
52
- end
53
-
54
- #
55
- # @see Stellar::Operation.create_passive_sell_offer
56
- def create_passive_sell_offer(attributes = {})
57
- make :create_passive_sell_offer, attributes
58
- end
59
-
60
- #
61
- # @see Stellar::Operation.set_options
62
- def set_options(attributes = {})
63
- make :set_options, attributes
64
- end
65
-
66
- #
67
- # @see Stellar::Operation.allow_trust
68
- def allow_trust(attributes = {})
69
- make :allow_trust, attributes
70
- end
71
-
72
- #
73
- # @see Stellar::Operation.account_merge
74
- def account_merge(attributes = {})
75
- make :account_merge, attributes
76
- end
77
-
78
- #
79
- # @see Stellar::Operation.inflation
80
- def inflation(attributes = {})
81
- make :inflation, attributes
82
- end
83
-
84
- #
85
- # @see Stellar::Operation.manage_data
86
- def manage_data(attributes = {})
87
- make :manage_data, attributes
88
- end
89
-
90
- #
91
- # @see Stellar::Operation.manage_data
92
- def bump_sequence(attributes = {})
93
- make :bump_sequence, attributes
94
- end
95
-
96
- #
97
- # DEPRECATED
98
- #
99
- # All methods calling make() have been deprecated in favor of Stellar::TransactionBuilder.
100
- # These functions only create single-operation transactions and essentially duplicate the
101
- # methods provided by Stellar::Operation. Stellar::TransactionBuilder enables the construction
102
- # of multi-operation transactions and mirrors the functionality provided by the Python and
103
- # JavaScript SDKs.
104
- #
105
- # Helper method to create a transaction with a single
106
- # operation of the provided type. See class methods
107
- # on Stellar::Operation for available values for
108
- # operation_type.
109
- #
110
- # @see Stellar::Operation
111
- #
112
- # @param operation_type [Symbol] the operation to use
113
- # @param attributes={} [Hash] attributes to use for both the transaction and the operation
114
- #
115
- # @return [Stellar::Transaction] the resulting transaction
116
- def make(operation_type, attributes = {})
117
- Stellar::Deprecation.warn(
118
- "Transaction.#{operation_type} is deprecated. Use Stellar::TransactionBuilder instead."
119
- )
120
- for_account(attributes).tap do |result|
121
- result.operations << Operation.send(operation_type, attributes)
122
- end
123
- end
124
-
125
- #
126
- # Helper method to create the skeleton of a transaction.
127
- # The resulting transaction will have its source account,
128
- # sequence, fee, min ledger and max ledger set.
129
- #
130
- #
131
- # @param attributes={} [type] [description]
132
- #
133
- # @return [Stellar::Transaction] the resulting skeleton
134
- def for_account(attributes = {})
135
- account = attributes[:account]
136
- sequence = attributes[:sequence]
137
- fee = attributes[:fee]
138
-
139
- raise ArgumentError, "Bad :account" unless account.is_a?(KeyPair)
140
- raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer)
141
- raise ArgumentError, "Bad :fee #{sequence}" if fee.present? && !fee.is_a?(Integer)
142
-
143
- new.tap do |result|
144
- result.seq_num = sequence
145
- result.fee = fee
146
- result.memo = make_memo(attributes[:memo])
147
- result.source_account = account.muxed_account
148
- result.apply_defaults
149
- end
150
- end
151
-
152
- private
153
-
154
- def make_memo(memo)
155
- case memo
156
- when Stellar::Memo
157
- memo
158
- when nil
159
- nil
160
- when Integer
161
- Memo.new(:memo_id, memo)
162
- when String
163
- Memo.new(:memo_text, memo)
164
- when Array
165
- t, val = *memo
166
- Memo.new(:"memo_#{t}", val)
167
- else
168
- raise ArgumentError, "Bad :memo"
169
- end
170
- end
171
- end
172
-
173
5
  def to_v0
174
6
  ed25519 = if source_account.switch == Stellar::CryptoKeyType.key_type_ed25519
175
7
  source_account.ed25519!