stellar-base 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -6
  3. data/CHANGELOG.md +17 -2
  4. data/examples/allow_trust.rb +51 -0
  5. data/generated/stellar-base-generated.rb +14 -4
  6. data/generated/stellar/allow_trust_op.rb +2 -2
  7. data/generated/stellar/allow_trust_op/asset.rb +4 -4
  8. data/generated/stellar/asset.rb +2 -2
  9. data/generated/stellar/asset/alpha_num12.rb +2 -2
  10. data/generated/stellar/asset/alpha_num4.rb +2 -2
  11. data/generated/stellar/bucket_entry.rb +6 -0
  12. data/generated/stellar/bucket_entry_type.rb +8 -2
  13. data/generated/stellar/bucket_metadata.rb +32 -0
  14. data/generated/stellar/bucket_metadata/ext.rb +24 -0
  15. data/generated/stellar/change_trust_result_code.rb +1 -1
  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/envelope_type.rb +6 -4
  19. data/generated/stellar/ledger_close_value_signature.rb +20 -0
  20. data/generated/stellar/ledger_key.rb +1 -1
  21. data/generated/stellar/ledger_key/offer.rb +2 -2
  22. data/generated/stellar/manage_buy_offer_op.rb +29 -0
  23. data/generated/stellar/{manage_offer_result.rb → manage_buy_offer_result.rb} +5 -5
  24. data/generated/stellar/manage_buy_offer_result_code.rb +50 -0
  25. data/generated/stellar/{manage_offer_op.rb → manage_sell_offer_op.rb} +4 -4
  26. data/generated/stellar/manage_sell_offer_result.rb +26 -0
  27. data/generated/stellar/manage_sell_offer_result_code.rb +50 -0
  28. data/generated/stellar/offer_entry.rb +2 -2
  29. data/generated/stellar/operation.rb +6 -4
  30. data/generated/stellar/operation/body.rb +30 -26
  31. data/generated/stellar/operation_result.rb +6 -4
  32. data/generated/stellar/operation_result/tr.rb +32 -28
  33. data/generated/stellar/operation_result_code.rb +9 -5
  34. data/generated/stellar/operation_type.rb +17 -15
  35. data/generated/stellar/signer.rb +1 -1
  36. data/generated/stellar/stellar_value.rb +7 -5
  37. data/generated/stellar/stellar_value/ext.rb +8 -4
  38. data/generated/stellar/stellar_value_type.rb +22 -0
  39. data/generated/stellar/time_bounds.rb +4 -4
  40. data/generated/stellar/transaction.rb +2 -2
  41. data/generated/stellar/transaction_meta_v1.rb +1 -1
  42. data/lib/stellar-base.rb +2 -0
  43. data/lib/stellar/base/compat.rb +22 -0
  44. data/lib/stellar/base/version.rb +1 -1
  45. data/lib/stellar/operation.rb +27 -7
  46. data/lib/stellar/transaction.rb +12 -6
  47. data/spec/lib/stellar/price_spec.rb +3 -3
  48. data/tasks/xdr.rake +34 -39
  49. data/xdr/Stellar-ledger-entries.x +13 -6
  50. data/xdr/Stellar-ledger.x +45 -10
  51. data/xdr/Stellar-transaction.x +103 -46
  52. metadata +16 -7
  53. data/generated/stellar/manage_offer_result_code.rb +0 -50
@@ -11,16 +11,20 @@ require 'xdr'
11
11
  #
12
12
  # opBAD_AUTH = -1, // too few valid signatures / wrong network
13
13
  # opNO_ACCOUNT = -2, // source account was not found
14
- # opNOT_SUPPORTED = -3 // operation not supported at this time
14
+ # opNOT_SUPPORTED = -3, // operation not supported at this time
15
+ # opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached
16
+ # opEXCEEDED_WORK_LIMIT = -5 // operation did too much work
15
17
  # };
16
18
  #
17
19
  # ===========================================================================
18
20
  module Stellar
19
21
  class OperationResultCode < XDR::Enum
20
- member :op_inner, 0
21
- member :op_bad_auth, -1
22
- member :op_no_account, -2
23
- member :op_not_supported, -3
22
+ member :op_inner, 0
23
+ member :op_bad_auth, -1
24
+ member :op_no_account, -2
25
+ member :op_not_supported, -3
26
+ member :op_too_many_subentries, -4
27
+ member :op_exceeded_work_limit, -5
24
28
 
25
29
  seal
26
30
  end
@@ -10,32 +10,34 @@ require 'xdr'
10
10
  # CREATE_ACCOUNT = 0,
11
11
  # PAYMENT = 1,
12
12
  # PATH_PAYMENT = 2,
13
- # MANAGE_OFFER = 3,
14
- # CREATE_PASSIVE_OFFER = 4,
13
+ # MANAGE_SELL_OFFER = 3,
14
+ # CREATE_PASSIVE_SELL_OFFER = 4,
15
15
  # SET_OPTIONS = 5,
16
16
  # CHANGE_TRUST = 6,
17
17
  # ALLOW_TRUST = 7,
18
18
  # ACCOUNT_MERGE = 8,
19
19
  # INFLATION = 9,
20
20
  # MANAGE_DATA = 10,
21
- # BUMP_SEQUENCE = 11
21
+ # BUMP_SEQUENCE = 11,
22
+ # MANAGE_BUY_OFFER = 12
22
23
  # };
23
24
  #
24
25
  # ===========================================================================
25
26
  module Stellar
26
27
  class OperationType < XDR::Enum
27
- member :create_account, 0
28
- member :payment, 1
29
- member :path_payment, 2
30
- member :manage_offer, 3
31
- member :create_passive_offer, 4
32
- member :set_options, 5
33
- member :change_trust, 6
34
- member :allow_trust, 7
35
- member :account_merge, 8
36
- member :inflation, 9
37
- member :manage_data, 10
38
- member :bump_sequence, 11
28
+ member :create_account, 0
29
+ member :payment, 1
30
+ member :path_payment, 2
31
+ member :manage_sell_offer, 3
32
+ member :create_passive_sell_offer, 4
33
+ member :set_options, 5
34
+ member :change_trust, 6
35
+ member :allow_trust, 7
36
+ member :account_merge, 8
37
+ member :inflation, 9
38
+ member :manage_data, 10
39
+ member :bump_sequence, 11
40
+ member :manage_buy_offer, 12
39
41
 
40
42
  seal
41
43
  end
@@ -8,7 +8,7 @@ require 'xdr'
8
8
  # struct Signer
9
9
  # {
10
10
  # SignerKey key;
11
- # uint32 weight; // really only need 1byte
11
+ # uint32 weight; // really only need 1 byte
12
12
  # };
13
13
  #
14
14
  # ===========================================================================
@@ -7,8 +7,8 @@ require 'xdr'
7
7
  #
8
8
  # struct StellarValue
9
9
  # {
10
- # Hash txSetHash; // transaction set to apply to previous ledger
11
- # uint64 closeTime; // network close time
10
+ # Hash txSetHash; // transaction set to apply to previous ledger
11
+ # TimePoint closeTime; // network close time
12
12
  #
13
13
  # // upgrades to apply to the previous ledger (usually empty)
14
14
  # // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop
@@ -18,10 +18,12 @@ require 'xdr'
18
18
  # UpgradeType upgrades<6>;
19
19
  #
20
20
  # // reserved for future use
21
- # union switch (int v)
21
+ # union switch (StellarValueType v)
22
22
  # {
23
- # case 0:
23
+ # case STELLAR_VALUE_BASIC:
24
24
  # void;
25
+ # case STELLAR_VALUE_SIGNED:
26
+ # LedgerCloseValueSignature lcValueSignature;
25
27
  # }
26
28
  # ext;
27
29
  # };
@@ -34,7 +36,7 @@ module Stellar
34
36
  autoload :Ext
35
37
 
36
38
  attribute :tx_set_hash, Hash
37
- attribute :close_time, Uint64
39
+ attribute :close_time, TimePoint
38
40
  attribute :upgrades, XDR::VarArray[UpgradeType, 6]
39
41
  attribute :ext, Ext
40
42
  end
@@ -5,20 +5,24 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # union switch (int v)
8
+ # union switch (StellarValueType v)
9
9
  # {
10
- # case 0:
10
+ # case STELLAR_VALUE_BASIC:
11
11
  # void;
12
+ # case STELLAR_VALUE_SIGNED:
13
+ # LedgerCloseValueSignature lcValueSignature;
12
14
  # }
13
15
  #
14
16
  # ===========================================================================
15
17
  module Stellar
16
18
  class StellarValue
17
19
  class Ext < XDR::Union
18
- switch_on XDR::Int, :v
20
+ switch_on StellarValueType, :v
19
21
 
20
- switch 0
22
+ switch :stellar_value_basic
23
+ switch :stellar_value_signed, :lc_value_signature
21
24
 
25
+ attribute :lc_value_signature, LedgerCloseValueSignature
22
26
  end
23
27
  end
24
28
  end
@@ -0,0 +1,22 @@
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
+ # enum StellarValueType
9
+ # {
10
+ # STELLAR_VALUE_BASIC = 0,
11
+ # STELLAR_VALUE_SIGNED = 1
12
+ # };
13
+ #
14
+ # ===========================================================================
15
+ module Stellar
16
+ class StellarValueType < XDR::Enum
17
+ member :stellar_value_basic, 0
18
+ member :stellar_value_signed, 1
19
+
20
+ seal
21
+ end
22
+ end
@@ -7,14 +7,14 @@ require 'xdr'
7
7
  #
8
8
  # struct TimeBounds
9
9
  # {
10
- # uint64 minTime;
11
- # uint64 maxTime; // 0 here means no maxTime
10
+ # TimePoint minTime;
11
+ # TimePoint maxTime; // 0 here means no maxTime
12
12
  # };
13
13
  #
14
14
  # ===========================================================================
15
15
  module Stellar
16
16
  class TimeBounds < XDR::Struct
17
- attribute :min_time, Uint64
18
- attribute :max_time, Uint64
17
+ attribute :min_time, TimePoint
18
+ attribute :max_time, TimePoint
19
19
  end
20
20
  end
@@ -21,7 +21,7 @@ require 'xdr'
21
21
  #
22
22
  # Memo memo;
23
23
  #
24
- # Operation operations<100>;
24
+ # Operation operations<MAX_OPS_PER_TX>;
25
25
  #
26
26
  # // reserved for future use
27
27
  # union switch (int v)
@@ -44,7 +44,7 @@ module Stellar
44
44
  attribute :seq_num, SequenceNumber
45
45
  attribute :time_bounds, XDR::Option[TimeBounds]
46
46
  attribute :memo, Memo
47
- attribute :operations, XDR::VarArray[Operation, 100]
47
+ attribute :operations, XDR::VarArray[Operation, MAX_OPS_PER_TX]
48
48
  attribute :ext, Ext
49
49
  end
50
50
  end
@@ -8,7 +8,7 @@ require 'xdr'
8
8
  # struct TransactionMetaV1
9
9
  # {
10
10
  # LedgerEntryChanges txChanges; // tx level changes if any
11
- # OperationMeta operations<>; // meta for each operation
11
+ # OperationMeta operations<>; // meta for each operation
12
12
  # };
13
13
  #
14
14
  # ===========================================================================
@@ -31,3 +31,5 @@ require_relative './stellar/util/continued_fraction'
31
31
  require_relative './stellar/convert'
32
32
  require_relative './stellar/networks'
33
33
  require_relative './stellar/base/version'
34
+
35
+ require_relative './stellar/base/compat'
@@ -0,0 +1,22 @@
1
+ require 'active_support/deprecation'
2
+
3
+ Stellar::Deprecation ||= ActiveSupport::Deprecation.new('next release', 'stellar-base')
4
+
5
+ class << Stellar::Operation
6
+ alias_method :manage_offer, :manage_sell_offer
7
+ alias_method :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_method :manage_offer, :manage_sell_offer
16
+ alias_method :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
22
+
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.19.0"
3
+ VERSION = "0.20.0"
4
4
  end
5
5
  end
@@ -141,14 +141,14 @@ module Stellar
141
141
  }))
142
142
  end
143
143
 
144
- def self.manage_offer(attributes={})
144
+ def self.manage_sell_offer(attributes={})
145
145
  buying = Asset.send(*attributes[:buying])
146
146
  selling = Asset.send(*attributes[:selling])
147
147
  amount = interpret_amount(attributes[:amount])
148
148
  offer_id = attributes[:offer_id] || 0
149
149
  price = interpret_price(attributes[:price])
150
150
 
151
- op = ManageOfferOp.new({
151
+ op = ManageSellOfferOp.new({
152
152
  buying: buying,
153
153
  selling: selling,
154
154
  amount: amount,
@@ -157,17 +157,37 @@ module Stellar
157
157
  })
158
158
 
159
159
  return make(attributes.merge({
160
- body:[:manage_offer, op]
160
+ body:[:manage_sell_offer, op]
161
161
  }))
162
162
  end
163
163
 
164
- def self.create_passive_offer(attributes={})
164
+ def self.manage_buy_offer(attributes={})
165
+ buying = Asset.send(*attributes[:buying])
166
+ selling = Asset.send(*attributes[:selling])
167
+ amount = interpret_amount(attributes[:amount])
168
+ offer_id = attributes[:offer_id] || 0
169
+ price = interpret_price(attributes[:price])
170
+
171
+ op = ManageBuyOfferOp.new({
172
+ buying: buying,
173
+ selling: selling,
174
+ amount: amount,
175
+ price: price,
176
+ offer_id: offer_id
177
+ })
178
+
179
+ return make(attributes.merge({
180
+ body:[:manage_buy_offer, op]
181
+ }))
182
+ end
183
+
184
+ def self.create_passive_sell_offer(attributes={})
165
185
  buying = Asset.send(*attributes[:buying])
166
186
  selling = Asset.send(*attributes[:selling])
167
187
  amount = interpret_amount(attributes[:amount])
168
188
  price = interpret_price(attributes[:price])
169
189
 
170
- op = CreatePassiveOfferOp.new({
190
+ op = CreatePassiveSellOfferOp.new({
171
191
  buying: buying,
172
192
  selling: selling,
173
193
  amount: amount,
@@ -175,7 +195,7 @@ module Stellar
175
195
  })
176
196
 
177
197
  return make(attributes.merge({
178
- body:[:create_passive_offer, op]
198
+ body:[:create_passive_sell_offer, op]
179
199
  }))
180
200
  end
181
201
 
@@ -340,7 +360,7 @@ module Stellar
340
360
  def self.interpret_amount(amount)
341
361
  case amount
342
362
  when String
343
- (BigDecimal.new(amount) * Stellar::ONE).floor
363
+ (BigDecimal(amount) * Stellar::ONE).floor
344
364
  when Integer
345
365
  amount * Stellar::ONE
346
366
  when Numeric
@@ -26,15 +26,21 @@ module Stellar
26
26
  end
27
27
 
28
28
  #
29
- # @see Stellar::Operation.create_offer
30
- def self.manage_offer(attributes={})
31
- make :manage_offer, attributes
29
+ # @see Stellar::Operation.manage_sell_offer
30
+ def self.manage_sell_offer(attributes={})
31
+ make :manage_sell_offer, attributes
32
32
  end
33
33
 
34
34
  #
35
- # @see Stellar::Operation.create_passive_offer
36
- def self.create_passive_offer(attributes={})
37
- make :create_passive_offer, attributes
35
+ # @see Stellar::Operation.manage_buy_offer
36
+ def self.manage_buy_offer(attributes={})
37
+ make :manage_buy_offer, attributes
38
+ end
39
+
40
+ #
41
+ # @see Stellar::Operation.create_passive_sell_offer
42
+ def self.create_passive_sell_offer(attributes={})
43
+ make :create_passive_sell_offer, attributes
38
44
  end
39
45
 
40
46
  #
@@ -22,11 +22,11 @@ describe Stellar::Price, "#from_f" do
22
22
  whole = random.rand(1_000_000)
23
23
  fractional = random.rand(10_000_000) # seven significant digits available for fractional
24
24
 
25
- expected = BigDecimal.new("#{whole}.#{fractional}")
25
+ expected = BigDecimal("#{whole}.#{fractional}")
26
26
  actual_p = subject.from_f(expected)
27
- actual = BigDecimal.new(actual_p.n) / BigDecimal.new(actual_p.d)
27
+ actual = BigDecimal(actual_p.n) / BigDecimal(actual_p.d)
28
28
 
29
- expect(actual).to be_within(BigDecimal.new("0.000000001")).of(actual)
29
+ expect(actual).to be_within(BigDecimal("0.000000001")).of(actual)
30
30
  expect(actual_p.n).to be <= Stellar::Price::MAX_PRECISION
31
31
  expect(actual_p.d).to be <= Stellar::Price::MAX_PRECISION
32
32
  end
@@ -1,50 +1,45 @@
1
1
  namespace :xdr do
2
-
3
- # As Hayashi adds more .x files, we'll need to update this array
4
- # Prior to launch, we should be separating our .x files into a separate
5
- # repo, and should be able to improve this integration.
6
- HAYASHI_XDR = [
7
- "src/xdr/Stellar-types.x",
8
- "src/xdr/Stellar-ledger-entries.x",
9
- "src/xdr/Stellar-transaction.x",
10
- "src/xdr/Stellar-ledger.x",
11
- "src/xdr/Stellar-overlay.x",
12
- "src/xdr/Stellar-SCP.x",
13
- ]
14
-
15
- LOCAL_XDR_PATHS = HAYASHI_XDR.map{ |src| "xdr/" + File.basename(src) }
16
-
17
- task :update => [:download, :generate]
18
-
19
- task :download do
20
- require 'octokit'
21
- require 'base64'
22
- FileUtils.rm_rf "xdr/"
23
- FileUtils.mkdir_p "xdr"
24
-
25
- client = Octokit::Client.new(:netrc => true)
26
-
27
- HAYASHI_XDR.each do |src|
28
- local_path = "xdr/" + File.basename(src)
29
- encoded = client.contents("stellar/stellar-core", path: src).content
30
- decoded = Base64.decode64 encoded
31
-
32
- IO.write(local_path, decoded)
33
- end
34
- end
35
-
36
- task :generate do
37
- require "pathname"
2
+ xdr_defs = FileList[
3
+ 'xdr/Stellar-types.x',
4
+ 'xdr/Stellar-ledger-entries.x',
5
+ 'xdr/Stellar-transaction.x',
6
+ 'xdr/Stellar-ledger.x',
7
+ 'xdr/Stellar-overlay.x',
8
+ 'xdr/Stellar-SCP.x',
9
+ ]
10
+
11
+ task :update, [:ref] => [:clean, :generate]
12
+ task :generate => 'generated/stellar-base-generated.rb'
13
+
14
+ directory 'xdr'
15
+ directory 'generated'
16
+
17
+ file 'generated/stellar-base-generated.rb' => xdr_defs do |t|
38
18
  require "xdrgen"
39
- require 'fileutils'
40
- FileUtils.rm_rf "generated"
41
19
 
42
20
  compilation = Xdrgen::Compilation.new(
43
- LOCAL_XDR_PATHS,
21
+ t.sources,
44
22
  output_dir: "generated",
45
23
  namespace: "stellar-base-generated",
46
24
  language: :ruby
47
25
  )
48
26
  compilation.compile
49
27
  end
28
+
29
+ rule '.x', [:ref] => ['xdr'] do |t, args|
30
+ args.with_defaults(ref: :master)
31
+ core_file = github_client.contents("stellar/stellar-core", path: "src/#{t.name}", ref: args.ref)
32
+ IO.write(t.name, core_file.rels[:download].get.data)
33
+ end
34
+
35
+ task :clean do
36
+ rm_rf 'xdr'
37
+ rm_rf 'generated'
38
+ end
39
+
40
+ def github_client
41
+ return @github_client if defined?(@github_client)
42
+ require 'octokit'
43
+ @github_client = Octokit::Client.new(netrc: true)
44
+ end
50
45
  end