stellar-base 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -6
- data/CHANGELOG.md +17 -2
- data/examples/allow_trust.rb +51 -0
- data/generated/stellar-base-generated.rb +14 -4
- data/generated/stellar/allow_trust_op.rb +2 -2
- data/generated/stellar/allow_trust_op/asset.rb +4 -4
- data/generated/stellar/asset.rb +2 -2
- data/generated/stellar/asset/alpha_num12.rb +2 -2
- data/generated/stellar/asset/alpha_num4.rb +2 -2
- data/generated/stellar/bucket_entry.rb +6 -0
- data/generated/stellar/bucket_entry_type.rb +8 -2
- data/generated/stellar/bucket_metadata.rb +32 -0
- data/generated/stellar/bucket_metadata/ext.rb +24 -0
- data/generated/stellar/change_trust_result_code.rb +1 -1
- data/generated/stellar/claim_offer_atom.rb +2 -2
- data/generated/stellar/{create_passive_offer_op.rb → create_passive_sell_offer_op.rb} +2 -2
- data/generated/stellar/envelope_type.rb +6 -4
- data/generated/stellar/ledger_close_value_signature.rb +20 -0
- data/generated/stellar/ledger_key.rb +1 -1
- data/generated/stellar/ledger_key/offer.rb +2 -2
- data/generated/stellar/manage_buy_offer_op.rb +29 -0
- data/generated/stellar/{manage_offer_result.rb → manage_buy_offer_result.rb} +5 -5
- data/generated/stellar/manage_buy_offer_result_code.rb +50 -0
- data/generated/stellar/{manage_offer_op.rb → manage_sell_offer_op.rb} +4 -4
- data/generated/stellar/manage_sell_offer_result.rb +26 -0
- data/generated/stellar/manage_sell_offer_result_code.rb +50 -0
- data/generated/stellar/offer_entry.rb +2 -2
- data/generated/stellar/operation.rb +6 -4
- data/generated/stellar/operation/body.rb +30 -26
- data/generated/stellar/operation_result.rb +6 -4
- data/generated/stellar/operation_result/tr.rb +32 -28
- data/generated/stellar/operation_result_code.rb +9 -5
- data/generated/stellar/operation_type.rb +17 -15
- data/generated/stellar/signer.rb +1 -1
- data/generated/stellar/stellar_value.rb +7 -5
- data/generated/stellar/stellar_value/ext.rb +8 -4
- data/generated/stellar/stellar_value_type.rb +22 -0
- data/generated/stellar/time_bounds.rb +4 -4
- data/generated/stellar/transaction.rb +2 -2
- data/generated/stellar/transaction_meta_v1.rb +1 -1
- data/lib/stellar-base.rb +2 -0
- data/lib/stellar/base/compat.rb +22 -0
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/operation.rb +27 -7
- data/lib/stellar/transaction.rb +12 -6
- data/spec/lib/stellar/price_spec.rb +3 -3
- data/tasks/xdr.rake +34 -39
- data/xdr/Stellar-ledger-entries.x +13 -6
- data/xdr/Stellar-ledger.x +45 -10
- data/xdr/Stellar-transaction.x +103 -46
- metadata +16 -7
- 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,
|
21
|
-
member :op_bad_auth,
|
22
|
-
member :op_no_account,
|
23
|
-
member :op_not_supported,
|
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
|
-
#
|
14
|
-
#
|
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,
|
28
|
-
member :payment,
|
29
|
-
member :path_payment,
|
30
|
-
member :
|
31
|
-
member :
|
32
|
-
member :set_options,
|
33
|
-
member :change_trust,
|
34
|
-
member :allow_trust,
|
35
|
-
member :account_merge,
|
36
|
-
member :inflation,
|
37
|
-
member :manage_data,
|
38
|
-
member :bump_sequence,
|
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
|
data/generated/stellar/signer.rb
CHANGED
@@ -7,8 +7,8 @@ require 'xdr'
|
|
7
7
|
#
|
8
8
|
# struct StellarValue
|
9
9
|
# {
|
10
|
-
# Hash txSetHash;
|
11
|
-
#
|
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 (
|
21
|
+
# union switch (StellarValueType v)
|
22
22
|
# {
|
23
|
-
# case
|
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,
|
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 (
|
8
|
+
# union switch (StellarValueType v)
|
9
9
|
# {
|
10
|
-
# case
|
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
|
20
|
+
switch_on StellarValueType, :v
|
19
21
|
|
20
|
-
switch
|
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
|
-
#
|
11
|
-
#
|
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,
|
18
|
-
attribute :max_time,
|
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<
|
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,
|
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<>;
|
11
|
+
# OperationMeta operations<>; // meta for each operation
|
12
12
|
# };
|
13
13
|
#
|
14
14
|
# ===========================================================================
|
data/lib/stellar-base.rb
CHANGED
@@ -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
|
+
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/operation.rb
CHANGED
@@ -141,14 +141,14 @@ module Stellar
|
|
141
141
|
}))
|
142
142
|
end
|
143
143
|
|
144
|
-
def self.
|
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 =
|
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:[:
|
160
|
+
body:[:manage_sell_offer, op]
|
161
161
|
}))
|
162
162
|
end
|
163
163
|
|
164
|
-
def self.
|
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 =
|
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:[:
|
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
|
363
|
+
(BigDecimal(amount) * Stellar::ONE).floor
|
344
364
|
when Integer
|
345
365
|
amount * Stellar::ONE
|
346
366
|
when Numeric
|
data/lib/stellar/transaction.rb
CHANGED
@@ -26,15 +26,21 @@ module Stellar
|
|
26
26
|
end
|
27
27
|
|
28
28
|
#
|
29
|
-
# @see Stellar::Operation.
|
30
|
-
def self.
|
31
|
-
make :
|
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.
|
36
|
-
def self.
|
37
|
-
make :
|
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
|
25
|
+
expected = BigDecimal("#{whole}.#{fractional}")
|
26
26
|
actual_p = subject.from_f(expected)
|
27
|
-
actual = BigDecimal
|
27
|
+
actual = BigDecimal(actual_p.n) / BigDecimal(actual_p.d)
|
28
28
|
|
29
|
-
expect(actual).to be_within(BigDecimal
|
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
|
data/tasks/xdr.rake
CHANGED
@@ -1,50 +1,45 @@
|
|
1
1
|
namespace :xdr do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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
|