coinbase-sdk 0.0.13 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/external_address.rb +3 -166
  3. data/lib/coinbase/address/wallet_address.rb +51 -4
  4. data/lib/coinbase/address.rb +164 -0
  5. data/lib/coinbase/client/api/assets_api.rb +2 -2
  6. data/lib/coinbase/client/api/contract_events_api.rb +121 -0
  7. data/lib/coinbase/client/api/external_addresses_api.rb +85 -0
  8. data/lib/coinbase/client/api/networks_api.rb +85 -0
  9. data/lib/coinbase/client/api/stake_api.rb +361 -0
  10. data/lib/coinbase/client/api/webhooks_api.rb +286 -0
  11. data/lib/coinbase/client/models/address_historical_balance_list.rb +258 -0
  12. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +239 -0
  13. data/lib/coinbase/client/models/contract_event.rb +336 -0
  14. data/lib/coinbase/client/models/contract_event_list.rb +259 -0
  15. data/lib/coinbase/client/models/create_staking_operation_request.rb +274 -0
  16. data/lib/coinbase/client/models/create_transfer_request.rb +14 -4
  17. data/lib/coinbase/client/models/create_webhook_request.rb +282 -0
  18. data/lib/coinbase/client/models/ethereum_validator.rb +374 -0
  19. data/lib/coinbase/client/models/feature_set.rb +307 -0
  20. data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +258 -0
  21. data/lib/coinbase/client/models/get_validator200_response.rb +221 -0
  22. data/lib/coinbase/client/models/get_validator200_response_validator.rb +214 -0
  23. data/lib/coinbase/client/models/historical_balance.rb +273 -0
  24. data/lib/coinbase/client/models/network.rb +355 -0
  25. data/lib/coinbase/client/models/network_identifier.rb +44 -0
  26. data/lib/coinbase/client/models/sponsored_send.rb +338 -0
  27. data/lib/coinbase/client/models/staking_balance.rb +289 -0
  28. data/lib/coinbase/client/models/staking_context_context.rb +222 -74
  29. data/lib/coinbase/client/models/staking_operation.rb +15 -5
  30. data/lib/coinbase/client/models/staking_reward.rb +22 -6
  31. data/lib/coinbase/client/models/staking_reward_format.rb +2 -1
  32. data/lib/coinbase/client/models/staking_reward_usd_value.rb +257 -0
  33. data/lib/coinbase/client/models/transaction.rb +2 -2
  34. data/lib/coinbase/client/models/transaction_type.rb +2 -1
  35. data/lib/coinbase/client/models/transfer.rb +29 -24
  36. data/lib/coinbase/client/models/update_webhook_request.rb +289 -0
  37. data/lib/coinbase/client/models/validator_list_data.rb +216 -0
  38. data/lib/coinbase/client/models/wallet.rb +13 -16
  39. data/lib/coinbase/client/models/webhook.rb +299 -0
  40. data/lib/coinbase/client/models/webhook_event_filter.rb +236 -0
  41. data/lib/coinbase/client/models/webhook_event_type.rb +42 -0
  42. data/lib/coinbase/client/models/webhook_list.rb +244 -0
  43. data/lib/coinbase/client.rb +22 -3
  44. data/lib/coinbase/errors.rb +7 -0
  45. data/lib/coinbase/historical_balance.rb +53 -0
  46. data/lib/coinbase/middleware.rb +12 -0
  47. data/lib/coinbase/server_signer.rb +14 -3
  48. data/lib/coinbase/sponsored_send.rb +110 -0
  49. data/lib/coinbase/staking_balance.rb +86 -0
  50. data/lib/coinbase/staking_operation.rb +106 -5
  51. data/lib/coinbase/staking_reward.rb +18 -0
  52. data/lib/coinbase/trade.rb +1 -1
  53. data/lib/coinbase/transaction.rb +7 -3
  54. data/lib/coinbase/transfer.rb +56 -29
  55. data/lib/coinbase/wallet/data.rb +31 -0
  56. data/lib/coinbase/wallet.rb +91 -46
  57. data/lib/coinbase.rb +17 -4
  58. metadata +74 -2
@@ -14,92 +14,240 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module Coinbase::Client
17
- module StakingContextContext
18
- class << self
19
- # List of class defined in oneOf (OpenAPI v3)
20
- def openapi_one_of
21
- [
22
- :'NativeEthStakingContext',
23
- :'PartialEthStakingContext'
24
- ]
17
+ class StakingContextContext
18
+ attr_accessor :stakeable_balance
19
+
20
+ attr_accessor :unstakeable_balance
21
+
22
+ attr_accessor :claimable_balance
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'stakeable_balance' => :'stakeable_balance',
28
+ :'unstakeable_balance' => :'unstakeable_balance',
29
+ :'claimable_balance' => :'claimable_balance'
30
+ }
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'stakeable_balance' => :'Balance',
42
+ :'unstakeable_balance' => :'Balance',
43
+ :'claimable_balance' => :'Balance'
44
+ }
45
+ end
46
+
47
+ # List of attributes with nullable: true
48
+ def self.openapi_nullable
49
+ Set.new([
50
+ ])
51
+ end
52
+
53
+ # Initializes the object
54
+ # @param [Hash] attributes Model attributes in the form of hash
55
+ def initialize(attributes = {})
56
+ if (!attributes.is_a?(Hash))
57
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::StakingContextContext` initialize method"
25
58
  end
26
59
 
27
- # Builds the object
28
- # @param [Mixed] Data to be matched against the list of oneOf items
29
- # @return [Object] Returns the model or the data itself
30
- def build(data)
31
- # Go through the list of oneOf items and attempt to identify the appropriate one.
32
- # Note:
33
- # - We do not attempt to check whether exactly one item matches.
34
- # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
35
- # due to the way the deserialization is made in the base_object template (it just casts without verifying).
36
- # - TODO: scalar values are de facto behaving as if they were nullable.
37
- # - TODO: logging when debugging is set.
38
- openapi_one_of.each do |klass|
39
- begin
40
- next if klass == :AnyType # "nullable: true"
41
- typed_data = find_and_cast_into_type(klass, data)
42
- return typed_data if typed_data
43
- rescue # rescue all errors so we keep iterating even if the current item lookup raises
44
- end
60
+ # check to see if the attribute exists and convert string to symbol for hash key
61
+ attributes = attributes.each_with_object({}) { |(k, v), h|
62
+ if (!self.class.attribute_map.key?(k.to_sym))
63
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::StakingContextContext`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
45
64
  end
65
+ h[k.to_sym] = v
66
+ }
46
67
 
47
- openapi_one_of.include?(:AnyType) ? data : nil
68
+ if attributes.key?(:'stakeable_balance')
69
+ self.stakeable_balance = attributes[:'stakeable_balance']
70
+ else
71
+ self.stakeable_balance = nil
48
72
  end
49
73
 
50
- private
51
-
52
- SchemaMismatchError = Class.new(StandardError)
53
-
54
- # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
55
- def find_and_cast_into_type(klass, data)
56
- return if data.nil?
57
-
58
- case klass.to_s
59
- when 'Boolean'
60
- return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
61
- when 'Float'
62
- return data if data.instance_of?(Float)
63
- when 'Integer'
64
- return data if data.instance_of?(Integer)
65
- when 'Time'
66
- return Time.parse(data)
67
- when 'Date'
68
- return Date.parse(data)
69
- when 'String'
70
- return data if data.instance_of?(String)
71
- when 'Object' # "type: object"
72
- return data if data.instance_of?(Hash)
73
- when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
74
- if data.instance_of?(Array)
75
- sub_type = Regexp.last_match[:sub_type]
76
- return data.map { |item| find_and_cast_into_type(sub_type, item) }
77
- end
78
- when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
79
- if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
80
- sub_type = Regexp.last_match[:sub_type]
81
- return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
74
+ if attributes.key?(:'unstakeable_balance')
75
+ self.unstakeable_balance = attributes[:'unstakeable_balance']
76
+ else
77
+ self.unstakeable_balance = nil
78
+ end
79
+
80
+ if attributes.key?(:'claimable_balance')
81
+ self.claimable_balance = attributes[:'claimable_balance']
82
+ else
83
+ self.claimable_balance = nil
84
+ end
85
+ end
86
+
87
+ # Show invalid properties with the reasons. Usually used together with valid?
88
+ # @return Array for valid properties with the reasons
89
+ def list_invalid_properties
90
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
91
+ invalid_properties = Array.new
92
+ if @stakeable_balance.nil?
93
+ invalid_properties.push('invalid value for "stakeable_balance", stakeable_balance cannot be nil.')
94
+ end
95
+
96
+ if @unstakeable_balance.nil?
97
+ invalid_properties.push('invalid value for "unstakeable_balance", unstakeable_balance cannot be nil.')
98
+ end
99
+
100
+ if @claimable_balance.nil?
101
+ invalid_properties.push('invalid value for "claimable_balance", claimable_balance cannot be nil.')
102
+ end
103
+
104
+ invalid_properties
105
+ end
106
+
107
+ # Check to see if the all the properties in the model are valid
108
+ # @return true if the model is valid
109
+ def valid?
110
+ warn '[DEPRECATED] the `valid?` method is obsolete'
111
+ return false if @stakeable_balance.nil?
112
+ return false if @unstakeable_balance.nil?
113
+ return false if @claimable_balance.nil?
114
+ true
115
+ end
116
+
117
+ # Checks equality by comparing each attribute.
118
+ # @param [Object] Object to be compared
119
+ def ==(o)
120
+ return true if self.equal?(o)
121
+ self.class == o.class &&
122
+ stakeable_balance == o.stakeable_balance &&
123
+ unstakeable_balance == o.unstakeable_balance &&
124
+ claimable_balance == o.claimable_balance
125
+ end
126
+
127
+ # @see the `==` method
128
+ # @param [Object] Object to be compared
129
+ def eql?(o)
130
+ self == o
131
+ end
132
+
133
+ # Calculates hash code according to all attributes.
134
+ # @return [Integer] Hash code
135
+ def hash
136
+ [stakeable_balance, unstakeable_balance, claimable_balance].hash
137
+ end
138
+
139
+ # Builds the object from hash
140
+ # @param [Hash] attributes Model attributes in the form of hash
141
+ # @return [Object] Returns the model itself
142
+ def self.build_from_hash(attributes)
143
+ return nil unless attributes.is_a?(Hash)
144
+ attributes = attributes.transform_keys(&:to_sym)
145
+ transformed_hash = {}
146
+ openapi_types.each_pair do |key, type|
147
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
148
+ transformed_hash["#{key}"] = nil
149
+ elsif type =~ /\AArray<(.*)>/i
150
+ # check to ensure the input is an array given that the attribute
151
+ # is documented as an array but the input is not
152
+ if attributes[attribute_map[key]].is_a?(Array)
153
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
82
154
  end
83
- else # model
84
- const = Coinbase::Client.const_get(klass)
85
- if const
86
- if const.respond_to?(:openapi_one_of) # nested oneOf model
87
- model = const.build(data)
88
- return model if model
89
- else
90
- # raise if data contains keys that are not known to the model
91
- raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
92
- model = const.build_from_hash(data)
93
- return model if model
94
- end
155
+ elsif !attributes[attribute_map[key]].nil?
156
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
157
+ end
158
+ end
159
+ new(transformed_hash)
160
+ end
161
+
162
+ # Deserializes the data based on type
163
+ # @param string type Data type
164
+ # @param string value Value to be deserialized
165
+ # @return [Object] Deserialized data
166
+ def self._deserialize(type, value)
167
+ case type.to_sym
168
+ when :Time
169
+ Time.parse(value)
170
+ when :Date
171
+ Date.parse(value)
172
+ when :String
173
+ value.to_s
174
+ when :Integer
175
+ value.to_i
176
+ when :Float
177
+ value.to_f
178
+ when :Boolean
179
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
180
+ true
181
+ else
182
+ false
183
+ end
184
+ when :Object
185
+ # generic object (usually a Hash), return directly
186
+ value
187
+ when /\AArray<(?<inner_type>.+)>\z/
188
+ inner_type = Regexp.last_match[:inner_type]
189
+ value.map { |v| _deserialize(inner_type, v) }
190
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
191
+ k_type = Regexp.last_match[:k_type]
192
+ v_type = Regexp.last_match[:v_type]
193
+ {}.tap do |hash|
194
+ value.each do |k, v|
195
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
95
196
  end
96
197
  end
198
+ else # model
199
+ # models (e.g. Pet) or oneOf
200
+ klass = Coinbase::Client.const_get(type)
201
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
202
+ end
203
+ end
204
+
205
+ # Returns the string representation of the object
206
+ # @return [String] String presentation of the object
207
+ def to_s
208
+ to_hash.to_s
209
+ end
97
210
 
98
- raise # if no match by now, raise
99
- rescue
100
- raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
211
+ # to_body is an alias to to_hash (backward compatibility)
212
+ # @return [Hash] Returns the object in the form of hash
213
+ def to_body
214
+ to_hash
215
+ end
216
+
217
+ # Returns the object in the form of hash
218
+ # @return [Hash] Returns the object in the form of hash
219
+ def to_hash
220
+ hash = {}
221
+ self.class.attribute_map.each_pair do |attr, param|
222
+ value = self.send(attr)
223
+ if value.nil?
224
+ is_nullable = self.class.openapi_nullable.include?(attr)
225
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
226
+ end
227
+
228
+ hash[param] = _to_hash(value)
229
+ end
230
+ hash
231
+ end
232
+
233
+ # Outputs non-array value in the form of hash
234
+ # For object, use to_hash. Otherwise, just return the value
235
+ # @param [Object] value Any valid value
236
+ # @return [Hash] Returns the value in the form of hash
237
+ def _to_hash(value)
238
+ if value.is_a?(Array)
239
+ value.compact.map { |v| _to_hash(v) }
240
+ elsif value.is_a?(Hash)
241
+ {}.tap do |hash|
242
+ value.each { |k, v| hash[k] = _to_hash(v) }
243
+ end
244
+ elsif value.respond_to? :to_hash
245
+ value.to_hash
246
+ else
247
+ value
101
248
  end
102
249
  end
250
+
103
251
  end
104
252
 
105
253
  end
@@ -19,16 +19,19 @@ module Coinbase::Client
19
19
  # The unique ID of the staking operation.
20
20
  attr_accessor :id
21
21
 
22
+ # The ID of the wallet that owns the address.
23
+ attr_accessor :wallet_id
24
+
22
25
  # The ID of the blockchain network.
23
26
  attr_accessor :network_id
24
27
 
25
28
  # The onchain address orchestrating the staking operation.
26
29
  attr_accessor :address_id
27
30
 
28
- # The status of the staking operation
31
+ # The status of the staking operation.
29
32
  attr_accessor :status
30
33
 
31
- # The transaction(s) that will execute the staking operation onchain
34
+ # The transaction(s) that will execute the staking operation onchain.
32
35
  attr_accessor :transactions
33
36
 
34
37
  attr_accessor :metadata
@@ -59,6 +62,7 @@ module Coinbase::Client
59
62
  def self.attribute_map
60
63
  {
61
64
  :'id' => :'id',
65
+ :'wallet_id' => :'wallet_id',
62
66
  :'network_id' => :'network_id',
63
67
  :'address_id' => :'address_id',
64
68
  :'status' => :'status',
@@ -76,6 +80,7 @@ module Coinbase::Client
76
80
  def self.openapi_types
77
81
  {
78
82
  :'id' => :'String',
83
+ :'wallet_id' => :'String',
79
84
  :'network_id' => :'String',
80
85
  :'address_id' => :'String',
81
86
  :'status' => :'String',
@@ -111,6 +116,10 @@ module Coinbase::Client
111
116
  self.id = nil
112
117
  end
113
118
 
119
+ if attributes.key?(:'wallet_id')
120
+ self.wallet_id = attributes[:'wallet_id']
121
+ end
122
+
114
123
  if attributes.key?(:'network_id')
115
124
  self.network_id = attributes[:'network_id']
116
125
  else
@@ -178,7 +187,7 @@ module Coinbase::Client
178
187
  return false if @network_id.nil?
179
188
  return false if @address_id.nil?
180
189
  return false if @status.nil?
181
- status_validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed"])
190
+ status_validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed", "unspecified", "unknown_default_open_api"])
182
191
  return false unless status_validator.valid?(@status)
183
192
  return false if @transactions.nil?
184
193
  true
@@ -187,7 +196,7 @@ module Coinbase::Client
187
196
  # Custom attribute writer method checking allowed values (enum).
188
197
  # @param [Object] status Object to be assigned
189
198
  def status=(status)
190
- validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed"])
199
+ validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed", "unspecified", "unknown_default_open_api"])
191
200
  unless validator.valid?(status)
192
201
  fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
193
202
  end
@@ -200,6 +209,7 @@ module Coinbase::Client
200
209
  return true if self.equal?(o)
201
210
  self.class == o.class &&
202
211
  id == o.id &&
212
+ wallet_id == o.wallet_id &&
203
213
  network_id == o.network_id &&
204
214
  address_id == o.address_id &&
205
215
  status == o.status &&
@@ -216,7 +226,7 @@ module Coinbase::Client
216
226
  # Calculates hash code according to all attributes.
217
227
  # @return [Integer] Hash code
218
228
  def hash
219
- [id, network_id, address_id, status, transactions, metadata].hash
229
+ [id, wallet_id, network_id, address_id, status, transactions, metadata].hash
220
230
  end
221
231
 
222
232
  # Builds the object from hash
@@ -30,6 +30,8 @@ module Coinbase::Client
30
30
 
31
31
  attr_accessor :format
32
32
 
33
+ attr_accessor :usd_value
34
+
33
35
  class EnumAttributeValidator
34
36
  attr_reader :datatype
35
37
  attr_reader :allowable_values
@@ -59,7 +61,8 @@ module Coinbase::Client
59
61
  :'date' => :'date',
60
62
  :'amount' => :'amount',
61
63
  :'state' => :'state',
62
- :'format' => :'format'
64
+ :'format' => :'format',
65
+ :'usd_value' => :'usd_value'
63
66
  }
64
67
  end
65
68
 
@@ -75,7 +78,8 @@ module Coinbase::Client
75
78
  :'date' => :'Date',
76
79
  :'amount' => :'String',
77
80
  :'state' => :'String',
78
- :'format' => :'StakingRewardFormat'
81
+ :'format' => :'StakingRewardFormat',
82
+ :'usd_value' => :'StakingRewardUSDValue'
79
83
  }
80
84
  end
81
85
 
@@ -129,6 +133,12 @@ module Coinbase::Client
129
133
  else
130
134
  self.format = 'usd'
131
135
  end
136
+
137
+ if attributes.key?(:'usd_value')
138
+ self.usd_value = attributes[:'usd_value']
139
+ else
140
+ self.usd_value = nil
141
+ end
132
142
  end
133
143
 
134
144
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -156,6 +166,10 @@ module Coinbase::Client
156
166
  invalid_properties.push('invalid value for "format", format cannot be nil.')
157
167
  end
158
168
 
169
+ if @usd_value.nil?
170
+ invalid_properties.push('invalid value for "usd_value", usd_value cannot be nil.')
171
+ end
172
+
159
173
  invalid_properties
160
174
  end
161
175
 
@@ -167,16 +181,17 @@ module Coinbase::Client
167
181
  return false if @date.nil?
168
182
  return false if @amount.nil?
169
183
  return false if @state.nil?
170
- state_validator = EnumAttributeValidator.new('String', ["pending", "distributed"])
184
+ state_validator = EnumAttributeValidator.new('String', ["pending", "distributed", "unknown_default_open_api"])
171
185
  return false unless state_validator.valid?(@state)
172
186
  return false if @format.nil?
187
+ return false if @usd_value.nil?
173
188
  true
174
189
  end
175
190
 
176
191
  # Custom attribute writer method checking allowed values (enum).
177
192
  # @param [Object] state Object to be assigned
178
193
  def state=(state)
179
- validator = EnumAttributeValidator.new('String', ["pending", "distributed"])
194
+ validator = EnumAttributeValidator.new('String', ["pending", "distributed", "unknown_default_open_api"])
180
195
  unless validator.valid?(state)
181
196
  fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}."
182
197
  end
@@ -192,7 +207,8 @@ module Coinbase::Client
192
207
  date == o.date &&
193
208
  amount == o.amount &&
194
209
  state == o.state &&
195
- format == o.format
210
+ format == o.format &&
211
+ usd_value == o.usd_value
196
212
  end
197
213
 
198
214
  # @see the `==` method
@@ -204,7 +220,7 @@ module Coinbase::Client
204
220
  # Calculates hash code according to all attributes.
205
221
  # @return [Integer] Hash code
206
222
  def hash
207
- [address_id, date, amount, state, format].hash
223
+ [address_id, date, amount, state, format, usd_value].hash
208
224
  end
209
225
 
210
226
  # Builds the object from hash
@@ -17,9 +17,10 @@ module Coinbase::Client
17
17
  class StakingRewardFormat
18
18
  USD = "usd".freeze
19
19
  NATIVE = "native".freeze
20
+ UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze
20
21
 
21
22
  def self.all_vars
22
- @all_vars ||= [USD, NATIVE].freeze
23
+ @all_vars ||= [USD, NATIVE, UNKNOWN_DEFAULT_OPEN_API].freeze
23
24
  end
24
25
 
25
26
  # Builds the enum from string