coinbase-sdk 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address.rb +73 -19
  3. data/lib/coinbase/asset.rb +80 -56
  4. data/lib/coinbase/balance.rb +10 -6
  5. data/lib/coinbase/client/api/assets_api.rb +91 -0
  6. data/lib/coinbase/client/api/balances_api.rb +97 -0
  7. data/lib/coinbase/client/api/external_addresses_api.rb +242 -0
  8. data/lib/coinbase/client/api/server_signers_api.rb +13 -3
  9. data/lib/coinbase/client/api/stake_api.rb +236 -0
  10. data/lib/coinbase/client/api/transfer_api.rb +114 -0
  11. data/lib/coinbase/client/models/broadcast_trade_request.rb +14 -4
  12. data/lib/coinbase/client/models/build_staking_operation_request.rb +291 -0
  13. data/lib/coinbase/client/models/feature.rb +42 -0
  14. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +258 -0
  15. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +343 -0
  16. data/lib/coinbase/client/models/get_staking_context_request.rb +274 -0
  17. data/lib/coinbase/client/models/partial_eth_staking_context.rb +257 -0
  18. data/lib/coinbase/client/models/request_faucet_funds200_response.rb +222 -0
  19. data/lib/coinbase/client/models/server_signer_list.rb +275 -0
  20. data/lib/coinbase/client/models/staking_context.rb +222 -0
  21. data/lib/coinbase/client/models/staking_context_context.rb +104 -0
  22. data/lib/coinbase/client/models/staking_operation.rb +222 -0
  23. data/lib/coinbase/client/models/staking_reward.rb +308 -0
  24. data/lib/coinbase/client/models/trade.rb +13 -4
  25. data/lib/coinbase/client/models/transaction.rb +45 -1
  26. data/lib/coinbase/client/models/transfer.rb +33 -1
  27. data/lib/coinbase/client/models/wallet.rb +20 -1
  28. data/lib/coinbase/client.rb +14 -0
  29. data/lib/coinbase/constants.rb +2 -27
  30. data/lib/coinbase/errors.rb +50 -62
  31. data/lib/coinbase/network.rb +6 -20
  32. data/lib/coinbase/server_signer.rb +57 -0
  33. data/lib/coinbase/trade.rb +147 -0
  34. data/lib/coinbase/transaction.rb +125 -0
  35. data/lib/coinbase/transfer.rb +22 -55
  36. data/lib/coinbase/wallet.rb +14 -3
  37. data/lib/coinbase.rb +11 -11
  38. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee1676ef79c89fd46c217eacbffecf507bed15a7362b8550d3110df96d45cd47
4
- data.tar.gz: 21627d8b1bd0aefd94f33e5638eb514d8984aea244fb353c21e6fc17e899bf8d
3
+ metadata.gz: c52613ebb145609813f96508c0eff76721ee6afebf3f3207394dad4c91b51635
4
+ data.tar.gz: d7f86c6cfbc02b6dd8866717cc9a89439b81da9ae8838dc34855dd10bf9f3fa9
5
5
  SHA512:
6
- metadata.gz: 8b4ea7efb7b44a82b7b508ae8145ac7df6f467c55a17b27c10fe66aed6a72a7d4408d24ff1253b9ab9cbd6eca19d46def359d094673a066eb6479656ed47d30a
7
- data.tar.gz: 79557441fda3a63c564976f8568cb0ab5b724063dd793fc5ad32085e2eb533355720d1084cace42d3b7a92e3bdf3748434389c0f1f8a7989c402b7191054be2f
6
+ metadata.gz: 6fa544e18af4ad42457ec8615e7a6e652fb15e1ae00cfa14924dcb86c53aab1ba90b21a8e1b7b29f193b1e0039d030cba1f45631b8dac23b287617105b88478b
7
+ data.tar.gz: 3625e897b9681e208cd921e8118275bd012996c17fb62fc235eac8624e6742ce18cff8d8177a1d379bfb5fa71ebec3db02a70d2bb683aeb067ccac7f89345945
@@ -77,20 +77,43 @@ module Coinbase
77
77
  # @param asset_id [Symbol] The ID of the Asset to send. For Ether, :eth, :gwei, and :wei are supported.
78
78
  # @param destination [Wallet | Address | String] The destination of the transfer. If a Wallet, sends to the Wallet's
79
79
  # default address. If a String, interprets it as the address ID.
80
- # @return [String] The hash of the Transfer transaction.
80
+ # @return [Coinbase::Transfer] The Transfer object.
81
81
  def transfer(amount, asset_id, destination)
82
+ asset = Asset.fetch(network_id, asset_id)
83
+
82
84
  destination_address, destination_network = destination_address_and_network(destination)
83
85
 
84
- validate_can_transfer!(amount, asset_id, destination_network)
86
+ validate_can_transfer!(amount, asset, destination_network)
85
87
 
86
- transfer = create_transfer(amount, asset_id, destination_address)
88
+ transfer = create_transfer(amount, asset, destination_address)
87
89
 
88
90
  # If a server signer is managing keys, it will sign and broadcast the underlying transfer transaction out of band.
89
91
  return transfer if Coinbase.use_server_signer?
90
92
 
91
- signed_payload = sign_transfer(transfer)
93
+ broadcast_transfer(transfer, transfer.transaction.sign(@key))
94
+ end
95
+
96
+ # Trades the given amount of the given Asset for another Asset.
97
+ # Only same-network Trades are supported.
98
+ # @param amount [Integer, Float, BigDecimal] The amount of the Asset to send.
99
+ # @param from_asset_id [Symbol] The ID of the Asset to trade from. For Ether, :eth, :gwei, and :wei are supported.
100
+ # @param to_asset_id [Symbol] The ID of the Asset to trade to. For Ether, :eth, :gwei, and :wei are supported.
101
+ # @return [Coinbase::Trade] The Trade object.
102
+ def trade(amount, from_asset_id, to_asset_id)
103
+ from_asset = Asset.fetch(network_id, from_asset_id)
104
+ to_asset = Asset.fetch(network_id, to_asset_id)
105
+
106
+ validate_can_trade!(amount, from_asset)
107
+
108
+ trade = create_trade(amount, from_asset, to_asset)
109
+
110
+ # NOTE: Trading does not yet support server signers at this point.
111
+
112
+ payloads = { signed_payload: trade.transaction.sign(@key) }
113
+
114
+ payloads[:approve_tx_signed_payload] = trade.approve_transaction.sign(@key) unless trade.approve_transaction.nil?
92
115
 
93
- broadcast_transfer(transfer, signed_payload)
116
+ broadcast_trade(trade, **payloads)
94
117
  end
95
118
 
96
119
  # Returns whether the Address has a private key backing it to sign transactions.
@@ -163,6 +186,10 @@ module Coinbase
163
186
  @transfers_api ||= Coinbase::Client::TransfersApi.new(Coinbase.configuration.api_client)
164
187
  end
165
188
 
189
+ def trades_api
190
+ @trades_api ||= Coinbase::Client::TradesApi.new(Coinbase.configuration.api_client)
191
+ end
192
+
166
193
  def destination_address_and_network(destination)
167
194
  return [destination.default_address.id, destination.network_id] if destination.is_a?(Wallet)
168
195
  return [destination.id, destination.network_id] if destination.is_a?(Address)
@@ -170,25 +197,23 @@ module Coinbase
170
197
  [destination, network_id]
171
198
  end
172
199
 
173
- def validate_can_transfer!(amount, asset_id, destination_network_id)
200
+ def validate_can_transfer!(amount, asset, destination_network_id)
174
201
  raise 'Cannot transfer from address without private key loaded' unless can_sign? || Coinbase.use_server_signer?
175
202
 
176
- raise ArgumentError, "Unsupported asset: #{asset_id}" unless Coinbase::Asset.supported?(asset_id)
177
-
178
203
  raise ArgumentError, 'Transfer must be on the same Network' unless destination_network_id == network_id
179
204
 
180
- current_balance = balance(asset_id)
205
+ current_balance = balance(asset.asset_id)
181
206
 
182
207
  return unless current_balance < amount
183
208
 
184
209
  raise ArgumentError, "Insufficient funds: #{amount} requested, but only #{current_balance} available"
185
210
  end
186
211
 
187
- def create_transfer(amount, asset_id, destination)
212
+ def create_transfer(amount, asset, destination)
188
213
  create_transfer_request = {
189
- amount: Coinbase::Asset.to_atomic_amount(amount, asset_id).to_i.to_s,
214
+ amount: asset.to_atomic_amount(amount).to_i.to_s,
190
215
  network_id: network_id,
191
- asset_id: Coinbase::Asset.primary_denomination(asset_id).to_s,
216
+ asset_id: asset.primary_denomination.to_s,
192
217
  destination: destination
193
218
  }
194
219
 
@@ -199,13 +224,6 @@ module Coinbase
199
224
  Coinbase::Transfer.new(transfer_model)
200
225
  end
201
226
 
202
- def sign_transfer(transfer)
203
- transaction = transfer.transaction
204
- transaction.sign(@key)
205
-
206
- transaction.hex
207
- end
208
-
209
227
  def broadcast_transfer(transfer, signed_payload)
210
228
  transfer_model = Coinbase.call_api do
211
229
  transfers_api.broadcast_transfer(wallet_id, id, transfer.id, { signed_payload: signed_payload })
@@ -213,5 +231,41 @@ module Coinbase
213
231
 
214
232
  Coinbase::Transfer.new(transfer_model)
215
233
  end
234
+
235
+ def validate_can_trade!(amount, from_asset)
236
+ raise 'Cannot trade from address without private key loaded' unless can_sign?
237
+
238
+ current_balance = balance(from_asset.asset_id)
239
+
240
+ return unless current_balance < amount
241
+
242
+ raise ArgumentError, "Insufficient funds: #{amount} requested, but only #{current_balance} available"
243
+ end
244
+
245
+ def create_trade(amount, from_asset, to_asset)
246
+ create_trade_request = {
247
+ amount: from_asset.to_atomic_amount(amount).to_i.to_s,
248
+ from_asset_id: from_asset.primary_denomination.to_s,
249
+ to_asset_id: to_asset.primary_denomination.to_s
250
+ }
251
+
252
+ trade_model = Coinbase.call_api do
253
+ trades_api.create_trade(wallet_id, id, create_trade_request)
254
+ end
255
+
256
+ Coinbase::Trade.new(trade_model)
257
+ end
258
+
259
+ def broadcast_trade(trade, signed_payload:, approve_tx_signed_payload: nil)
260
+ req = { signed_payload: signed_payload }
261
+
262
+ req[:approve_transaction_signed_payload] = approve_tx_signed_payload unless approve_tx_signed_payload.nil?
263
+
264
+ trade_model = Coinbase.call_api do
265
+ trades_api.broadcast_trade(wallet_id, id, trade.id, req)
266
+ end
267
+
268
+ Coinbase::Trade.new(trade_model)
269
+ end
216
270
  end
217
271
  end
@@ -3,84 +3,108 @@
3
3
  module Coinbase
4
4
  # A representation of an Asset.
5
5
  class Asset
6
- # Retuns whether the provided asset ID is supported.
7
- # @param asset_id [Symbol] The Asset ID
8
- # @return [Boolean] Whether the Asset ID is supported
9
- def self.supported?(asset_id)
10
- !!Coinbase::SUPPORTED_ASSET_IDS[asset_id]
11
- end
6
+ class << self
7
+ # Returns the primary denomination for the provided Asset ID.
8
+ # For assets with multiple denominations, e.g. eth can also be denominated in wei and gwei,
9
+ # this method will return the primary denomination.
10
+ # e.g. eth.
11
+ # @param asset_id [Symbol] The Asset ID
12
+ # @return [Symbol] The primary denomination for the Asset ID
13
+ def primary_denomination(asset_id)
14
+ return :eth if %i[wei gwei].include?(asset_id)
12
15
 
13
- # Converts the amount of the Asset to the atomic units of the primary denomination of the Asset.
14
- # @param amount [Integer, Float, BigDecimal] The amount to normalize
15
- # @param asset_id [Symbol] The ID of the Asset being transferred
16
- # @return [BigDecimal] The normalized amount in atomic units
17
- def self.to_atomic_amount(amount, asset_id)
18
- case asset_id
19
- when :eth
20
- amount * BigDecimal(Coinbase::WEI_PER_ETHER.to_s)
21
- when :gwei
22
- amount * BigDecimal(Coinbase::WEI_PER_GWEI.to_s)
23
- when :usdc
24
- amount * BigDecimal(Coinbase::ATOMIC_UNITS_PER_USDC.to_s)
25
- when :weth
26
- amount * BigDecimal(Coinbase::WEI_PER_ETHER)
27
- else
28
- amount
16
+ asset_id
29
17
  end
30
- end
31
18
 
32
- # Converts an amount from the atomic value of the primary denomination of the provided Asset ID
33
- # to whole units of the specified asset ID.
34
- # @param atomic_amount [BigDecimal] The amount in atomic units
35
- # @param asset_id [Symbol] The Asset ID
36
- # @return [BigDecimal] The amount in whole units of the specified asset ID
37
- def self.from_atomic_amount(atomic_amount, asset_id)
38
- case asset_id
39
- when :eth
40
- atomic_amount / BigDecimal(Coinbase::WEI_PER_ETHER.to_s)
41
- when :gwei
42
- atomic_amount / BigDecimal(Coinbase::WEI_PER_GWEI.to_s)
43
- when :usdc
44
- atomic_amount / BigDecimal(Coinbase::ATOMIC_UNITS_PER_USDC.to_s)
45
- when :weth
46
- atomic_amount / BigDecimal(Coinbase::WEI_PER_ETHER)
47
- else
48
- atomic_amount
19
+ def from_model(asset_model, asset_id: nil)
20
+ raise unless asset_model.is_a?(Coinbase::Client::Asset)
21
+
22
+ decimals = asset_model.decimals
23
+
24
+ # Handle the non-primary denomination case at the asset level.
25
+ # TODO: Push this logic down to the backend.
26
+ if asset_id && asset_id != Coinbase.to_sym(asset_model.asset_id)
27
+ case asset_id
28
+ when :gwei
29
+ decimals = GWEI_DECIMALS
30
+ when :wei
31
+ decimals = 0
32
+ else
33
+ raise ArgumentError, "Unsupported asset ID: #{asset_id}"
34
+ end
35
+ end
36
+
37
+ new(
38
+ network_id: Coinbase.to_sym(asset_model.network_id),
39
+ asset_id: asset_id || Coinbase.to_sym(asset_model.asset_id),
40
+ address_id: asset_model.contract_address,
41
+ decimals: decimals
42
+ )
49
43
  end
50
- end
51
44
 
52
- # Returns the primary denomination for the provided Asset ID.
53
- # For assets with multiple denominations, e.g. eth can also be denominated in wei and gwei,
54
- # this method will return the primary denomination.
55
- # e.g. eth.
56
- # @param asset_id [Symbol] The Asset ID
57
- # @return [Symbol] The primary denomination for the Asset ID
58
- def self.primary_denomination(asset_id)
59
- return :eth if %i[wei gwei].include?(asset_id)
45
+ # Fetches the Asset with the provided Asset ID.
46
+ # @param asset_id [Symbol] The Asset ID
47
+ # @return [Coinbase::Asset] The Asset
48
+ def fetch(network_id, asset_id)
49
+ asset_model = Coinbase.call_api do
50
+ assets_api.get_asset(
51
+ Coinbase.normalize_network(network_id),
52
+ primary_denomination(asset_id).to_s
53
+ )
54
+ end
60
55
 
61
- asset_id
56
+ from_model(asset_model, asset_id: asset_id)
57
+ end
58
+
59
+ private
60
+
61
+ def assets_api
62
+ Coinbase::Client::AssetsApi.new(Coinbase.configuration.api_client)
63
+ end
62
64
  end
63
65
 
64
66
  # Returns a new Asset object. Do not use this method. Instead, use the Asset constants defined in
65
67
  # the Coinbase module.
66
68
  # @param network_id [Symbol] The ID of the Network to which the Asset belongs
67
69
  # @param asset_id [Symbol] The Asset ID
68
- # @param display_name [String] The Asset's display name
69
70
  # @param address_id [String] (Optional) The Asset's address ID, if one exists
70
- def initialize(network_id:, asset_id:, display_name:, address_id: nil)
71
+ # @param decimals [Integer] (Optional) The number of decimal places the Asset uses
72
+ def initialize(network_id:, asset_id:, decimals:, address_id: nil)
71
73
  @network_id = network_id
72
74
  @asset_id = asset_id
73
- @display_name = display_name
74
75
  @address_id = address_id
76
+ @decimals = decimals
75
77
  end
76
78
 
77
- attr_reader :network_id, :asset_id, :display_name, :address_id
79
+ attr_reader :network_id, :asset_id, :address_id, :decimals
80
+
81
+ # Converts the amount of the Asset from atomic to whole units.
82
+ # @param atomic_amount [Integer, Float, BigDecimal] The atomic amount to convert to whole units.
83
+ # @return [BigDecimal] The amount in whole units
84
+ def from_atomic_amount(atomic_amount)
85
+ BigDecimal(atomic_amount) / BigDecimal(10).power(decimals)
86
+ end
87
+
88
+ # Converts the amount of the Asset from whole to atomic units.
89
+ # @param whole_amount [Integer, Float, BigDecimal] The whole amount to convert to atomic units.
90
+ # @return [BigDecimal] The amount in atomic units
91
+ def to_atomic_amount(whole_amount)
92
+ whole_amount * BigDecimal(10).power(decimals)
93
+ end
94
+
95
+ # Returns the primary denomination for the Asset.
96
+ # For `gwei` and `wei` the primary denomination is `eth`.
97
+ # For all other assets, the primary denomination is the same asset ID.
98
+ # @return [Symbol] The primary denomination for the Asset
99
+ def primary_denomination
100
+ self.class.primary_denomination(asset_id)
101
+ end
78
102
 
79
103
  # Returns a string representation of the Asset.
80
104
  # @return [String] a string representation of the Asset
81
105
  def to_s
82
- "Coinbase::Asset{network_id: '#{network_id}', asset_id: '#{asset_id}', display_name: '#{display_name}'" +
83
- (address_id.nil? ? '}' : ", address_id: '#{address_id}'}")
106
+ "Coinbase::Asset{network_id: '#{network_id}', asset_id: '#{asset_id}', decimals: '#{decimals}'" \
107
+ "#{address_id.nil? ? '' : ", address_id: '#{address_id}'"}}"
84
108
  end
85
109
 
86
110
  # Same as to_s.
@@ -7,9 +7,9 @@ module Coinbase
7
7
  # @param balance_model [Coinbase::Client::Balance] The balance fetched from the API.
8
8
  # @return [Balance] The converted Balance object.
9
9
  def self.from_model(balance_model)
10
- asset_id = Coinbase.to_sym(balance_model.asset.asset_id.downcase)
10
+ asset = Coinbase::Asset.from_model(balance_model.asset)
11
11
 
12
- from_model_and_asset_id(balance_model, asset_id)
12
+ new(amount: asset.from_atomic_amount(balance_model.amount), asset: asset)
13
13
  end
14
14
 
15
15
  # Converts a Coinbase::Client::Balance model and asset ID to a Coinbase::Balance
@@ -19,8 +19,11 @@ module Coinbase
19
19
  # @param asset_id [Symbol] The Asset ID of the denomination we want returned.
20
20
  # @return [Balance] The converted Balance object.
21
21
  def self.from_model_and_asset_id(balance_model, asset_id)
22
+ asset = Coinbase::Asset.from_model(balance_model.asset, asset_id: asset_id)
23
+
22
24
  new(
23
- amount: Coinbase::Asset.from_atomic_amount(BigDecimal(balance_model.amount), asset_id),
25
+ amount: asset.from_atomic_amount(balance_model.amount),
26
+ asset: asset,
24
27
  asset_id: asset_id
25
28
  )
26
29
  end
@@ -29,12 +32,13 @@ module Coinbase
29
32
  # Balance.from_model_and_asset_id.
30
33
  # @param amount [BigDecimal] The amount of the Asset
31
34
  # @param asset_id [Symbol] The Asset ID
32
- def initialize(amount:, asset_id:)
35
+ def initialize(amount:, asset:, asset_id: nil)
33
36
  @amount = amount
34
- @asset_id = asset_id
37
+ @asset = asset
38
+ @asset_id = asset_id || asset.asset_id
35
39
  end
36
40
 
37
- attr_reader :amount, :asset_id
41
+ attr_reader :amount, :asset, :asset_id
38
42
 
39
43
  # Returns a string representation of the Balance.
40
44
  # @return [String] a string representation of the Balance
@@ -0,0 +1,91 @@
1
+ =begin
2
+ #Coinbase Platform API
3
+
4
+ #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
+
6
+ The version of the OpenAPI document: 0.0.1-alpha
7
+ Contact: yuga.cohler@coinbase.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.5.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Coinbase::Client
16
+ class AssetsApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Get the asset for the specified asset ID.
23
+ # Get the asset for the specified asset ID.
24
+ # @param network_id [String] The ID of the blockchain network
25
+ # @param asset_id [String] The ID of the asset to fetch
26
+ # @param [Hash] opts the optional parameters
27
+ # @return [Asset]
28
+ def get_asset(network_id, asset_id, opts = {})
29
+ data, _status_code, _headers = get_asset_with_http_info(network_id, asset_id, opts)
30
+ data
31
+ end
32
+
33
+ # Get the asset for the specified asset ID.
34
+ # Get the asset for the specified asset ID.
35
+ # @param network_id [String] The ID of the blockchain network
36
+ # @param asset_id [String] The ID of the asset to fetch
37
+ # @param [Hash] opts the optional parameters
38
+ # @return [Array<(Asset, Integer, Hash)>] Asset data, response status code and response headers
39
+ def get_asset_with_http_info(network_id, asset_id, opts = {})
40
+ if @api_client.config.debugging
41
+ @api_client.config.logger.debug 'Calling API: AssetsApi.get_asset ...'
42
+ end
43
+ # verify the required parameter 'network_id' is set
44
+ if @api_client.config.client_side_validation && network_id.nil?
45
+ fail ArgumentError, "Missing the required parameter 'network_id' when calling AssetsApi.get_asset"
46
+ end
47
+ # verify the required parameter 'asset_id' is set
48
+ if @api_client.config.client_side_validation && asset_id.nil?
49
+ fail ArgumentError, "Missing the required parameter 'asset_id' when calling AssetsApi.get_asset"
50
+ end
51
+ # resource path
52
+ local_var_path = '/v1/networks/{network_id}/assets/{asset_id}'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'asset_id' + '}', CGI.escape(asset_id.to_s))
53
+
54
+ # query parameters
55
+ query_params = opts[:query_params] || {}
56
+
57
+ # header parameters
58
+ header_params = opts[:header_params] || {}
59
+ # HTTP header 'Accept' (if needed)
60
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
61
+
62
+ # form parameters
63
+ form_params = opts[:form_params] || {}
64
+
65
+ # http body (model)
66
+ post_body = opts[:debug_body]
67
+
68
+ # return_type
69
+ return_type = opts[:debug_return_type] || 'Asset'
70
+
71
+ # auth_names
72
+ auth_names = opts[:debug_auth_names] || []
73
+
74
+ new_options = opts.merge(
75
+ :operation => :"AssetsApi.get_asset",
76
+ :header_params => header_params,
77
+ :query_params => query_params,
78
+ :form_params => form_params,
79
+ :body => post_body,
80
+ :auth_names => auth_names,
81
+ :return_type => return_type
82
+ )
83
+
84
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
85
+ if @api_client.config.debugging
86
+ @api_client.config.logger.debug "API called: AssetsApi#get_asset\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
87
+ end
88
+ return data, status_code, headers
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,97 @@
1
+ =begin
2
+ #Coinbase Platform API
3
+
4
+ #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
+
6
+ The version of the OpenAPI document: 0.0.1-alpha
7
+ Contact: yuga.cohler@coinbase.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.5.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Coinbase::Client
16
+ class BalancesApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Get the balance of an asset in an external address
23
+ # Get the balance of an asset in an external address
24
+ # @param network_id [String] The ID of the blockchain network
25
+ # @param address_id [String] The ID of the address to fetch the balance for
26
+ # @param asset_id [String] The ID of the asset to fetch the balance for
27
+ # @param [Hash] opts the optional parameters
28
+ # @return [Balance]
29
+ def get_external_address_balance(network_id, address_id, asset_id, opts = {})
30
+ data, _status_code, _headers = get_external_address_balance_with_http_info(network_id, address_id, asset_id, opts)
31
+ data
32
+ end
33
+
34
+ # Get the balance of an asset in an external address
35
+ # Get the balance of an asset in an external address
36
+ # @param network_id [String] The ID of the blockchain network
37
+ # @param address_id [String] The ID of the address to fetch the balance for
38
+ # @param asset_id [String] The ID of the asset to fetch the balance for
39
+ # @param [Hash] opts the optional parameters
40
+ # @return [Array<(Balance, Integer, Hash)>] Balance data, response status code and response headers
41
+ def get_external_address_balance_with_http_info(network_id, address_id, asset_id, opts = {})
42
+ if @api_client.config.debugging
43
+ @api_client.config.logger.debug 'Calling API: BalancesApi.get_external_address_balance ...'
44
+ end
45
+ # verify the required parameter 'network_id' is set
46
+ if @api_client.config.client_side_validation && network_id.nil?
47
+ fail ArgumentError, "Missing the required parameter 'network_id' when calling BalancesApi.get_external_address_balance"
48
+ end
49
+ # verify the required parameter 'address_id' is set
50
+ if @api_client.config.client_side_validation && address_id.nil?
51
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling BalancesApi.get_external_address_balance"
52
+ end
53
+ # verify the required parameter 'asset_id' is set
54
+ if @api_client.config.client_side_validation && asset_id.nil?
55
+ fail ArgumentError, "Missing the required parameter 'asset_id' when calling BalancesApi.get_external_address_balance"
56
+ end
57
+ # resource path
58
+ local_var_path = '/v1/networks/{network_id}/addresses/{address_id}/balances/{asset_id}'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'asset_id' + '}', CGI.escape(asset_id.to_s))
59
+
60
+ # query parameters
61
+ query_params = opts[:query_params] || {}
62
+
63
+ # header parameters
64
+ header_params = opts[:header_params] || {}
65
+ # HTTP header 'Accept' (if needed)
66
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
67
+
68
+ # form parameters
69
+ form_params = opts[:form_params] || {}
70
+
71
+ # http body (model)
72
+ post_body = opts[:debug_body]
73
+
74
+ # return_type
75
+ return_type = opts[:debug_return_type] || 'Balance'
76
+
77
+ # auth_names
78
+ auth_names = opts[:debug_auth_names] || []
79
+
80
+ new_options = opts.merge(
81
+ :operation => :"BalancesApi.get_external_address_balance",
82
+ :header_params => header_params,
83
+ :query_params => query_params,
84
+ :form_params => form_params,
85
+ :body => post_body,
86
+ :auth_names => auth_names,
87
+ :return_type => return_type
88
+ )
89
+
90
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
91
+ if @api_client.config.debugging
92
+ @api_client.config.logger.debug "API called: BalancesApi#get_external_address_balance\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
93
+ end
94
+ return data, status_code, headers
95
+ end
96
+ end
97
+ end