coinbase-sdk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c18b015a028c3b795a618318ab244f31d58861f66f67e6d76a7b70ee3b664e2f
4
- data.tar.gz: c82577524824f743ac16624ffc042c2017183d366a5c849d1baa3d2028b85c96
3
+ metadata.gz: cac6b46a83009db9f165f0a2c4396122a2bf4bfa5bf895867b135695c346465e
4
+ data.tar.gz: 0b8cfea979b389b9890a09104b8c7533e334873a789b19d7f704789cdcf6a70d
5
5
  SHA512:
6
- metadata.gz: 92efa9bc82a0d753698bae8de9e60768c696ce6ef5019cbb3eab6ae7bd25d9257f289dd95164a6440a7f25f0cd90b02a0d267b07ea1d82ebe6b0d4cb142fe82f
7
- data.tar.gz: 204120f5e22ec7bfd4b87f0e09bdd8600740106d11a0e7d04264d39f650b8a1154472de209537da510cef03daeb669e6a84c5ee5f212c82d9eda66207f5f8e81
6
+ metadata.gz: bccd3af15fec48789603988eadf3c67ad4ec67e5b3081fd2f06c7877d6ac35c6d2eda16db533ff149cf2f9f38d59ba38527284a0205529c84da6ac781dad8e3a
7
+ data.tar.gz: 072d5372f38da2b9a3eb97a024f4a289ac7ef1906df8cf1da22de0b37c77e18b9a724db7771019fc9c6eb3834720f48010edb869f310dcc114429cb0e0bd1403
@@ -43,7 +43,10 @@ module Coinbase
43
43
  # @return [BalanceMap] The balances of the Address, keyed by asset ID. Ether balances are denominated
44
44
  # in ETH.
45
45
  def list_balances
46
- response = addresses_api.list_address_balances(wallet_id, address_id)
46
+ response = Coinbase.call_api do
47
+ addresses_api.list_address_balances(wallet_id, address_id)
48
+ end
49
+
47
50
  Coinbase.to_balance_map(response)
48
51
  end
49
52
 
@@ -53,7 +56,9 @@ module Coinbase
53
56
  def get_balance(asset_id)
54
57
  normalized_asset_id = normalize_asset_id(asset_id)
55
58
 
56
- response = addresses_api.get_address_balance(wallet_id, address_id, normalized_asset_id.to_s)
59
+ response = Coinbase.call_api do
60
+ addresses_api.get_address_balance(wallet_id, address_id, normalized_asset_id.to_s)
61
+ end
57
62
 
58
63
  return BigDecimal('0') if response.nil?
59
64
 
@@ -106,21 +111,76 @@ module Coinbase
106
111
  destination: destination
107
112
  }
108
113
 
109
- transfer_model = transfers_api.create_transfer(wallet_id, address_id, create_transfer_request)
114
+ transfer_model = Coinbase.call_api do
115
+ transfers_api.create_transfer(wallet_id, address_id, create_transfer_request)
116
+ end
110
117
 
111
118
  transfer = Coinbase::Transfer.new(transfer_model)
112
119
 
113
120
  transaction = transfer.transaction
114
121
  transaction.sign(@key)
115
- Coinbase.configuration.base_sepolia_client.eth_sendRawTransaction("0x#{transaction.hex}")
116
122
 
117
- transfer
123
+ signed_payload = transaction.hex
124
+
125
+ broadcast_transfer_request = {
126
+ signed_payload: signed_payload
127
+ }
128
+
129
+ transfer_model = Coinbase.call_api do
130
+ transfers_api.broadcast_transfer(wallet_id, address_id, transfer.transfer_id, broadcast_transfer_request)
131
+ end
132
+
133
+ Coinbase::Transfer.new(transfer_model)
118
134
  end
119
135
 
120
- # Returns the address as a string.
121
- # @return [String] The address
136
+ # Returns a String representation of the Address.
137
+ # @return [String] a String representation of the Address
122
138
  def to_s
123
- address_id
139
+ "Coinbase::Address{address_id: '#{address_id}', network_id: '#{network_id}', wallet_id: '#{wallet_id}'}"
140
+ end
141
+
142
+ # Same as to_s.
143
+ # @return [String] a String representation of the Address
144
+ def inspect
145
+ to_s
146
+ end
147
+
148
+ # Requests funds for the address from the faucet and returns the faucet transaction.
149
+ # This is only supported on testnet networks.
150
+ # @return [Coinbase::FaucetTransaction] The successful faucet transaction
151
+ # @raise [Coinbase::FaucetLimitReached] If the faucet limit has been reached for the address or user.
152
+ # @raise [Coinbase::Client::ApiError] If an unexpected error occurs while requesting faucet funds.
153
+ def faucet
154
+ Coinbase.call_api do
155
+ Coinbase::FaucetTransaction.new(addresses_api.request_faucet_funds(wallet_id, address_id))
156
+ end
157
+ end
158
+
159
+ # Exports the Address's private key to a hex string.
160
+ # @return [String] The Address's private key as a hex String
161
+ def export
162
+ @key.private_hex
163
+ end
164
+
165
+ # Lists the IDs of all Transfers associated with the given Wallet and Address.
166
+ # @return [Array<String>] The IDs of all Transfers belonging to the Wallet and Address
167
+ def list_transfer_ids
168
+ transfer_ids = []
169
+ page = nil
170
+
171
+ loop do
172
+ response = Coinbase.call_api do
173
+ transfers_api.list_transfers(wallet_id, address_id, { limit: 100, page: page })
174
+ end
175
+
176
+ transfer_ids.concat(response.data.map(&:transfer_id)) if response.data
177
+
178
+ break unless response.has_more
179
+
180
+ page = response.next_page
181
+ end
182
+
183
+ transfer_ids
124
184
  end
125
185
 
126
186
  private
@@ -139,6 +199,8 @@ module Coinbase
139
199
  big_amount * Coinbase::WEI_PER_GWEI
140
200
  when :usdc
141
201
  big_amount * Coinbase::ATOMIC_UNITS_PER_USDC
202
+ when :weth
203
+ big_amount * Coinbase::WEI_PER_ETHER
142
204
  else
143
205
  big_amount
144
206
  end
@@ -42,7 +42,7 @@ module Coinbase
42
42
  result[asset_id] = str
43
43
  end
44
44
 
45
- result
45
+ result.to_s
46
46
  end
47
47
  end
48
48
  end
@@ -381,5 +381,74 @@ module Coinbase::Client
381
381
  end
382
382
  return data, status_code, headers
383
383
  end
384
+
385
+ # Request faucet funds for onchain address.
386
+ # Request faucet funds to be sent to onchain address.
387
+ # @param wallet_id [String] The ID of the wallet the address belongs to.
388
+ # @param address_id [String] The onchain address of the address that is being fetched.
389
+ # @param [Hash] opts the optional parameters
390
+ # @return [FaucetTransaction]
391
+ def request_faucet_funds(wallet_id, address_id, opts = {})
392
+ data, _status_code, _headers = request_faucet_funds_with_http_info(wallet_id, address_id, opts)
393
+ data
394
+ end
395
+
396
+ # Request faucet funds for onchain address.
397
+ # Request faucet funds to be sent to onchain address.
398
+ # @param wallet_id [String] The ID of the wallet the address belongs to.
399
+ # @param address_id [String] The onchain address of the address that is being fetched.
400
+ # @param [Hash] opts the optional parameters
401
+ # @return [Array<(FaucetTransaction, Integer, Hash)>] FaucetTransaction data, response status code and response headers
402
+ def request_faucet_funds_with_http_info(wallet_id, address_id, opts = {})
403
+ if @api_client.config.debugging
404
+ @api_client.config.logger.debug 'Calling API: AddressesApi.request_faucet_funds ...'
405
+ end
406
+ # verify the required parameter 'wallet_id' is set
407
+ if @api_client.config.client_side_validation && wallet_id.nil?
408
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling AddressesApi.request_faucet_funds"
409
+ end
410
+ # verify the required parameter 'address_id' is set
411
+ if @api_client.config.client_side_validation && address_id.nil?
412
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling AddressesApi.request_faucet_funds"
413
+ end
414
+ # resource path
415
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/faucet'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))
416
+
417
+ # query parameters
418
+ query_params = opts[:query_params] || {}
419
+
420
+ # header parameters
421
+ header_params = opts[:header_params] || {}
422
+ # HTTP header 'Accept' (if needed)
423
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
424
+
425
+ # form parameters
426
+ form_params = opts[:form_params] || {}
427
+
428
+ # http body (model)
429
+ post_body = opts[:debug_body]
430
+
431
+ # return_type
432
+ return_type = opts[:debug_return_type] || 'FaucetTransaction'
433
+
434
+ # auth_names
435
+ auth_names = opts[:debug_auth_names] || []
436
+
437
+ new_options = opts.merge(
438
+ :operation => :"AddressesApi.request_faucet_funds",
439
+ :header_params => header_params,
440
+ :query_params => query_params,
441
+ :form_params => form_params,
442
+ :body => post_body,
443
+ :auth_names => auth_names,
444
+ :return_type => return_type
445
+ )
446
+
447
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
448
+ if @api_client.config.debugging
449
+ @api_client.config.logger.debug "API called: AddressesApi#request_faucet_funds\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
450
+ end
451
+ return data, status_code, headers
452
+ end
384
453
  end
385
454
  end
@@ -19,6 +19,92 @@ module Coinbase::Client
19
19
  def initialize(api_client = ApiClient.default)
20
20
  @api_client = api_client
21
21
  end
22
+ # Broadcast a transfer
23
+ # Broadcast a transfer
24
+ # @param wallet_id [String] The ID of the wallet the address belongs to
25
+ # @param address_id [String] The ID of the address the transfer belongs to
26
+ # @param transfer_id [String] The ID of the transfer to broadcast
27
+ # @param broadcast_transfer_request [BroadcastTransferRequest]
28
+ # @param [Hash] opts the optional parameters
29
+ # @return [Transfer]
30
+ def broadcast_transfer(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts = {})
31
+ data, _status_code, _headers = broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts)
32
+ data
33
+ end
34
+
35
+ # Broadcast a transfer
36
+ # Broadcast a transfer
37
+ # @param wallet_id [String] The ID of the wallet the address belongs to
38
+ # @param address_id [String] The ID of the address the transfer belongs to
39
+ # @param transfer_id [String] The ID of the transfer to broadcast
40
+ # @param broadcast_transfer_request [BroadcastTransferRequest]
41
+ # @param [Hash] opts the optional parameters
42
+ # @return [Array<(Transfer, Integer, Hash)>] Transfer data, response status code and response headers
43
+ def broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts = {})
44
+ if @api_client.config.debugging
45
+ @api_client.config.logger.debug 'Calling API: TransfersApi.broadcast_transfer ...'
46
+ end
47
+ # verify the required parameter 'wallet_id' is set
48
+ if @api_client.config.client_side_validation && wallet_id.nil?
49
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling TransfersApi.broadcast_transfer"
50
+ end
51
+ # verify the required parameter 'address_id' is set
52
+ if @api_client.config.client_side_validation && address_id.nil?
53
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling TransfersApi.broadcast_transfer"
54
+ end
55
+ # verify the required parameter 'transfer_id' is set
56
+ if @api_client.config.client_side_validation && transfer_id.nil?
57
+ fail ArgumentError, "Missing the required parameter 'transfer_id' when calling TransfersApi.broadcast_transfer"
58
+ end
59
+ # verify the required parameter 'broadcast_transfer_request' is set
60
+ if @api_client.config.client_side_validation && broadcast_transfer_request.nil?
61
+ fail ArgumentError, "Missing the required parameter 'broadcast_transfer_request' when calling TransfersApi.broadcast_transfer"
62
+ end
63
+ # resource path
64
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/transfers/{transfer_id}/broadcast'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'transfer_id' + '}', CGI.escape(transfer_id.to_s))
65
+
66
+ # query parameters
67
+ query_params = opts[:query_params] || {}
68
+
69
+ # header parameters
70
+ header_params = opts[:header_params] || {}
71
+ # HTTP header 'Accept' (if needed)
72
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
73
+ # HTTP header 'Content-Type'
74
+ content_type = @api_client.select_header_content_type(['application/json'])
75
+ if !content_type.nil?
76
+ header_params['Content-Type'] = content_type
77
+ end
78
+
79
+ # form parameters
80
+ form_params = opts[:form_params] || {}
81
+
82
+ # http body (model)
83
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(broadcast_transfer_request)
84
+
85
+ # return_type
86
+ return_type = opts[:debug_return_type] || 'Transfer'
87
+
88
+ # auth_names
89
+ auth_names = opts[:debug_auth_names] || []
90
+
91
+ new_options = opts.merge(
92
+ :operation => :"TransfersApi.broadcast_transfer",
93
+ :header_params => header_params,
94
+ :query_params => query_params,
95
+ :form_params => form_params,
96
+ :body => post_body,
97
+ :auth_names => auth_names,
98
+ :return_type => return_type
99
+ )
100
+
101
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
102
+ if @api_client.config.debugging
103
+ @api_client.config.logger.debug "API called: TransfersApi#broadcast_transfer\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
104
+ end
105
+ return data, status_code, headers
106
+ end
107
+
22
108
  # Create a new transfer for an address
23
109
  # Create a new transfer
24
110
  # @param wallet_id [String] The ID of the wallet the source address belongs to
@@ -0,0 +1,222 @@
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 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ class BroadcastTransferRequest
18
+ # The hex-encoded signed payload of the transfer
19
+ attr_accessor :signed_payload
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'signed_payload' => :'signed_payload'
25
+ }
26
+ end
27
+
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'signed_payload' => :'String'
37
+ }
38
+ end
39
+
40
+ # List of attributes with nullable: true
41
+ def self.openapi_nullable
42
+ Set.new([
43
+ ])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::BroadcastTransferRequest` initialize method"
51
+ end
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::BroadcastTransferRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
60
+
61
+ if attributes.key?(:'signed_payload')
62
+ self.signed_payload = attributes[:'signed_payload']
63
+ else
64
+ self.signed_payload = nil
65
+ end
66
+ end
67
+
68
+ # Show invalid properties with the reasons. Usually used together with valid?
69
+ # @return Array for valid properties with the reasons
70
+ def list_invalid_properties
71
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
72
+ invalid_properties = Array.new
73
+ if @signed_payload.nil?
74
+ invalid_properties.push('invalid value for "signed_payload", signed_payload cannot be nil.')
75
+ end
76
+
77
+ invalid_properties
78
+ end
79
+
80
+ # Check to see if the all the properties in the model are valid
81
+ # @return true if the model is valid
82
+ def valid?
83
+ warn '[DEPRECATED] the `valid?` method is obsolete'
84
+ return false if @signed_payload.nil?
85
+ true
86
+ end
87
+
88
+ # Checks equality by comparing each attribute.
89
+ # @param [Object] Object to be compared
90
+ def ==(o)
91
+ return true if self.equal?(o)
92
+ self.class == o.class &&
93
+ signed_payload == o.signed_payload
94
+ end
95
+
96
+ # @see the `==` method
97
+ # @param [Object] Object to be compared
98
+ def eql?(o)
99
+ self == o
100
+ end
101
+
102
+ # Calculates hash code according to all attributes.
103
+ # @return [Integer] Hash code
104
+ def hash
105
+ [signed_payload].hash
106
+ end
107
+
108
+ # Builds the object from hash
109
+ # @param [Hash] attributes Model attributes in the form of hash
110
+ # @return [Object] Returns the model itself
111
+ def self.build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ attributes = attributes.transform_keys(&:to_sym)
114
+ transformed_hash = {}
115
+ openapi_types.each_pair do |key, type|
116
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
117
+ transformed_hash["#{key}"] = nil
118
+ elsif type =~ /\AArray<(.*)>/i
119
+ # check to ensure the input is an array given that the attribute
120
+ # is documented as an array but the input is not
121
+ if attributes[attribute_map[key]].is_a?(Array)
122
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
123
+ end
124
+ elsif !attributes[attribute_map[key]].nil?
125
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
126
+ end
127
+ end
128
+ new(transformed_hash)
129
+ end
130
+
131
+ # Deserializes the data based on type
132
+ # @param string type Data type
133
+ # @param string value Value to be deserialized
134
+ # @return [Object] Deserialized data
135
+ def self._deserialize(type, value)
136
+ case type.to_sym
137
+ when :Time
138
+ Time.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :Boolean
148
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
+ true
150
+ else
151
+ false
152
+ end
153
+ when :Object
154
+ # generic object (usually a Hash), return directly
155
+ value
156
+ when /\AArray<(?<inner_type>.+)>\z/
157
+ inner_type = Regexp.last_match[:inner_type]
158
+ value.map { |v| _deserialize(inner_type, v) }
159
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
160
+ k_type = Regexp.last_match[:k_type]
161
+ v_type = Regexp.last_match[:v_type]
162
+ {}.tap do |hash|
163
+ value.each do |k, v|
164
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
165
+ end
166
+ end
167
+ else # model
168
+ # models (e.g. Pet) or oneOf
169
+ klass = Coinbase::Client.const_get(type)
170
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
171
+ end
172
+ end
173
+
174
+ # Returns the string representation of the object
175
+ # @return [String] String presentation of the object
176
+ def to_s
177
+ to_hash.to_s
178
+ end
179
+
180
+ # to_body is an alias to to_hash (backward compatibility)
181
+ # @return [Hash] Returns the object in the form of hash
182
+ def to_body
183
+ to_hash
184
+ end
185
+
186
+ # Returns the object in the form of hash
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_hash
189
+ hash = {}
190
+ self.class.attribute_map.each_pair do |attr, param|
191
+ value = self.send(attr)
192
+ if value.nil?
193
+ is_nullable = self.class.openapi_nullable.include?(attr)
194
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
195
+ end
196
+
197
+ hash[param] = _to_hash(value)
198
+ end
199
+ hash
200
+ end
201
+
202
+ # Outputs non-array value in the form of hash
203
+ # For object, use to_hash. Otherwise, just return the value
204
+ # @param [Object] value Any valid value
205
+ # @return [Hash] Returns the value in the form of hash
206
+ def _to_hash(value)
207
+ if value.is_a?(Array)
208
+ value.compact.map { |v| _to_hash(v) }
209
+ elsif value.is_a?(Hash)
210
+ {}.tap do |hash|
211
+ value.each { |k, v| hash[k] = _to_hash(v) }
212
+ end
213
+ elsif value.respond_to? :to_hash
214
+ value.to_hash
215
+ else
216
+ value
217
+ end
218
+ end
219
+
220
+ end
221
+
222
+ end