stellar-base 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/examples/create_account.rb +2 -2
- data/examples/mid_level_transaction_post.rb +1 -1
- data/examples/non_native_payment.rb +3 -3
- data/examples/offer.rb +3 -3
- data/examples/transaction_merge.rb +4 -4
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/operation.rb +18 -5
- data/spec/lib/stellar/operation_spec.rb +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bac71a17429d471bf8a252b4555a83cf79f32c4
|
4
|
+
data.tar.gz: 12011ffc9af15865d2f60c79b7783f9d3534842f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f390f799a717fab8ce23eba8b924d242fdf501b3eaf11e24239570b1710c4557305aacdd12095f8f79812c681daa164b633f153161db51a13f200ce5b0c30ed
|
7
|
+
data.tar.gz: 9324b9f53c10f45770585e76caf0c537c90a071c1ad10ae238a05703c4b97235d2ae1aad23f394d06fa8304e2dee908ad866b4d3e107420c4a9372f95ba31402
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog All notable changes to this project will be documented in this
|
2
|
+
file. This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
As this project is pre 1.0, breaking changes may happen for minor version
|
5
|
+
bumps. A breaking change will get clearly notified in this log.
|
6
|
+
|
7
|
+
## [0.4.0](https://github.com/stellar/ruby-stellar-base/compare/v0.3.0...v0.4.0)
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
- BREAKING CHANGE: "Amounts", that is, input parameters that represent a
|
11
|
+
certain amount of a given asset, such as the `:starting_balance` option for
|
12
|
+
`Operation.create_account` are now interpreted using the convention of 7
|
13
|
+
fixed-decimal places. For example, specifying a payment where the amount is
|
14
|
+
`50` will result in a transaction with an amount set to `500000000`.
|
data/examples/create_account.rb
CHANGED
@@ -17,10 +17,10 @@ tx = Stellar::Transaction.create_account({
|
|
17
17
|
account: master,
|
18
18
|
destination: destination,
|
19
19
|
sequence: 1,
|
20
|
-
starting_balance: 50
|
20
|
+
starting_balance: 50
|
21
21
|
})
|
22
22
|
|
23
23
|
b64 = tx.to_envelope(master).to_xdr(:base64)
|
24
|
-
|
24
|
+
p b64
|
25
25
|
result = $server.get('tx', blob: b64)
|
26
26
|
p result.body
|
@@ -28,14 +28,14 @@ def submit(key, tx)
|
|
28
28
|
p response.body
|
29
29
|
end
|
30
30
|
|
31
|
-
master = Stellar::KeyPair.
|
32
|
-
destination = Stellar::KeyPair.
|
31
|
+
master = Stellar::KeyPair.master
|
32
|
+
destination = Stellar::KeyPair.master
|
33
33
|
|
34
34
|
submit master, Stellar::Transaction.payment({
|
35
35
|
account: master,
|
36
36
|
destination: destination,
|
37
37
|
sequence: 1,
|
38
|
-
amount: [:native, 2000
|
38
|
+
amount: [:native, 2000]
|
39
39
|
})
|
40
40
|
|
41
41
|
# NOTE: after this step, you need to get the sequence number for destination
|
data/examples/offer.rb
CHANGED
@@ -27,14 +27,14 @@ def submit(key, tx)
|
|
27
27
|
p response.body
|
28
28
|
end
|
29
29
|
|
30
|
-
master = Stellar::KeyPair.
|
31
|
-
destination = Stellar::KeyPair.
|
30
|
+
master = Stellar::KeyPair.master
|
31
|
+
destination = Stellar::KeyPair.master
|
32
32
|
|
33
33
|
submit master, Stellar::Transaction.payment({
|
34
34
|
account: master,
|
35
35
|
destination: destination,
|
36
36
|
sequence: 1,
|
37
|
-
amount: [:native, 2000
|
37
|
+
amount: [:native, 2000]
|
38
38
|
})
|
39
39
|
|
40
40
|
# NOTE: after this step, you need to get the sequence number for destination
|
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'stellar-base'
|
4
4
|
|
5
|
-
master = Stellar::KeyPair.
|
6
|
-
destination = Stellar::KeyPair.
|
5
|
+
master = Stellar::KeyPair.master
|
6
|
+
destination = Stellar::KeyPair.master
|
7
7
|
|
8
8
|
tx1 = Stellar::Transaction.payment({
|
9
9
|
account: master,
|
10
10
|
destination: destination,
|
11
11
|
sequence: 1,
|
12
|
-
amount: [:native, 20
|
12
|
+
amount: [:native, 20]
|
13
13
|
})
|
14
14
|
|
15
15
|
tx2 = Stellar::Transaction.payment({
|
16
16
|
account: master,
|
17
17
|
destination: destination,
|
18
18
|
sequence: 2,
|
19
|
-
amount: [:native, 20
|
19
|
+
amount: [:native, 20]
|
20
20
|
})
|
21
21
|
|
22
22
|
hex = tx1.merge(tx2).to_envelope(master).to_xdr(:base64)
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/operation.rb
CHANGED
@@ -95,7 +95,7 @@ module Stellar
|
|
95
95
|
|
96
96
|
def self.create_account(attributes={})
|
97
97
|
destination = attributes[:destination]
|
98
|
-
starting_balance = attributes[:starting_balance]
|
98
|
+
starting_balance = interpret_amount(attributes[:starting_balance])
|
99
99
|
|
100
100
|
raise ArgumentError unless destination.is_a?(KeyPair)
|
101
101
|
|
@@ -121,7 +121,7 @@ module Stellar
|
|
121
121
|
# Stellar::ChangeTrustOp body
|
122
122
|
def self.change_trust(attributes={})
|
123
123
|
line = Asset.send(*attributes[:line])
|
124
|
-
limit =
|
124
|
+
limit =interpret_amount(attributes[:limit])
|
125
125
|
|
126
126
|
raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer)
|
127
127
|
|
@@ -135,7 +135,7 @@ module Stellar
|
|
135
135
|
def self.manage_offer(attributes={})
|
136
136
|
buying = Asset.send(*attributes[:buying])
|
137
137
|
selling = Asset.send(*attributes[:selling])
|
138
|
-
amount = attributes[:amount]
|
138
|
+
amount = interpret_amount(attributes[:amount])
|
139
139
|
offer_id = attributes[:offer_id] || 0
|
140
140
|
price = interpret_price(attributes[:price])
|
141
141
|
|
@@ -155,7 +155,7 @@ module Stellar
|
|
155
155
|
def self.create_passive_offer(attributes={})
|
156
156
|
buying = Asset.send(*attributes[:buying])
|
157
157
|
selling = Asset.send(*attributes[:selling])
|
158
|
-
amount = attributes[:amount]
|
158
|
+
amount = interpret_amount(attributes[:amount])
|
159
159
|
price = interpret_price(attributes[:price])
|
160
160
|
|
161
161
|
op = CreatePassiveOfferOp.new({
|
@@ -280,12 +280,25 @@ module Stellar
|
|
280
280
|
|
281
281
|
private
|
282
282
|
def self.extract_amount(a)
|
283
|
-
amount = a.last
|
283
|
+
amount = interpret_amount(a.last)
|
284
284
|
asset = Stellar::Asset.send(*a[0...-1])
|
285
285
|
|
286
286
|
return asset, amount
|
287
287
|
end
|
288
288
|
|
289
|
+
def self.interpret_amount(amount)
|
290
|
+
case amount
|
291
|
+
when String
|
292
|
+
(BigDecimal.new(amount) * Stellar::ONE).floor
|
293
|
+
when Integer
|
294
|
+
amount * Stellar::ONE
|
295
|
+
when Numeric
|
296
|
+
(amount * Stellar::ONE).floor
|
297
|
+
else
|
298
|
+
raise ArgumentError, "Invalid amount type: #{amount.class}. Must be String or Numeric"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
289
302
|
|
290
303
|
def self.interpret_price(price)
|
291
304
|
case price
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stellar::Operation, ".payment" do
|
4
|
+
|
5
|
+
|
6
|
+
it "correctly translates the provided amount to the native representation" do
|
7
|
+
op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, 20])
|
8
|
+
expect(op.body.value.amount).to eql(20_0000000)
|
9
|
+
op = Stellar::Operation.payment(destination: Stellar::KeyPair.random, amount: [:native, "20"])
|
10
|
+
expect(op.body.value.amount).to eql(20_0000000)
|
11
|
+
end
|
12
|
+
|
13
|
+
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.
|
4
|
+
version: 0.4.0
|
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-09-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdr
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- ".gitignore"
|
231
231
|
- ".travis.yml"
|
232
232
|
- ".yardopts"
|
233
|
+
- CHANGELOG.md
|
233
234
|
- CONTRIBUTING.md
|
234
235
|
- Gemfile
|
235
236
|
- Guardfile
|
@@ -381,6 +382,7 @@ files:
|
|
381
382
|
- spec/lib/stellar/convert_spec.rb
|
382
383
|
- spec/lib/stellar/key_pair_spec.rb
|
383
384
|
- spec/lib/stellar/networks_spec.rb
|
385
|
+
- spec/lib/stellar/operation_spec.rb
|
384
386
|
- spec/lib/stellar/path_payment_result_spec.rb
|
385
387
|
- spec/lib/stellar/price_spec.rb
|
386
388
|
- spec/lib/stellar/thresholds_spec.rb
|
@@ -431,6 +433,7 @@ test_files:
|
|
431
433
|
- spec/lib/stellar/convert_spec.rb
|
432
434
|
- spec/lib/stellar/key_pair_spec.rb
|
433
435
|
- spec/lib/stellar/networks_spec.rb
|
436
|
+
- spec/lib/stellar/operation_spec.rb
|
434
437
|
- spec/lib/stellar/path_payment_result_spec.rb
|
435
438
|
- spec/lib/stellar/price_spec.rb
|
436
439
|
- spec/lib/stellar/thresholds_spec.rb
|