stellar-base 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf6776556e7768bfa027ac24a2f5db5ab06cc2c5
4
- data.tar.gz: 27742e565e992025460c86d1a85f95fccad3f238
3
+ metadata.gz: 19c996423e6ccb1a43a3da3de6338838ef443b8a
4
+ data.tar.gz: 1310708e376a5cd4dfe246d2a91e196f2c214cc2
5
5
  SHA512:
6
- metadata.gz: 1e5322413bba96a461eb56e22203affb4b70fd1ac7cbca8db2dfafa9a61b143f90ce500ea282e2f77da8046bcf49b8d8094a3b5c4cc111ae64d5d2af0f4873bd
7
- data.tar.gz: e55615e11ab0f4fc661a8887fae017f5822391b863d79aae8e3eb98275abbbed57029fbb788626434f8b651cc97b286d79e746318af6224dc77f6e9376cbf4bf
6
+ metadata.gz: 8fec9593753a0aa9928f57f62bc1079b7a55605aa4233c6faffb4b405d24b7e4a64db7080cde242ce3afb4495ba9c088432b9187b116d846c9816147e3070f9d
7
+ data.tar.gz: d66d8e6dbfe8c1557da22c11d484fe8593952ba2a06c122f703078423da1b87986626f83c40aa93e43ced422622b3c031bd5c44740c605d274cef13b34b9aa8a
data/Guardfile CHANGED
@@ -1,5 +1,5 @@
1
- guard :rspec, cmd: 'rspec' do
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
- end
5
+ end
@@ -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.from_raw_seed("allmylifemyhearthasbeensearching")
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: 2,
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
- if switch == AssetType.asset_type_native
22
+ case switch
23
+ when AssetType.asset_type_native
16
24
  "native"
17
- else
18
- issuer_address = Stellar::Util::StrKey.check_encode(:account_id,alpha_num.issuer)
19
- "#{alpha_num.asset_code}/#{issuer_address}"
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
- self.alpha_num!.asset_code
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 <= 4 bytes" if code.length > 4
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(4, "\x00")
66
+ code.ljust(length, "\x00")
36
67
  end
37
68
  end
38
69
  end
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -27,6 +27,10 @@ module Stellar
27
27
  new(public_key, secret_key)
28
28
  end
29
29
 
30
+ def self.master
31
+ from_raw_seed("allmylifemyhearthasbeensearching")
32
+ end
33
+
30
34
  def initialize(public_key, secret_key=nil)
31
35
  @public_key = public_key
32
36
  @secret_key = secret_key
@@ -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.2
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-22 00:00:00.000000000 Z
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