coinbase-sdk 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +24 -17
  3. data/lib/coinbase/address.rb +17 -19
  4. data/lib/coinbase/asset.rb +11 -8
  5. data/lib/coinbase/client/api/addresses_api.rb +1 -1
  6. data/lib/coinbase/client/api/assets_api.rb +1 -1
  7. data/lib/coinbase/client/api/contract_events_api.rb +18 -10
  8. data/lib/coinbase/client/api/external_addresses_api.rb +1 -1
  9. data/lib/coinbase/client/api/networks_api.rb +1 -1
  10. data/lib/coinbase/client/api/server_signers_api.rb +1 -1
  11. data/lib/coinbase/client/api/stake_api.rb +1 -242
  12. data/lib/coinbase/client/api/trades_api.rb +1 -1
  13. data/lib/coinbase/client/api/transfers_api.rb +1 -1
  14. data/lib/coinbase/client/api/users_api.rb +1 -1
  15. data/lib/coinbase/client/api/validators_api.rb +3 -3
  16. data/lib/coinbase/client/api/wallet_stake_api.rb +263 -0
  17. data/lib/coinbase/client/api/wallets_api.rb +1 -1
  18. data/lib/coinbase/client/api/webhooks_api.rb +1 -1
  19. data/lib/coinbase/client/api_client.rb +1 -1
  20. data/lib/coinbase/client/api_error.rb +1 -1
  21. data/lib/coinbase/client/configuration.rb +11 -1
  22. data/lib/coinbase/client/models/address.rb +22 -5
  23. data/lib/coinbase/client/models/address_balance_list.rb +1 -1
  24. data/lib/coinbase/client/models/address_historical_balance_list.rb +1 -1
  25. data/lib/coinbase/client/models/address_list.rb +1 -1
  26. data/lib/coinbase/client/models/asset.rb +1 -1
  27. data/lib/coinbase/client/models/balance.rb +1 -1
  28. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
  29. data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
  30. data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
  31. data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
  32. data/lib/coinbase/client/models/contract_event.rb +100 -9
  33. data/lib/coinbase/client/models/contract_event_list.rb +1 -1
  34. data/lib/coinbase/client/models/create_address_request.rb +15 -5
  35. data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
  36. data/lib/coinbase/client/models/create_staking_operation_request.rb +1 -1
  37. data/lib/coinbase/client/models/create_trade_request.rb +1 -1
  38. data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
  39. data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
  40. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
  41. data/lib/coinbase/client/models/create_webhook_request.rb +1 -1
  42. data/lib/coinbase/client/models/error.rb +1 -1
  43. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +12 -12
  44. data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
  45. data/lib/coinbase/client/models/feature.rb +3 -2
  46. data/lib/coinbase/client/models/feature_set.rb +1 -1
  47. data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +1 -1
  48. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
  49. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
  50. data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
  51. data/lib/coinbase/client/models/historical_balance.rb +1 -1
  52. data/lib/coinbase/client/models/network.rb +15 -5
  53. data/lib/coinbase/client/models/network_identifier.rb +1 -1
  54. data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
  55. data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
  56. data/lib/coinbase/client/models/server_signer.rb +1 -1
  57. data/lib/coinbase/client/models/server_signer_event.rb +1 -1
  58. data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
  59. data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
  60. data/lib/coinbase/client/models/server_signer_list.rb +1 -1
  61. data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
  62. data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
  63. data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
  64. data/lib/coinbase/client/models/sponsored_send.rb +1 -1
  65. data/lib/coinbase/client/models/staking_balance.rb +1 -1
  66. data/lib/coinbase/client/models/staking_context.rb +1 -1
  67. data/lib/coinbase/client/models/staking_context_context.rb +1 -1
  68. data/lib/coinbase/client/models/staking_operation.rb +3 -3
  69. data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
  70. data/lib/coinbase/client/models/staking_reward.rb +1 -1
  71. data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
  72. data/lib/coinbase/client/models/staking_reward_usd_value.rb +1 -1
  73. data/lib/coinbase/client/models/trade.rb +1 -1
  74. data/lib/coinbase/client/models/trade_list.rb +1 -1
  75. data/lib/coinbase/client/models/transaction.rb +16 -6
  76. data/lib/coinbase/client/models/transaction_type.rb +1 -1
  77. data/lib/coinbase/client/models/transfer.rb +1 -1
  78. data/lib/coinbase/client/models/transfer_list.rb +1 -1
  79. data/lib/coinbase/client/models/update_webhook_request.rb +1 -1
  80. data/lib/coinbase/client/models/user.rb +1 -1
  81. data/lib/coinbase/client/models/validator.rb +24 -3
  82. data/lib/coinbase/client/models/validator_details.rb +1 -1
  83. data/lib/coinbase/client/models/validator_list.rb +1 -1
  84. data/lib/coinbase/client/models/validator_status.rb +52 -0
  85. data/lib/coinbase/client/models/wallet.rb +1 -1
  86. data/lib/coinbase/client/models/wallet_list.rb +1 -1
  87. data/lib/coinbase/client/models/webhook.rb +1 -1
  88. data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
  89. data/lib/coinbase/client/models/webhook_event_type.rb +1 -1
  90. data/lib/coinbase/client/models/webhook_list.rb +1 -1
  91. data/lib/coinbase/client/version.rb +1 -1
  92. data/lib/coinbase/client.rb +3 -1
  93. data/lib/coinbase/constants.rb +0 -10
  94. data/lib/coinbase/contract_event.rb +104 -0
  95. data/lib/coinbase/correlation.rb +30 -0
  96. data/lib/coinbase/destination.rb +11 -9
  97. data/lib/coinbase/errors.rb +7 -0
  98. data/lib/coinbase/middleware.rb +2 -0
  99. data/lib/coinbase/network.rb +103 -20
  100. data/lib/coinbase/smart_contract.rb +106 -0
  101. data/lib/coinbase/staking_balance.rb +11 -5
  102. data/lib/coinbase/staking_operation.rb +134 -36
  103. data/lib/coinbase/staking_reward.rb +1 -1
  104. data/lib/coinbase/trade.rb +10 -9
  105. data/lib/coinbase/transaction.rb +6 -0
  106. data/lib/coinbase/transfer.rb +11 -10
  107. data/lib/coinbase/validator.rb +18 -10
  108. data/lib/coinbase/version.rb +5 -0
  109. data/lib/coinbase/wallet.rb +137 -145
  110. data/lib/coinbase/webhook.rb +181 -0
  111. data/lib/coinbase.rb +50 -19
  112. metadata +9 -9
  113. data/lib/coinbase/client/models/ethereum_validator.rb +0 -374
  114. data/lib/coinbase/client/models/get_validator200_response.rb +0 -221
  115. data/lib/coinbase/client/models/get_validator200_response_validator.rb +0 -214
  116. data/lib/coinbase/client/models/native_eth_staking_context.rb +0 -254
  117. data/lib/coinbase/client/models/partial_eth_staking_context.rb +0 -254
  118. data/lib/coinbase/client/models/validator_list_data.rb +0 -216
  119. 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 network_id [Symbol] The Network ID
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, network_id, asset_id, address_id, action, mode, options)
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(network_id),
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 network_id [Symbol] The Network ID
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, network_id, asset_id, address_id, wallet_id, action, mode, options)
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
- asset = Coinbase::Asset.fetch(network_id, asset_id)
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(network_id),
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
- from_model(model)
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 ID of the Staking Operation.
86
- # @return [Symbol] The Network ID
87
- def network_id
88
- Coinbase.to_sym(@model.network_id)
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. Raises a
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 status == 'complete'
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,58 @@ 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
+ 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
+
215
+ self
216
+ end
217
+
132
218
  # Fetch the StakingOperation with the provided network, address and staking operation ID.
133
- # @param network_id [Symbol] The Network ID
219
+ # @param network [Coinbase::Network, Symbol] The Network or Network ID
134
220
  # @param address_id [Symbol] The Address ID
135
221
  # @param id [String] The ID of the StakingOperation
136
222
  # @param wallet_id [String] The optional Wallet ID
137
223
  # @return [Coinbase::StakingOperation] The staking operation
138
- def self.fetch(network_id, address_id, id, wallet_id: nil)
224
+ def self.fetch(network, address_id, id, wallet_id: nil)
225
+ network = Coinbase::Network.from_id(network)
226
+
139
227
  staking_operation_model = Coinbase.call_api do
140
228
  if wallet_id.nil?
141
- stake_api.get_external_staking_operation(network_id, address_id, id)
229
+ stake_api.get_external_staking_operation(network.id, address_id, id)
142
230
  else
143
- stake_api.get_staking_operation(wallet_id, address_id, id)
231
+ wallet_stake_api.get_staking_operation(wallet_id, address_id, id)
144
232
  end
145
233
  end
146
234
 
@@ -160,13 +248,15 @@ module Coinbase
160
248
  def reload
161
249
  @model = Coinbase.call_api do
162
250
  if wallet_id.nil?
163
- stake_api.get_external_staking_operation(network_id, address_id, id)
251
+ stake_api.get_external_staking_operation(network.id, address_id, id)
164
252
  else
165
- stake_api.get_staking_operation(wallet_id, address_id, id)
253
+ wallet_stake_api.get_staking_operation(wallet_id, address_id, id)
166
254
  end
167
255
  end
168
256
 
169
- from_model(@model)
257
+ update_transactions(@model.transactions)
258
+
259
+ self
170
260
  end
171
261
 
172
262
  # Fetches the presigned_voluntary exit messages for the staking operation
@@ -191,7 +281,7 @@ module Coinbase
191
281
  raise TransactionNotSignedError unless transaction.signed?
192
282
 
193
283
  Coinbase.call_api do
194
- stake_api.broadcast_staking_operation(
284
+ wallet_stake_api.broadcast_staking_operation(
195
285
  wallet_id,
196
286
  address_id,
197
287
  id,
@@ -203,24 +293,32 @@ module Coinbase
203
293
  self
204
294
  end
205
295
 
206
- def self.stake_api
207
- Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
208
- end
209
-
210
296
  private
211
297
 
212
298
  def stake_api
213
- @stake_api ||= self.class.stake_api
299
+ @stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
214
300
  end
215
301
 
216
- def from_model(model)
217
- @model = model
218
- @status = model.status
219
- @transactions = model.transactions.map do |transaction_model|
220
- Transaction.new(transaction_model)
302
+ def wallet_stake_api
303
+ @wallet_stake_api ||= Coinbase::Client::WalletStakeApi.new(Coinbase.configuration.api_client)
304
+ end
305
+
306
+ def update_transactions(transactions)
307
+ # Only overwrite the transactions if the response is populated.
308
+ return unless transactions && !transactions.empty?
309
+
310
+ # Create a set of existing unsigned payloads to avoid duplicates.
311
+ existing_unsigned_payloads = Set.new
312
+ @transactions.each do |transaction|
313
+ existing_unsigned_payloads.add(transaction.unsigned_payload)
221
314
  end
222
315
 
223
- self
316
+ # Add transactions that are not already in the transactions array.
317
+ transactions.each do |transaction_model|
318
+ unless existing_unsigned_payloads.include?(transaction_model.unsigned_payload)
319
+ @transactions << Transaction.new(transaction_model)
320
+ end
321
+ end
224
322
  end
225
323
  end
226
324
  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) / BigDecimal(100)
65
+ BigDecimal(@model.usd_value.conversion_price.to_i)
66
66
  end
67
67
 
68
68
  # Returns the USD conversion time of the StakingReward.
@@ -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 network_id [Symbol] The Network ID of the Asset
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:, network_id:, wallet_id:)
22
- from_asset = Asset.fetch(network_id, from_asset_id)
23
- to_asset = Asset.fetch(network_id, to_asset_id)
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 ID of the Trade.
79
- # @return [Symbol] The Network ID
80
- def network_id
81
- Coinbase.to_sym(@model.network_id)
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: '#{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}'}"
@@ -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?
@@ -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 network_id [Symbol] The Network ID of the Asset
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:, network_id:, wallet_id:, gasless: false)
28
- asset = Asset.fetch(network_id, asset_id)
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, network_id: network_id).address_id,
38
- network_id: Coinbase.normalize_network(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 ID of the Transfer.
86
- # @return [Symbol] The Network ID
87
- def network_id
88
- Coinbase.to_sym(@model.network_id)
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: '#{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}'}"
@@ -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 network_id [Symbol] The network ID
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(network_id, asset_id, status: nil)
18
- Coinbase::Pagination.enumerate(
19
- ->(page) { list_page(network_id, asset_id, status, page) }
20
- ) do |validator|
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 network_id [Symbol] The network ID
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(network_id, asset_id, validator_id)
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
- network_id,
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(network_id, asset_id, status, page)
69
+ def self.list_page(network, asset_id, status, page)
66
70
  Coinbase.call_api do
67
71
  validators_api.list_validators(
68
- network_id,
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ VERSION = '0.1.0'
5
+ end