stellar-base 0.0.20 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5ccdbf9c969e49fdac7bf759a71330a9f2b4b88
4
- data.tar.gz: 941f08106de210e0607b0c66c05981b83c0cf519
3
+ metadata.gz: 00b588bb83ab0ec33e7a92e5dfef2284df773fd5
4
+ data.tar.gz: 3595b669f01ce541ed9050e76d1657aca9582c2c
5
5
  SHA512:
6
- metadata.gz: 7fa06709f25ef7d48892e6db72ba6c5ac1e5ff9be05151613cfeb09cc1e24ee14dd4c44346a228f3ab26180789b5d467696171035ba48fc318b28675f2e781a8
7
- data.tar.gz: 6eeb0145b27fe11c81972f9ac1cc76dc9272e2742245369679f254ad8d90133192c9178e0c958d1bb678e85de4f733ca93cbdbbcf533fb9c0fb81893d153a5ce
6
+ metadata.gz: f3b104f6e9339fde162a8612818b40a2951f36d9dc2b679e426cd970ebded35fc6d538590a10300cdd63037c74008217e7de4faa3da500f8fbb085ea2aa5dabd
7
+ data.tar.gz: 50d90cf7c604be3f91f37b1ac6c52623502acd2f53828ee4f186bf36eef8dd63f55ea466ce0dfee85eca6374e88db6f7a9690967e130a2ccec37f8bc56ee672f
data/README.md CHANGED
@@ -35,10 +35,10 @@ We wrap rbnacl with `Stellar::KeyPair`, providing some stellar specific function
35
35
  ```ruby
36
36
 
37
37
  # Create a keypair from a stellar secret seed
38
- signer = Stellar::KeyPair.from_seed("s3tUdZbCmLoMdrZ6nhqztatMFaiD85P54oVj93g1NeSBwWQpTnE")
38
+ signer = Stellar::KeyPair.from_seed("SCBASSEX34FJNIPLUYQPSMZHHYXXQNWOOV42XYZFXM6EGYX2DPIZVIA3")
39
39
 
40
40
  # Create a keypair from a stellar address
41
- verifier = Stellar::KeyPair.from_address("gsTe6bDX54bPwtUAm2TER4shBF8nQNVtEvB8fmRkRoWvq3Y8XmY")
41
+ verifier = Stellar::KeyPair.from_address("GBQWWBFLRP3BXD2RI2FH7XNNU2MKIYVUI7QXUAIVG34JY6MQGXVUO3RX")
42
42
 
43
43
  # Produce a stellar compliant "decorated signature" that is compliant with stellar transactions
44
44
 
@@ -46,25 +46,19 @@ signer.sign_decorated("Hello world!") # => #<Stellar::DecoratedSignature ...>
46
46
 
47
47
  ```
48
48
 
49
- This library also provides an impementation of base58 and base58check encoding, with support for the bitcoin and stellar alphabets:
49
+ This library also provides an impementation of Stellar's "StrKey" encoding (RFC-4648 Base32 + CCITT-XModem CRC16):
50
50
 
51
51
  ```ruby
52
- b58 = Stellar::Util::Base58.stellar
53
52
 
54
- encoded = b58.encode("\x00\x00\x00") # => "ggg"
55
- b58.decode(encoded) # => "\x00\x00\x00"
56
-
57
- # we can also use check encoding
58
-
59
- b58.check_encode(:account_id, "\x00\x00\x00") # => "gggghbdQd2"
60
- b58.check_encode(:seed, "\x00\x00\x00") # => "aX9UTew55Eh"
53
+ Stellar::Util::StrCheck.check_encode(:account_id, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF") # => "GD777777777764TU"
54
+ Stellar::Util::StrCheck.check_encode(:seed, "\x00\x00\x00\x00\x00\x00\x39") # => "SAAAAAAAAAADST3H"
61
55
 
62
56
  # To prevent interpretation mistakes, you must pass the expected version byte
63
57
  # when decoding a check_encoded value
64
58
 
65
- encoded = b58.check_encode(:account_id, "\x00\x00\x00")
66
- b58.check_decode(:account_id, encoded) # => "\x00\x00\x00"
67
- b58.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version: :account_id
59
+ encoded = Stellar::Util::StrCheck.check_encode(:account_id, "\x61\x6b\x04\xab\x8b\xf6\x1b")
60
+ Stellar::Util::StrCheck.check_decode(:account_id, encoded) # => "\x61\x6b\x04\xab\x8b\xf6\x1b"
61
+ Stellar::Util::StrCheck.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version: :account_id
68
62
 
69
63
  ```
70
64
 
@@ -21,7 +21,7 @@ tx.seq_num = 1
21
21
 
22
22
  payment = Stellar::PaymentOp.new
23
23
  payment.destination = destination.verify_key.to_bytes
24
- payment.currency = Stellar::Currency.new(:native)
24
+ payment.asset = Stellar::Asset.new(:native)
25
25
  payment.amount = 200 * Stellar::ONE
26
26
 
27
27
  op = Stellar::Operation.new
@@ -48,7 +48,7 @@ destination_sequence = FILL_ME_IN
48
48
  submit destination, Stellar::Transaction.change_trust({
49
49
  account: destination,
50
50
  sequence: destination_sequence,
51
- line: [:alphanum, "USD\x00", master],
51
+ line: [:alphanum4, "USD\x00", master],
52
52
  limit: 1000
53
53
  })
54
54
 
@@ -56,5 +56,5 @@ submit master, Stellar::Transaction.payment({
56
56
  account: master,
57
57
  destination: destination,
58
58
  sequence: 3,
59
- amount: [:alphanum, "USD\x00", master, 100]
59
+ amount: [:alphanum4, "USD\x00", master, 100]
60
60
  })
@@ -47,14 +47,14 @@ destination_sequence = FILL_ME_IN
47
47
  submit destination, Stellar::Transaction.change_trust({
48
48
  account: destination,
49
49
  sequence: destination_sequence,
50
- line: [:alphanum, "USD\x00", master],
50
+ line: [:alphanum4, "USD\x00", master],
51
51
  limit: 1000
52
52
  })
53
53
 
54
54
  submit destination, Stellar::Transaction.change_trust({
55
55
  account: destination,
56
56
  sequence: destination_sequence + 1,
57
- line: [:alphanum, "EUR\x00", master],
57
+ line: [:alphanum4, "EUR\x00", master],
58
58
  limit: 1000
59
59
  })
60
60
 
@@ -62,14 +62,14 @@ submit master, Stellar::Transaction.payment({
62
62
  account: master,
63
63
  destination: destination,
64
64
  sequence: destination_sequence + 2,
65
- amount: [:alphanum, "USD\x00", master, 1000]
65
+ amount: [:alphanum4, "USD\x00", master, 1000]
66
66
  })
67
67
 
68
68
  submit master, Stellar::Transaction.manage_offer({
69
69
  account: destination,
70
70
  sequence: destination_sequence + 3
71
- taker_gets: [:alphanum, "USD\x00", usd_gateway],
72
- taker_pays: [:alphanum, "EUR\x00", eur_gateway],
71
+ taker_gets: [:alphanum4, "USD\x00", usd_gateway],
72
+ taker_pays: [:alphanum4, "EUR\x00", eur_gateway],
73
73
  amount: 100,
74
74
  price: 2.0,
75
75
  })
@@ -25,8 +25,8 @@ module Stellar
25
25
  Thresholds = XDR::Opaque[4]
26
26
  String32 = XDR::String[32]
27
27
  SequenceNumber = Uint64
28
- autoload :CurrencyType
29
- autoload :Currency
28
+ autoload :AssetType
29
+ autoload :Asset
30
30
  autoload :Price
31
31
  autoload :ThresholdIndexes
32
32
  autoload :LedgerEntryType
@@ -107,6 +107,8 @@ module Stellar
107
107
  autoload :LedgerHeaderHistoryEntry
108
108
  autoload :LedgerEntryChangeType
109
109
  autoload :LedgerEntryChange
110
+ LedgerEntryChanges = XDR::VarArray[LedgerEntryChange]
111
+ autoload :OperationMeta
110
112
  autoload :TransactionMeta
111
113
  end
112
114
  module Stellar
@@ -119,9 +121,6 @@ module Stellar
119
121
  autoload :DontHave
120
122
  autoload :StellarMessage
121
123
  end
122
- module Stellar
123
- include XDR::Namespace
124
- end
125
124
  module Stellar
126
125
  include XDR::Namespace
127
126
 
@@ -11,7 +11,7 @@ require 'xdr'
11
11
  # // if set, TrustLines are created with authorized set to "false"
12
12
  # // requiring the issuer to set it for each TrustLine
13
13
  # AUTH_REQUIRED_FLAG = 0x1,
14
- # // if set, the authorized flag in TrustTines can be cleared
14
+ # // if set, the authorized flag in TrustLines can be cleared
15
15
  # // otherwise, authorization cannot be revoked
16
16
  # AUTH_REVOCABLE_FLAG = 0x2
17
17
  # };
@@ -8,15 +8,18 @@ require 'xdr'
8
8
  # struct AllowTrustOp
9
9
  # {
10
10
  # AccountID trustor;
11
- # union switch (CurrencyType type)
11
+ # union switch (AssetType type)
12
12
  # {
13
- # // CURRENCY_TYPE_NATIVE is not allowed
14
- # case CURRENCY_TYPE_ALPHANUM:
15
- # opaque currencyCode[4];
13
+ # // ASSET_TYPE_NATIVE is not allowed
14
+ # case ASSET_TYPE_CREDIT_ALPHANUM4:
15
+ # opaque assetCode4[4];
16
16
  #
17
- # // add other currency types here in the future
17
+ # case ASSET_TYPE_CREDIT_ALPHANUM12:
18
+ # opaque assetCode12[12];
19
+ #
20
+ # // add other asset types here in the future
18
21
  # }
19
- # currency;
22
+ # asset;
20
23
  #
21
24
  # bool authorize;
22
25
  # };
@@ -26,10 +29,10 @@ module Stellar
26
29
  class AllowTrustOp < XDR::Struct
27
30
  include XDR::Namespace
28
31
 
29
- autoload :Currency
32
+ autoload :Asset
30
33
 
31
34
  attribute :trustor, AccountID
32
- attribute :currency, Currency
35
+ attribute :asset, Asset
33
36
  attribute :authorize, XDR::Bool
34
37
  end
35
38
  end
@@ -0,0 +1,33 @@
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 (AssetType type)
9
+ # {
10
+ # // ASSET_TYPE_NATIVE is not allowed
11
+ # case ASSET_TYPE_CREDIT_ALPHANUM4:
12
+ # opaque assetCode4[4];
13
+ #
14
+ # case ASSET_TYPE_CREDIT_ALPHANUM12:
15
+ # opaque assetCode12[12];
16
+ #
17
+ # // add other asset types here in the future
18
+ # }
19
+ #
20
+ # ===========================================================================
21
+ module Stellar
22
+ class AllowTrustOp
23
+ class Asset < XDR::Union
24
+ switch_on AssetType, :type
25
+
26
+ switch :asset_type_credit_alphanum4, :asset_code4
27
+ switch :asset_type_credit_alphanum12, :asset_code12
28
+
29
+ attribute :asset_code4, XDR::Opaque[4]
30
+ attribute :asset_code12, XDR::Opaque[12]
31
+ end
32
+ end
33
+ end
@@ -10,7 +10,7 @@ require 'xdr'
10
10
  # // codes considered as "success" for the operation
11
11
  # ALLOW_TRUST_SUCCESS = 0,
12
12
  # // codes considered as "failure" for the operation
13
- # ALLOW_TRUST_MALFORMED = -1, // currency is not CURRENCY_TYPE_ALPHANUM
13
+ # ALLOW_TRUST_MALFORMED = -1, // asset is not ASSET_TYPE_ALPHANUM
14
14
  # ALLOW_TRUST_NO_TRUST_LINE = -2, // trustor does not have a trustline
15
15
  # // source account does not require trust
16
16
  # ALLOW_TRUST_TRUST_NOT_REQUIRED = -3,
@@ -0,0 +1,47 @@
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 Asset switch (AssetType type)
9
+ # {
10
+ # case ASSET_TYPE_NATIVE: // Not credit
11
+ # void;
12
+ #
13
+ # case ASSET_TYPE_CREDIT_ALPHANUM4:
14
+ # struct
15
+ # {
16
+ # opaque assetCode[4];
17
+ # AccountID issuer;
18
+ # } alphaNum4;
19
+ #
20
+ # case ASSET_TYPE_CREDIT_ALPHANUM12:
21
+ # struct
22
+ # {
23
+ # opaque assetCode[12];
24
+ # AccountID issuer;
25
+ # } alphaNum12;
26
+ #
27
+ # // add other asset types here in the future
28
+ # };
29
+ #
30
+ # ===========================================================================
31
+ module Stellar
32
+ class Asset < XDR::Union
33
+ include XDR::Namespace
34
+
35
+ autoload :AlphaNum4
36
+ autoload :AlphaNum12
37
+
38
+ switch_on AssetType, :type
39
+
40
+ switch :asset_type_native
41
+ switch :asset_type_credit_alphanum4, :alpha_num4
42
+ switch :asset_type_credit_alphanum12, :alpha_num12
43
+
44
+ attribute :alpha_num4, AlphaNum4
45
+ attribute :alpha_num12, AlphaNum12
46
+ end
47
+ end
@@ -7,16 +7,16 @@ require 'xdr'
7
7
  #
8
8
  # struct
9
9
  # {
10
- # opaque currencyCode[4];
10
+ # opaque assetCode[12];
11
11
  # AccountID issuer;
12
12
  # }
13
13
  #
14
14
  # ===========================================================================
15
15
  module Stellar
16
- class Currency
17
- class AlphaNum < XDR::Struct
18
- attribute :currency_code, XDR::Opaque[4]
19
- attribute :issuer, AccountID
16
+ class Asset
17
+ class AlphaNum12 < XDR::Struct
18
+ attribute :asset_code, XDR::Opaque[12]
19
+ attribute :issuer, AccountID
20
20
  end
21
21
  end
22
22
  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
+ # opaque assetCode[4];
11
+ # AccountID issuer;
12
+ # }
13
+ #
14
+ # ===========================================================================
15
+ module Stellar
16
+ class Asset
17
+ class AlphaNum4 < XDR::Struct
18
+ attribute :asset_code, XDR::Opaque[4]
19
+ attribute :issuer, AccountID
20
+ end
21
+ end
22
+ 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
+ # enum AssetType
9
+ # {
10
+ # ASSET_TYPE_NATIVE = 0,
11
+ # ASSET_TYPE_CREDIT_ALPHANUM4 = 1,
12
+ # ASSET_TYPE_CREDIT_ALPHANUM12 = 2
13
+ # };
14
+ #
15
+ # ===========================================================================
16
+ module Stellar
17
+ class AssetType < XDR::Enum
18
+ member :asset_type_native, 0
19
+ member :asset_type_credit_alphanum4, 1
20
+ member :asset_type_credit_alphanum12, 2
21
+
22
+ seal
23
+ end
24
+ end
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # struct ChangeTrustOp
9
9
  # {
10
- # Currency line;
10
+ # Asset line;
11
11
  #
12
12
  # // if limit is set to 0, deletes the trust line
13
13
  # int64 limit;
@@ -16,7 +16,7 @@ require 'xdr'
16
16
  # ===========================================================================
17
17
  module Stellar
18
18
  class ChangeTrustOp < XDR::Struct
19
- attribute :line, Currency
19
+ attribute :line, Asset
20
20
  attribute :limit, Int64
21
21
  end
22
22
  end
@@ -11,23 +11,23 @@ require 'xdr'
11
11
  # AccountID offerOwner; // Account that owns the offer
12
12
  # uint64 offerID;
13
13
  #
14
- # // amount and currency taken from the owner
15
- # Currency currencyClaimed;
14
+ # // amount and asset taken from the owner
15
+ # Asset assetClaimed;
16
16
  # int64 amountClaimed;
17
17
  #
18
- # // amount and currencysent to the owner
19
- # Currency currencySend;
18
+ # // amount and assetsent to the owner
19
+ # Asset assetSend;
20
20
  # int64 amountSend;
21
21
  # };
22
22
  #
23
23
  # ===========================================================================
24
24
  module Stellar
25
25
  class ClaimOfferAtom < XDR::Struct
26
- attribute :offer_owner, AccountID
27
- attribute :offer_id, Uint64
28
- attribute :currency_claimed, Currency
29
- attribute :amount_claimed, Int64
30
- attribute :currency_send, Currency
31
- attribute :amount_send, Int64
26
+ attribute :offer_owner, AccountID
27
+ attribute :offer_id, Uint64
28
+ attribute :asset_claimed, Asset
29
+ attribute :amount_claimed, Int64
30
+ attribute :asset_send, Asset
31
+ attribute :amount_send, Int64
32
32
  end
33
33
  end
@@ -7,18 +7,18 @@ require 'xdr'
7
7
  #
8
8
  # struct CreatePassiveOfferOp
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; // A
11
+ # Asset buying; // B
12
+ # int64 amount; // amount taker gets. if set to 0, delete the offer
13
+ # Price price; // cost of A in terms of B
14
14
  # };
15
15
  #
16
16
  # ===========================================================================
17
17
  module Stellar
18
18
  class CreatePassiveOfferOp < XDR::Struct
19
- attribute :taker_gets, Currency
20
- attribute :taker_pays, Currency
21
- attribute :amount, Int64
22
- attribute :price, Price
19
+ attribute :selling, Asset
20
+ attribute :buying, Asset
21
+ attribute :amount, Int64
22
+ attribute :price, Price
23
23
  end
24
24
  end
@@ -7,13 +7,13 @@ require 'xdr'
7
7
  #
8
8
  # enum CryptoKeyType
9
9
  # {
10
- # KEY_TYPES_ED25519 = 0
10
+ # KEY_TYPE_ED25519 = 0
11
11
  # };
12
12
  #
13
13
  # ===========================================================================
14
14
  module Stellar
15
15
  class CryptoKeyType < XDR::Enum
16
- member :key_types_ed25519, 0
16
+ member :key_type_ed25519, 0
17
17
 
18
18
  seal
19
19
  end