stellar-base 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/stellar-base.rb +1 -0
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/path_payment_result.rb +17 -0
- data/ruby-stellar-base.gemspec +1 -1
- data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf391f6f810bd73ec555ce1c91258206098d527
|
4
|
+
data.tar.gz: afba8f6e5f53d4f63033fa0f25a25cfffcc183cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 551e1d62b63cbdf5856a90a95a040987f87442f3c93d4d79ecde59e8e42386ca3fb610e0cbcb4355128cfde624ba3e98927c18fa9b8c0ec35616ff43c8c41e79
|
7
|
+
data.tar.gz: 92163ef24f44cc2ad53631561893b630de04feff9b000ce186fe61ab8e426c0ffab63fdca6541c8523f51d06ab71ddb30b0946cb75eba254d6a731363f860759
|
data/README.md
CHANGED
@@ -68,6 +68,10 @@ b58.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version:
|
|
68
68
|
|
69
69
|
```
|
70
70
|
|
71
|
+
## Updating Generated Code
|
72
|
+
|
73
|
+
The generated code of this library must be refreshed each time the Stellar network's protocol is updated. To perform this task, run `rake xdr:update`, which will download the latest `.x` files into the `xdr` folder and will run `xdrgen` to regenerate the built ruby code.
|
74
|
+
|
71
75
|
## Caveats
|
72
76
|
|
73
77
|
The current integration of user-written code with auto-generated classes is to put it nicely, weird. We intend to segregate the auto-generated code into its own namespace and refrain from monkey patching them. This will happen before 1.0, and hopefully will happen soon.
|
@@ -75,4 +79,3 @@ The current integration of user-written code with auto-generated classes is to p
|
|
75
79
|
## Contributing
|
76
80
|
|
77
81
|
Please [see CONTRIBUTING.md for details](CONTRIBUTING.md).
|
78
|
-
|
data/lib/stellar-base.rb
CHANGED
@@ -21,6 +21,7 @@ require_relative './stellar/account_flags'
|
|
21
21
|
require_relative './stellar/currency'
|
22
22
|
require_relative './stellar/key_pair'
|
23
23
|
require_relative './stellar/operation'
|
24
|
+
require_relative './stellar/path_payment_result'
|
24
25
|
require_relative './stellar/price'
|
25
26
|
require_relative './stellar/thresholds'
|
26
27
|
require_relative './stellar/transaction'
|
data/lib/stellar/base/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Stellar
|
2
|
+
class PathPaymentResult
|
3
|
+
# send_amount returns the actual amount paid for the corresponding
|
4
|
+
# PathPaymentOp to this result.
|
5
|
+
#
|
6
|
+
def send_amount
|
7
|
+
s = success!
|
8
|
+
return s.last.amount if s.offers.blank?
|
9
|
+
|
10
|
+
source_currency = s.offers.first.currency_send
|
11
|
+
source_offers = s.offers.take_while{|o| o.currency_send == source_currency}
|
12
|
+
|
13
|
+
source_offers.map(&:amount_send).sum
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/ruby-stellar-base.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["generated", "lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "xdr", "~> 0.0.
|
20
|
+
spec.add_dependency "xdr", "~> 0.0.3"
|
21
21
|
spec.add_dependency "rbnacl"
|
22
22
|
spec.add_dependency "rbnacl-libsodium", "~> 1.0.3"
|
23
23
|
spec.add_dependency "activesupport", "~> 4"
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Stellar::PathPaymentResult, "#send_amount" do
|
4
|
+
|
5
|
+
|
6
|
+
context "when the result is not successful" do
|
7
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_malformed) }
|
8
|
+
|
9
|
+
it "raises an exception if the result is not successful" do
|
10
|
+
expect{ subject.send_amount }.to raise_error(XDR::ArmNotSetError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when the result has no claimed offers" do
|
15
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
16
|
+
let(:path_success){ Stellar::PathPaymentResult::Success.new(last: simple_success) }
|
17
|
+
|
18
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
19
|
+
|
20
|
+
it "returns the amount from the 'last' component" do
|
21
|
+
expect(subject.send_amount).to eql(100)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
context "with simple 1-hop result" do
|
27
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
28
|
+
let(:offers) do
|
29
|
+
[Stellar::ClaimOfferAtom.new(currency_send: Stellar::Currency.native, amount_send: 200)]
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:path_success) do
|
33
|
+
Stellar::PathPaymentResult::Success.new({
|
34
|
+
offers: offers,
|
35
|
+
last: simple_success,
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
40
|
+
|
41
|
+
it "returns the amount from the ClaimOfferAtom" do
|
42
|
+
expect(subject.send_amount).to eql(200)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with 1-hop result that claimed multiple offers" do
|
47
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
48
|
+
let(:offers) do
|
49
|
+
[
|
50
|
+
Stellar::ClaimOfferAtom.new(currency_send: Stellar::Currency.native, amount_send: 200),
|
51
|
+
Stellar::ClaimOfferAtom.new(currency_send: Stellar::Currency.native, amount_send: 200),
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:path_success) do
|
56
|
+
Stellar::PathPaymentResult::Success.new({
|
57
|
+
offers: offers,
|
58
|
+
last: simple_success,
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
63
|
+
|
64
|
+
it "returns the summed amount from the ClaimOfferAtoms" do
|
65
|
+
expect(subject.send_amount).to eql(400)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
context "with multi-hop result that claimed multiple offers" do
|
71
|
+
let(:simple_success){ Stellar::SimplePaymentResult.new(amount: 100) }
|
72
|
+
let(:otherCurrency){ Stellar::Currency.alphanum("USD", Stellar::KeyPair.random) }
|
73
|
+
let(:offers) do
|
74
|
+
[
|
75
|
+
Stellar::ClaimOfferAtom.new(currency_send: Stellar::Currency.native, amount_send: 200),
|
76
|
+
Stellar::ClaimOfferAtom.new(currency_send: Stellar::Currency.native, amount_send: 200),
|
77
|
+
Stellar::ClaimOfferAtom.new(currency_send: otherCurrency, amount_send: 200),
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:path_success) do
|
82
|
+
Stellar::PathPaymentResult::Success.new({
|
83
|
+
offers: offers,
|
84
|
+
last: simple_success,
|
85
|
+
})
|
86
|
+
end
|
87
|
+
|
88
|
+
subject{ Stellar::PathPaymentResult.new(:path_payment_success, path_success) }
|
89
|
+
|
90
|
+
it "returns the summed amount from the ClaimOfferAtoms" do
|
91
|
+
expect(subject.send_amount).to eql(400)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stellar-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Fleckenstein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdr
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rbnacl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -316,6 +316,7 @@ files:
|
|
316
316
|
- lib/stellar/currency.rb
|
317
317
|
- lib/stellar/key_pair.rb
|
318
318
|
- lib/stellar/operation.rb
|
319
|
+
- lib/stellar/path_payment_result.rb
|
319
320
|
- lib/stellar/price.rb
|
320
321
|
- lib/stellar/thresholds.rb
|
321
322
|
- lib/stellar/transaction.rb
|
@@ -326,6 +327,7 @@ files:
|
|
326
327
|
- spec/lib/stellar/account_flags_spec.rb
|
327
328
|
- spec/lib/stellar/convert_spec.rb
|
328
329
|
- spec/lib/stellar/key_pair_spec.rb
|
330
|
+
- spec/lib/stellar/path_payment_result_spec.rb
|
329
331
|
- spec/lib/stellar/price_spec.rb
|
330
332
|
- spec/lib/stellar/thresholds_spec.rb
|
331
333
|
- spec/lib/stellar/transaction_envelope_spec.rb
|
@@ -374,6 +376,7 @@ test_files:
|
|
374
376
|
- spec/lib/stellar/account_flags_spec.rb
|
375
377
|
- spec/lib/stellar/convert_spec.rb
|
376
378
|
- spec/lib/stellar/key_pair_spec.rb
|
379
|
+
- spec/lib/stellar/path_payment_result_spec.rb
|
377
380
|
- spec/lib/stellar/price_spec.rb
|
378
381
|
- spec/lib/stellar/thresholds_spec.rb
|
379
382
|
- spec/lib/stellar/transaction_envelope_spec.rb
|