coinbase-sdk 0.0.9 → 0.0.10
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/lib/coinbase/address/external_address.rb +4 -4
- data/lib/coinbase/client/api/stake_api.rb +75 -0
- data/lib/coinbase/client/api/validators_api.rb +179 -0
- data/lib/coinbase/client/models/create_server_signer_request.rb +2 -9
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +357 -0
- data/lib/coinbase/client/models/native_eth_staking_context.rb +254 -0
- data/lib/coinbase/client/models/partial_eth_staking_context.rb +1 -1
- data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +257 -0
- data/lib/coinbase/client/models/staking_context_context.rb +1 -0
- data/lib/coinbase/client/models/staking_operation.rb +116 -5
- data/lib/coinbase/client/models/staking_operation_metadata.rb +104 -0
- data/lib/coinbase/client/models/staking_reward.rb +3 -3
- data/lib/coinbase/client/models/transaction.rb +2 -2
- data/lib/coinbase/client/models/validator.rb +283 -0
- data/lib/coinbase/client/models/validator_details.rb +104 -0
- data/lib/coinbase/client/models/validator_list.rb +258 -0
- data/lib/coinbase/client.rb +8 -0
- data/lib/coinbase/staking_operation.rb +100 -4
- data/lib/coinbase/staking_reward.rb +7 -1
- data/lib/coinbase/validator.rb +82 -0
- data/lib/coinbase.rb +1 -0
- metadata +11 -2
@@ -4,18 +4,75 @@ module Coinbase
|
|
4
4
|
# A representation of a staking operation (stake, unstake, claim rewards, etc). It
|
5
5
|
# may have multiple steps with some being transactions to sign, and others to wait.
|
6
6
|
# @attr_reader [Array<Coinbase::Transaction>] transactions The list of current
|
7
|
-
# transactions associated with the operation
|
7
|
+
# transactions associated with the operation.
|
8
|
+
# @attr_reader [Symbol] status The status of the operation
|
8
9
|
class StakingOperation
|
9
10
|
attr_reader :transactions
|
10
11
|
|
11
12
|
# Returns a new StakingOperation object.
|
12
13
|
# @param model [Coinbase::Client::StakingOperation] The underlying StakingOperation object
|
13
14
|
def initialize(model)
|
14
|
-
|
15
|
+
from_model(model)
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
# Returns the Staking Operation ID.
|
19
|
+
# @return [String] The Staking Operation ID
|
20
|
+
def id
|
21
|
+
@model.id
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the Network ID of the Staking Operation.
|
25
|
+
# @return [Symbol] The Network ID
|
26
|
+
def network_id
|
27
|
+
Coinbase.to_sym(@model.network_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the Address ID of the Staking Operation.
|
31
|
+
# @return [String] The Address ID
|
32
|
+
def address_id
|
33
|
+
@model.address_id
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the status of the Staking Operation.
|
37
|
+
# @return [Symbol] The status
|
38
|
+
def status
|
39
|
+
@model.status
|
40
|
+
end
|
41
|
+
|
42
|
+
# Waits until the Staking Operation is completed or failed by polling its status at the given interval. Raises a
|
43
|
+
# Timeout::Error if the Staking Operation takes longer than the given timeout.
|
44
|
+
# @param interval_seconds [Integer] The interval at which to poll, in seconds
|
45
|
+
# @param timeout_seconds [Integer] The maximum amount of time
|
46
|
+
# to wait for the StakingOperation to complete, in seconds
|
47
|
+
# @return [StakingOperation] The completed StakingOperation object
|
48
|
+
def wait!(interval_seconds = 5, timeout_seconds = 3600)
|
49
|
+
start_time = Time.now
|
50
|
+
|
51
|
+
loop do
|
52
|
+
reload
|
53
|
+
|
54
|
+
# Wait for the Staking Operation to be in a terminal state.
|
55
|
+
break if status == 'complete'
|
56
|
+
|
57
|
+
raise Timeout::Error, 'Staking Operation timed out' if Time.now - start_time > timeout_seconds
|
58
|
+
|
59
|
+
self.sleep interval_seconds
|
60
|
+
end
|
61
|
+
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
# Fetch the StakingOperation with the provided network, address and staking operation ID.
|
66
|
+
# @param network_id [Symbol] The Network ID
|
67
|
+
# @param address_id [Symbol] The Address ID
|
68
|
+
# @param id [String] The ID of the StakingOperation
|
69
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
70
|
+
def self.fetch(network_id, address_id, id)
|
71
|
+
staking_operation_model = Coinbase.call_api do
|
72
|
+
stake_api.get_external_staking_operation(network_id, address_id, id)
|
18
73
|
end
|
74
|
+
|
75
|
+
from_model(staking_operation_model)
|
19
76
|
end
|
20
77
|
|
21
78
|
# Signs the Open Transactions with the provided key
|
@@ -25,5 +82,44 @@ module Coinbase
|
|
25
82
|
transaction.sign(key) unless transaction.signed?
|
26
83
|
end
|
27
84
|
end
|
85
|
+
|
86
|
+
# Reloads the staking_operation from the service
|
87
|
+
# @return [Coinbase::StakingOperation] The updated staking operation
|
88
|
+
def reload
|
89
|
+
@model = Coinbase.call_api do
|
90
|
+
stake_api.get_external_staking_operation(network_id, address_id, id)
|
91
|
+
end
|
92
|
+
|
93
|
+
from_model(@model)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Fetches the presigned_voluntary exit messages for the staking operation
|
97
|
+
# @return [Array<string>] The list of presigned exit transaction messages
|
98
|
+
def signed_voluntary_exit_messages
|
99
|
+
return [] unless @model.metadata
|
100
|
+
|
101
|
+
signed_voluntary_exit_messages = []
|
102
|
+
|
103
|
+
@model.metadata.each do |metadata|
|
104
|
+
decoded_string = Base64.decode64(metadata.signed_voluntary_exit)
|
105
|
+
signed_voluntary_exit_messages.push(decoded_string)
|
106
|
+
end
|
107
|
+
|
108
|
+
signed_voluntary_exit_messages
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def stake_api
|
114
|
+
@stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
115
|
+
end
|
116
|
+
|
117
|
+
def from_model(model)
|
118
|
+
@model = model
|
119
|
+
@status = model.status
|
120
|
+
@transactions = model.transactions.map do |transaction_model|
|
121
|
+
Transaction.new(transaction_model)
|
122
|
+
end
|
123
|
+
end
|
28
124
|
end
|
29
125
|
end
|
@@ -47,10 +47,16 @@ module Coinbase
|
|
47
47
|
@model.date
|
48
48
|
end
|
49
49
|
|
50
|
+
# Returns the onchain address of the StakingReward.
|
51
|
+
# @return [Time] The onchain address
|
52
|
+
def address_id
|
53
|
+
@model.address_id
|
54
|
+
end
|
55
|
+
|
50
56
|
# Returns a string representation of the StakingReward.
|
51
57
|
# @return [String] a string representation of the StakingReward
|
52
58
|
def to_s
|
53
|
-
"Coinbase::StakingReward{amount: '#{amount}'}"
|
59
|
+
"Coinbase::StakingReward{date: '#{date}' address_id: '#{address_id}' amount: '#{amount.to_f}'}"
|
54
60
|
end
|
55
61
|
|
56
62
|
# Same as to_s.
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coinbase
|
4
|
+
# A representation of a staking validator.
|
5
|
+
class Validator
|
6
|
+
# Returns a new Validator object.
|
7
|
+
# @param model [Coinbase::Client::Validator] The underlying Validator object
|
8
|
+
def initialize(model)
|
9
|
+
@model = model
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a list of Validators for the provided network and asset.
|
13
|
+
# @param network_id [Symbol] The network ID
|
14
|
+
# @param asset_id [Symbol] The asset ID
|
15
|
+
# @param status [Symbol] The status of the validator. Defaults to nil.
|
16
|
+
# @return [Enumerable<Coinbase::Validator>] The validators
|
17
|
+
def self.list(network_id, asset_id, status: nil)
|
18
|
+
Coinbase::Pagination.enumerate(
|
19
|
+
->(page) { list_page(network_id, asset_id, status, page) }
|
20
|
+
) do |validator|
|
21
|
+
new(validator)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns a Validator for the provided network, asset, and validator.
|
26
|
+
# @param network_id [Symbol] The network ID
|
27
|
+
# @param asset_id [Symbol] The asset ID
|
28
|
+
# @param validator_id [String] The validator ID
|
29
|
+
# @return [Coinbase::Validator] The validator
|
30
|
+
def self.fetch(network_id, asset_id, validator_id)
|
31
|
+
validator = Coinbase.call_api do
|
32
|
+
validators_api.get_validator(
|
33
|
+
network_id,
|
34
|
+
asset_id,
|
35
|
+
validator_id
|
36
|
+
)
|
37
|
+
end
|
38
|
+
new(validator)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the public identifiable id of the Validator.
|
42
|
+
# @return [String] The validator ID
|
43
|
+
def validator_id
|
44
|
+
@model.validator_id
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the status of the Validator.
|
48
|
+
# @return [Symbol] The status
|
49
|
+
def status
|
50
|
+
@model.status
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns a string representation of the Validator.
|
54
|
+
# @return [String] a string representation of the Validator
|
55
|
+
def to_s
|
56
|
+
"Coinbase::Validator{id: '#{validator_id}' status: '#{status}'}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Same as to_s.
|
60
|
+
# @return [String] a string representation of the Validator
|
61
|
+
def inspect
|
62
|
+
to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.list_page(network_id, asset_id, status, page)
|
66
|
+
Coinbase.call_api do
|
67
|
+
validators_api.list_validators(
|
68
|
+
network_id,
|
69
|
+
asset_id,
|
70
|
+
{
|
71
|
+
status: status,
|
72
|
+
page: page
|
73
|
+
}
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.validators_api
|
79
|
+
Coinbase::Client::ValidatorsApi.new(Coinbase.configuration.api_client)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/coinbase.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinbase-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuga Cohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- lib/coinbase/client/api/trades_api.rb
|
244
244
|
- lib/coinbase/client/api/transfers_api.rb
|
245
245
|
- lib/coinbase/client/api/users_api.rb
|
246
|
+
- lib/coinbase/client/api/validators_api.rb
|
246
247
|
- lib/coinbase/client/api/wallets_api.rb
|
247
248
|
- lib/coinbase/client/api_client.rb
|
248
249
|
- lib/coinbase/client/api_error.rb
|
@@ -262,11 +263,13 @@ files:
|
|
262
263
|
- lib/coinbase/client/models/create_wallet_request.rb
|
263
264
|
- lib/coinbase/client/models/create_wallet_request_wallet.rb
|
264
265
|
- lib/coinbase/client/models/error.rb
|
266
|
+
- lib/coinbase/client/models/ethereum_validator_metadata.rb
|
265
267
|
- lib/coinbase/client/models/faucet_transaction.rb
|
266
268
|
- lib/coinbase/client/models/feature.rb
|
267
269
|
- lib/coinbase/client/models/fetch_staking_rewards200_response.rb
|
268
270
|
- lib/coinbase/client/models/fetch_staking_rewards_request.rb
|
269
271
|
- lib/coinbase/client/models/get_staking_context_request.rb
|
272
|
+
- lib/coinbase/client/models/native_eth_staking_context.rb
|
270
273
|
- lib/coinbase/client/models/partial_eth_staking_context.rb
|
271
274
|
- lib/coinbase/client/models/seed_creation_event.rb
|
272
275
|
- lib/coinbase/client/models/seed_creation_event_result.rb
|
@@ -277,9 +280,11 @@ files:
|
|
277
280
|
- lib/coinbase/client/models/server_signer_list.rb
|
278
281
|
- lib/coinbase/client/models/signature_creation_event.rb
|
279
282
|
- lib/coinbase/client/models/signature_creation_event_result.rb
|
283
|
+
- lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb
|
280
284
|
- lib/coinbase/client/models/staking_context.rb
|
281
285
|
- lib/coinbase/client/models/staking_context_context.rb
|
282
286
|
- lib/coinbase/client/models/staking_operation.rb
|
287
|
+
- lib/coinbase/client/models/staking_operation_metadata.rb
|
283
288
|
- lib/coinbase/client/models/staking_reward.rb
|
284
289
|
- lib/coinbase/client/models/staking_reward_format.rb
|
285
290
|
- lib/coinbase/client/models/trade.rb
|
@@ -289,6 +294,9 @@ files:
|
|
289
294
|
- lib/coinbase/client/models/transfer.rb
|
290
295
|
- lib/coinbase/client/models/transfer_list.rb
|
291
296
|
- lib/coinbase/client/models/user.rb
|
297
|
+
- lib/coinbase/client/models/validator.rb
|
298
|
+
- lib/coinbase/client/models/validator_details.rb
|
299
|
+
- lib/coinbase/client/models/validator_list.rb
|
292
300
|
- lib/coinbase/client/models/wallet.rb
|
293
301
|
- lib/coinbase/client/models/wallet_list.rb
|
294
302
|
- lib/coinbase/client/version.rb
|
@@ -305,6 +313,7 @@ files:
|
|
305
313
|
- lib/coinbase/transaction.rb
|
306
314
|
- lib/coinbase/transfer.rb
|
307
315
|
- lib/coinbase/user.rb
|
316
|
+
- lib/coinbase/validator.rb
|
308
317
|
- lib/coinbase/wallet.rb
|
309
318
|
homepage: https://github.com/coinbase/coinbase-sdk-ruby
|
310
319
|
licenses:
|