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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee9599bb2ea3b55e55516019cbe4afaa3905d8791eb807cfa3f8e7d1fd45c8cc
4
- data.tar.gz: 61f3f0d3b1627831ef9a386083963a88a3ab93df1e0d7c2ea949a02213e8b905
3
+ metadata.gz: 3b8dff89d6b3abd5d98273482fba0c6f8eb53dad18fb7ec52db7b92cc39f9f55
4
+ data.tar.gz: 1d33ebd79f033631a5a0bc3e9ff007c120a5318da4210b4af02b32c2a92b01ca
5
5
  SHA512:
6
- metadata.gz: 27ff0126aed943226f8b8c27e947de7d064ff1811b869b2a35366aa97a045cd964a98ba1e6651e70c8d2faf38cf9c798dd2f920f22ae91e2ebfb557cab4eef1f
7
- data.tar.gz: d4708f217a557fb3a393186dab70fbf2b2bbcf4cf0102e216339ab89a0aba3dc83e90bcaf9f6263dc330f0b5fc97dcbe5148638e60bd259c221153badcfe02fb
6
+ metadata.gz: ed5867a1d348e71b9d8c2075fedadb9028eefd227b0db6f634d33b29c98413dea0b9f8c5684f5be703eec2cc1b1311167093131bf5d367b8bbc678f9bc63500d
7
+ data.tar.gz: fd80f67dda204736abd078f1f64617ca93534e02baffd59042f7512d83e9603408ffc1df81f4b8c344416460fb8956d199a33727e54d4211f32bad2207495701
@@ -1,12 +1,15 @@
1
+ dist: xenial
1
2
  language: ruby
2
3
  rvm:
3
- - 2.5.1
4
- - 2.6.2
4
+ - 2.5
5
+ - 2.6
6
+ cache: bundler
7
+ addons:
8
+ apt:
9
+ packages:
10
+ - libsodium-dev
5
11
  before_install:
6
- - sudo add-apt-repository -y ppa:chris-lea/libsodium
7
- - sudo apt-get -y update
8
- - sudo apt-get install -y libsodium-dev
9
- - gem update bundler
12
+ - gem update --system && gem install --no-document bundler
10
13
  script: bundle exec rake travis
11
14
  notifications:
12
15
  slack:
@@ -6,13 +6,28 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
6
6
  As this project is pre 1.0, breaking changes may happen for minor version
7
7
  bumps. A breaking change will get clearly notified in this log.
8
8
 
9
- ## [0.19.0](https://github.com/stellar/ruby-stellar-base/compare/v0.17.0...master)
9
+ ## [0.20.0](https://github.com/stellar/ruby-stellar-base/compare/v0.19.0...master) - 2019-05-22
10
+ ### Added
11
+ - Stellar Protocol 11 compatibility (#48)
12
+ - XDR changes for [CAP-0006 Buy Offers](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0006.md)
13
+ - XDR changes for [CAP-0020 Bucket Initial Entries](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0020.md)
14
+ - Add `manage_buy_offer`, `manage_sell_offer` and `create_passive_sell_offer` factory methods to `Stellar::Transaction` and `Stellar::Operation`
15
+
16
+ ### Changed
17
+ - Deprecate `manage_offer` and `create_passive_offer` factory methods in `Stellar::Transaction` and `Stellar::Operation`
18
+ - Add an option to pass the exact stellar-core revision into `xdr:update` Rake task
19
+
20
+ ## [0.19.0](https://github.com/stellar/ruby-stellar-base/compare/v0.18.0...v0.19.0)
21
+ ### Changed
22
+ - Loosen ActiveSupport to >= 5.0.0
23
+
24
+ ## [0.18.0](https://github.com/stellar/ruby-stellar-base/compare/v0.17.0...v0.18.0)
10
25
  ### Added
11
26
  - Update XDR definitions for stellar-core v10.0.0 (introduces Liabilities and other changes to support asset-backed offers as per [CAP-0003 Specification](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0003.md#specification))
27
+ - Add factories for ledger, transaction, operation.
12
28
 
13
29
  ### Changed
14
30
  - Use rbnacl instead of rbnacl-libsodium (the latter has been [deprecated](https://github.com/crypto-rb/rbnacl-libsodium/issues/29))
15
- - Loosen ActiveSupport to >= 5.0.0
16
31
 
17
32
  ## [0.17.0](https://github.com/stellar/ruby-stellar-base/compare/v0.16.0...v0.17.0)
18
33
  ### Fixed
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rest-client'
4
+ require 'stellar-base'
5
+
6
+ # This is an example of using a higher level allow_trust operation.
7
+ # This assumes that a stellar account is already created and a trustline
8
+ # to an anchor's asset has been established.
9
+
10
+ HUG_ASSET_CODE = 'HUG'
11
+
12
+ def sequence_from_account(account)
13
+ data = get_account_data(account)
14
+ data['sequence'].to_i
15
+ end
16
+
17
+ def get_account_data(keypair, network_url)
18
+ response = RestClient.get "#{network_url}/accounts/#{keypair.address}"
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def submit_transaction_operation(xdr_envelope, network_url)
23
+ begin
24
+ response = RestClient.post "#{network_url}/transactions", { tx: xdr_envelope }
25
+ JSON.parse(response.body)
26
+
27
+ rescue RestClient::ExceptionWithResponse => e
28
+ # handle exceptions here
29
+ end
30
+ end
31
+
32
+ def allow_trust(address, issuer_keypair)
33
+ account = Stellar::KeyPair.from_address(address)
34
+ current_sequence = sequence_from_account(issuer_keypair)
35
+
36
+ tx = Stellar::Transaction.allow_trust({
37
+ trustor: account,
38
+ account: issuer_keypair,
39
+ asset: [:alphanum4, HUG_ASSET_CODE, issuer_keypair],
40
+ authorize: true,
41
+ sequence: current_sequence + 1,
42
+ })
43
+
44
+ xdr_envelope = tx.to_envelope(issuer_keypair).to_xdr(:base64)
45
+ submit_transaction_operation(xdr_envelope)
46
+ end
47
+
48
+ # Usage:
49
+ # issuer_keypair must be a keypair from an anchor with both the public and
50
+ # private key i.e type Stellar::KeyPair
51
+ allow_trust("GCHOWITWOUNRUXGJWYUB4IMICZKROLHDRC2TJH5W324LBJVM4JUVXOZL", issuer_keypair)
@@ -33,7 +33,10 @@ module Stellar
33
33
  String32 = XDR::String[32]
34
34
  String64 = XDR::String[64]
35
35
  SequenceNumber = Int64
36
+ TimePoint = Uint64
36
37
  DataValue = XDR::VarOpaque[64]
38
+ AssetCode4 = XDR::Opaque[4]
39
+ AssetCode12 = XDR::Opaque[12]
37
40
  autoload :AssetType
38
41
  autoload :Asset
39
42
  autoload :Price
@@ -62,8 +65,9 @@ module Stellar
62
65
  autoload :CreateAccountOp
63
66
  autoload :PaymentOp
64
67
  autoload :PathPaymentOp
65
- autoload :ManageOfferOp
66
- autoload :CreatePassiveOfferOp
68
+ autoload :ManageSellOfferOp
69
+ autoload :ManageBuyOfferOp
70
+ autoload :CreatePassiveSellOfferOp
67
71
  autoload :SetOptionsOp
68
72
  autoload :ChangeTrustOp
69
73
  autoload :AllowTrustOp
@@ -73,6 +77,7 @@ module Stellar
73
77
  autoload :MemoType
74
78
  autoload :Memo
75
79
  autoload :TimeBounds
80
+ MAX_OPS_PER_TX = 100
76
81
  autoload :Transaction
77
82
  autoload :TransactionSignaturePayload
78
83
  autoload :TransactionEnvelope
@@ -84,10 +89,12 @@ module Stellar
84
89
  autoload :PathPaymentResultCode
85
90
  autoload :SimplePaymentResult
86
91
  autoload :PathPaymentResult
87
- autoload :ManageOfferResultCode
92
+ autoload :ManageSellOfferResultCode
88
93
  autoload :ManageOfferEffect
89
94
  autoload :ManageOfferSuccessResult
90
- autoload :ManageOfferResult
95
+ autoload :ManageSellOfferResult
96
+ autoload :ManageBuyOfferResultCode
97
+ autoload :ManageBuyOfferResult
91
98
  autoload :SetOptionsResultCode
92
99
  autoload :SetOptionsResult
93
100
  autoload :ChangeTrustResultCode
@@ -112,12 +119,15 @@ module Stellar
112
119
  include XDR::Namespace
113
120
 
114
121
  UpgradeType = XDR::VarOpaque[128]
122
+ autoload :StellarValueType
123
+ autoload :LedgerCloseValueSignature
115
124
  autoload :StellarValue
116
125
  autoload :LedgerHeader
117
126
  autoload :LedgerUpgradeType
118
127
  autoload :LedgerUpgrade
119
128
  autoload :LedgerKey
120
129
  autoload :BucketEntryType
130
+ autoload :BucketMetadata
121
131
  autoload :BucketEntry
122
132
  autoload :TransactionSet
123
133
  autoload :TransactionResultPair
@@ -12,10 +12,10 @@ require 'xdr'
12
12
  # {
13
13
  # // ASSET_TYPE_NATIVE is not allowed
14
14
  # case ASSET_TYPE_CREDIT_ALPHANUM4:
15
- # opaque assetCode4[4];
15
+ # AssetCode4 assetCode4;
16
16
  #
17
17
  # case ASSET_TYPE_CREDIT_ALPHANUM12:
18
- # opaque assetCode12[12];
18
+ # AssetCode12 assetCode12;
19
19
  #
20
20
  # // add other asset types here in the future
21
21
  # }
@@ -9,10 +9,10 @@ require 'xdr'
9
9
  # {
10
10
  # // ASSET_TYPE_NATIVE is not allowed
11
11
  # case ASSET_TYPE_CREDIT_ALPHANUM4:
12
- # opaque assetCode4[4];
12
+ # AssetCode4 assetCode4;
13
13
  #
14
14
  # case ASSET_TYPE_CREDIT_ALPHANUM12:
15
- # opaque assetCode12[12];
15
+ # AssetCode12 assetCode12;
16
16
  #
17
17
  # // add other asset types here in the future
18
18
  # }
@@ -26,8 +26,8 @@ module Stellar
26
26
  switch :asset_type_credit_alphanum4, :asset_code4
27
27
  switch :asset_type_credit_alphanum12, :asset_code12
28
28
 
29
- attribute :asset_code4, XDR::Opaque[4]
30
- attribute :asset_code12, XDR::Opaque[12]
29
+ attribute :asset_code4, AssetCode4
30
+ attribute :asset_code12, AssetCode12
31
31
  end
32
32
  end
33
33
  end
@@ -13,14 +13,14 @@ require 'xdr'
13
13
  # case ASSET_TYPE_CREDIT_ALPHANUM4:
14
14
  # struct
15
15
  # {
16
- # opaque assetCode[4]; // 1 to 4 characters
16
+ # AssetCode4 assetCode;
17
17
  # AccountID issuer;
18
18
  # } alphaNum4;
19
19
  #
20
20
  # case ASSET_TYPE_CREDIT_ALPHANUM12:
21
21
  # struct
22
22
  # {
23
- # opaque assetCode[12]; // 5 to 12 characters
23
+ # AssetCode12 assetCode;
24
24
  # AccountID issuer;
25
25
  # } alphaNum12;
26
26
  #
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # struct
9
9
  # {
10
- # opaque assetCode[12]; // 5 to 12 characters
10
+ # AssetCode12 assetCode;
11
11
  # AccountID issuer;
12
12
  # }
13
13
  #
@@ -15,7 +15,7 @@ require 'xdr'
15
15
  module Stellar
16
16
  class Asset
17
17
  class AlphaNum12 < XDR::Struct
18
- attribute :asset_code, XDR::Opaque[12]
18
+ attribute :asset_code, AssetCode12
19
19
  attribute :issuer, AccountID
20
20
  end
21
21
  end
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # struct
9
9
  # {
10
- # opaque assetCode[4]; // 1 to 4 characters
10
+ # AssetCode4 assetCode;
11
11
  # AccountID issuer;
12
12
  # }
13
13
  #
@@ -15,7 +15,7 @@ require 'xdr'
15
15
  module Stellar
16
16
  class Asset
17
17
  class AlphaNum4 < XDR::Struct
18
- attribute :asset_code, XDR::Opaque[4]
18
+ attribute :asset_code, AssetCode4
19
19
  attribute :issuer, AccountID
20
20
  end
21
21
  end
@@ -8,10 +8,13 @@ require 'xdr'
8
8
  # union BucketEntry switch (BucketEntryType type)
9
9
  # {
10
10
  # case LIVEENTRY:
11
+ # case INITENTRY:
11
12
  # LedgerEntry liveEntry;
12
13
  #
13
14
  # case DEADENTRY:
14
15
  # LedgerKey deadEntry;
16
+ # case METAENTRY:
17
+ # BucketMetadata metaEntry;
15
18
  # };
16
19
  #
17
20
  # ===========================================================================
@@ -20,9 +23,12 @@ module Stellar
20
23
  switch_on BucketEntryType, :type
21
24
 
22
25
  switch :liveentry, :live_entry
26
+ switch :initentry, :live_entry
23
27
  switch :deadentry, :dead_entry
28
+ switch :metaentry, :meta_entry
24
29
 
25
30
  attribute :live_entry, LedgerEntry
26
31
  attribute :dead_entry, LedgerKey
32
+ attribute :meta_entry, BucketMetadata
27
33
  end
28
34
  end
@@ -7,15 +7,21 @@ require 'xdr'
7
7
  #
8
8
  # enum BucketEntryType
9
9
  # {
10
- # LIVEENTRY = 0,
11
- # DEADENTRY = 1
10
+ # METAENTRY =
11
+ # -1, // At-and-after protocol 11: bucket metadata, should come first.
12
+ # LIVEENTRY = 0, // Before protocol 11: created-or-updated;
13
+ # // At-and-after protocol 11: only updated.
14
+ # DEADENTRY = 1,
15
+ # INITENTRY = 2 // At-and-after protocol 11: only created.
12
16
  # };
13
17
  #
14
18
  # ===========================================================================
15
19
  module Stellar
16
20
  class BucketEntryType < XDR::Enum
21
+ member :metaentry, -1
17
22
  member :liveentry, 0
18
23
  member :deadentry, 1
24
+ member :initentry, 2
19
25
 
20
26
  seal
21
27
  end
@@ -0,0 +1,32 @@
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
+ # struct BucketMetadata
9
+ # {
10
+ # // Indicates the protocol version used to create / merge this bucket.
11
+ # uint32 ledgerVersion;
12
+ #
13
+ # // reserved for future use
14
+ # union switch (int v)
15
+ # {
16
+ # case 0:
17
+ # void;
18
+ # }
19
+ # ext;
20
+ # };
21
+ #
22
+ # ===========================================================================
23
+ module Stellar
24
+ class BucketMetadata < XDR::Struct
25
+ include XDR::Namespace
26
+
27
+ autoload :Ext
28
+
29
+ attribute :ledger_version, Uint32
30
+ attribute :ext, Ext
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # This code was automatically generated using xdrgen
2
+ # DO NOT EDIT or your changes may be overwritten
3
+
4
+ require 'xdr'
5
+
6
+ # === xdr source ============================================================
7
+ #
8
+ # union switch (int v)
9
+ # {
10
+ # case 0:
11
+ # void;
12
+ # }
13
+ #
14
+ # ===========================================================================
15
+ module Stellar
16
+ class BucketMetadata
17
+ class Ext < XDR::Union
18
+ switch_on XDR::Int, :v
19
+
20
+ switch 0
21
+
22
+ end
23
+ end
24
+ end
@@ -16,7 +16,7 @@ require 'xdr'
16
16
  # // cannot create with a limit of 0
17
17
  # CHANGE_TRUST_LOW_RESERVE =
18
18
  # -4, // not enough funds to create a new trust line,
19
- # CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed
19
+ # CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed
20
20
  # };
21
21
  #
22
22
  # ===========================================================================
@@ -9,7 +9,7 @@ require 'xdr'
9
9
  # {
10
10
  # // emitted to identify the offer
11
11
  # AccountID sellerID; // Account that owns the offer
12
- # uint64 offerID;
12
+ # int64 offerID;
13
13
  #
14
14
  # // amount and asset taken from the owner
15
15
  # Asset assetSold;
@@ -24,7 +24,7 @@ require 'xdr'
24
24
  module Stellar
25
25
  class ClaimOfferAtom < XDR::Struct
26
26
  attribute :seller_id, AccountID
27
- attribute :offer_id, Uint64
27
+ attribute :offer_id, Int64
28
28
  attribute :asset_sold, Asset
29
29
  attribute :amount_sold, Int64
30
30
  attribute :asset_bought, Asset
@@ -5,7 +5,7 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # struct CreatePassiveOfferOp
8
+ # struct CreatePassiveSellOfferOp
9
9
  # {
10
10
  # Asset selling; // A
11
11
  # Asset buying; // B
@@ -15,7 +15,7 @@ require 'xdr'
15
15
  #
16
16
  # ===========================================================================
17
17
  module Stellar
18
- class CreatePassiveOfferOp < XDR::Struct
18
+ class CreatePassiveSellOfferOp < XDR::Struct
19
19
  attribute :selling, Asset
20
20
  attribute :buying, Asset
21
21
  attribute :amount, Int64
@@ -9,15 +9,17 @@ require 'xdr'
9
9
  # {
10
10
  # ENVELOPE_TYPE_SCP = 1,
11
11
  # ENVELOPE_TYPE_TX = 2,
12
- # ENVELOPE_TYPE_AUTH = 3
12
+ # ENVELOPE_TYPE_AUTH = 3,
13
+ # ENVELOPE_TYPE_SCPVALUE = 4
13
14
  # };
14
15
  #
15
16
  # ===========================================================================
16
17
  module Stellar
17
18
  class EnvelopeType < XDR::Enum
18
- member :envelope_type_scp, 1
19
- member :envelope_type_tx, 2
20
- member :envelope_type_auth, 3
19
+ member :envelope_type_scp, 1
20
+ member :envelope_type_tx, 2
21
+ member :envelope_type_auth, 3
22
+ member :envelope_type_scpvalue, 4
21
23
 
22
24
  seal
23
25
  end