coinbase-sdk 0.0.16 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coinbase/address/wallet_address.rb +24 -17
- data/lib/coinbase/address.rb +17 -19
- data/lib/coinbase/asset.rb +11 -8
- data/lib/coinbase/client/api/addresses_api.rb +1 -1
- data/lib/coinbase/client/api/assets_api.rb +1 -1
- data/lib/coinbase/client/api/contract_events_api.rb +18 -10
- data/lib/coinbase/client/api/external_addresses_api.rb +1 -1
- data/lib/coinbase/client/api/networks_api.rb +1 -1
- data/lib/coinbase/client/api/server_signers_api.rb +1 -1
- data/lib/coinbase/client/api/stake_api.rb +1 -242
- data/lib/coinbase/client/api/trades_api.rb +1 -1
- data/lib/coinbase/client/api/transfers_api.rb +1 -1
- data/lib/coinbase/client/api/users_api.rb +1 -1
- data/lib/coinbase/client/api/validators_api.rb +3 -3
- data/lib/coinbase/client/api/wallet_stake_api.rb +263 -0
- data/lib/coinbase/client/api/wallets_api.rb +1 -1
- data/lib/coinbase/client/api/webhooks_api.rb +1 -1
- data/lib/coinbase/client/api_client.rb +1 -1
- data/lib/coinbase/client/api_error.rb +1 -1
- data/lib/coinbase/client/configuration.rb +11 -1
- data/lib/coinbase/client/models/address.rb +22 -5
- data/lib/coinbase/client/models/address_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_historical_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_list.rb +1 -1
- data/lib/coinbase/client/models/asset.rb +1 -1
- data/lib/coinbase/client/models/balance.rb +1 -1
- data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/contract_event.rb +100 -9
- data/lib/coinbase/client/models/contract_event_list.rb +1 -1
- data/lib/coinbase/client/models/create_address_request.rb +15 -5
- data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
- data/lib/coinbase/client/models/create_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/create_trade_request.rb +1 -1
- data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
- data/lib/coinbase/client/models/create_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/error.rb +1 -1
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +12 -12
- data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
- data/lib/coinbase/client/models/feature.rb +3 -2
- data/lib/coinbase/client/models/feature_set.rb +1 -1
- data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
- data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
- data/lib/coinbase/client/models/historical_balance.rb +1 -1
- data/lib/coinbase/client/models/network.rb +15 -5
- data/lib/coinbase/client/models/network_identifier.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/server_signer.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
- data/lib/coinbase/client/models/server_signer_list.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
- data/lib/coinbase/client/models/sponsored_send.rb +1 -1
- data/lib/coinbase/client/models/staking_balance.rb +1 -1
- data/lib/coinbase/client/models/staking_context.rb +1 -1
- data/lib/coinbase/client/models/staking_context_context.rb +1 -1
- data/lib/coinbase/client/models/staking_operation.rb +3 -3
- data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
- data/lib/coinbase/client/models/staking_reward.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_usd_value.rb +1 -1
- data/lib/coinbase/client/models/trade.rb +1 -1
- data/lib/coinbase/client/models/trade_list.rb +1 -1
- data/lib/coinbase/client/models/transaction.rb +16 -6
- data/lib/coinbase/client/models/transaction_type.rb +1 -1
- data/lib/coinbase/client/models/transfer.rb +1 -1
- data/lib/coinbase/client/models/transfer_list.rb +1 -1
- data/lib/coinbase/client/models/update_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/user.rb +1 -1
- data/lib/coinbase/client/models/validator.rb +24 -3
- data/lib/coinbase/client/models/validator_details.rb +1 -1
- data/lib/coinbase/client/models/validator_list.rb +1 -1
- data/lib/coinbase/client/models/validator_status.rb +52 -0
- data/lib/coinbase/client/models/wallet.rb +1 -1
- data/lib/coinbase/client/models/wallet_list.rb +1 -1
- data/lib/coinbase/client/models/webhook.rb +1 -1
- data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
- data/lib/coinbase/client/models/webhook_event_type.rb +1 -1
- data/lib/coinbase/client/models/webhook_list.rb +1 -1
- data/lib/coinbase/client/version.rb +1 -1
- data/lib/coinbase/client.rb +3 -1
- data/lib/coinbase/constants.rb +0 -10
- data/lib/coinbase/contract_event.rb +104 -0
- data/lib/coinbase/correlation.rb +30 -0
- data/lib/coinbase/destination.rb +11 -9
- data/lib/coinbase/errors.rb +7 -0
- data/lib/coinbase/middleware.rb +2 -0
- data/lib/coinbase/network.rb +103 -20
- data/lib/coinbase/smart_contract.rb +106 -0
- data/lib/coinbase/staking_balance.rb +11 -5
- data/lib/coinbase/staking_operation.rb +132 -36
- data/lib/coinbase/staking_reward.rb +1 -1
- data/lib/coinbase/trade.rb +10 -9
- data/lib/coinbase/transaction.rb +6 -0
- data/lib/coinbase/transfer.rb +11 -10
- data/lib/coinbase/validator.rb +18 -10
- data/lib/coinbase/version.rb +5 -0
- data/lib/coinbase/wallet.rb +137 -145
- data/lib/coinbase/webhook.rb +181 -0
- data/lib/coinbase.rb +50 -19
- metadata +9 -9
- data/lib/coinbase/client/models/ethereum_validator.rb +0 -374
- data/lib/coinbase/client/models/get_validator200_response.rb +0 -221
- data/lib/coinbase/client/models/get_validator200_response_validator.rb +0 -214
- data/lib/coinbase/client/models/native_eth_staking_context.rb +0 -254
- data/lib/coinbase/client/models/partial_eth_staking_context.rb +0 -254
- data/lib/coinbase/client/models/validator_list_data.rb +0 -216
- data/lib/coinbase/user.rb +0 -65
@@ -11,22 +11,24 @@ module Coinbase
|
|
11
11
|
|
12
12
|
# Builds an ephemeral staking operation this is intended to be called via an Address or Wallet.
|
13
13
|
# @param amount [BigDecimal] The amount to stake, in the primary denomination of the asset
|
14
|
-
# @param
|
14
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID
|
15
15
|
# @param asset_id [Symbol] The Asset ID
|
16
16
|
# @param address_id [String] The Address ID
|
17
17
|
# @param action [Symbol] The action to perform
|
18
18
|
# @param mode [Symbol] The staking mode
|
19
19
|
# @param options [Hash] Additional options
|
20
20
|
# @return [Coinbase::StakingOperation] The staking operation
|
21
|
-
def self.build(amount,
|
21
|
+
def self.build(amount, network, asset_id, address_id, action, mode, options)
|
22
|
+
network = Coinbase::Network.from_id(network)
|
23
|
+
asset = network.get_asset(asset_id)
|
24
|
+
|
22
25
|
model = Coinbase.call_api do
|
23
|
-
asset = Coinbase::Asset.fetch(network_id, asset_id)
|
24
26
|
stake_api.build_staking_operation(
|
25
27
|
{
|
26
28
|
asset_id: asset.primary_denomination.to_s,
|
27
29
|
address_id: address_id,
|
28
30
|
action: action,
|
29
|
-
network_id: Coinbase.normalize_network(
|
31
|
+
network_id: Coinbase.normalize_network(network),
|
30
32
|
options: {
|
31
33
|
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
32
34
|
mode: mode
|
@@ -40,7 +42,7 @@ module Coinbase
|
|
40
42
|
|
41
43
|
# Creates a persisted staking operation this is intended to be called via an Address or Wallet.
|
42
44
|
# @param amount [BigDecimal] The amount to stake, in the primary denomination of the asset
|
43
|
-
# @param
|
45
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID
|
44
46
|
# @param asset_id [Symbol] The Asset ID
|
45
47
|
# @param address_id [String] The Address ID
|
46
48
|
# @param wallet_id [String] The Wallet ID
|
@@ -48,17 +50,19 @@ module Coinbase
|
|
48
50
|
# @param mode [Symbol] The staking mode
|
49
51
|
# @param options [Hash] Additional options
|
50
52
|
# @return [Coinbase::StakingOperation] The staking operation
|
51
|
-
def self.create(amount,
|
53
|
+
def self.create(amount, network, asset_id, address_id, wallet_id, action, mode, options)
|
54
|
+
network = Coinbase::Network.from_id(network)
|
55
|
+
asset = network.get_asset(asset_id)
|
56
|
+
|
52
57
|
model = Coinbase.call_api do
|
53
|
-
|
54
|
-
stake_api.create_staking_operation(
|
58
|
+
wallet_stake_api.create_staking_operation(
|
55
59
|
wallet_id,
|
56
60
|
address_id,
|
57
61
|
{
|
58
62
|
asset_id: asset.primary_denomination.to_s,
|
59
63
|
address_id: address_id,
|
60
64
|
action: action,
|
61
|
-
network_id: Coinbase.normalize_network(
|
65
|
+
network_id: Coinbase.normalize_network(network),
|
62
66
|
options: {
|
63
67
|
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
64
68
|
mode: mode
|
@@ -70,10 +74,24 @@ module Coinbase
|
|
70
74
|
new(model)
|
71
75
|
end
|
72
76
|
|
77
|
+
def self.stake_api
|
78
|
+
Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
79
|
+
end
|
80
|
+
|
81
|
+
private_class_method :stake_api
|
82
|
+
|
83
|
+
def self.wallet_stake_api
|
84
|
+
Coinbase::Client::WalletStakeApi.new(Coinbase.configuration.api_client)
|
85
|
+
end
|
86
|
+
|
87
|
+
private_class_method :wallet_stake_api
|
88
|
+
|
73
89
|
# Returns a new StakingOperation object.
|
74
90
|
# @param model [Coinbase::Client::StakingOperation] The underlying StakingOperation object
|
75
91
|
def initialize(model)
|
76
|
-
|
92
|
+
@model = model
|
93
|
+
@transactions ||= []
|
94
|
+
update_transactions(model.transactions)
|
77
95
|
end
|
78
96
|
|
79
97
|
# Returns the Staking Operation ID.
|
@@ -82,10 +100,10 @@ module Coinbase
|
|
82
100
|
@model.id
|
83
101
|
end
|
84
102
|
|
85
|
-
# Returns the Network
|
86
|
-
# @return [
|
87
|
-
def
|
88
|
-
Coinbase.
|
103
|
+
# Returns the Network of the Staking Operation.
|
104
|
+
# @return [Coinbase::Network] The Network
|
105
|
+
def network
|
106
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
89
107
|
end
|
90
108
|
|
91
109
|
# Returns the Address ID of the Staking Operation.
|
@@ -100,18 +118,48 @@ module Coinbase
|
|
100
118
|
@model.status
|
101
119
|
end
|
102
120
|
|
121
|
+
# Returns whether the Staking Operation is in a terminal state.
|
122
|
+
# @return [Boolean] Whether the Staking Operation is in a terminal state
|
123
|
+
def terminal_state?
|
124
|
+
failed? || completed?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns whether the Staking Operation is in a failed state.
|
128
|
+
# @return [Boolean] Whether the Staking Operation is in a failed state
|
129
|
+
def failed?
|
130
|
+
status == 'failed'
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns whether the Staking Operation is in a complete state.
|
134
|
+
# @return [Boolean] Whether the Staking Operation is in a complete state
|
135
|
+
def completed?
|
136
|
+
status == 'complete'
|
137
|
+
end
|
138
|
+
|
139
|
+
# Returns a String representation of the Staking Operation.
|
140
|
+
# @return [String] a String representation of the Staking Operation
|
141
|
+
def to_s
|
142
|
+
Coinbase.pretty_print_object(
|
143
|
+
self.class,
|
144
|
+
id: id,
|
145
|
+
status: status,
|
146
|
+
network_id: network.id,
|
147
|
+
address_id: address_id
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
103
151
|
# Returns the Wallet ID of the Staking Operation.
|
104
152
|
# @return [String] The Wallet ID
|
105
153
|
def wallet_id
|
106
154
|
@model.wallet_id
|
107
155
|
end
|
108
156
|
|
109
|
-
# Waits until the Staking Operation is completed or failed by polling its status at the given interval.
|
110
|
-
# Timeout::Error if the Staking Operation takes longer than the given timeout.
|
157
|
+
# Waits until the Staking Operation is completed or failed by polling its status at the given interval.
|
111
158
|
# @param interval_seconds [Integer] The interval at which to poll, in seconds
|
112
159
|
# @param timeout_seconds [Integer] The maximum amount of time
|
113
160
|
# to wait for the StakingOperation to complete, in seconds
|
114
161
|
# @return [StakingOperation] The completed StakingOperation object
|
162
|
+
# @raise [Timeout::Error] if the Staking Operation takes longer than the given timeout.
|
115
163
|
def wait!(interval_seconds = 5, timeout_seconds = 3600)
|
116
164
|
start_time = Time.now
|
117
165
|
|
@@ -119,7 +167,7 @@ module Coinbase
|
|
119
167
|
reload
|
120
168
|
|
121
169
|
# Wait for the Staking Operation to be in a terminal state.
|
122
|
-
break if
|
170
|
+
break if terminal_state?
|
123
171
|
|
124
172
|
raise Timeout::Error, 'Staking Operation timed out' if Time.now - start_time > timeout_seconds
|
125
173
|
|
@@ -129,18 +177,56 @@ module Coinbase
|
|
129
177
|
self
|
130
178
|
end
|
131
179
|
|
180
|
+
# Complete helps the Staking Operation reach complete state, by polling its status at the given interval, signing
|
181
|
+
# and broadcasting any available transaction.
|
182
|
+
# @param key [Eth::Key] The key to sign the Staking Operation transactions with
|
183
|
+
# @param interval_seconds [Integer] The interval at which to poll, in seconds
|
184
|
+
# @param timeout_seconds [Integer] The maximum amount of time
|
185
|
+
# to wait for the StakingOperation to complete, in seconds
|
186
|
+
# @return [StakingOperation] The completed StakingOperation object
|
187
|
+
# @raise [Timeout::Error] if the Staking Operation takes longer than the given timeout.
|
188
|
+
def complete(key, interval_seconds: 5, timeout_seconds: 600)
|
189
|
+
start_time = Time.now
|
190
|
+
|
191
|
+
loop do
|
192
|
+
@transactions.each_with_index do |transaction, i|
|
193
|
+
next if transaction.signed?
|
194
|
+
|
195
|
+
transaction.sign(key)
|
196
|
+
@model = Coinbase.call_api do
|
197
|
+
wallet_stake_api.broadcast_staking_operation(
|
198
|
+
wallet_id,
|
199
|
+
address_id,
|
200
|
+
id,
|
201
|
+
{ signed_payload: transaction.raw.hex, transaction_index: i }
|
202
|
+
)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
return self if terminal_state?
|
207
|
+
|
208
|
+
reload
|
209
|
+
|
210
|
+
raise Timeout::Error, 'Staking Operation timed out' if Time.now - start_time > timeout_seconds
|
211
|
+
|
212
|
+
sleep interval_seconds
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
132
216
|
# Fetch the StakingOperation with the provided network, address and staking operation ID.
|
133
|
-
# @param
|
217
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID
|
134
218
|
# @param address_id [Symbol] The Address ID
|
135
219
|
# @param id [String] The ID of the StakingOperation
|
136
220
|
# @param wallet_id [String] The optional Wallet ID
|
137
221
|
# @return [Coinbase::StakingOperation] The staking operation
|
138
|
-
def self.fetch(
|
222
|
+
def self.fetch(network, address_id, id, wallet_id: nil)
|
223
|
+
network = Coinbase::Network.from_id(network)
|
224
|
+
|
139
225
|
staking_operation_model = Coinbase.call_api do
|
140
226
|
if wallet_id.nil?
|
141
|
-
stake_api.get_external_staking_operation(
|
227
|
+
stake_api.get_external_staking_operation(network.id, address_id, id)
|
142
228
|
else
|
143
|
-
|
229
|
+
wallet_stake_api.get_staking_operation(wallet_id, address_id, id)
|
144
230
|
end
|
145
231
|
end
|
146
232
|
|
@@ -160,13 +246,15 @@ module Coinbase
|
|
160
246
|
def reload
|
161
247
|
@model = Coinbase.call_api do
|
162
248
|
if wallet_id.nil?
|
163
|
-
stake_api.get_external_staking_operation(
|
249
|
+
stake_api.get_external_staking_operation(network.id, address_id, id)
|
164
250
|
else
|
165
|
-
|
251
|
+
wallet_stake_api.get_staking_operation(wallet_id, address_id, id)
|
166
252
|
end
|
167
253
|
end
|
168
254
|
|
169
|
-
|
255
|
+
update_transactions(@model.transactions)
|
256
|
+
|
257
|
+
self
|
170
258
|
end
|
171
259
|
|
172
260
|
# Fetches the presigned_voluntary exit messages for the staking operation
|
@@ -191,7 +279,7 @@ module Coinbase
|
|
191
279
|
raise TransactionNotSignedError unless transaction.signed?
|
192
280
|
|
193
281
|
Coinbase.call_api do
|
194
|
-
|
282
|
+
wallet_stake_api.broadcast_staking_operation(
|
195
283
|
wallet_id,
|
196
284
|
address_id,
|
197
285
|
id,
|
@@ -203,24 +291,32 @@ module Coinbase
|
|
203
291
|
self
|
204
292
|
end
|
205
293
|
|
206
|
-
def self.stake_api
|
207
|
-
Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
208
|
-
end
|
209
|
-
|
210
294
|
private
|
211
295
|
|
212
296
|
def stake_api
|
213
|
-
@stake_api ||=
|
297
|
+
@stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
214
298
|
end
|
215
299
|
|
216
|
-
def
|
217
|
-
@
|
218
|
-
|
219
|
-
|
220
|
-
|
300
|
+
def wallet_stake_api
|
301
|
+
@wallet_stake_api ||= Coinbase::Client::WalletStakeApi.new(Coinbase.configuration.api_client)
|
302
|
+
end
|
303
|
+
|
304
|
+
def update_transactions(transactions)
|
305
|
+
# Only overwrite the transactions if the response is populated.
|
306
|
+
return unless transactions && !transactions.empty?
|
307
|
+
|
308
|
+
# Create a set of existing unsigned payloads to avoid duplicates.
|
309
|
+
existing_unsigned_payloads = Set.new
|
310
|
+
@transactions.each do |transaction|
|
311
|
+
existing_unsigned_payloads.add(transaction.unsigned_payload)
|
221
312
|
end
|
222
313
|
|
223
|
-
|
314
|
+
# Add transactions that are not already in the transactions array.
|
315
|
+
transactions.each do |transaction_model|
|
316
|
+
unless existing_unsigned_payloads.include?(transaction_model.unsigned_payload)
|
317
|
+
@transactions << Transaction.new(transaction_model)
|
318
|
+
end
|
319
|
+
end
|
224
320
|
end
|
225
321
|
end
|
226
322
|
end
|
@@ -62,7 +62,7 @@ module Coinbase
|
|
62
62
|
# Returns the USD conversion price of the StakingReward.
|
63
63
|
# @return [BigDecimal] The USD conversion price
|
64
64
|
def usd_conversion_price
|
65
|
-
BigDecimal(@model.usd_value.conversion_price.to_i)
|
65
|
+
BigDecimal(@model.usd_value.conversion_price.to_i)
|
66
66
|
end
|
67
67
|
|
68
68
|
# Returns the USD conversion time of the StakingReward.
|
data/lib/coinbase/trade.rb
CHANGED
@@ -15,12 +15,13 @@ module Coinbase
|
|
15
15
|
# @param from_asset_id [Symbol] The Asset ID of the Asset to trade from
|
16
16
|
# @param to_asset_id [Symbol] The Asset ID of the Asset to trade to
|
17
17
|
# @param amount [BigDecimal] The amount of the Asset to send
|
18
|
-
# @param
|
18
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
19
19
|
# @param wallet_id [String] The Wallet ID of the sending Wallet
|
20
20
|
# @return [Send] The new pending Send object
|
21
|
-
def create(address_id:, from_asset_id:, to_asset_id:, amount:,
|
22
|
-
|
23
|
-
|
21
|
+
def create(address_id:, from_asset_id:, to_asset_id:, amount:, network:, wallet_id:)
|
22
|
+
network = Coinbase::Network.from_id(network)
|
23
|
+
from_asset = network.get_asset(from_asset_id)
|
24
|
+
to_asset = network.get_asset(to_asset_id)
|
24
25
|
|
25
26
|
model = Coinbase.call_api do
|
26
27
|
trades_api.create_trade(
|
@@ -75,10 +76,10 @@ module Coinbase
|
|
75
76
|
@model.trade_id
|
76
77
|
end
|
77
78
|
|
78
|
-
# Returns the Network
|
79
|
-
# @return [
|
80
|
-
def
|
81
|
-
Coinbase.
|
79
|
+
# Returns the Network of the Trade.
|
80
|
+
# @return [Coinbase::Network] The Network the Trade is on
|
81
|
+
def network
|
82
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
82
83
|
end
|
83
84
|
|
84
85
|
# Returns the Wallet ID of the Trade.
|
@@ -198,7 +199,7 @@ module Coinbase
|
|
198
199
|
# Returns a String representation of the Trade.
|
199
200
|
# @return [String] a String representation of the Trade
|
200
201
|
def to_s
|
201
|
-
"Coinbase::Trade{transfer_id: '#{id}', network_id: '#{
|
202
|
+
"Coinbase::Trade{transfer_id: '#{id}', network_id: '#{network.id}', " \
|
202
203
|
"address_id: '#{address_id}', from_asset_id: '#{from_asset_id}', " \
|
203
204
|
"to_asset_id: '#{to_asset_id}', from_amount: '#{from_amount}', " \
|
204
205
|
"to_amount: '#{to_amount}' status: '#{status}'}"
|
data/lib/coinbase/transaction.rb
CHANGED
@@ -68,6 +68,12 @@ module Coinbase
|
|
68
68
|
@model.from_address_id
|
69
69
|
end
|
70
70
|
|
71
|
+
# Returns the to address for the Transaction.
|
72
|
+
# @return [String] The to address
|
73
|
+
def to_address_id
|
74
|
+
@model.to_address_id
|
75
|
+
end
|
76
|
+
|
71
77
|
# Returns whether the Transaction is in a terminal state.
|
72
78
|
# @return [Boolean] Whether the Transaction is in a terminal state
|
73
79
|
def terminal_state?
|
data/lib/coinbase/transfer.rb
CHANGED
@@ -20,12 +20,13 @@ module Coinbase
|
|
20
20
|
# If the destination is a Wallet, it uses the default Address of the Wallet.
|
21
21
|
# If the destination is an Address, it uses the Address's ID.
|
22
22
|
# If the destination is a String, it uses it as the Address ID.
|
23
|
-
# @param
|
23
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
24
24
|
# @param wallet_id [String] The Wallet ID of the sending Wallet
|
25
25
|
# @return [Transfer] The new pending Transfer object
|
26
26
|
# @raise [Coinbase::ApiError] If the Transfer fails
|
27
|
-
def create(address_id:, amount:, asset_id:, destination:,
|
28
|
-
|
27
|
+
def create(address_id:, amount:, asset_id:, destination:, network:, wallet_id:, gasless: false)
|
28
|
+
network = Coinbase::Network.from_id(network)
|
29
|
+
asset = network.get_asset(asset_id)
|
29
30
|
|
30
31
|
model = Coinbase.call_api do
|
31
32
|
transfers_api.create_transfer(
|
@@ -34,8 +35,8 @@ module Coinbase
|
|
34
35
|
{
|
35
36
|
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
36
37
|
asset_id: asset.primary_denomination.to_s,
|
37
|
-
destination: Coinbase::Destination.new(destination,
|
38
|
-
network_id:
|
38
|
+
destination: Coinbase::Destination.new(destination, network: network).address_id,
|
39
|
+
network_id: network.normalized_id,
|
39
40
|
gasless: gasless
|
40
41
|
}
|
41
42
|
)
|
@@ -82,10 +83,10 @@ module Coinbase
|
|
82
83
|
@model.transfer_id
|
83
84
|
end
|
84
85
|
|
85
|
-
# Returns the Network
|
86
|
-
# @return [Symbol] The Network
|
87
|
-
def
|
88
|
-
Coinbase.
|
86
|
+
# Returns the Network of the Transfer.
|
87
|
+
# @return [Symbol] The Network
|
88
|
+
def network
|
89
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
89
90
|
end
|
90
91
|
|
91
92
|
# Returns the Wallet ID of the Transfer.
|
@@ -229,7 +230,7 @@ module Coinbase
|
|
229
230
|
# Returns a String representation of the Transfer.
|
230
231
|
# @return [String] a String representation of the Transfer
|
231
232
|
def to_s
|
232
|
-
"Coinbase::Transfer{transfer_id: '#{id}', network_id: '#{
|
233
|
+
"Coinbase::Transfer{transfer_id: '#{id}', network_id: '#{network.id}', " \
|
233
234
|
"from_address_id: '#{from_address_id}', destination_address_id: '#{destination_address_id}', " \
|
234
235
|
"asset_id: '#{asset_id}', amount: '#{amount}', transaction_link: '#{transaction_link}', " \
|
235
236
|
"status: '#{status}'}"
|
data/lib/coinbase/validator.rb
CHANGED
@@ -10,27 +10,31 @@ module Coinbase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns a list of Validators for the provided network and asset.
|
13
|
-
# @param
|
13
|
+
# @param network [Coinbase::Nework, Symbol] The Network or Network ID
|
14
14
|
# @param asset_id [Symbol] The asset ID
|
15
15
|
# @param status [Symbol] The status of the validator. Defaults to nil.
|
16
16
|
# @return [Enumerable<Coinbase::Validator>] The validators
|
17
|
-
def self.list(
|
18
|
-
Coinbase::
|
19
|
-
|
20
|
-
|
17
|
+
def self.list(network, asset_id, status: nil)
|
18
|
+
network = Coinbase::Network.from_id(network)
|
19
|
+
|
20
|
+
Coinbase::Pagination.enumerate(lambda { |page|
|
21
|
+
list_page(network, asset_id, status, page)
|
22
|
+
}) do |validator|
|
21
23
|
new(validator)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
# Returns a Validator for the provided network, asset, and validator.
|
26
|
-
# @param
|
28
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID
|
27
29
|
# @param asset_id [Symbol] The asset ID
|
28
30
|
# @param validator_id [String] The validator ID
|
29
31
|
# @return [Coinbase::Validator] The validator
|
30
|
-
def self.fetch(
|
32
|
+
def self.fetch(network, asset_id, validator_id)
|
33
|
+
network = Coinbase::Network.from_id(network)
|
34
|
+
|
31
35
|
validator = Coinbase.call_api do
|
32
36
|
validators_api.get_validator(
|
33
|
-
|
37
|
+
network.normalized_id,
|
34
38
|
asset_id,
|
35
39
|
validator_id
|
36
40
|
)
|
@@ -62,10 +66,10 @@ module Coinbase
|
|
62
66
|
to_s
|
63
67
|
end
|
64
68
|
|
65
|
-
def self.list_page(
|
69
|
+
def self.list_page(network, asset_id, status, page)
|
66
70
|
Coinbase.call_api do
|
67
71
|
validators_api.list_validators(
|
68
|
-
|
72
|
+
network.normalized_id,
|
69
73
|
asset_id,
|
70
74
|
{
|
71
75
|
status: status,
|
@@ -75,8 +79,12 @@ module Coinbase
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
82
|
+
private_class_method :list_page
|
83
|
+
|
78
84
|
def self.validators_api
|
79
85
|
Coinbase::Client::ValidatorsApi.new(Coinbase.configuration.api_client)
|
80
86
|
end
|
87
|
+
|
88
|
+
private_class_method :validators_api
|
81
89
|
end
|
82
90
|
end
|