stellar-sdk 0.29.0 → 0.30.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 +10 -0
- data/lib/stellar/federation.rb +2 -2
- data/lib/stellar-sdk.rb +2 -12
- metadata +24 -35
- data/lib/stellar/amount.rb +0 -36
- data/lib/stellar/client.rb +0 -300
- data/lib/stellar/compat.rb +0 -4
- data/lib/stellar/horizon/problem.rb +0 -45
- data/lib/stellar/transaction_page.rb +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5dc8d8d67076947afebdb2065fa08387d878e4250b5604ddfb4eb32b7056507a
|
|
4
|
+
data.tar.gz: 71b168f5ce4f97e76839d712eec86241a6839b0f93d7cd45544692703b28af22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf1ebdc0471f3884cfe207bcfc2f1131b6efbb9e35b7b4cce75044fea3b0c2245f7219af4b04bc868b79396d01303209fdc8ce041102b124ab92e64cb30e2dcc
|
|
7
|
+
data.tar.gz: 773d3492c23d37de50cafff1c6847aa0041136d235013e5d3526b44dc7a5e81ba18a77698eebcff3bb31f040bd958d903a803e2b9033205607cc47776c44e004
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [0.30.0](https://www.github.com/astroband/ruby-stellar-sdk/compare/v0.29.0...v0.30.0) (2021-10-14)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
* `stellar-sdk` now depends on `stellar-horizon`
|
|
12
|
+
### Changed
|
|
13
|
+
* `Stellar::Amount` class moved to `stellar-base` gem
|
|
14
|
+
* `Stellar::Horizon::Problem` class moved to `stellar-horizon` gem
|
|
15
|
+
* `Stellar::TransactionPage` is now `Stellar::Horizon::TransactionPage` in `stellar-horizon` gem
|
|
16
|
+
* `toml-rb` gem is replaced with `tomlrb` gem to work around [segfaults in Ruby 3.0](https://github.com/mjackson/citrus/issues/60)
|
|
17
|
+
|
|
8
18
|
## [0.29.0](https://www.github.com/astroband/ruby-stellar-sdk/compare/v0.28.0...v0.29.0) (2021-09-07)
|
|
9
19
|
|
|
10
20
|
### Added
|
data/lib/stellar/federation.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "tomlrb"
|
|
2
2
|
require "uri"
|
|
3
3
|
require "faraday"
|
|
4
4
|
require "json"
|
|
@@ -17,7 +17,7 @@ module Stellar
|
|
|
17
17
|
raise InvalidStellarDomain, "Domain does not contain stellar.toml file"
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
fed_server_url =
|
|
20
|
+
fed_server_url = Tomlrb.parse(domain_req.body)["FEDERATION_SERVER"]
|
|
21
21
|
if fed_server_url.nil?
|
|
22
22
|
raise InvalidStellarTOML, "Invalid Stellar TOML file"
|
|
23
23
|
end
|
data/lib/stellar-sdk.rb
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
require "stellar-base"
|
|
2
|
+
require "stellar-horizon"
|
|
2
3
|
|
|
3
4
|
module Stellar
|
|
4
5
|
module SDK
|
|
5
6
|
VERSION = ::Stellar::VERSION
|
|
6
7
|
end
|
|
8
|
+
Client = Horizon::Client
|
|
7
9
|
|
|
8
10
|
autoload :Amount
|
|
9
|
-
autoload :Client
|
|
10
11
|
autoload :Federation
|
|
11
12
|
autoload :SEP10
|
|
12
|
-
|
|
13
|
-
module Horizon
|
|
14
|
-
extend ActiveSupport::Autoload
|
|
15
|
-
|
|
16
|
-
autoload :Problem
|
|
17
|
-
autoload :Result
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
autoload :TransactionPage
|
|
21
13
|
end
|
|
22
|
-
|
|
23
|
-
require_relative "stellar/compat"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stellar-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.30.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott Fleckenstein
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2021-
|
|
13
|
+
date: 2021-10-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: stellar-base
|
|
@@ -18,61 +18,55 @@ dependencies:
|
|
|
18
18
|
requirements:
|
|
19
19
|
- - '='
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 0.
|
|
21
|
+
version: 0.30.0
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
requirements:
|
|
26
26
|
- - '='
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: 0.
|
|
28
|
+
version: 0.30.0
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
|
30
|
-
name:
|
|
30
|
+
name: stellar-horizon
|
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
|
32
32
|
requirements:
|
|
33
|
-
- -
|
|
34
|
-
- !ruby/object:Gem::Version
|
|
35
|
-
version: 5.0.0
|
|
36
|
-
- - "<"
|
|
33
|
+
- - '='
|
|
37
34
|
- !ruby/object:Gem::Version
|
|
38
|
-
version:
|
|
35
|
+
version: 0.30.0
|
|
39
36
|
type: :runtime
|
|
40
37
|
prerelease: false
|
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
39
|
requirements:
|
|
43
|
-
- -
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: 5.0.0
|
|
46
|
-
- - "<"
|
|
40
|
+
- - '='
|
|
47
41
|
- !ruby/object:Gem::Version
|
|
48
|
-
version:
|
|
42
|
+
version: 0.30.0
|
|
49
43
|
- !ruby/object:Gem::Dependency
|
|
50
|
-
name:
|
|
44
|
+
name: activesupport
|
|
51
45
|
requirement: !ruby/object:Gem::Requirement
|
|
52
46
|
requirements:
|
|
53
47
|
- - ">="
|
|
54
48
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: 0.
|
|
49
|
+
version: 5.0.0
|
|
56
50
|
- - "<"
|
|
57
51
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '
|
|
52
|
+
version: '7.0'
|
|
59
53
|
type: :runtime
|
|
60
54
|
prerelease: false
|
|
61
55
|
version_requirements: !ruby/object:Gem::Requirement
|
|
62
56
|
requirements:
|
|
63
57
|
- - ">="
|
|
64
58
|
- !ruby/object:Gem::Version
|
|
65
|
-
version: 0.
|
|
59
|
+
version: 5.0.0
|
|
66
60
|
- - "<"
|
|
67
61
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
62
|
+
version: '7.0'
|
|
69
63
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
64
|
+
name: faraday
|
|
71
65
|
requirement: !ruby/object:Gem::Requirement
|
|
72
66
|
requirements:
|
|
73
67
|
- - ">="
|
|
74
68
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
69
|
+
version: 1.6.0
|
|
76
70
|
- - "<"
|
|
77
71
|
- !ruby/object:Gem::Version
|
|
78
72
|
version: '2.0'
|
|
@@ -82,17 +76,17 @@ dependencies:
|
|
|
82
76
|
requirements:
|
|
83
77
|
- - ">="
|
|
84
78
|
- !ruby/object:Gem::Version
|
|
85
|
-
version:
|
|
79
|
+
version: 1.6.0
|
|
86
80
|
- - "<"
|
|
87
81
|
- !ruby/object:Gem::Version
|
|
88
82
|
version: '2.0'
|
|
89
83
|
- !ruby/object:Gem::Dependency
|
|
90
|
-
name:
|
|
84
|
+
name: tomlrb
|
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
|
92
86
|
requirements:
|
|
93
87
|
- - ">="
|
|
94
88
|
- !ruby/object:Gem::Version
|
|
95
|
-
version:
|
|
89
|
+
version: 2.0.1
|
|
96
90
|
- - "<"
|
|
97
91
|
- !ruby/object:Gem::Version
|
|
98
92
|
version: '3.0'
|
|
@@ -102,7 +96,7 @@ dependencies:
|
|
|
102
96
|
requirements:
|
|
103
97
|
- - ">="
|
|
104
98
|
- !ruby/object:Gem::Version
|
|
105
|
-
version:
|
|
99
|
+
version: 2.0.1
|
|
106
100
|
- - "<"
|
|
107
101
|
- !ruby/object:Gem::Version
|
|
108
102
|
version: '3.0'
|
|
@@ -161,23 +155,18 @@ files:
|
|
|
161
155
|
- LICENSE
|
|
162
156
|
- README.md
|
|
163
157
|
- lib/stellar-sdk.rb
|
|
164
|
-
- lib/stellar/amount.rb
|
|
165
|
-
- lib/stellar/client.rb
|
|
166
|
-
- lib/stellar/compat.rb
|
|
167
158
|
- lib/stellar/federation.rb
|
|
168
|
-
- lib/stellar/horizon/problem.rb
|
|
169
159
|
- lib/stellar/sep10.rb
|
|
170
|
-
- lib/stellar/transaction_page.rb
|
|
171
160
|
homepage: https://github.com/astroband/ruby-stellar-sdk
|
|
172
161
|
licenses:
|
|
173
162
|
- Apache-2.0
|
|
174
163
|
metadata:
|
|
175
164
|
bug_tracker_uri: https://github.com/astroband/ruby-stellar-sdk/issues
|
|
176
|
-
changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.
|
|
177
|
-
documentation_uri: https://rubydoc.info/gems/stellar-sdk/0.
|
|
165
|
+
changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.30.0/sdk/CHANGELOG.md
|
|
166
|
+
documentation_uri: https://rubydoc.info/gems/stellar-sdk/0.30.0/
|
|
178
167
|
github_repo: ssh://github.com/astroband/ruby-stellar-sdk
|
|
179
168
|
homepage_uri: https://github.com/astroband/ruby-stellar-sdk/tree/main/sdk
|
|
180
|
-
source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.
|
|
169
|
+
source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.30.0/sdk
|
|
181
170
|
post_install_message:
|
|
182
171
|
rdoc_options: []
|
|
183
172
|
require_paths:
|
|
@@ -193,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
193
182
|
- !ruby/object:Gem::Version
|
|
194
183
|
version: '0'
|
|
195
184
|
requirements: []
|
|
196
|
-
rubygems_version: 3.
|
|
185
|
+
rubygems_version: 3.2.22
|
|
197
186
|
signing_key:
|
|
198
187
|
specification_version: 4
|
|
199
188
|
summary: Stellar client library
|
data/lib/stellar/amount.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module Stellar
|
|
2
|
-
class Amount
|
|
3
|
-
attr_reader :amount
|
|
4
|
-
attr_reader :asset
|
|
5
|
-
|
|
6
|
-
# @param [Fixnum] amount
|
|
7
|
-
# @param [Stellar::Asset] asset
|
|
8
|
-
def initialize(amount, asset = Stellar::Asset.native)
|
|
9
|
-
# TODO: how are we going to handle decimal considerations?
|
|
10
|
-
|
|
11
|
-
@amount = amount
|
|
12
|
-
@asset = asset
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# @return [Array(Symbol, Fixnum)] in case of a native asset
|
|
16
|
-
# @return [Array(Symbol, String, Stellar::KeyPair, Fixnum)] in case of alphanum asset
|
|
17
|
-
def to_payment
|
|
18
|
-
case asset.type
|
|
19
|
-
when AssetType.asset_type_native
|
|
20
|
-
[:native, amount]
|
|
21
|
-
when AssetType.asset_type_credit_alphanum4
|
|
22
|
-
keypair = KeyPair.from_public_key(asset.issuer.value)
|
|
23
|
-
[:alphanum4, asset.code, keypair, amount]
|
|
24
|
-
when AssetType.asset_type_credit_alphanum12
|
|
25
|
-
keypair = KeyPair.from_public_key(asset.issuer.value)
|
|
26
|
-
[:alphanum12, asset.code, keypair, amount]
|
|
27
|
-
else
|
|
28
|
-
raise "Unknown asset type: #{asset.type}"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def inspect
|
|
33
|
-
"#<Stellar::Amount #{asset}(#{amount})>"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/lib/stellar/client.rb
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
require "hyperclient"
|
|
2
|
-
require "active_support/core_ext/object/blank"
|
|
3
|
-
require "securerandom"
|
|
4
|
-
|
|
5
|
-
module Stellar
|
|
6
|
-
class AccountRequiresMemoError < StandardError
|
|
7
|
-
attr_reader :account_id, :operation_index
|
|
8
|
-
|
|
9
|
-
def initialize(message, account_id, operation_index)
|
|
10
|
-
super(message)
|
|
11
|
-
@account_id = account_id
|
|
12
|
-
@operation_index = operation_index
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class Client
|
|
17
|
-
DEFAULT_FEE = 100
|
|
18
|
-
|
|
19
|
-
HORIZON_LOCALHOST_URL = "http://127.0.0.1:8000"
|
|
20
|
-
HORIZON_MAINNET_URL = "https://horizon.stellar.org"
|
|
21
|
-
HORIZON_TESTNET_URL = "https://horizon-testnet.stellar.org"
|
|
22
|
-
FRIENDBOT_URL = "https://friendbot.stellar.org".freeze
|
|
23
|
-
|
|
24
|
-
def self.default(options = {})
|
|
25
|
-
new options.merge(
|
|
26
|
-
horizon: HORIZON_MAINNET_URL
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def self.default_testnet(options = {})
|
|
31
|
-
new options.merge(
|
|
32
|
-
horizon: HORIZON_TESTNET_URL,
|
|
33
|
-
friendbot: HORIZON_TESTNET_URL
|
|
34
|
-
)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def self.localhost(options = {})
|
|
38
|
-
new options.merge(
|
|
39
|
-
horizon: HORIZON_LOCALHOST_URL
|
|
40
|
-
)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
attr_reader :horizon
|
|
44
|
-
|
|
45
|
-
# @option options [String] :horizon The Horizon server URL.
|
|
46
|
-
def initialize(options)
|
|
47
|
-
ActiveSupport::Deprecation.warn("`Stellar::Horizon` is deprecated and will be removed from `stellar-sdk` next relase. Use `stellar-horizon` gem for requesting Horizon API")
|
|
48
|
-
|
|
49
|
-
@options = options
|
|
50
|
-
@horizon = Hyperclient.new(options[:horizon]) { |client|
|
|
51
|
-
client.faraday_block = lambda do |conn|
|
|
52
|
-
conn.use Faraday::Response::RaiseError
|
|
53
|
-
conn.use FaradayMiddleware::FollowRedirects
|
|
54
|
-
conn.request :url_encoded
|
|
55
|
-
conn.response :hal_json, content_type: /\bjson$/
|
|
56
|
-
conn.adapter :excon
|
|
57
|
-
end
|
|
58
|
-
client.headers = {
|
|
59
|
-
"Accept" => "application/hal+json,application/problem+json,application/json",
|
|
60
|
-
"X-Client-Name" => "ruby-stellar-sdk",
|
|
61
|
-
"X-Client-Version" => VERSION
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# @param [Stellar::Account|String] account_or_address
|
|
67
|
-
def account_info(account_or_address)
|
|
68
|
-
account_id = if account_or_address.is_a?(Stellar::Account)
|
|
69
|
-
account_or_address.address
|
|
70
|
-
else
|
|
71
|
-
account_or_address
|
|
72
|
-
end
|
|
73
|
-
@horizon.account(account_id: account_id)._get
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# @option options [Stellar::Account] :account
|
|
77
|
-
# @option options [Stellar::Account] :destination
|
|
78
|
-
def account_merge(options = {})
|
|
79
|
-
account = options[:account]
|
|
80
|
-
destination = options[:destination]
|
|
81
|
-
sequence = options[:sequence] || (account_info(account).sequence.to_i + 1)
|
|
82
|
-
|
|
83
|
-
transaction = Stellar::TransactionBuilder.account_merge(
|
|
84
|
-
source_account: destination.keypair,
|
|
85
|
-
sequence_number: sequence,
|
|
86
|
-
destination: destination.keypair
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
envelope = transaction.to_envelope(account.keypair)
|
|
90
|
-
submit_transaction(tx_envelope: envelope)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def friendbot(account)
|
|
94
|
-
uri = URI.parse(FRIENDBOT_URL)
|
|
95
|
-
uri.query = "addr=#{account.address}"
|
|
96
|
-
Faraday.post(uri.to_s)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# @option options [Stellar::Account] :account
|
|
100
|
-
# @option options [Stellar::Account] :funder
|
|
101
|
-
# @option options [Integer] :starting_balance
|
|
102
|
-
def create_account(options = {})
|
|
103
|
-
funder = options[:funder]
|
|
104
|
-
sequence = options[:sequence] || (account_info(funder).sequence.to_i + 1)
|
|
105
|
-
# In the future, the fee should be grabbed from the network's last transactions,
|
|
106
|
-
# instead of using a hard-coded default value.
|
|
107
|
-
fee = options[:fee] || DEFAULT_FEE
|
|
108
|
-
|
|
109
|
-
payment = Stellar::TransactionBuilder.create_account(
|
|
110
|
-
source_account: funder.keypair,
|
|
111
|
-
sequence_number: sequence,
|
|
112
|
-
base_fee: fee,
|
|
113
|
-
destination: options[:account].keypair,
|
|
114
|
-
starting_balance: options[:starting_balance]
|
|
115
|
-
)
|
|
116
|
-
envelope = payment.to_envelope(funder.keypair)
|
|
117
|
-
submit_transaction(tx_envelope: envelope)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# @option options [Stellar::Account] :from The source account
|
|
121
|
-
# @option options [Stellar::Account] :to The destination account
|
|
122
|
-
# @option options [Stellar::Amount] :amount The amount to send
|
|
123
|
-
def send_payment(options = {})
|
|
124
|
-
from_account = options[:from]
|
|
125
|
-
tx_source_account = options[:transaction_source] || from_account
|
|
126
|
-
op_source_account = from_account if tx_source_account.present?
|
|
127
|
-
|
|
128
|
-
sequence = options[:sequence] ||
|
|
129
|
-
(account_info(tx_source_account).sequence.to_i + 1)
|
|
130
|
-
|
|
131
|
-
payment = Stellar::TransactionBuilder.new(
|
|
132
|
-
source_account: tx_source_account.keypair,
|
|
133
|
-
sequence_number: sequence
|
|
134
|
-
).add_operation(
|
|
135
|
-
Stellar::Operation.payment(
|
|
136
|
-
source_account: op_source_account.keypair,
|
|
137
|
-
destination: options[:to].keypair,
|
|
138
|
-
amount: options[:amount].to_payment
|
|
139
|
-
)
|
|
140
|
-
).set_memo(options[:memo]).set_timeout(0).build
|
|
141
|
-
|
|
142
|
-
signers = [tx_source_account, op_source_account].uniq(&:address)
|
|
143
|
-
to_envelope_args = signers.map(&:keypair)
|
|
144
|
-
|
|
145
|
-
envelope = payment.to_envelope(*to_envelope_args)
|
|
146
|
-
submit_transaction(tx_envelope: envelope)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# @option options [Stellar::Account] :account
|
|
150
|
-
# @option options [Integer] :limit
|
|
151
|
-
# @option options [Integer] :cursor
|
|
152
|
-
# @return [Stellar::TransactionPage]
|
|
153
|
-
def transactions(options = {})
|
|
154
|
-
args = options.slice(:limit, :cursor)
|
|
155
|
-
|
|
156
|
-
resource = if options[:account]
|
|
157
|
-
args = args.merge(account_id: options[:account].address)
|
|
158
|
-
@horizon.account_transactions(args)
|
|
159
|
-
else
|
|
160
|
-
@horizon.transactions(args)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
TransactionPage.new(resource)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
# @param [Array(Symbol,String,Stellar::KeyPair|Stellar::Account)] asset
|
|
167
|
-
# @param [Stellar::Account] source
|
|
168
|
-
# @param [Integer] sequence
|
|
169
|
-
# @param [Integer] fee
|
|
170
|
-
# @param [Integer] limit
|
|
171
|
-
def change_trust(
|
|
172
|
-
asset:,
|
|
173
|
-
source:,
|
|
174
|
-
sequence: nil,
|
|
175
|
-
fee: DEFAULT_FEE,
|
|
176
|
-
limit: nil
|
|
177
|
-
)
|
|
178
|
-
sequence ||= (account_info(source).sequence.to_i + 1)
|
|
179
|
-
|
|
180
|
-
op_args = {
|
|
181
|
-
account: source.keypair,
|
|
182
|
-
sequence: sequence,
|
|
183
|
-
line: asset
|
|
184
|
-
}
|
|
185
|
-
op_args[:limit] = limit unless limit.nil?
|
|
186
|
-
|
|
187
|
-
tx = Stellar::TransactionBuilder.change_trust(
|
|
188
|
-
source_account: source.keypair,
|
|
189
|
-
sequence_number: sequence,
|
|
190
|
-
**op_args
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
envelope = tx.to_envelope(source.keypair)
|
|
194
|
-
submit_transaction(tx_envelope: envelope)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# @param [Stellar::TransactionEnvelope] tx_envelope
|
|
198
|
-
# @option options [Boolean] :skip_memo_required_check (false)
|
|
199
|
-
def submit_transaction(tx_envelope:, options: {skip_memo_required_check: false})
|
|
200
|
-
unless options[:skip_memo_required_check]
|
|
201
|
-
check_memo_required(tx_envelope)
|
|
202
|
-
end
|
|
203
|
-
@horizon.transactions._post(tx: tx_envelope.to_xdr(:base64))
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
# Required by SEP-0029
|
|
207
|
-
# @param [Stellar::TransactionEnvelope] tx_envelope
|
|
208
|
-
def check_memo_required(tx_envelope)
|
|
209
|
-
tx = tx_envelope.tx
|
|
210
|
-
|
|
211
|
-
if tx.is_a?(Stellar::FeeBumpTransaction)
|
|
212
|
-
tx = tx.inner_tx.v1!.tx
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
# Check transactions where the .memo field is nil or of type MemoType.memo_none
|
|
216
|
-
if !tx.memo.nil? && tx.memo.type != Stellar::MemoType.memo_none
|
|
217
|
-
return
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
destinations = Set.new
|
|
221
|
-
ot = Stellar::OperationType
|
|
222
|
-
|
|
223
|
-
tx.operations.each_with_index do |op, idx|
|
|
224
|
-
destination = case op.body.type
|
|
225
|
-
when ot.payment, ot.path_payment_strict_receive, ot.path_payment_strict_send
|
|
226
|
-
op.body.value.destination
|
|
227
|
-
when ot.account_merge
|
|
228
|
-
# There is no AccountMergeOp, op.body is an Operation object
|
|
229
|
-
# and op.body.value is a PublicKey (or AccountID) object.
|
|
230
|
-
op.body.value
|
|
231
|
-
else
|
|
232
|
-
next
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
if destinations.include?(destination) || destination.switch == Stellar::CryptoKeyType.key_type_muxed_ed25519
|
|
236
|
-
next
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
destinations.add(destination)
|
|
240
|
-
kp = Stellar::KeyPair.from_public_key(destination.value)
|
|
241
|
-
|
|
242
|
-
begin
|
|
243
|
-
info = account_info(kp.address)
|
|
244
|
-
rescue Faraday::ResourceNotFound
|
|
245
|
-
# Don't raise an error if its a 404, but throw one otherwise
|
|
246
|
-
next
|
|
247
|
-
end
|
|
248
|
-
if info.data["config.memo_required"] == "MQ=="
|
|
249
|
-
# MQ== is the base64 encoded string for the string "1"
|
|
250
|
-
raise AccountRequiresMemoError.new("account requires memo", destination, idx)
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
# DEPRECATED: this function has been moved Stellar::SEP10.build_challenge_tx and
|
|
256
|
-
# will be removed in the next major version release.
|
|
257
|
-
#
|
|
258
|
-
# A wrapper function for Stellar::SEP10::build_challenge_tx.
|
|
259
|
-
#
|
|
260
|
-
# @param server [Stellar::KeyPair] Keypair for server's signing account.
|
|
261
|
-
# @param client [Stellar::KeyPair] Keypair for the account whishing to authenticate with the server.
|
|
262
|
-
# @param anchor_name [String] Anchor's name to be used in the manage_data key.
|
|
263
|
-
# @param timeout [Integer] Challenge duration (default to 5 minutes).
|
|
264
|
-
#
|
|
265
|
-
# @return [String] A base64 encoded string of the raw TransactionEnvelope xdr struct for the transaction.
|
|
266
|
-
def build_challenge_tx(server:, client:, anchor_name:, timeout: 300)
|
|
267
|
-
Stellar::SEP10.build_challenge_tx(
|
|
268
|
-
server: server, client: client, anchor_name: anchor_name, timeout: timeout
|
|
269
|
-
)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
# DEPRECATED: this function has been moved to Stellar::SEP10::read_challenge_tx and
|
|
273
|
-
# will be removed in the next major version release.
|
|
274
|
-
#
|
|
275
|
-
# A wrapper function for Stellar::SEP10.verify_challenge_transaction
|
|
276
|
-
#
|
|
277
|
-
# @param challenge [String] SEP0010 transaction challenge in base64.
|
|
278
|
-
# @param server [Stellar::KeyPair] Stellar::KeyPair for server where the challenge was generated.
|
|
279
|
-
#
|
|
280
|
-
# @return [Boolean]
|
|
281
|
-
def verify_challenge_tx(challenge:, server:)
|
|
282
|
-
Stellar::SEP10.verify_challenge_tx(challenge_xdr: challenge, server: server)
|
|
283
|
-
true
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
# DEPRECATED: this function has been moved to Stellar::SEP10::verify_tx_signed_by and
|
|
287
|
-
# will be removed in the next major version release.
|
|
288
|
-
#
|
|
289
|
-
# @param transaction_envelope [Stellar::TransactionEnvelope]
|
|
290
|
-
# @param keypair [Stellar::KeyPair]
|
|
291
|
-
#
|
|
292
|
-
# @return [Boolean]
|
|
293
|
-
#
|
|
294
|
-
def verify_tx_signed_by(transaction_envelope:, keypair:)
|
|
295
|
-
Stellar::SEP10.verify_tx_signed_by(
|
|
296
|
-
tx_envelope: transaction_envelope, keypair: keypair
|
|
297
|
-
)
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
end
|
data/lib/stellar/compat.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Stellar
|
|
2
|
-
module Horizon
|
|
3
|
-
class Problem
|
|
4
|
-
def initialize(attributes)
|
|
5
|
-
@attributes = attributes.reverse_merge({
|
|
6
|
-
type: "about:blank",
|
|
7
|
-
title: "Unknown Error",
|
|
8
|
-
status: 500
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
@meta = @attributes.except!(:type, :title, :status, :detail, :instance)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# @return [String]
|
|
15
|
-
def type
|
|
16
|
-
@attributes[:type]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# @return [String]
|
|
20
|
-
def title
|
|
21
|
-
@attributes[:title]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# @return [Integer]
|
|
25
|
-
def status
|
|
26
|
-
@attributes[:status]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# @return [String]
|
|
30
|
-
def detail
|
|
31
|
-
@attributes[:detail]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @return [String]
|
|
35
|
-
def instance
|
|
36
|
-
@attributes[:instance]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @return [{String => Object}]
|
|
40
|
-
def meta
|
|
41
|
-
@attributes[:instance]
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module Stellar
|
|
2
|
-
class TransactionPage
|
|
3
|
-
include Enumerable
|
|
4
|
-
|
|
5
|
-
# @param [Hyperclient::Link] resource
|
|
6
|
-
def initialize(resource)
|
|
7
|
-
@resource = resource
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def each
|
|
11
|
-
@resource.records.each do |tx|
|
|
12
|
-
yield tx if block_given?
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# @return [Stellar::TransactionPage]
|
|
17
|
-
def next_page
|
|
18
|
-
self.class.new(@resource.next)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def next_page!
|
|
22
|
-
@resource = @resource.next
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|