stellar-sdk 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4aa578fb224a0afd75fbf3c65f3fa87cec56ede
4
- data.tar.gz: 35db6e2fe51dec1846ae32ec545352bfd46ed2ef
3
+ metadata.gz: d4aaec9c5a35f4373484c41fcc22795572e4a8a8
4
+ data.tar.gz: 80ac0dd562f6f4cc5e14a2a99d0ffb3c50a65dfd
5
5
  SHA512:
6
- metadata.gz: 714339c880444dd968673f8db1ee42348f2dca63b9097fc36f1e6c46fbccf6e42721d5c1b8824188891e902ec92577ccd3078c61a08197fcad4bb8b43d8d9594
7
- data.tar.gz: 6a47049ff8c0908a34377989f67e50feec2cf14e88dbef924448d3103ef606e5244e257ec20d791e8f41d6db2e2946b073a01381d8174189f749925fd05776a6
6
+ metadata.gz: 30e977ea4ee7ef94b1403432354c97798df61d941a802dba6bb39aedb6fb61e044a754c145b081020b2be5753f51ab0a6a4c9eefe2a61a170de36db5eb4970c2
7
+ data.tar.gz: 5348ac5e5adf3b01a70ac4748795c9fbcb428465d355060e94a3995be80dd098930ff64c1f081fee5da58e70c640f8669395310e06cc6683e0786d089754f38a
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ /spec/config.yml
@@ -0,0 +1 @@
1
+ ruby-2.3.1
@@ -1,15 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.5
5
- - 2.0.0
6
- - 1.9.3
7
- - jruby-1.7.9
8
- - jruby-head
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - jruby-9.1.6.0
6
+ cache: bundler
9
7
  script: LD_LIBRARY_PATH=lib bundle exec rake travis
10
- matrix:
11
- allow_failures:
12
- - rvm: jruby-head
8
+ before_script:
9
+ - cp spec/config.yml.sample spec/config.yml
13
10
  notifications:
14
11
  slack:
15
12
  secure: D1gWWsjE9i9XLRM6Bfw2pu3tTPW025iqjhgwE3KNw1QwP2TrehbCwRpjVR4rrnaju9FhYqM0+eT4rFc9g6itBPf2pfN1WziVf/CVJORYTzR9HbLL1rMOaWhEv4x/+Uwu0kxQon9ThnM9w6XjjD1+NoBfGn4Lcgc/OgmUGw1jAvQ=
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [Unreleased]
8
+ ### Changed
9
+ - Update stellar-base to `~> 0.12.0`
10
+
11
+ ### Fixed
12
+ - `#create_account`, along with `#send_payment`
13
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ruby Stellar
2
2
 
3
- [![Build Status](https://travis-ci.org/stellar/ruby-stellar-sdk.svg)](https://travis-ci.org/stellar/ruby-stellar-lib)
3
+ [![Build Status](https://travis-ci.org/stellar/ruby-stellar-sdk.svg)](https://travis-ci.org/stellar/ruby-stellar-sdk)
4
4
  [![Code Climate](https://codeclimate.com/github/stellar/ruby-stellar-sdk/badges/gpa.svg)](https://codeclimate.com/github/stellar/ruby-stellar-sdk)
5
5
 
6
6
  *STATUS: this library is very early and incomplete. The examples provided do not work, yet*
@@ -45,6 +45,12 @@ client.send_payment({
45
45
  })
46
46
  ```
47
47
 
48
+ ## Development
49
+
50
+ - Copy `spec/config.yml.sample` to `spec/config.yml`
51
+ - Replace anything in `spec/config.yml` especially if you will re-record specs
52
+ - `rspec spec`
53
+
48
54
  ## Contributing
49
55
 
50
56
  1. Sign the [Contributor License Agreement](https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form)
@@ -1,3 +1,6 @@
1
+ require 'toml-rb'
2
+ require 'uri'
3
+
1
4
  module Stellar
2
5
  class Account
3
6
  include Contracts
@@ -20,7 +23,36 @@ module Stellar
20
23
  end
21
24
 
22
25
  def self.lookup(federated_name)
23
- raise NotImplementedError
26
+ _, domain = federated_name.split('*')
27
+ if domain.nil?
28
+ raise InvalidFederationAddress.new
29
+ end
30
+
31
+ domain_req = Faraday.new("https://#{domain}/.well-known/stellar.toml").get
32
+
33
+ unless domain_req.status == 200
34
+ raise InvalidStellarDomain.new('Domain does not contain stellar.toml file')
35
+ end
36
+
37
+ fed_server_url = TomlRB.parse(domain_req.body)["FEDERATION_SERVER"]
38
+ if fed_server_url.nil?
39
+ raise InvalidStellarTOML.new('Invalid Stellar TOML file')
40
+ end
41
+
42
+ unless fed_server_url =~ URI::regexp
43
+ raise InvalidFederationURL.new('Invalid Federation Server URL')
44
+ end
45
+
46
+ lookup_req = Faraday.new(fed_server_url).get do |req|
47
+ req.params[:q] = federated_name
48
+ req.params[:type] = 'name'
49
+ end
50
+
51
+ unless lookup_req.status == 200
52
+ raise AccountNotFound.new('Account not found')
53
+ end
54
+
55
+ JSON.parse(lookup_req.body)["account_id"]
24
56
  end
25
57
 
26
58
  def self.master
@@ -35,4 +67,19 @@ module Stellar
35
67
  @keypair = keypair
36
68
  end
37
69
  end
70
+
71
+ class AccountNotFound < StandardError
72
+ end
73
+
74
+ class InvalidStellarTOML < StandardError
75
+ end
76
+
77
+ class InvalidFederationAddress < StandardError
78
+ end
79
+
80
+ class InvalidStellarDomain < StandardError
81
+ end
82
+
83
+ class InvalidFederationURL < StandardError
84
+ end
38
85
  end
@@ -15,7 +15,7 @@ module Stellar
15
15
 
16
16
 
17
17
  Contract None => Or[
18
- [Or[:credit_alphanum4, :credit_alphanum12], String, KeyPair, Pos],
18
+ [Or[:alphanum4, :alphanum12], String, KeyPair, Pos],
19
19
  [:native, Pos],
20
20
  ]
21
21
  def to_payment
@@ -23,11 +23,11 @@ module Stellar
23
23
  when AssetType.asset_type_native
24
24
  [:native, amount]
25
25
  when AssetType.asset_type_credit_alphanum4
26
- keypair = KeyPair.from_public_key(asset.issuer)
27
- [:credit_alphanum4, asset, keypair, amount]
26
+ keypair = KeyPair.from_public_key(asset.issuer.value)
27
+ [:alphanum4, asset.code, keypair, amount]
28
28
  when AssetType.asset_type_credit_alphanum12
29
- keypair = KeyPair.from_public_key(asset.issuer)
30
- [:credit_alphanum12, asset, keypair, amount]
29
+ keypair = KeyPair.from_public_key(asset.issuer.value)
30
+ [:alphanum12, asset.code, keypair, amount]
31
31
  else
32
32
  raise "Unknown asset type: #{asset.type}"
33
33
  end
@@ -37,4 +37,4 @@ module Stellar
37
37
  "#<Stellar::Amount #{asset}(#{amount})>"
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -49,8 +49,8 @@ module Stellar
49
49
  # Contract Stellar::Account => Stellar::AccountInfo
50
50
  Contract Stellar::Account => Any
51
51
  def account_info(account)
52
- address = account.address
53
- @horizon.account(address:address)
52
+ account_id = account.address
53
+ @horizon.account(account_id:account_id)
54
54
  end
55
55
 
56
56
  Contract ({
@@ -60,7 +60,7 @@ module Stellar
60
60
  }) => Any
61
61
  def send_payment(options={})
62
62
  from = options[:from]
63
- sequence = options[:sequence] || (account_info(from).sequence + 1)
63
+ sequence = options[:sequence] || (account_info(from).sequence.to_i + 1)
64
64
 
65
65
  payment = Stellar::Transaction.payment({
66
66
  account: from.keypair,
@@ -69,28 +69,30 @@ module Stellar
69
69
  amount: options[:amount].to_payment,
70
70
  })
71
71
 
72
- envelope_hex = payment.to_envelope(from.keypair).to_xdr(:hex)
73
- @horizon.transactions._post(tx: envelope_hex)
72
+ envelope_base64 = payment.to_envelope(from.keypair).to_xdr(:base64)
73
+ @horizon.transactions._post(tx: envelope_base64)
74
74
  end
75
75
 
76
76
  Contract ({
77
77
  account: Stellar::Account,
78
78
  funder: Stellar::Account,
79
- starting_balance: Fixnum
79
+ starting_balance: Integer
80
80
  }) => Any
81
81
  def create_account(options={})
82
82
  funder = options[:funder]
83
- sequence = options[:sequence] || (account_info(funder).sequence + 1)
83
+ sequence = options[:sequence] || (account_info(funder).sequence.to_i + 1)
84
+ fee = options[:fee] || 100 * Stellar::ONE
84
85
 
85
86
  payment = Stellar::Transaction.create_account({
86
87
  account: funder.keypair,
87
88
  destination: options[:account].keypair,
88
89
  sequence: sequence,
89
90
  starting_balance: options[:starting_balance],
91
+ fee: fee,
90
92
  })
91
93
 
92
- envelope_hex = payment.to_envelope(funder.keypair).to_xdr(:hex)
93
- @horizon.transactions._post(tx: envelope_hex)
94
+ envelope_base64 = payment.to_envelope(funder.keypair).to_xdr(:base64)
95
+ @horizon.transactions._post(tx: envelope_base64)
94
96
  end
95
97
 
96
98
  Contract ({
@@ -101,7 +103,7 @@ module Stellar
101
103
  args = options.slice(:limit)
102
104
 
103
105
  resource = if options[:account]
104
- args = args.merge(address: options[:account].address)
106
+ args = args.merge(account_id: options[:account].address)
105
107
  @horizon.account_transactions(args)
106
108
  else
107
109
  @horizon.transactions(args)
@@ -1,3 +1,3 @@
1
1
  module Stellar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -17,11 +17,12 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "stellar-base", "~> 0.11.0"
20
+ spec.add_dependency "stellar-base", "~> 0.13.0"
21
21
  spec.add_dependency "hyperclient", "~> 0.7.0"
22
22
  spec.add_dependency "excon", "~> 0.44.4"
23
23
  spec.add_dependency "contracts", "~> 0.7"
24
- spec.add_dependency "activesupport", "~> 4"
24
+ spec.add_dependency "activesupport", ">= 4.2.7"
25
+ spec.add_dependency "toml-rb", "~> 1.1.1"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.7"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
@@ -29,5 +30,7 @@ Gem::Specification.new do |spec|
29
30
  spec.add_development_dependency "guard-rspec"
30
31
  spec.add_development_dependency "simplecov"
31
32
  spec.add_development_dependency "yard"
33
+ spec.add_development_dependency "vcr", "~> 3.0"
34
+ spec.add_development_dependency "webmock", "~> 2.3"
32
35
 
33
36
  end
@@ -0,0 +1,10 @@
1
+ ---
2
+ # Source must be funded already. It is also used as an issuer of BTC
3
+ source_seed: "SABJWDUVR2AHZEJ6FSVTHAPDHMR3K7A6VP3APHFHRJTUXEHMDS6AL3VY"
4
+ source_address: "GCQSESW66AX4ZRZB7QWCIXSPX2BD7KLOYSS33IUGDCLO4XCPURZEEC6R"
5
+
6
+ # Destination is used to test sending of assets. Until this gem supports
7
+ # creating trustlines, we have to do this. The following account must trust the
8
+ # source's BTC asset
9
+ destination_seed: "SCPIADRAFSPKE5KEUZ6BKXSMRFFSO7UCSTRKALT23U3DVQ3WWNTPA44Z"
10
+ destination_address: "GCQSESW66AX4ZRZB7QWCIXSPX2BD7KLOYSS33IUGDCLO4XCPURZEEC6R"
@@ -0,0 +1,133 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://stellarfed.org/.well-known/stellar.toml
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.14.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Tue, 20 Feb 2018 18:58:58 GMT
23
+ Content-Type:
24
+ - text/plain; charset=utf-8
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=de30e4abf7a551661d3deb92e6e3716011519153138; expires=Wed, 20-Feb-19
31
+ 18:58:58 GMT; path=/; domain=.stellarfed.org; HttpOnly; Secure
32
+ X-Frame-Options:
33
+ - SAMEORIGIN
34
+ X-Xss-Protection:
35
+ - 1; mode=block
36
+ X-Content-Type-Options:
37
+ - nosniff
38
+ X-Download-Options:
39
+ - noopen
40
+ X-Permitted-Cross-Domain-Policies:
41
+ - none
42
+ Referrer-Policy:
43
+ - strict-origin-when-cross-origin
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Etag:
47
+ - W/"e00cc6ea5aab41de546253c69965d937"
48
+ Cache-Control:
49
+ - max-age=0, private, must-revalidate
50
+ X-Request-Id:
51
+ - 6a387582-adbe-4bfd-836b-eabf658fce22
52
+ X-Runtime:
53
+ - '0.002500'
54
+ Strict-Transport-Security:
55
+ - max-age=15552000; includeSubDomains
56
+ Via:
57
+ - 1.1 vegur
58
+ Expect-Ct:
59
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
60
+ Server:
61
+ - cloudflare
62
+ Cf-Ray:
63
+ - 3f03b34b0e799266-EWR
64
+ body:
65
+ encoding: ASCII-8BIT
66
+ string: FEDERATION_SERVER = "https://stellarfed.org/federation"
67
+ http_version:
68
+ recorded_at: Tue, 20 Feb 2018 18:58:58 GMT
69
+ - request:
70
+ method: get
71
+ uri: https://stellarfed.org/federation?q=jane@email.com*stellarfed.org&type=name
72
+ body:
73
+ encoding: US-ASCII
74
+ string: ''
75
+ headers:
76
+ User-Agent:
77
+ - Faraday v0.14.0
78
+ Accept-Encoding:
79
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
80
+ Accept:
81
+ - "*/*"
82
+ response:
83
+ status:
84
+ code: 404
85
+ message: Not Found
86
+ headers:
87
+ Date:
88
+ - Tue, 20 Feb 2018 18:58:58 GMT
89
+ Content-Type:
90
+ - application/json; charset=utf-8
91
+ Transfer-Encoding:
92
+ - chunked
93
+ Connection:
94
+ - keep-alive
95
+ Set-Cookie:
96
+ - __cfduid=d164f4eba862038aaf9e96d9ac755d9471519153138; expires=Wed, 20-Feb-19
97
+ 18:58:58 GMT; path=/; domain=.stellarfed.org; HttpOnly; Secure
98
+ X-Frame-Options:
99
+ - SAMEORIGIN
100
+ X-Xss-Protection:
101
+ - 1; mode=block
102
+ X-Content-Type-Options:
103
+ - nosniff
104
+ X-Download-Options:
105
+ - noopen
106
+ X-Permitted-Cross-Domain-Policies:
107
+ - none
108
+ Referrer-Policy:
109
+ - strict-origin-when-cross-origin
110
+ Access-Control-Allow-Origin:
111
+ - "*"
112
+ Cache-Control:
113
+ - no-cache
114
+ X-Request-Id:
115
+ - 2b9424e9-6cb3-4cdc-915e-469f8e2123e3
116
+ X-Runtime:
117
+ - '0.004981'
118
+ Strict-Transport-Security:
119
+ - max-age=15552000; includeSubDomains
120
+ Via:
121
+ - 1.1 vegur
122
+ Expect-Ct:
123
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
124
+ Server:
125
+ - cloudflare
126
+ Cf-Ray:
127
+ - 3f03b34bbd5c91d0-EWR
128
+ body:
129
+ encoding: ASCII-8BIT
130
+ string: '{"detail":"no record found"}'
131
+ http_version:
132
+ recorded_at: Tue, 20 Feb 2018 18:58:58 GMT
133
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://stellar.org/.well-known/stellar.toml
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.14.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 301
19
+ message: Moved Permanently
20
+ headers:
21
+ Date:
22
+ - Tue, 20 Feb 2018 19:11:53 GMT
23
+ Transfer-Encoding:
24
+ - chunked
25
+ Connection:
26
+ - keep-alive
27
+ Cache-Control:
28
+ - max-age=3600
29
+ Expires:
30
+ - Tue, 20 Feb 2018 20:11:53 GMT
31
+ Location:
32
+ - https://www.stellar.org/.well-known/stellar.toml
33
+ Expect-Ct:
34
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
35
+ Server:
36
+ - cloudflare
37
+ Cf-Ray:
38
+ - 3f03c6383855215c-EWR
39
+ body:
40
+ encoding: UTF-8
41
+ string: ''
42
+ http_version:
43
+ recorded_at: Tue, 20 Feb 2018 19:11:53 GMT
44
+ recorded_with: VCR 3.0.3