stellar-base 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +2 -2
- data/examples/create_account.rb +2 -2
- data/lib/stellar/asset.rb +40 -9
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/key_pair.rb +4 -0
- data/spec/lib/stellar/asset_spec.rb +45 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c996423e6ccb1a43a3da3de6338838ef443b8a
|
4
|
+
data.tar.gz: 1310708e376a5cd4dfe246d2a91e196f2c214cc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fec9593753a0aa9928f57f62bc1079b7a55605aa4233c6faffb4b405d24b7e4a64db7080cde242ce3afb4495ba9c088432b9187b116d846c9816147e3070f9d
|
7
|
+
data.tar.gz: d66d8e6dbfe8c1557da22c11d484fe8593952ba2a06c122f703078423da1b87986626f83c40aa93e43ced422622b3c031bd5c44740c605d274cef13b34b9aa8a
|
data/Guardfile
CHANGED
data/examples/create_account.rb
CHANGED
@@ -10,13 +10,13 @@ $server = Faraday.new(url: "http://localhost:39132") do |conn|
|
|
10
10
|
conn.adapter Faraday.default_adapter
|
11
11
|
end
|
12
12
|
|
13
|
-
master = Stellar::KeyPair.
|
13
|
+
master = Stellar::KeyPair.master
|
14
14
|
destination = Stellar::KeyPair.random
|
15
15
|
|
16
16
|
tx = Stellar::Transaction.create_account({
|
17
17
|
account: master,
|
18
18
|
destination: destination,
|
19
|
-
sequence:
|
19
|
+
sequence: 1,
|
20
20
|
starting_balance: 50 * Stellar::ONE
|
21
21
|
})
|
22
22
|
|
data/lib/stellar/asset.rb
CHANGED
@@ -6,17 +6,30 @@ module Stellar
|
|
6
6
|
|
7
7
|
def self.alphanum4(code, issuer)
|
8
8
|
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
9
|
-
code = normalize_code(code)
|
9
|
+
code = normalize_code(code, 4)
|
10
10
|
an = AlphaNum4.new({asset_code:code, issuer:issuer.account_id})
|
11
11
|
new(:asset_type_credit_alphanum4, an)
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.alphanum12(code, issuer)
|
15
|
+
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
16
|
+
code = normalize_code(code, 12)
|
17
|
+
an = AlphaNum12.new({asset_code:code, issuer:issuer.account_id})
|
18
|
+
new(:asset_type_credit_alphanum12, an)
|
19
|
+
end
|
20
|
+
|
14
21
|
def to_s
|
15
|
-
|
22
|
+
case switch
|
23
|
+
when AssetType.asset_type_native
|
16
24
|
"native"
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
when AssetType.asset_type_credit_alphanum4
|
26
|
+
anum = alpha_num4!
|
27
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
28
|
+
"#{anum.asset_code}/#{issuer_address}"
|
29
|
+
when AssetType.asset_type_credit_alphanum12
|
30
|
+
anum = alpha_num12!
|
31
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
32
|
+
"#{anum.asset_code}/#{issuer_address}"
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
@@ -26,13 +39,31 @@ module Stellar
|
|
26
39
|
end
|
27
40
|
|
28
41
|
def code
|
29
|
-
|
42
|
+
case switch
|
43
|
+
when AssetType.asset_type_credit_alphanum4
|
44
|
+
alpha_num4!.asset_code
|
45
|
+
when AssetType.asset_type_credit_alphanum12
|
46
|
+
alpha_num12!.asset_code
|
47
|
+
else
|
48
|
+
raise "#{switch} assets do not have a code"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def issuer
|
53
|
+
case switch
|
54
|
+
when AssetType.asset_type_credit_alphanum4
|
55
|
+
alpha_num4!.issuer
|
56
|
+
when AssetType.asset_type_credit_alphanum12
|
57
|
+
alpha_num12!.issuer
|
58
|
+
else
|
59
|
+
raise "#{switch} assets do not have a isuuer"
|
60
|
+
end
|
30
61
|
end
|
31
62
|
|
32
|
-
def self.normalize_code(code)
|
33
|
-
raise ArgumentError, "Invalid asset code: #{code}, must be <=
|
63
|
+
def self.normalize_code(code, length)
|
64
|
+
raise ArgumentError, "Invalid asset code: #{code}, must be <= #{length} bytes" if code.length > length
|
34
65
|
|
35
|
-
code.ljust(
|
66
|
+
code.ljust(length, "\x00")
|
36
67
|
end
|
37
68
|
end
|
38
69
|
end
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/key_pair.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Stellar::Asset, ".native" do
|
4
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_native'" do
|
5
|
+
expect(Stellar::Asset.native.type).to eq(Stellar::AssetType.asset_type_native)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Stellar::Asset, ".alphanum4" do
|
10
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum4'" do
|
11
|
+
result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
12
|
+
expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum4)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "pads the code to 4 bytes, padding on the right and with null bytes" do
|
16
|
+
result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
17
|
+
expect(result.code).to eq("USD\x00")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Stellar::Asset, ".alphanum12" do
|
22
|
+
it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum12'" do
|
23
|
+
result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
24
|
+
expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum12)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "pads the code to 12 bytes, padding on the right and with null bytes" do
|
28
|
+
result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
29
|
+
expect(result.code).to eq("USD\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Stellar::Asset, "#code" do
|
34
|
+
it "returns the asset_code for either alphanum4 or alphanum12 assets" do
|
35
|
+
a4 = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
|
36
|
+
a12 = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
|
37
|
+
|
38
|
+
expect(a4.code.strip).to eq("USD")
|
39
|
+
expect(a12.code.strip).to eq("USD")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises an error when called on a native asset" do
|
43
|
+
expect{ Stellar::Asset.native.code }.to raise_error
|
44
|
+
end
|
45
|
+
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.1.
|
4
|
+
version: 0.1.3
|
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-07-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdr
|
@@ -374,6 +374,7 @@ files:
|
|
374
374
|
- lib/stellar/util/strkey.rb
|
375
375
|
- ruby-stellar-base.gemspec
|
376
376
|
- spec/lib/stellar/account_flags_spec.rb
|
377
|
+
- spec/lib/stellar/asset_spec.rb
|
377
378
|
- spec/lib/stellar/convert_spec.rb
|
378
379
|
- spec/lib/stellar/key_pair_spec.rb
|
379
380
|
- spec/lib/stellar/path_payment_result_spec.rb
|
@@ -422,6 +423,7 @@ specification_version: 4
|
|
422
423
|
summary: 'Stellar client library: XDR'
|
423
424
|
test_files:
|
424
425
|
- spec/lib/stellar/account_flags_spec.rb
|
426
|
+
- spec/lib/stellar/asset_spec.rb
|
425
427
|
- spec/lib/stellar/convert_spec.rb
|
426
428
|
- spec/lib/stellar/key_pair_spec.rb
|
427
429
|
- spec/lib/stellar/path_payment_result_spec.rb
|