stellar-base 0.20.0 → 0.21.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -21
  3. data/CONTRIBUTING.md +5 -5
  4. data/README.md +1 -1
  5. data/generated/stellar-base-generated.rb +6 -3
  6. data/generated/stellar/operation.rb +4 -2
  7. data/generated/stellar/operation/body.rb +30 -26
  8. data/generated/stellar/operation_result.rb +4 -2
  9. data/generated/stellar/operation_result/tr.rb +32 -28
  10. data/generated/stellar/operation_type.rb +17 -15
  11. data/generated/stellar/{path_payment_op.rb → path_payment_strict_receive_op.rb} +2 -2
  12. data/generated/stellar/path_payment_strict_receive_result.rb +38 -0
  13. data/generated/stellar/path_payment_strict_receive_result/success.rb +22 -0
  14. data/generated/stellar/path_payment_strict_receive_result_code.rb +47 -0
  15. data/generated/stellar/path_payment_strict_send_op.rb +32 -0
  16. data/generated/stellar/{path_payment_result.rb → path_payment_strict_send_result.rb} +7 -7
  17. data/generated/stellar/{path_payment_result → path_payment_strict_send_result}/success.rb +1 -1
  18. data/generated/stellar/path_payment_strict_send_result_code.rb +47 -0
  19. data/lib/stellar-base.rb +1 -1
  20. data/lib/stellar/base/version.rb +1 -1
  21. data/lib/stellar/operation.rb +63 -6
  22. data/lib/stellar/{path_payment_result.rb → path_payment_strict_receive_result.rb} +1 -1
  23. data/lib/stellar/transaction.rb +12 -0
  24. data/spec/lib/stellar/operation_spec.rb +63 -1
  25. data/spec/lib/stellar/{path_payment_result_spec.rb → path_payment_strict_receive_result_spec.rb} +10 -10
  26. data/spec/lib/stellar/transaction_spec.rb +32 -0
  27. data/xdr/Stellar-transaction.x +94 -27
  28. metadata +14 -10
  29. data/generated/stellar/path_payment_result_code.rb +0 -47
@@ -5,7 +5,7 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # struct PathPaymentOp
8
+ # struct PathPaymentStrictReceiveOp
9
9
  # {
10
10
  # Asset sendAsset; // asset we pay with
11
11
  # int64 sendMax; // the maximum amount of sendAsset to
@@ -21,7 +21,7 @@ require 'xdr'
21
21
  #
22
22
  # ===========================================================================
23
23
  module Stellar
24
- class PathPaymentOp < XDR::Struct
24
+ class PathPaymentStrictReceiveOp < XDR::Struct
25
25
  attribute :send_asset, Asset
26
26
  attribute :send_max, Int64
27
27
  attribute :destination, AccountID
@@ -0,0 +1,38 @@
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 PathPaymentStrictReceiveResult switch (PathPaymentStrictReceiveResultCode code)
9
+ # {
10
+ # case PATH_PAYMENT_STRICT_RECEIVE_SUCCESS:
11
+ # struct
12
+ # {
13
+ # ClaimOfferAtom offers<>;
14
+ # SimplePaymentResult last;
15
+ # } success;
16
+ # case PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER:
17
+ # Asset noIssuer; // the asset that caused the error
18
+ # default:
19
+ # void;
20
+ # };
21
+ #
22
+ # ===========================================================================
23
+ module Stellar
24
+ class PathPaymentStrictReceiveResult < XDR::Union
25
+ include XDR::Namespace
26
+
27
+ autoload :Success
28
+
29
+ switch_on PathPaymentStrictReceiveResultCode, :code
30
+
31
+ switch :path_payment_strict_receive_success, :success
32
+ switch :path_payment_strict_receive_no_issuer, :no_issuer
33
+ switch :default
34
+
35
+ attribute :success, Success
36
+ attribute :no_issuer, Asset
37
+ end
38
+ 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
+ # ClaimOfferAtom offers<>;
11
+ # SimplePaymentResult last;
12
+ # }
13
+ #
14
+ # ===========================================================================
15
+ module Stellar
16
+ class PathPaymentStrictReceiveResult
17
+ class Success < XDR::Struct
18
+ attribute :offers, XDR::VarArray[ClaimOfferAtom]
19
+ attribute :last, SimplePaymentResult
20
+ end
21
+ end
22
+ end
@@ -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
+ # enum PathPaymentStrictReceiveResultCode
9
+ # {
10
+ # // codes considered as "success" for the operation
11
+ # PATH_PAYMENT_STRICT_RECEIVE_SUCCESS = 0, // success
12
+ #
13
+ # // codes considered as "failure" for the operation
14
+ # PATH_PAYMENT_STRICT_RECEIVE_MALFORMED = -1, // bad input
15
+ # PATH_PAYMENT_STRICT_RECEIVE_UNDERFUNDED = -2, // not enough funds in source account
16
+ # PATH_PAYMENT_STRICT_RECEIVE_SRC_NO_TRUST = -3, // no trust line on source account
17
+ # PATH_PAYMENT_STRICT_RECEIVE_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
18
+ # PATH_PAYMENT_STRICT_RECEIVE_NO_DESTINATION = -5, // destination account does not exist
19
+ # PATH_PAYMENT_STRICT_RECEIVE_NO_TRUST = -6, // dest missing a trust line for asset
20
+ # PATH_PAYMENT_STRICT_RECEIVE_NOT_AUTHORIZED = -7, // dest not authorized to hold asset
21
+ # PATH_PAYMENT_STRICT_RECEIVE_LINE_FULL = -8, // dest would go above their limit
22
+ # PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER = -9, // missing issuer on one asset
23
+ # PATH_PAYMENT_STRICT_RECEIVE_TOO_FEW_OFFERS = -10, // not enough offers to satisfy path
24
+ # PATH_PAYMENT_STRICT_RECEIVE_OFFER_CROSS_SELF = -11, // would cross one of its own offers
25
+ # PATH_PAYMENT_STRICT_RECEIVE_OVER_SENDMAX = -12 // could not satisfy sendmax
26
+ # };
27
+ #
28
+ # ===========================================================================
29
+ module Stellar
30
+ class PathPaymentStrictReceiveResultCode < XDR::Enum
31
+ member :path_payment_strict_receive_success, 0
32
+ member :path_payment_strict_receive_malformed, -1
33
+ member :path_payment_strict_receive_underfunded, -2
34
+ member :path_payment_strict_receive_src_no_trust, -3
35
+ member :path_payment_strict_receive_src_not_authorized, -4
36
+ member :path_payment_strict_receive_no_destination, -5
37
+ member :path_payment_strict_receive_no_trust, -6
38
+ member :path_payment_strict_receive_not_authorized, -7
39
+ member :path_payment_strict_receive_line_full, -8
40
+ member :path_payment_strict_receive_no_issuer, -9
41
+ member :path_payment_strict_receive_too_few_offers, -10
42
+ member :path_payment_strict_receive_offer_cross_self, -11
43
+ member :path_payment_strict_receive_over_sendmax, -12
44
+
45
+ seal
46
+ end
47
+ 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 PathPaymentStrictSendOp
9
+ # {
10
+ # Asset sendAsset; // asset we pay with
11
+ # int64 sendAmount; // amount of sendAsset to send (excluding fees)
12
+ #
13
+ # AccountID destination; // recipient of the payment
14
+ # Asset destAsset; // what they end up with
15
+ # int64 destMin; // the minimum amount of dest asset to
16
+ # // be received
17
+ # // The operation will fail if it can't be met
18
+ #
19
+ # Asset path<5>; // additional hops it must go through to get there
20
+ # };
21
+ #
22
+ # ===========================================================================
23
+ module Stellar
24
+ class PathPaymentStrictSendOp < XDR::Struct
25
+ attribute :send_asset, Asset
26
+ attribute :send_amount, Int64
27
+ attribute :destination, AccountID
28
+ attribute :dest_asset, Asset
29
+ attribute :dest_min, Int64
30
+ attribute :path, XDR::VarArray[Asset, 5]
31
+ end
32
+ end
@@ -5,15 +5,15 @@ require 'xdr'
5
5
 
6
6
  # === xdr source ============================================================
7
7
  #
8
- # union PathPaymentResult switch (PathPaymentResultCode code)
8
+ # union PathPaymentStrictSendResult switch (PathPaymentStrictSendResultCode code)
9
9
  # {
10
- # case PATH_PAYMENT_SUCCESS:
10
+ # case PATH_PAYMENT_STRICT_SEND_SUCCESS:
11
11
  # struct
12
12
  # {
13
13
  # ClaimOfferAtom offers<>;
14
14
  # SimplePaymentResult last;
15
15
  # } success;
16
- # case PATH_PAYMENT_NO_ISSUER:
16
+ # case PATH_PAYMENT_STRICT_SEND_NO_ISSUER:
17
17
  # Asset noIssuer; // the asset that caused the error
18
18
  # default:
19
19
  # void;
@@ -21,15 +21,15 @@ require 'xdr'
21
21
  #
22
22
  # ===========================================================================
23
23
  module Stellar
24
- class PathPaymentResult < XDR::Union
24
+ class PathPaymentStrictSendResult < XDR::Union
25
25
  include XDR::Namespace
26
26
 
27
27
  autoload :Success
28
28
 
29
- switch_on PathPaymentResultCode, :code
29
+ switch_on PathPaymentStrictSendResultCode, :code
30
30
 
31
- switch :path_payment_success, :success
32
- switch :path_payment_no_issuer, :no_issuer
31
+ switch :path_payment_strict_send_success, :success
32
+ switch :path_payment_strict_send_no_issuer, :no_issuer
33
33
  switch :default
34
34
 
35
35
  attribute :success, Success
@@ -13,7 +13,7 @@ require 'xdr'
13
13
  #
14
14
  # ===========================================================================
15
15
  module Stellar
16
- class PathPaymentResult
16
+ class PathPaymentStrictSendResult
17
17
  class Success < XDR::Struct
18
18
  attribute :offers, XDR::VarArray[ClaimOfferAtom]
19
19
  attribute :last, SimplePaymentResult
@@ -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
+ # enum PathPaymentStrictSendResultCode
9
+ # {
10
+ # // codes considered as "success" for the operation
11
+ # PATH_PAYMENT_STRICT_SEND_SUCCESS = 0, // success
12
+ #
13
+ # // codes considered as "failure" for the operation
14
+ # PATH_PAYMENT_STRICT_SEND_MALFORMED = -1, // bad input
15
+ # PATH_PAYMENT_STRICT_SEND_UNDERFUNDED = -2, // not enough funds in source account
16
+ # PATH_PAYMENT_STRICT_SEND_SRC_NO_TRUST = -3, // no trust line on source account
17
+ # PATH_PAYMENT_STRICT_SEND_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
18
+ # PATH_PAYMENT_STRICT_SEND_NO_DESTINATION = -5, // destination account does not exist
19
+ # PATH_PAYMENT_STRICT_SEND_NO_TRUST = -6, // dest missing a trust line for asset
20
+ # PATH_PAYMENT_STRICT_SEND_NOT_AUTHORIZED = -7, // dest not authorized to hold asset
21
+ # PATH_PAYMENT_STRICT_SEND_LINE_FULL = -8, // dest would go above their limit
22
+ # PATH_PAYMENT_STRICT_SEND_NO_ISSUER = -9, // missing issuer on one asset
23
+ # PATH_PAYMENT_STRICT_SEND_TOO_FEW_OFFERS = -10, // not enough offers to satisfy path
24
+ # PATH_PAYMENT_STRICT_SEND_OFFER_CROSS_SELF = -11, // would cross one of its own offers
25
+ # PATH_PAYMENT_STRICT_SEND_UNDER_DESTMIN = -12 // could not satisfy destMin
26
+ # };
27
+ #
28
+ # ===========================================================================
29
+ module Stellar
30
+ class PathPaymentStrictSendResultCode < XDR::Enum
31
+ member :path_payment_strict_send_success, 0
32
+ member :path_payment_strict_send_malformed, -1
33
+ member :path_payment_strict_send_underfunded, -2
34
+ member :path_payment_strict_send_src_no_trust, -3
35
+ member :path_payment_strict_send_src_not_authorized, -4
36
+ member :path_payment_strict_send_no_destination, -5
37
+ member :path_payment_strict_send_no_trust, -6
38
+ member :path_payment_strict_send_not_authorized, -7
39
+ member :path_payment_strict_send_line_full, -8
40
+ member :path_payment_strict_send_no_issuer, -9
41
+ member :path_payment_strict_send_too_few_offers, -10
42
+ member :path_payment_strict_send_offer_cross_self, -11
43
+ member :path_payment_strict_send_under_destmin, -12
44
+
45
+ seal
46
+ end
47
+ end
data/lib/stellar-base.rb CHANGED
@@ -20,7 +20,7 @@ require_relative './stellar/account_flags'
20
20
  require_relative './stellar/asset'
21
21
  require_relative './stellar/key_pair'
22
22
  require_relative './stellar/operation'
23
- require_relative './stellar/path_payment_result'
23
+ require_relative './stellar/path_payment_strict_receive_result'
24
24
  require_relative './stellar/price'
25
25
  require_relative './stellar/signer_key'
26
26
  require_relative './stellar/thresholds'
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.20.0"
3
+ VERSION = "0.21.0"
4
4
  end
5
5
  end
@@ -59,21 +59,42 @@ module Stellar
59
59
  end
60
60
 
61
61
  #
62
- # Helper method to create a valid PathPaymentOp, wrapped
62
+ # Helper method to create a valid PathPaymentStrictReceiveOp, wrapped
63
63
  # in the necessary XDR structs to be included within a
64
64
  # transactions `operations` array.
65
+ #
66
+ # @deprecated Please use Operation.path_payment_strict_receive
65
67
  #
66
68
  # @see Stellar::Asset
67
69
  #
68
70
  # @param [Hash] attributes the attributes to create the operation with
69
71
  # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
70
- # @option attributes [Array] :amount the amount to pay
72
+ # @option attributes [Array] :amount the destination asset and the amount to pay
71
73
  # @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
72
74
  # @option attributes [Array<Stellar::Asset>] :path the payment path to use
73
75
  #
74
- # @return [Stellar::Operation] the built operation, containing a
75
- # Stellar::PaymentOp body
76
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
77
+ #
76
78
  def self.path_payment(attributes={})
79
+ path_payment_strict_receive(attributes)
80
+ end
81
+
82
+ #
83
+ # Helper method to create a valid PathPaymentStrictReceiveOp, wrapped
84
+ # in the necessary XDR structs to be included within a
85
+ # transactions `operations` array.
86
+ #
87
+ # @see Stellar::Asset
88
+ #
89
+ # @param [Hash] attributes the attributes to create the operation with
90
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
91
+ # @option attributes [Array] :amount the destination asset and the amount to pay
92
+ # @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
93
+ # @option attributes [Array<Stellar::Asset>] :path the payment path to use
94
+ #
95
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
96
+ #
97
+ def self.path_payment_strict_receive(attributes={})
77
98
  destination = attributes[:destination]
78
99
  asset, amount = extract_amount(attributes[:amount])
79
100
  send_asset, send_max = extract_amount(attributes[:with])
@@ -81,7 +102,7 @@ module Stellar
81
102
 
82
103
  raise ArgumentError unless destination.is_a?(KeyPair)
83
104
 
84
- op = PathPaymentOp.new
105
+ op = PathPaymentStrictReceiveOp.new
85
106
  op.send_asset = send_asset
86
107
  op.send_max = send_max
87
108
  op.destination = destination.account_id
@@ -90,7 +111,43 @@ module Stellar
90
111
  op.path = path
91
112
 
92
113
  return make(attributes.merge({
93
- body:[:path_payment, op]
114
+ body:[:path_payment_strict_receive, op]
115
+ }))
116
+ end
117
+
118
+ #
119
+ # Helper method to create a valid PathPaymentStrictSendOp, wrapped
120
+ # in the necessary XDR structs to be included within a
121
+ # transactions `operations` array.
122
+ #
123
+ # @see Stellar::Asset
124
+ #
125
+ # @param [Hash] attributes the attributes to create the operation with
126
+ # @option attributes [Stellar::KeyPair] :destination the receiver of the payment
127
+ # @option attributes [Array] :amount the destination asset and the minimum amount of destination asset to be received
128
+ # @option attributes [Array] :with the source asset and amount to pay with
129
+ # @option attributes [Array<Stellar::Asset>] :path the payment path to use
130
+ #
131
+ # @return [Stellar::Operation] the built operation, containing a Stellar::PaymentOp body
132
+ #
133
+ def self.path_payment_strict_send(attributes={})
134
+ destination = attributes[:destination]
135
+ asset, dest_min = extract_amount(attributes[:amount])
136
+ send_asset, send_amount = extract_amount(attributes[:with])
137
+ path = (attributes[:path] || []).map{|p| Stellar::Asset.send(*p)}
138
+
139
+ raise ArgumentError unless destination.is_a?(KeyPair)
140
+
141
+ op = PathPaymentStrictSendOp.new
142
+ op.send_asset = send_asset
143
+ op.send_amount = send_amount
144
+ op.destination = destination.account_id
145
+ op.dest_asset = asset
146
+ op.dest_min = dest_min
147
+ op.path = path
148
+
149
+ return make(attributes.merge({
150
+ body:[:path_payment_strict_send, op]
94
151
  }))
95
152
  end
96
153
 
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
- class PathPaymentResult
2
+ class PathPaymentStrictReceiveResult
3
3
  # send_amount returns the actual amount paid for the corresponding
4
4
  # PathPaymentOp to this result.
5
5
  #
@@ -13,6 +13,18 @@ module Stellar
13
13
  make :path_payment, attributes
14
14
  end
15
15
 
16
+ #
17
+ # @see Stellar::Operation.path_payment_strict_receive
18
+ def self.path_payment_strict_receive(attributes={})
19
+ make :path_payment_strict_receive, attributes
20
+ end
21
+
22
+ #
23
+ # @see Stellar::Operation.path_payment_strict_send
24
+ def self.path_payment_strict_send(attributes={})
25
+ make :path_payment_strict_send, attributes
26
+ end
27
+
16
28
  #
17
29
  # @see Stellar::Operation.create_account
18
30
  def self.create_account(attributes={})
@@ -12,6 +12,69 @@ describe Stellar::Operation, ".payment" do
12
12
 
13
13
  end
14
14
 
15
+ def pk_to_address(pk)
16
+ Stellar::Convert.pk_to_address(pk)
17
+ end
18
+
19
+ describe "path payment operations" do
20
+ let(:destination){ Stellar::KeyPair.random }
21
+ let(:send_asset_issuer){ Stellar::KeyPair.master }
22
+ let(:send_asset){ Stellar::Asset.alphanum4("USD", send_asset_issuer) }
23
+ let(:dest_asset_issuer){ Stellar::KeyPair.master }
24
+ let(:dest_asset){ Stellar::Asset.alphanum4("EUR", dest_asset_issuer) }
25
+ let(:amount){ [:alphanum4, dest_asset.code, dest_asset_issuer, 9.2] }
26
+ let(:with){ [:alphanum4, send_asset.code, send_asset_issuer, 10] }
27
+
28
+ describe Stellar::Operation, ".path_payment" do
29
+ it "works" do
30
+ destination = Stellar::KeyPair.random
31
+ amount = [:alphanum4, "USD", Stellar::KeyPair.master, 10]
32
+ with = [:alphanum4, "EUR", Stellar::KeyPair.master, 9.2]
33
+
34
+ op = Stellar::Operation.path_payment(
35
+ destination: destination,
36
+ amount: amount,
37
+ with: with
38
+ )
39
+
40
+ expect(op.body.arm).to eql(:path_payment_strict_receive_op)
41
+ end
42
+ end
43
+
44
+ describe Stellar::Operation, ".path_payment_strict_receive" do
45
+ it "works" do
46
+ op = Stellar::Operation.path_payment_strict_receive(
47
+ destination: destination,
48
+ amount: amount,
49
+ with: with
50
+ )
51
+
52
+ expect(op.body.arm).to eql(:path_payment_strict_receive_op)
53
+ expect(op.body.value.destination).to eql(destination.public_key)
54
+ expect(op.body.value.send_asset).to eql(send_asset)
55
+ expect(op.body.value.dest_asset).to eql(dest_asset)
56
+ expect(op.body.value.send_max).to eq(100000000)
57
+ expect(op.body.value.dest_amount).to eq(92000000)
58
+ end
59
+ end
60
+
61
+ describe Stellar::Operation, ".path_payment_strict_send" do
62
+ it "works" do
63
+ op = Stellar::Operation.path_payment_strict_send(
64
+ destination: destination,
65
+ amount: amount,
66
+ with: with
67
+ )
68
+
69
+ expect(op.body.arm).to eql(:path_payment_strict_send_op)
70
+ expect(op.body.value.destination).to eql(destination.public_key)
71
+ expect(op.body.value.send_asset).to eql(send_asset)
72
+ expect(op.body.value.dest_asset).to eql(dest_asset)
73
+ expect(op.body.value.send_amount).to eq(100000000)
74
+ expect(op.body.value.dest_min).to eq(92000000)
75
+ end
76
+ end
77
+ end
15
78
 
16
79
  describe Stellar::Operation, ".manage_data" do
17
80
 
@@ -67,5 +130,4 @@ describe Stellar::Operation, ".change_trust" do
67
130
  Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: true)
68
131
  }.to raise_error(ArgumentError)
69
132
  end
70
-
71
133
  end