stellar-base 0.0.20 → 0.1.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -14
  3. data/examples/low_level_transaction_post.rb +1 -1
  4. data/examples/non_native_payment.rb +2 -2
  5. data/examples/offer.rb +5 -5
  6. data/generated/stellar-base-generated.rb +4 -5
  7. data/generated/stellar/account_flags.rb +1 -1
  8. data/generated/stellar/allow_trust_op.rb +11 -8
  9. data/generated/stellar/allow_trust_op/asset.rb +33 -0
  10. data/generated/stellar/allow_trust_result_code.rb +1 -1
  11. data/generated/stellar/asset.rb +47 -0
  12. data/generated/stellar/{currency/alpha_num.rb → asset/alpha_num12.rb} +5 -5
  13. data/generated/stellar/asset/alpha_num4.rb +22 -0
  14. data/generated/stellar/asset_type.rb +24 -0
  15. data/generated/stellar/change_trust_op.rb +2 -2
  16. data/generated/stellar/claim_offer_atom.rb +10 -10
  17. data/generated/stellar/create_passive_offer_op.rb +8 -8
  18. data/generated/stellar/crypto_key_type.rb +2 -2
  19. data/generated/stellar/ledger_key.rb +2 -2
  20. data/generated/stellar/ledger_key/offer.rb +3 -3
  21. data/generated/stellar/ledger_key/trust_line.rb +2 -2
  22. data/generated/stellar/manage_offer_op.rb +9 -9
  23. data/generated/stellar/offer_entry.rb +11 -11
  24. data/generated/stellar/{currency_type.rb → operation_meta.rb} +4 -8
  25. data/generated/stellar/path_payment_op.rb +10 -10
  26. data/generated/stellar/path_payment_result_code.rb +2 -2
  27. data/generated/stellar/payment_op.rb +2 -2
  28. data/generated/stellar/payment_result_code.rb +2 -2
  29. data/generated/stellar/public_key.rb +2 -2
  30. data/generated/stellar/simple_payment_result.rb +2 -2
  31. data/generated/stellar/transaction_meta.rb +17 -4
  32. data/generated/stellar/transaction_meta/v0.rb +22 -0
  33. data/generated/stellar/trust_line_entry.rb +4 -4
  34. data/lib/stellar-base.rb +2 -2
  35. data/lib/stellar/asset.rb +38 -0
  36. data/lib/stellar/base/version.rb +1 -1
  37. data/lib/stellar/convert.rb +1 -5
  38. data/lib/stellar/key_pair.rb +6 -6
  39. data/lib/stellar/operation.rb +24 -24
  40. data/lib/stellar/path_payment_result.rb +2 -2
  41. data/lib/stellar/util/strkey.rb +43 -0
  42. data/ruby-stellar-base.gemspec +2 -0
  43. data/spec/lib/stellar/key_pair_spec.rb +12 -12
  44. data/spec/lib/stellar/path_payment_result_spec.rb +7 -7
  45. data/spec/lib/stellar/transaction_spec.rb +1 -1
  46. data/spec/lib/stellar/util/strkey_spec.rb +46 -0
  47. data/spec/support/matchers/be_strkey.rb +9 -0
  48. data/tasks/xdr.rake +7 -8
  49. data/xdr/Stellar-SCP.x +1 -1
  50. data/xdr/Stellar-ledger-entries.x +26 -18
  51. data/xdr/Stellar-ledger.x +17 -5
  52. data/xdr/Stellar-overlay.x +1 -1
  53. data/xdr/Stellar-transaction.x +39 -36
  54. data/xdr/Stellar-types.x +2 -3
  55. metadata +43 -13
  56. data/generated/stellar/allow_trust_op/currency.rb +0 -28
  57. data/generated/stellar/currency.rb +0 -37
  58. data/lib/stellar/currency.rb +0 -39
  59. data/lib/stellar/util/base58.rb +0 -127
  60. data/spec/lib/stellar/util/base58_spec.rb +0 -74
  61. data/spec/support/matchers/be_base58_check.rb +0 -9
  62. data/xdr/StellarXDR.x +0 -11
@@ -17,13 +17,13 @@ require 'xdr'
17
17
  # struct
18
18
  # {
19
19
  # AccountID accountID;
20
- # Currency currency;
20
+ # Asset asset;
21
21
  # } trustLine;
22
22
  #
23
23
  # case OFFER:
24
24
  # struct
25
25
  # {
26
- # AccountID accountID;
26
+ # AccountID sellerID;
27
27
  # uint64 offerID;
28
28
  # } offer;
29
29
  # };
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # struct
9
9
  # {
10
- # AccountID accountID;
10
+ # AccountID sellerID;
11
11
  # uint64 offerID;
12
12
  # }
13
13
  #
@@ -15,8 +15,8 @@ require 'xdr'
15
15
  module Stellar
16
16
  class LedgerKey
17
17
  class Offer < XDR::Struct
18
- attribute :account_id, AccountID
19
- attribute :offer_id, Uint64
18
+ attribute :seller_id, AccountID
19
+ attribute :offer_id, Uint64
20
20
  end
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@ require 'xdr'
8
8
  # struct
9
9
  # {
10
10
  # AccountID accountID;
11
- # Currency currency;
11
+ # Asset asset;
12
12
  # }
13
13
  #
14
14
  # ===========================================================================
@@ -16,7 +16,7 @@ module Stellar
16
16
  class LedgerKey
17
17
  class TrustLine < XDR::Struct
18
18
  attribute :account_id, AccountID
19
- attribute :currency, Currency
19
+ attribute :asset, Asset
20
20
  end
21
21
  end
22
22
  end
@@ -7,10 +7,10 @@ require 'xdr'
7
7
  #
8
8
  # struct ManageOfferOp
9
9
  # {
10
- # Currency takerGets;
11
- # Currency takerPays;
12
- # int64 amount; // amount taker gets. if set to 0, delete the offer
13
- # Price price; // =takerPaysAmount/takerGetsAmount
10
+ # Asset selling;
11
+ # Asset buying;
12
+ # int64 amount; // amount being sold. if set to 0, delete the offer
13
+ # Price price; // price of thing being sold in terms of what you are buying
14
14
  #
15
15
  # // 0=create a new offer, otherwise edit an existing offer
16
16
  # uint64 offerID;
@@ -19,10 +19,10 @@ require 'xdr'
19
19
  # ===========================================================================
20
20
  module Stellar
21
21
  class ManageOfferOp < XDR::Struct
22
- attribute :taker_gets, Currency
23
- attribute :taker_pays, Currency
24
- attribute :amount, Int64
25
- attribute :price, Price
26
- attribute :offer_id, Uint64
22
+ attribute :selling, Asset
23
+ attribute :buying, Asset
24
+ attribute :amount, Int64
25
+ attribute :price, Price
26
+ attribute :offer_id, Uint64
27
27
  end
28
28
  end
@@ -7,10 +7,10 @@ require 'xdr'
7
7
  #
8
8
  # struct OfferEntry
9
9
  # {
10
- # AccountID accountID;
10
+ # AccountID sellerID;
11
11
  # uint64 offerID;
12
- # Currency takerGets; // A
13
- # Currency takerPays; // B
12
+ # Asset selling; // A
13
+ # Asset buying; // B
14
14
  # int64 amount; // amount of A
15
15
  #
16
16
  # /* price for this offer:
@@ -37,13 +37,13 @@ module Stellar
37
37
 
38
38
  autoload :Ext
39
39
 
40
- attribute :account_id, AccountID
41
- attribute :offer_id, Uint64
42
- attribute :taker_gets, Currency
43
- attribute :taker_pays, Currency
44
- attribute :amount, Int64
45
- attribute :price, Price
46
- attribute :flags, Uint32
47
- attribute :ext, Ext
40
+ attribute :seller_id, AccountID
41
+ attribute :offer_id, Uint64
42
+ attribute :selling, Asset
43
+ attribute :buying, Asset
44
+ attribute :amount, Int64
45
+ attribute :price, Price
46
+ attribute :flags, Uint32
47
+ attribute :ext, Ext
48
48
  end
49
49
  end
@@ -5,18 +5,14 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # enum CurrencyType
8
+ # struct OperationMeta
9
9
  # {
10
- # CURRENCY_TYPE_NATIVE = 0,
11
- # CURRENCY_TYPE_ALPHANUM = 1
10
+ # LedgerEntryChanges changes;
12
11
  # };
13
12
  #
14
13
  # ===========================================================================
15
14
  module Stellar
16
- class CurrencyType < XDR::Enum
17
- member :currency_type_native, 0
18
- member :currency_type_alphanum, 1
19
-
20
- seal
15
+ class OperationMeta < XDR::Struct
16
+ attribute :changes, LedgerEntryChanges
21
17
  end
22
18
  end
@@ -7,26 +7,26 @@ require 'xdr'
7
7
  #
8
8
  # struct PathPaymentOp
9
9
  # {
10
- # Currency sendCurrency; // currency we pay with
11
- # int64 sendMax; // the maximum amount of sendCurrency to
10
+ # Asset sendAsset; // asset we pay with
11
+ # int64 sendMax; // the maximum amount of sendAsset to
12
12
  # // send (excluding fees).
13
13
  # // The operation will fail if can't be met
14
14
  #
15
15
  # AccountID destination; // recipient of the payment
16
- # Currency destCurrency; // what they end up with
16
+ # Asset destAsset; // what they end up with
17
17
  # int64 destAmount; // amount they end up with
18
18
  #
19
- # Currency path<5>; // additional hops it must go through to get there
19
+ # Asset path<5>; // additional hops it must go through to get there
20
20
  # };
21
21
  #
22
22
  # ===========================================================================
23
23
  module Stellar
24
24
  class PathPaymentOp < XDR::Struct
25
- attribute :send_currency, Currency
26
- attribute :send_max, Int64
27
- attribute :destination, AccountID
28
- attribute :dest_currency, Currency
29
- attribute :dest_amount, Int64
30
- attribute :path, XDR::VarArray[Currency, 5]
25
+ attribute :send_asset, Asset
26
+ attribute :send_max, Int64
27
+ attribute :destination, AccountID
28
+ attribute :dest_asset, Asset
29
+ attribute :dest_amount, Int64
30
+ attribute :path, XDR::VarArray[Asset, 5]
31
31
  end
32
32
  end
@@ -16,8 +16,8 @@ require 'xdr'
16
16
  # PATH_PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account
17
17
  # PATH_PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
18
18
  # PATH_PAYMENT_NO_DESTINATION = -5, // destination account does not exist
19
- # PATH_PAYMENT_NO_TRUST = -6, // dest missing a trust line for currency
20
- # PATH_PAYMENT_NOT_AUTHORIZED = -7, // dest not authorized to hold currency
19
+ # PATH_PAYMENT_NO_TRUST = -6, // dest missing a trust line for asset
20
+ # PATH_PAYMENT_NOT_AUTHORIZED = -7, // dest not authorized to hold asset
21
21
  # PATH_PAYMENT_LINE_FULL = -8, // dest would go above their limit
22
22
  # PATH_PAYMENT_TOO_FEW_OFFERS = -9, // not enough offers to satisfy path
23
23
  # PATH_PAYMENT_OVER_SENDMAX = -10 // could not satisfy sendmax
@@ -8,7 +8,7 @@ require 'xdr'
8
8
  # struct PaymentOp
9
9
  # {
10
10
  # AccountID destination; // recipient of the payment
11
- # Currency currency; // what they end up with
11
+ # Asset asset; // what they end up with
12
12
  # int64 amount; // amount they end up with
13
13
  # };
14
14
  #
@@ -16,7 +16,7 @@ require 'xdr'
16
16
  module Stellar
17
17
  class PaymentOp < XDR::Struct
18
18
  attribute :destination, AccountID
19
- attribute :currency, Currency
19
+ attribute :asset, Asset
20
20
  attribute :amount, Int64
21
21
  end
22
22
  end
@@ -16,8 +16,8 @@ require 'xdr'
16
16
  # PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account
17
17
  # PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
18
18
  # PAYMENT_NO_DESTINATION = -5, // destination account does not exist
19
- # PAYMENT_NO_TRUST = -6, // destination missing a trust line for currency
20
- # PAYMENT_NOT_AUTHORIZED = -7, // destination not authorized to hold currency
19
+ # PAYMENT_NO_TRUST = -6, // destination missing a trust line for asset
20
+ # PAYMENT_NOT_AUTHORIZED = -7, // destination not authorized to hold asset
21
21
  # PAYMENT_LINE_FULL = -8 // destination would go above their limit
22
22
  # };
23
23
  #
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # union PublicKey switch (CryptoKeyType type)
9
9
  # {
10
- # case KEY_TYPES_ED25519:
10
+ # case KEY_TYPE_ED25519:
11
11
  # uint256 ed25519;
12
12
  # };
13
13
  #
@@ -16,7 +16,7 @@ module Stellar
16
16
  class PublicKey < XDR::Union
17
17
  switch_on CryptoKeyType, :type
18
18
 
19
- switch :key_types_ed25519, :ed25519
19
+ switch :key_type_ed25519, :ed25519
20
20
 
21
21
  attribute :ed25519, Uint256
22
22
  end
@@ -8,7 +8,7 @@ require 'xdr'
8
8
  # struct SimplePaymentResult
9
9
  # {
10
10
  # AccountID destination;
11
- # Currency currency;
11
+ # Asset asset;
12
12
  # int64 amount;
13
13
  # };
14
14
  #
@@ -16,7 +16,7 @@ require 'xdr'
16
16
  module Stellar
17
17
  class SimplePaymentResult < XDR::Struct
18
18
  attribute :destination, AccountID
19
- attribute :currency, Currency
19
+ attribute :asset, Asset
20
20
  attribute :amount, Int64
21
21
  end
22
22
  end
@@ -5,14 +5,27 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # struct TransactionMeta
8
+ # union TransactionMeta switch (int v)
9
9
  # {
10
- # LedgerEntryChange changes<>;
10
+ # case 0:
11
+ # struct
12
+ # {
13
+ # LedgerEntryChanges changes;
14
+ # OperationMeta operations<>;
15
+ # } v0;
11
16
  # };
12
17
  #
13
18
  # ===========================================================================
14
19
  module Stellar
15
- class TransactionMeta < XDR::Struct
16
- attribute :changes, XDR::VarArray[LedgerEntryChange]
20
+ class TransactionMeta < XDR::Union
21
+ include XDR::Namespace
22
+
23
+ autoload :V0
24
+
25
+ switch_on XDR::Int, :v
26
+
27
+ switch 0, :v0
28
+
29
+ attribute :v0, V0
17
30
  end
18
31
  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
+ # struct
9
+ # {
10
+ # LedgerEntryChanges changes;
11
+ # OperationMeta operations<>;
12
+ # }
13
+ #
14
+ # ===========================================================================
15
+ module Stellar
16
+ class TransactionMeta
17
+ class V0 < XDR::Struct
18
+ attribute :changes, LedgerEntryChanges
19
+ attribute :operations, XDR::VarArray[OperationMeta]
20
+ end
21
+ end
22
+ end
@@ -8,9 +8,9 @@ require 'xdr'
8
8
  # struct TrustLineEntry
9
9
  # {
10
10
  # AccountID accountID; // account this trustline belongs to
11
- # Currency currency; // currency (with issuer)
12
- # int64 balance; // how much of this currency the user has.
13
- # // Currency defines the unit for this;
11
+ # Asset asset; // type of asset (with issuer)
12
+ # int64 balance; // how much of this asset the user has.
13
+ # // Asset defines the unit for this;
14
14
  #
15
15
  # int64 limit; // balance cannot be above this
16
16
  # uint32 flags; // see TrustLineFlags
@@ -32,7 +32,7 @@ module Stellar
32
32
  autoload :Ext
33
33
 
34
34
  attribute :account_id, AccountID
35
- attribute :currency, Currency
35
+ attribute :asset, Asset
36
36
  attribute :balance, Int64
37
37
  attribute :limit, Int64
38
38
  attribute :flags, Uint32
@@ -18,7 +18,7 @@ Stellar::ONE = 1_0000000
18
18
  # extensions onto the generated files must be loaded manually, below
19
19
 
20
20
  require_relative './stellar/account_flags'
21
- require_relative './stellar/currency'
21
+ require_relative './stellar/asset'
22
22
  require_relative './stellar/key_pair'
23
23
  require_relative './stellar/operation'
24
24
  require_relative './stellar/path_payment_result'
@@ -26,6 +26,6 @@ require_relative './stellar/price'
26
26
  require_relative './stellar/thresholds'
27
27
  require_relative './stellar/transaction'
28
28
  require_relative './stellar/transaction_envelope'
29
- require_relative './stellar/util/base58'
29
+ require_relative './stellar/util/strkey'
30
30
  require_relative './stellar/util/continued_fraction'
31
31
  require_relative './stellar/convert'
@@ -0,0 +1,38 @@
1
+ module Stellar
2
+ class Asset
3
+ def self.native
4
+ new(:asset_type_native)
5
+ end
6
+
7
+ def self.alphanum4(code, issuer)
8
+ raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
9
+ code = normalize_code(code)
10
+ an = AlphaNum4.new({asset_code:code, issuer:issuer.account_id})
11
+ new(:asset_type_credit_alphanum4, an)
12
+ end
13
+
14
+ def to_s
15
+ if switch == AssetType.asset_type_native
16
+ "native"
17
+ else
18
+ issuer_address = Stellar::Util::StrKey.check_encode(:account_id,alpha_num.issuer)
19
+ "#{alpha_num.asset_code}/#{issuer_address}"
20
+ end
21
+ end
22
+
23
+ def inspect
24
+ label = switch.to_s
25
+ "#<Stellar::Asset #{to_s}>"
26
+ end
27
+
28
+ def code
29
+ self.alpha_num!.asset_code
30
+ end
31
+
32
+ def self.normalize_code(code)
33
+ raise ArgumentError, "Invalid asset code: #{code}, must be <= 4 bytes" if code.length > 4
34
+
35
+ code.ljust(4, "\x00")
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.0.20"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -21,12 +21,8 @@ module Stellar
21
21
  Base64.strict_decode64(base64_string)
22
22
  end
23
23
 
24
- def base58
25
- Stellar::Util::Base58.stellar
26
- end
27
-
28
24
  def pk_to_address(pk)
29
- base58.check_encode(:account_id, pk)
25
+ Stellar::util::StrKey.check_encode(:account_id, pk)
30
26
  end
31
27
 
32
28
  extend self
@@ -1,7 +1,7 @@
1
1
  module Stellar
2
2
  class KeyPair
3
3
  def self.from_seed(seed)
4
- seed_bytes = Util::Base58.stellar.check_decode(:seed, seed)
4
+ seed_bytes = Util::StrKey.check_decode(:seed, seed)
5
5
  from_raw_seed seed_bytes
6
6
  end
7
7
 
@@ -17,7 +17,7 @@ module Stellar
17
17
  end
18
18
 
19
19
  def self.from_address(address)
20
- pk_bytes = Util::Base58.stellar.check_decode(:account_id, address)
20
+ pk_bytes = Util::StrKey.check_decode(:account_id, address)
21
21
  from_public_key(pk_bytes)
22
22
  end
23
23
 
@@ -33,11 +33,11 @@ module Stellar
33
33
  end
34
34
 
35
35
  def account_id
36
- Stellar::AccountID.new :key_types_ed25519, raw_public_key
36
+ Stellar::AccountID.new :key_type_ed25519, raw_public_key
37
37
  end
38
38
 
39
39
  def public_key
40
- Stellar::PublicKey.new :key_types_ed25519, raw_public_key
40
+ Stellar::PublicKey.new :key_type_ed25519, raw_public_key
41
41
  end
42
42
 
43
43
  def raw_public_key
@@ -63,14 +63,14 @@ module Stellar
63
63
 
64
64
  def address
65
65
  pk_bytes = raw_public_key
66
- Util::Base58.stellar.check_encode(:account_id, pk_bytes)
66
+ Util::StrKey.check_encode(:account_id, pk_bytes)
67
67
  end
68
68
 
69
69
  def seed
70
70
  raise "no private key" if @secret_key.nil?
71
71
  #TODO: improve the error class above
72
72
  seed_bytes = raw_seed
73
- encoder = Util::Base58.stellar.check_encode(:seed, seed_bytes)
73
+ encoder = Util::StrKey.check_encode(:seed, seed_bytes)
74
74
  end
75
75
 
76
76
  def sign?