xrpl-ruby 0.2.4 → 0.6.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 +31 -0
- data/LICENSE +21 -0
- data/README.md +94 -0
- data/lib/address-codec/address_codec.rb +21 -4
- data/lib/address-codec/codec.rb +15 -2
- data/lib/address-codec/xrp_codec.rb +29 -2
- data/lib/binary-codec/binary_codec.rb +47 -21
- data/lib/binary-codec/enums/definitions.json +592 -1
- data/lib/binary-codec/enums/definitions.rb +23 -9
- data/lib/binary-codec/enums/fields.rb +3 -1
- data/lib/binary-codec/serdes/binary_parser.rb +44 -10
- data/lib/binary-codec/serdes/binary_serializer.rb +29 -6
- data/lib/binary-codec/serdes/bytes_list.rb +12 -1
- data/lib/binary-codec/types/account_id.rb +18 -37
- data/lib/binary-codec/types/amount.rb +123 -77
- data/lib/binary-codec/types/blob.rb +14 -5
- data/lib/binary-codec/types/currency.rb +15 -4
- data/lib/binary-codec/types/hash.rb +37 -36
- data/lib/binary-codec/types/issue.rb +47 -0
- data/lib/binary-codec/types/path_set.rb +93 -0
- data/lib/binary-codec/types/serialized_type.rb +52 -28
- data/lib/binary-codec/types/st_array.rb +106 -0
- data/lib/binary-codec/types/st_object.rb +150 -14
- data/lib/binary-codec/types/uint.rb +166 -3
- data/lib/binary-codec/types/vector256.rb +53 -0
- data/lib/binary-codec/types/xchain_bridge.rb +47 -0
- data/lib/binary-codec/utilities.rb +18 -0
- data/lib/core/base_58_xrp.rb +2 -0
- data/lib/core/base_x.rb +10 -0
- data/lib/core/core.rb +44 -6
- data/lib/core/utilities.rb +38 -0
- data/lib/key-pairs/ed25519.rb +69 -0
- data/lib/key-pairs/key_pairs.rb +92 -0
- data/lib/key-pairs/secp256k1.rb +169 -0
- data/lib/wallet/wallet.rb +179 -0
- data/lib/xrpl/client.rb +498 -0
- data/lib/xrpl/faucet.rb +138 -0
- data/lib/xrpl/version.rb +5 -0
- data/lib/xrpl-ruby.rb +30 -1
- metadata +80 -4
data/lib/xrpl/faucet.rb
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
require_relative 'client'
|
|
8
|
+
|
|
9
|
+
module XRPL
|
|
10
|
+
# Raised when a faucet request fails or funding does not complete in time.
|
|
11
|
+
class FaucetError < StandardError; end
|
|
12
|
+
|
|
13
|
+
# Funds (and thereby activates) a wallet on an XRP Ledger test network via the
|
|
14
|
+
# public faucet, then waits until the account shows up on the ledger.
|
|
15
|
+
#
|
|
16
|
+
# This is the Ruby equivalent of the +fundWallet()+ helper used in the other
|
|
17
|
+
# XRPL SDKs. It is intended for Testnet/Devnet only.
|
|
18
|
+
#
|
|
19
|
+
# @example Fund a fresh wallet on the Testnet
|
|
20
|
+
# client = XRPL::Client.new(:testnet)
|
|
21
|
+
# client.connect!
|
|
22
|
+
# result = XRPL.fund_wallet(client)
|
|
23
|
+
# result[:wallet].classic_address # => "r..."
|
|
24
|
+
# result[:balance] # => 100000000000 (drops)
|
|
25
|
+
class Faucet
|
|
26
|
+
TESTNET_FAUCET = 'https://faucet.altnet.rippletest.net/accounts'
|
|
27
|
+
DEVNET_FAUCET = 'https://faucet.devnet.rippletest.net/accounts'
|
|
28
|
+
|
|
29
|
+
DEFAULT_TIMEOUT = 40
|
|
30
|
+
DEFAULT_POLL_INTERVAL = 2
|
|
31
|
+
|
|
32
|
+
attr_reader :faucet_url
|
|
33
|
+
|
|
34
|
+
# @param faucet_url [String] the faucet endpoint to POST to.
|
|
35
|
+
def initialize(faucet_url: TESTNET_FAUCET)
|
|
36
|
+
@faucet_url = faucet_url
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Convenience wrapper matching the tutorial call style.
|
|
40
|
+
#
|
|
41
|
+
# @param client [XRPL::Client] a connected client used to poll for funding.
|
|
42
|
+
# @param wallet [Wallet::Wallet, nil] wallet to fund; a new one is generated when nil.
|
|
43
|
+
# @return [Hash] +{ wallet:, balance: }+ (balance in drops).
|
|
44
|
+
def self.fund_wallet(client, wallet = nil, faucet_url: TESTNET_FAUCET, **opts)
|
|
45
|
+
new(faucet_url: faucet_url).fund_wallet(client, wallet, **opts)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Funds (and activates) a wallet on a test network.
|
|
49
|
+
#
|
|
50
|
+
# @param client [XRPL::Client] a connected client used to poll for funding.
|
|
51
|
+
# @param wallet [Wallet::Wallet, nil] wallet to fund; a new one is generated when nil.
|
|
52
|
+
# @param amount [Numeric, String, nil] optional XRP amount to request.
|
|
53
|
+
# @param timeout [Numeric] seconds to wait for the account to be funded.
|
|
54
|
+
# @param poll_interval [Numeric] seconds between ledger polls.
|
|
55
|
+
# @return [Hash] +{ wallet:, balance: }+ (balance in drops).
|
|
56
|
+
# @raise [XRPL::FaucetError] if the faucet request fails or funding times out.
|
|
57
|
+
def fund_wallet(client, wallet = nil, amount: nil, timeout: DEFAULT_TIMEOUT,
|
|
58
|
+
poll_interval: DEFAULT_POLL_INTERVAL)
|
|
59
|
+
wallet ||= Wallet::Wallet.generate
|
|
60
|
+
|
|
61
|
+
request_funds(wallet.classic_address, amount)
|
|
62
|
+
balance = await_funding(
|
|
63
|
+
client, wallet.classic_address,
|
|
64
|
+
timeout: timeout, poll_interval: poll_interval
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
{ wallet: wallet, balance: balance }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
# POSTs a funding request to the faucet for the given address.
|
|
73
|
+
def request_funds(address, amount)
|
|
74
|
+
body = { destination: address }
|
|
75
|
+
body[:xrpAmount] = amount.to_s if amount
|
|
76
|
+
|
|
77
|
+
http_post(@faucet_url, body)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Polls the ledger until the account is funded, i.e. it exists and shows a
|
|
81
|
+
# positive balance. (For a Testnet/get-started helper this simple
|
|
82
|
+
# "funded = has a balance" rule is robust: unlike waiting for a strict
|
|
83
|
+
# balance *increase*, it can never hang when a wallet already holds XRP.)
|
|
84
|
+
def await_funding(client, address, timeout:, poll_interval:)
|
|
85
|
+
deadline = monotonic_time + timeout
|
|
86
|
+
|
|
87
|
+
loop do
|
|
88
|
+
balance = current_balance(client, address)
|
|
89
|
+
return balance if balance && balance.positive?
|
|
90
|
+
|
|
91
|
+
if monotonic_time >= deadline
|
|
92
|
+
raise FaucetError, "Account #{address} was not funded within #{timeout} seconds"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
sleep poll_interval
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Returns the account balance in drops, or nil if the account is not (yet)
|
|
100
|
+
# found or a transient lookup error occurs.
|
|
101
|
+
def current_balance(client, address)
|
|
102
|
+
response = client.account_info_response(account: address, ledger_index: 'validated')
|
|
103
|
+
drops = response.dig('result', 'account_data', 'Balance')
|
|
104
|
+
drops && Integer(drops)
|
|
105
|
+
rescue StandardError
|
|
106
|
+
nil
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def http_post(url, body)
|
|
110
|
+
uri = URI(url)
|
|
111
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
112
|
+
http.use_ssl = uri.scheme == 'https'
|
|
113
|
+
|
|
114
|
+
request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
|
|
115
|
+
request.body = JSON.generate(body)
|
|
116
|
+
|
|
117
|
+
response = http.request(request)
|
|
118
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
119
|
+
raise FaucetError, "Faucet request failed: #{response.code} #{response.message}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
JSON.parse(response.body)
|
|
123
|
+
rescue JSON::ParserError
|
|
124
|
+
{}
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def monotonic_time
|
|
128
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Top-level convenience mirroring the other SDKs' +fundWallet()+ sugar.
|
|
133
|
+
#
|
|
134
|
+
# @see Faucet#fund_wallet
|
|
135
|
+
def self.fund_wallet(client, wallet = nil, **opts)
|
|
136
|
+
Faucet.fund_wallet(client, wallet, **opts)
|
|
137
|
+
end
|
|
138
|
+
end
|
data/lib/xrpl/version.rb
ADDED
data/lib/xrpl-ruby.rb
CHANGED
|
@@ -1,14 +1,43 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'xrpl/version'
|
|
4
|
+
|
|
5
|
+
require_relative 'core/base_x'
|
|
6
|
+
require_relative 'core/base_58_xrp'
|
|
3
7
|
require_relative 'core/core'
|
|
8
|
+
require_relative 'core/utilities'
|
|
4
9
|
|
|
5
10
|
require_relative 'address-codec/codec'
|
|
6
11
|
require_relative 'address-codec/xrp_codec'
|
|
7
12
|
require_relative 'address-codec/address_codec'
|
|
8
13
|
|
|
14
|
+
require_relative 'binary-codec/enums/constants'
|
|
15
|
+
require_relative 'binary-codec/utilities'
|
|
9
16
|
require_relative 'binary-codec/enums/fields'
|
|
10
17
|
require_relative 'binary-codec/enums/definitions'
|
|
11
18
|
require_relative 'binary-codec/serdes/binary_parser'
|
|
12
19
|
require_relative 'binary-codec/serdes/bytes_list'
|
|
20
|
+
require_relative 'binary-codec/serdes/binary_serializer'
|
|
13
21
|
require_relative 'binary-codec/types/serialized_type'
|
|
14
|
-
require_relative 'binary-codec/types/hash'
|
|
22
|
+
require_relative 'binary-codec/types/hash'
|
|
23
|
+
require_relative 'binary-codec/types/uint'
|
|
24
|
+
require_relative 'binary-codec/types/account_id'
|
|
25
|
+
require_relative 'binary-codec/types/amount'
|
|
26
|
+
require_relative 'binary-codec/types/blob'
|
|
27
|
+
require_relative 'binary-codec/types/currency'
|
|
28
|
+
require_relative 'binary-codec/types/st_array'
|
|
29
|
+
require_relative 'binary-codec/types/st_object'
|
|
30
|
+
require_relative 'binary-codec/types/vector256'
|
|
31
|
+
require_relative 'binary-codec/types/path_set'
|
|
32
|
+
require_relative 'binary-codec/types/issue'
|
|
33
|
+
require_relative 'binary-codec/types/xchain_bridge'
|
|
34
|
+
require_relative 'binary-codec/binary_codec'
|
|
35
|
+
|
|
36
|
+
require_relative 'wallet/wallet'
|
|
37
|
+
|
|
38
|
+
require_relative 'key-pairs/ed25519'
|
|
39
|
+
require_relative 'key-pairs/secp256k1'
|
|
40
|
+
require_relative 'key-pairs/key_pairs'
|
|
41
|
+
|
|
42
|
+
require_relative 'xrpl/client'
|
|
43
|
+
require_relative 'xrpl/faucet'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xrpl-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Busse
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -52,6 +52,62 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: ed25519
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.3'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.3'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: ecdsa
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 1.2.0
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 1.2.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: faye-websocket
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.11'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.11'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: eventmachine
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '1.2'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '1.2'
|
|
55
111
|
description: This gem provides a Ruby interface to interact with the XRP Ledger (XRPL)
|
|
56
112
|
blockchain, allowing developers to easily integrate XRPL functionality into their
|
|
57
113
|
Ruby applications.
|
|
@@ -61,6 +117,9 @@ executables: []
|
|
|
61
117
|
extensions: []
|
|
62
118
|
extra_rdoc_files: []
|
|
63
119
|
files:
|
|
120
|
+
- CHANGELOG.md
|
|
121
|
+
- LICENSE
|
|
122
|
+
- README.md
|
|
64
123
|
- lib/address-codec/address_codec.rb
|
|
65
124
|
- lib/address-codec/codec.rb
|
|
66
125
|
- lib/address-codec/xrp_codec.rb
|
|
@@ -77,18 +136,35 @@ files:
|
|
|
77
136
|
- lib/binary-codec/types/blob.rb
|
|
78
137
|
- lib/binary-codec/types/currency.rb
|
|
79
138
|
- lib/binary-codec/types/hash.rb
|
|
139
|
+
- lib/binary-codec/types/issue.rb
|
|
140
|
+
- lib/binary-codec/types/path_set.rb
|
|
80
141
|
- lib/binary-codec/types/serialized_type.rb
|
|
142
|
+
- lib/binary-codec/types/st_array.rb
|
|
81
143
|
- lib/binary-codec/types/st_object.rb
|
|
82
144
|
- lib/binary-codec/types/uint.rb
|
|
145
|
+
- lib/binary-codec/types/vector256.rb
|
|
146
|
+
- lib/binary-codec/types/xchain_bridge.rb
|
|
83
147
|
- lib/binary-codec/utilities.rb
|
|
84
148
|
- lib/core/base_58_xrp.rb
|
|
85
149
|
- lib/core/base_x.rb
|
|
86
150
|
- lib/core/core.rb
|
|
151
|
+
- lib/core/utilities.rb
|
|
152
|
+
- lib/key-pairs/ed25519.rb
|
|
153
|
+
- lib/key-pairs/key_pairs.rb
|
|
154
|
+
- lib/key-pairs/secp256k1.rb
|
|
155
|
+
- lib/wallet/wallet.rb
|
|
87
156
|
- lib/xrpl-ruby.rb
|
|
157
|
+
- lib/xrpl/client.rb
|
|
158
|
+
- lib/xrpl/faucet.rb
|
|
159
|
+
- lib/xrpl/version.rb
|
|
88
160
|
homepage: https://github.com/AlexanderBuzz/xrpl-ruby
|
|
89
161
|
licenses:
|
|
90
162
|
- MIT
|
|
91
|
-
metadata:
|
|
163
|
+
metadata:
|
|
164
|
+
homepage_uri: https://github.com/AlexanderBuzz/xrpl-ruby
|
|
165
|
+
source_code_uri: https://github.com/AlexanderBuzz/xrpl-ruby
|
|
166
|
+
changelog_uri: https://github.com/AlexanderBuzz/xrpl-ruby/blob/main/CHANGELOG.md
|
|
167
|
+
bug_tracker_uri: https://github.com/AlexanderBuzz/xrpl-ruby/issues
|
|
92
168
|
post_install_message:
|
|
93
169
|
rdoc_options: []
|
|
94
170
|
require_paths:
|
|
@@ -97,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
97
173
|
requirements:
|
|
98
174
|
- - ">="
|
|
99
175
|
- !ruby/object:Gem::Version
|
|
100
|
-
version: '0'
|
|
176
|
+
version: '3.0'
|
|
101
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
178
|
requirements:
|
|
103
179
|
- - ">="
|