coinbase-sdk 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address.rb +88 -49
  3. data/lib/coinbase/asset.rb +2 -1
  4. data/lib/coinbase/authenticator.rb +52 -0
  5. data/lib/coinbase/balance_map.rb +1 -1
  6. data/lib/coinbase/client/api/addresses_api.rb +385 -0
  7. data/lib/coinbase/client/api/transfers_api.rb +256 -0
  8. data/lib/coinbase/client/api/users_api.rb +79 -0
  9. data/lib/coinbase/client/api/wallets_api.rb +348 -0
  10. data/lib/coinbase/client/api_client.rb +431 -0
  11. data/lib/coinbase/client/api_error.rb +58 -0
  12. data/lib/coinbase/client/configuration.rb +375 -0
  13. data/lib/coinbase/client/models/address.rb +273 -0
  14. data/lib/coinbase/client/models/address_balance_list.rb +275 -0
  15. data/lib/coinbase/client/models/address_list.rb +275 -0
  16. data/lib/coinbase/client/models/asset.rb +260 -0
  17. data/lib/coinbase/client/models/balance.rb +239 -0
  18. data/lib/coinbase/client/models/create_address_request.rb +239 -0
  19. data/lib/coinbase/client/models/create_transfer_request.rb +273 -0
  20. data/lib/coinbase/client/models/create_wallet_request.rb +221 -0
  21. data/lib/coinbase/client/models/error.rb +278 -0
  22. data/lib/coinbase/client/models/transfer.rb +393 -0
  23. data/lib/coinbase/client/models/transfer_list.rb +275 -0
  24. data/lib/coinbase/client/models/user.rb +231 -0
  25. data/lib/coinbase/client/models/wallet.rb +241 -0
  26. data/lib/coinbase/client/models/wallet_list.rb +275 -0
  27. data/lib/coinbase/client/version.rb +15 -0
  28. data/lib/coinbase/client.rb +57 -0
  29. data/lib/coinbase/constants.rb +5 -1
  30. data/lib/coinbase/middleware.rb +21 -0
  31. data/lib/coinbase/network.rb +2 -2
  32. data/lib/coinbase/transfer.rb +69 -54
  33. data/lib/coinbase/user.rb +64 -0
  34. data/lib/coinbase/wallet.rb +146 -54
  35. data/lib/coinbase.rb +73 -9
  36. metadata +74 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2952835a61e4e744db044ab91e1cf58000d578967783d6faf9da77e495790172
4
- data.tar.gz: '00378e6bfb704f649d3943bd26da6712e41a9852ca2e4650c168ea098061a8b1'
3
+ metadata.gz: c18b015a028c3b795a618318ab244f31d58861f66f67e6d76a7b70ee3b664e2f
4
+ data.tar.gz: c82577524824f743ac16624ffc042c2017183d366a5c849d1baa3d2028b85c96
5
5
  SHA512:
6
- metadata.gz: 10a9d9e6288bc1ab73b94be7e0cab8a37e64fa0398e644e570d385c342dd4a46d084e454f56acff0692c82424801ad92479a3ca7e4745d860c51086f28f559dd
7
- data.tar.gz: 131176725ada80cb046882a5fce27ec6355dd7395adf33cadace6f17507b326563ae4f945ceebc4566a10f94e815fda0fbcc3d735e7f7959d4a0b1da65e29b1e
6
+ metadata.gz: 92efa9bc82a0d753698bae8de9e60768c696ce6ef5019cbb3eab6ae7bd25d9257f289dd95164a6440a7f25f0cd90b02a0d267b07ea1d82ebe6b0d4cb142fe82f
7
+ data.tar.gz: 204120f5e22ec7bfd4b87f0e09bdd8600740106d11a0e7d04264d39f650b8a1154472de209537da510cef03daeb669e6a84c5ee5f212c82d9eda66207f5f8e81
@@ -2,65 +2,72 @@
2
2
 
3
3
  require_relative 'balance_map'
4
4
  require_relative 'constants'
5
+ require_relative 'wallet'
5
6
  require 'bigdecimal'
6
7
  require 'eth'
7
8
  require 'jimson'
8
9
 
9
10
  module Coinbase
10
11
  # A representation of a blockchain Address, which is a user-controlled account on a Network. Addresses are used to
11
- # send and receive Assets, and should be created using {link:Wallet#create_address}. Addresses require a
12
- # {link:Eth::Key} to sign transaction data.
12
+ # send and receive Assets, and should be created using Wallet#create_address. Addresses require an
13
+ # Eth::Key to sign transaction data.
13
14
  class Address
14
- attr_reader :network_id, :address_id, :wallet_id
15
-
16
- # Returns a new Address object.
17
- # @param network_id [Symbol] The ID of the Network on which the Address exists
18
- # @param address_id [String] The ID of the Address. On EVM Networks, for example, this is a hash of the public key.
19
- # @param wallet_id [String] The ID of the Wallet to which the Address belongs
15
+ # Returns a new Address object. Do not use this method directly. Instead, use Wallet#create_address, or use
16
+ # the Wallet's default_address.
17
+ # @param model [Coinbase::Client::Address] The underlying Address object
20
18
  # @param key [Eth::Key] The key backing the Address
21
- # @param client [Jimson::Client] (Optional) The JSON RPC client to use for interacting with the Network
22
- def initialize(network_id, address_id, wallet_id, key,
23
- client: Jimson::Client.new(Coinbase.base_sepolia_rpc_url))
24
- # TODO: Don't require key.
25
- @network_id = network_id
26
- @address_id = address_id
27
- @wallet_id = wallet_id
19
+ def initialize(model, key)
20
+ @model = model
28
21
  @key = key
29
- @client = client
30
22
  end
31
23
 
32
- # Returns the balances of the Address. Currently only ETH balances are supported.
24
+ # Returns the Network ID of the Address.
25
+ # @return [Symbol] The Network ID
26
+ def network_id
27
+ Coinbase.to_sym(@model.network_id)
28
+ end
29
+
30
+ # Returns the Wallet ID of the Address.
31
+ # @return [String] The Wallet ID
32
+ def wallet_id
33
+ @model.wallet_id
34
+ end
35
+
36
+ # Returns the Address ID.
37
+ # @return [String] The Address ID
38
+ def address_id
39
+ @model.address_id
40
+ end
41
+
42
+ # Returns the balances of the Address.
33
43
  # @return [BalanceMap] The balances of the Address, keyed by asset ID. Ether balances are denominated
34
44
  # in ETH.
35
45
  def list_balances
36
- # TODO: Handle multiple currencies.
37
- eth_balance_in_wei = BigDecimal(@client.eth_getBalance(@address_id, 'latest').to_i(16).to_s)
38
- eth_balance = BigDecimal(eth_balance_in_wei / BigDecimal(Coinbase::WEI_PER_ETHER.to_s))
39
-
40
- BalanceMap.new({ eth: eth_balance })
46
+ response = addresses_api.list_address_balances(wallet_id, address_id)
47
+ Coinbase.to_balance_map(response)
41
48
  end
42
49
 
43
- # Returns the balance of the provided Asset. Currently only ETH is supported.
50
+ # Returns the balance of the provided Asset.
44
51
  # @param asset_id [Symbol] The Asset to retrieve the balance for
45
52
  # @return [BigDecimal] The balance of the Asset
46
53
  def get_balance(asset_id)
47
- normalized_asset_id = if %i[wei gwei].include?(asset_id)
48
- :eth
49
- else
50
- asset_id
51
- end
54
+ normalized_asset_id = normalize_asset_id(asset_id)
55
+
56
+ response = addresses_api.get_address_balance(wallet_id, address_id, normalized_asset_id.to_s)
52
57
 
53
- eth_balance = list_balances[normalized_asset_id] || BigDecimal(0)
58
+ return BigDecimal('0') if response.nil?
59
+
60
+ amount = BigDecimal(response.amount)
54
61
 
55
62
  case asset_id
56
63
  when :eth
57
- eth_balance
64
+ amount / BigDecimal(Coinbase::WEI_PER_ETHER.to_s)
58
65
  when :gwei
59
- eth_balance * Coinbase::GWEI_PER_ETHER
60
- when :wei
61
- eth_balance * Coinbase::WEI_PER_ETHER
66
+ amount / BigDecimal(Coinbase::GWEI_PER_ETHER.to_s)
67
+ when :usdc
68
+ amount / BigDecimal(Coinbase::ATOMIC_UNITS_PER_USDC.to_s)
62
69
  else
63
- BigDecimal(0)
70
+ amount
64
71
  end
65
72
  end
66
73
 
@@ -71,15 +78,14 @@ module Coinbase
71
78
  # default address. If a String, interprets it as the address ID.
72
79
  # @return [String] The hash of the Transfer transaction.
73
80
  def transfer(amount, asset_id, destination)
74
- # TODO: Handle multiple currencies.
75
81
  raise ArgumentError, "Unsupported asset: #{asset_id}" unless Coinbase::SUPPORTED_ASSET_IDS[asset_id]
76
82
 
77
83
  if destination.is_a?(Wallet)
78
- raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != @network_id
84
+ raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != network_id
79
85
 
80
86
  destination = destination.default_address.address_id
81
87
  elsif destination.is_a?(Address)
82
- raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != @network_id
88
+ raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != network_id
83
89
 
84
90
  destination = destination.address_id
85
91
  end
@@ -89,12 +95,24 @@ module Coinbase
89
95
  raise ArgumentError, "Insufficient funds: #{amount} requested, but only #{current_balance} available"
90
96
  end
91
97
 
92
- transfer = Coinbase::Transfer.new(@network_id, @wallet_id, @address_id, amount, asset_id, destination,
93
- client: @client)
98
+ normalized_amount = normalize_asset_amount(amount, asset_id)
99
+
100
+ normalized_asset_id = normalize_asset_id(asset_id)
101
+
102
+ create_transfer_request = {
103
+ amount: normalized_amount.to_i.to_s,
104
+ network_id: network_id,
105
+ asset_id: normalized_asset_id.to_s,
106
+ destination: destination
107
+ }
108
+
109
+ transfer_model = transfers_api.create_transfer(wallet_id, address_id, create_transfer_request)
110
+
111
+ transfer = Coinbase::Transfer.new(transfer_model)
94
112
 
95
113
  transaction = transfer.transaction
96
114
  transaction.sign(@key)
97
- @client.eth_sendRawTransaction("0x#{transaction.hex}")
115
+ Coinbase.configuration.base_sepolia_client.eth_sendRawTransaction("0x#{transaction.hex}")
98
116
 
99
117
  transfer
100
118
  end
@@ -102,26 +120,47 @@ module Coinbase
102
120
  # Returns the address as a string.
103
121
  # @return [String] The address
104
122
  def to_s
105
- @address_id
123
+ address_id
106
124
  end
107
125
 
108
126
  private
109
127
 
110
- # Normalizes the amount of ETH to send based on the asset ID.
128
+ # Normalizes the amount of the Asset to send to the atomic unit.
111
129
  # @param amount [Integer, Float, BigDecimal] The amount to normalize
112
130
  # @param asset_id [Symbol] The ID of the Asset being transferred
113
- # @return [BigDecimal] The normalized amount in units of ETH
114
- def normalize_eth_amount(amount, asset_id)
131
+ # @return [BigDecimal] The normalized amount in atomic units
132
+ def normalize_asset_amount(amount, asset_id)
133
+ big_amount = BigDecimal(amount.to_s)
134
+
115
135
  case asset_id
116
136
  when :eth
117
- amount.is_a?(BigDecimal) ? amount : BigDecimal(amount.to_s)
137
+ big_amount * Coinbase::WEI_PER_ETHER
118
138
  when :gwei
119
- BigDecimal(amount / Coinbase::GWEI_PER_ETHER)
120
- when :wei
121
- BigDecimal(amount / Coinbase::WEI_PER_ETHER)
139
+ big_amount * Coinbase::WEI_PER_GWEI
140
+ when :usdc
141
+ big_amount * Coinbase::ATOMIC_UNITS_PER_USDC
122
142
  else
123
- raise ArgumentError, "Unsupported asset: #{asset_id}"
143
+ big_amount
124
144
  end
125
145
  end
146
+
147
+ # Normalizes the asset ID to use during requests.
148
+ # @param asset_id [Symbol] The asset ID to normalize
149
+ # @return [Symbol] The normalized asset ID
150
+ def normalize_asset_id(asset_id)
151
+ if %i[wei gwei].include?(asset_id)
152
+ :eth
153
+ else
154
+ asset_id
155
+ end
156
+ end
157
+
158
+ def addresses_api
159
+ @addresses_api ||= Coinbase::Client::AddressesApi.new(Coinbase.configuration.api_client)
160
+ end
161
+
162
+ def transfers_api
163
+ @transfers_api ||= Coinbase::Client::TransfersApi.new(Coinbase.configuration.api_client)
164
+ end
126
165
  end
127
166
  end
@@ -5,7 +5,8 @@ module Coinbase
5
5
  class Asset
6
6
  attr_reader :network_id, :asset_id, :display_name, :address_id
7
7
 
8
- # Returns a new Asset object.
8
+ # Returns a new Asset object. Do not use this method. Instead, use the Asset constants defined in
9
+ # the Coinbase module.
9
10
  # @param network_id [Symbol] The ID of the Network to which the Asset belongs
10
11
  # @param asset_id [Symbol] The Asset ID
11
12
  # @param display_name [String] The Asset's display name
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'jwt'
5
+ require 'openssl'
6
+ require 'securerandom'
7
+
8
+ module Coinbase
9
+ # A class that builds JWTs for authenticating with the Coinbase Platform APIs.
10
+ class Authenticator < Faraday::Middleware
11
+ # Initializes the Authenticator.
12
+ # @param app [Faraday::Connection] The Faraday connection
13
+ def initialize(app)
14
+ super(app)
15
+ @app = app
16
+ end
17
+
18
+ # Processes the request by adding the JWT to the Authorization header.
19
+ # @param env [Faraday::Env] The Faraday request environment
20
+ def call(env)
21
+ method = env.method.downcase.to_sym
22
+ uri = env.url.to_s
23
+ uri_without_protocol = URI(uri).host
24
+ token = build_jwt("#{method.upcase} #{uri_without_protocol}#{env.url.path}")
25
+ env.request_headers['Authorization'] = "Bearer #{token}"
26
+ @app.call(env)
27
+ end
28
+
29
+ # Builds the JWT for the given API endpoint URI. The JWT is signed with the API key's private key.
30
+ # @param uri [String] The API endpoint URI
31
+ # @return [String] The JWT
32
+ def build_jwt(uri)
33
+ header = {
34
+ typ: 'JWT',
35
+ kid: Coinbase.configuration.api_key_name,
36
+ nonce: SecureRandom.hex(16)
37
+ }
38
+
39
+ claims = {
40
+ sub: Coinbase.configuration.api_key_name,
41
+ iss: 'coinbase-cloud',
42
+ aud: ['cdp_service'],
43
+ nbf: Time.now.to_i,
44
+ exp: Time.now.to_i + 60, # Expiration time: 1 minute from now.
45
+ uris: [uri]
46
+ }
47
+
48
+ private_key = OpenSSL::PKey.read(Coinbase.configuration.api_key_private_key)
49
+ JWT.encode(claims, private_key, 'ES256', header)
50
+ end
51
+ end
52
+ end
@@ -3,7 +3,7 @@
3
3
  require 'bigdecimal'
4
4
 
5
5
  module Coinbase
6
- # A convenience class for printing out crypto asset balances in a human-readable format.
6
+ # A convenience class for printing out Asset balances in a human-readable format.
7
7
  class BalanceMap < Hash
8
8
  # Returns a new BalanceMap object.
9
9
  # @param hash [Map<Symbol, BigDecimal>] The hash to initialize with
@@ -0,0 +1,385 @@
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 AddressesApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Create a new address
23
+ # Create a new address scoped to the wallet.
24
+ # @param wallet_id [String] The ID of the wallet to create the address in.
25
+ # @param [Hash] opts the optional parameters
26
+ # @option opts [CreateAddressRequest] :create_address_request
27
+ # @return [Address]
28
+ def create_address(wallet_id, opts = {})
29
+ data, _status_code, _headers = create_address_with_http_info(wallet_id, opts)
30
+ data
31
+ end
32
+
33
+ # Create a new address
34
+ # Create a new address scoped to the wallet.
35
+ # @param wallet_id [String] The ID of the wallet to create the address in.
36
+ # @param [Hash] opts the optional parameters
37
+ # @option opts [CreateAddressRequest] :create_address_request
38
+ # @return [Array<(Address, Integer, Hash)>] Address data, response status code and response headers
39
+ def create_address_with_http_info(wallet_id, opts = {})
40
+ if @api_client.config.debugging
41
+ @api_client.config.logger.debug 'Calling API: AddressesApi.create_address ...'
42
+ end
43
+ # verify the required parameter 'wallet_id' is set
44
+ if @api_client.config.client_side_validation && wallet_id.nil?
45
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.create_address"
46
+ end
47
+ # resource path
48
+ local_var_path = '/v1/wallets/{wallet_id}/addresses'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s))
49
+
50
+ # query parameters
51
+ query_params = opts[:query_params] || {}
52
+
53
+ # header parameters
54
+ header_params = opts[:header_params] || {}
55
+ # HTTP header 'Accept' (if needed)
56
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
57
+ # HTTP header 'Content-Type'
58
+ content_type = @api_client.select_header_content_type(['application/json'])
59
+ if !content_type.nil?
60
+ header_params['Content-Type'] = content_type
61
+ end
62
+
63
+ # form parameters
64
+ form_params = opts[:form_params] || {}
65
+
66
+ # http body (model)
67
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'create_address_request'])
68
+
69
+ # return_type
70
+ return_type = opts[:debug_return_type] || 'Address'
71
+
72
+ # auth_names
73
+ auth_names = opts[:debug_auth_names] || []
74
+
75
+ new_options = opts.merge(
76
+ :operation => :"AddressesApi.create_address",
77
+ :header_params => header_params,
78
+ :query_params => query_params,
79
+ :form_params => form_params,
80
+ :body => post_body,
81
+ :auth_names => auth_names,
82
+ :return_type => return_type
83
+ )
84
+
85
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
86
+ if @api_client.config.debugging
87
+ @api_client.config.logger.debug "API called: AddressesApi#create_address\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
88
+ end
89
+ return data, status_code, headers
90
+ end
91
+
92
+ # Get address by onchain address
93
+ # Get address
94
+ # @param wallet_id [String] The ID of the wallet the address belongs to.
95
+ # @param address_id [String] The onchain address of the address that is being fetched.
96
+ # @param [Hash] opts the optional parameters
97
+ # @return [Address]
98
+ def get_address(wallet_id, address_id, opts = {})
99
+ data, _status_code, _headers = get_address_with_http_info(wallet_id, address_id, opts)
100
+ data
101
+ end
102
+
103
+ # Get address by onchain address
104
+ # Get address
105
+ # @param wallet_id [String] The ID of the wallet the address belongs to.
106
+ # @param address_id [String] The onchain address of the address that is being fetched.
107
+ # @param [Hash] opts the optional parameters
108
+ # @return [Array<(Address, Integer, Hash)>] Address data, response status code and response headers
109
+ def get_address_with_http_info(wallet_id, address_id, opts = {})
110
+ if @api_client.config.debugging
111
+ @api_client.config.logger.debug 'Calling API: AddressesApi.get_address ...'
112
+ end
113
+ # verify the required parameter 'wallet_id' is set
114
+ if @api_client.config.client_side_validation && wallet_id.nil?
115
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.get_address"
116
+ end
117
+ # verify the required parameter 'address_id' is set
118
+ if @api_client.config.client_side_validation && address_id.nil?
119
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling AddressesApi.get_address"
120
+ end
121
+ # resource path
122
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))
123
+
124
+ # query parameters
125
+ query_params = opts[:query_params] || {}
126
+
127
+ # header parameters
128
+ header_params = opts[:header_params] || {}
129
+ # HTTP header 'Accept' (if needed)
130
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
131
+
132
+ # form parameters
133
+ form_params = opts[:form_params] || {}
134
+
135
+ # http body (model)
136
+ post_body = opts[:debug_body]
137
+
138
+ # return_type
139
+ return_type = opts[:debug_return_type] || 'Address'
140
+
141
+ # auth_names
142
+ auth_names = opts[:debug_auth_names] || []
143
+
144
+ new_options = opts.merge(
145
+ :operation => :"AddressesApi.get_address",
146
+ :header_params => header_params,
147
+ :query_params => query_params,
148
+ :form_params => form_params,
149
+ :body => post_body,
150
+ :auth_names => auth_names,
151
+ :return_type => return_type
152
+ )
153
+
154
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
155
+ if @api_client.config.debugging
156
+ @api_client.config.logger.debug "API called: AddressesApi#get_address\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
157
+ end
158
+ return data, status_code, headers
159
+ end
160
+
161
+ # Get address balance for asset
162
+ # Get address balance
163
+ # @param wallet_id [String] The ID of the wallet to fetch the balance for
164
+ # @param address_id [String] The onchain address of the address that is being fetched.
165
+ # @param asset_id [String] The symbol of the asset to fetch the balance for
166
+ # @param [Hash] opts the optional parameters
167
+ # @return [Balance]
168
+ def get_address_balance(wallet_id, address_id, asset_id, opts = {})
169
+ data, _status_code, _headers = get_address_balance_with_http_info(wallet_id, address_id, asset_id, opts)
170
+ data
171
+ end
172
+
173
+ # Get address balance for asset
174
+ # Get address balance
175
+ # @param wallet_id [String] The ID of the wallet to fetch the balance for
176
+ # @param address_id [String] The onchain address of the address that is being fetched.
177
+ # @param asset_id [String] The symbol of the asset to fetch the balance for
178
+ # @param [Hash] opts the optional parameters
179
+ # @return [Array<(Balance, Integer, Hash)>] Balance data, response status code and response headers
180
+ def get_address_balance_with_http_info(wallet_id, address_id, asset_id, opts = {})
181
+ if @api_client.config.debugging
182
+ @api_client.config.logger.debug 'Calling API: AddressesApi.get_address_balance ...'
183
+ end
184
+ # verify the required parameter 'wallet_id' is set
185
+ if @api_client.config.client_side_validation && wallet_id.nil?
186
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.get_address_balance"
187
+ end
188
+ # verify the required parameter 'address_id' is set
189
+ if @api_client.config.client_side_validation && address_id.nil?
190
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling AddressesApi.get_address_balance"
191
+ end
192
+ # verify the required parameter 'asset_id' is set
193
+ if @api_client.config.client_side_validation && asset_id.nil?
194
+ fail ArgumentError, "Missing the required parameter 'asset_id' when calling AddressesApi.get_address_balance"
195
+ end
196
+ # resource path
197
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/balances/{asset_id}'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'asset_id' + '}', CGI.escape(asset_id.to_s))
198
+
199
+ # query parameters
200
+ query_params = opts[:query_params] || {}
201
+
202
+ # header parameters
203
+ header_params = opts[:header_params] || {}
204
+ # HTTP header 'Accept' (if needed)
205
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
206
+
207
+ # form parameters
208
+ form_params = opts[:form_params] || {}
209
+
210
+ # http body (model)
211
+ post_body = opts[:debug_body]
212
+
213
+ # return_type
214
+ return_type = opts[:debug_return_type] || 'Balance'
215
+
216
+ # auth_names
217
+ auth_names = opts[:debug_auth_names] || []
218
+
219
+ new_options = opts.merge(
220
+ :operation => :"AddressesApi.get_address_balance",
221
+ :header_params => header_params,
222
+ :query_params => query_params,
223
+ :form_params => form_params,
224
+ :body => post_body,
225
+ :auth_names => auth_names,
226
+ :return_type => return_type
227
+ )
228
+
229
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
230
+ if @api_client.config.debugging
231
+ @api_client.config.logger.debug "API called: AddressesApi#get_address_balance\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
232
+ end
233
+ return data, status_code, headers
234
+ end
235
+
236
+ # Get all balances for address
237
+ # Get address balances
238
+ # @param wallet_id [String] The ID of the wallet to fetch the balances for
239
+ # @param address_id [String] The onchain address of the address that is being fetched.
240
+ # @param [Hash] opts the optional parameters
241
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
242
+ # @return [AddressBalanceList]
243
+ def list_address_balances(wallet_id, address_id, opts = {})
244
+ data, _status_code, _headers = list_address_balances_with_http_info(wallet_id, address_id, opts)
245
+ data
246
+ end
247
+
248
+ # Get all balances for address
249
+ # Get address balances
250
+ # @param wallet_id [String] The ID of the wallet to fetch the balances for
251
+ # @param address_id [String] The onchain address of the address that is being fetched.
252
+ # @param [Hash] opts the optional parameters
253
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
254
+ # @return [Array<(AddressBalanceList, Integer, Hash)>] AddressBalanceList data, response status code and response headers
255
+ def list_address_balances_with_http_info(wallet_id, address_id, opts = {})
256
+ if @api_client.config.debugging
257
+ @api_client.config.logger.debug 'Calling API: AddressesApi.list_address_balances ...'
258
+ end
259
+ # verify the required parameter 'wallet_id' is set
260
+ if @api_client.config.client_side_validation && wallet_id.nil?
261
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.list_address_balances"
262
+ end
263
+ # verify the required parameter 'address_id' is set
264
+ if @api_client.config.client_side_validation && address_id.nil?
265
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling AddressesApi.list_address_balances"
266
+ end
267
+ if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
268
+ fail ArgumentError, 'invalid value for "opts[:"page"]" when calling AddressesApi.list_address_balances, the character length must be smaller than or equal to 5000.'
269
+ end
270
+
271
+ # resource path
272
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/balances'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))
273
+
274
+ # query parameters
275
+ query_params = opts[:query_params] || {}
276
+ query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
277
+
278
+ # header parameters
279
+ header_params = opts[:header_params] || {}
280
+ # HTTP header 'Accept' (if needed)
281
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
282
+
283
+ # form parameters
284
+ form_params = opts[:form_params] || {}
285
+
286
+ # http body (model)
287
+ post_body = opts[:debug_body]
288
+
289
+ # return_type
290
+ return_type = opts[:debug_return_type] || 'AddressBalanceList'
291
+
292
+ # auth_names
293
+ auth_names = opts[:debug_auth_names] || []
294
+
295
+ new_options = opts.merge(
296
+ :operation => :"AddressesApi.list_address_balances",
297
+ :header_params => header_params,
298
+ :query_params => query_params,
299
+ :form_params => form_params,
300
+ :body => post_body,
301
+ :auth_names => auth_names,
302
+ :return_type => return_type
303
+ )
304
+
305
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
306
+ if @api_client.config.debugging
307
+ @api_client.config.logger.debug "API called: AddressesApi#list_address_balances\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
308
+ end
309
+ return data, status_code, headers
310
+ end
311
+
312
+ # List addresses in a wallet.
313
+ # List addresses in the wallet.
314
+ # @param wallet_id [String] The ID of the wallet whose addresses to fetch
315
+ # @param [Hash] opts the optional parameters
316
+ # @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
317
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
318
+ # @return [AddressList]
319
+ def list_addresses(wallet_id, opts = {})
320
+ data, _status_code, _headers = list_addresses_with_http_info(wallet_id, opts)
321
+ data
322
+ end
323
+
324
+ # List addresses in a wallet.
325
+ # List addresses in the wallet.
326
+ # @param wallet_id [String] The ID of the wallet whose addresses to fetch
327
+ # @param [Hash] opts the optional parameters
328
+ # @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
329
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
330
+ # @return [Array<(AddressList, Integer, Hash)>] AddressList data, response status code and response headers
331
+ def list_addresses_with_http_info(wallet_id, opts = {})
332
+ if @api_client.config.debugging
333
+ @api_client.config.logger.debug 'Calling API: AddressesApi.list_addresses ...'
334
+ end
335
+ # verify the required parameter 'wallet_id' is set
336
+ if @api_client.config.client_side_validation && wallet_id.nil?
337
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.list_addresses"
338
+ end
339
+ if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
340
+ fail ArgumentError, 'invalid value for "opts[:"page"]" when calling AddressesApi.list_addresses, the character length must be smaller than or equal to 5000.'
341
+ end
342
+
343
+ # resource path
344
+ local_var_path = '/v1/wallets/{wallet_id}/addresses'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s))
345
+
346
+ # query parameters
347
+ query_params = opts[:query_params] || {}
348
+ query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
349
+ query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
350
+
351
+ # header parameters
352
+ header_params = opts[:header_params] || {}
353
+ # HTTP header 'Accept' (if needed)
354
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
355
+
356
+ # form parameters
357
+ form_params = opts[:form_params] || {}
358
+
359
+ # http body (model)
360
+ post_body = opts[:debug_body]
361
+
362
+ # return_type
363
+ return_type = opts[:debug_return_type] || 'AddressList'
364
+
365
+ # auth_names
366
+ auth_names = opts[:debug_auth_names] || []
367
+
368
+ new_options = opts.merge(
369
+ :operation => :"AddressesApi.list_addresses",
370
+ :header_params => header_params,
371
+ :query_params => query_params,
372
+ :form_params => form_params,
373
+ :body => post_body,
374
+ :auth_names => auth_names,
375
+ :return_type => return_type
376
+ )
377
+
378
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
379
+ if @api_client.config.debugging
380
+ @api_client.config.logger.debug "API called: AddressesApi#list_addresses\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
381
+ end
382
+ return data, status_code, headers
383
+ end
384
+ end
385
+ end