coinbase-sdk 0.0.9 → 0.0.10

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.
@@ -0,0 +1,257 @@
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.6.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ # Signed voluntary exit message metadata to be provided to beacon chain to exit a validator.
18
+ class SignedVoluntaryExitMessageMetadata
19
+ # The public key of the validator associated with the exit message.
20
+ attr_accessor :validator_pub_key
21
+
22
+ # The current fork version of the Ethereum beacon chain.
23
+ attr_accessor :fork
24
+
25
+ # A base64 encoded version of a json string representing a voluntary exit message.
26
+ attr_accessor :signed_voluntary_exit
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'validator_pub_key' => :'validator_pub_key',
32
+ :'fork' => :'fork',
33
+ :'signed_voluntary_exit' => :'signed_voluntary_exit'
34
+ }
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :'validator_pub_key' => :'String',
46
+ :'fork' => :'String',
47
+ :'signed_voluntary_exit' => :'String'
48
+ }
49
+ end
50
+
51
+ # List of attributes with nullable: true
52
+ def self.openapi_nullable
53
+ Set.new([
54
+ ])
55
+ end
56
+
57
+ # Initializes the object
58
+ # @param [Hash] attributes Model attributes in the form of hash
59
+ def initialize(attributes = {})
60
+ if (!attributes.is_a?(Hash))
61
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::SignedVoluntaryExitMessageMetadata` initialize method"
62
+ end
63
+
64
+ # check to see if the attribute exists and convert string to symbol for hash key
65
+ attributes = attributes.each_with_object({}) { |(k, v), h|
66
+ if (!self.class.attribute_map.key?(k.to_sym))
67
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::SignedVoluntaryExitMessageMetadata`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
68
+ end
69
+ h[k.to_sym] = v
70
+ }
71
+
72
+ if attributes.key?(:'validator_pub_key')
73
+ self.validator_pub_key = attributes[:'validator_pub_key']
74
+ else
75
+ self.validator_pub_key = nil
76
+ end
77
+
78
+ if attributes.key?(:'fork')
79
+ self.fork = attributes[:'fork']
80
+ else
81
+ self.fork = nil
82
+ end
83
+
84
+ if attributes.key?(:'signed_voluntary_exit')
85
+ self.signed_voluntary_exit = attributes[:'signed_voluntary_exit']
86
+ else
87
+ self.signed_voluntary_exit = nil
88
+ end
89
+ end
90
+
91
+ # Show invalid properties with the reasons. Usually used together with valid?
92
+ # @return Array for valid properties with the reasons
93
+ def list_invalid_properties
94
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
95
+ invalid_properties = Array.new
96
+ if @validator_pub_key.nil?
97
+ invalid_properties.push('invalid value for "validator_pub_key", validator_pub_key cannot be nil.')
98
+ end
99
+
100
+ if @fork.nil?
101
+ invalid_properties.push('invalid value for "fork", fork cannot be nil.')
102
+ end
103
+
104
+ if @signed_voluntary_exit.nil?
105
+ invalid_properties.push('invalid value for "signed_voluntary_exit", signed_voluntary_exit cannot be nil.')
106
+ end
107
+
108
+ invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ warn '[DEPRECATED] the `valid?` method is obsolete'
115
+ return false if @validator_pub_key.nil?
116
+ return false if @fork.nil?
117
+ return false if @signed_voluntary_exit.nil?
118
+ true
119
+ end
120
+
121
+ # Checks equality by comparing each attribute.
122
+ # @param [Object] Object to be compared
123
+ def ==(o)
124
+ return true if self.equal?(o)
125
+ self.class == o.class &&
126
+ validator_pub_key == o.validator_pub_key &&
127
+ fork == o.fork &&
128
+ signed_voluntary_exit == o.signed_voluntary_exit
129
+ end
130
+
131
+ # @see the `==` method
132
+ # @param [Object] Object to be compared
133
+ def eql?(o)
134
+ self == o
135
+ end
136
+
137
+ # Calculates hash code according to all attributes.
138
+ # @return [Integer] Hash code
139
+ def hash
140
+ [validator_pub_key, fork, signed_voluntary_exit].hash
141
+ end
142
+
143
+ # Builds the object from hash
144
+ # @param [Hash] attributes Model attributes in the form of hash
145
+ # @return [Object] Returns the model itself
146
+ def self.build_from_hash(attributes)
147
+ return nil unless attributes.is_a?(Hash)
148
+ attributes = attributes.transform_keys(&:to_sym)
149
+ transformed_hash = {}
150
+ openapi_types.each_pair do |key, type|
151
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
152
+ transformed_hash["#{key}"] = nil
153
+ elsif type =~ /\AArray<(.*)>/i
154
+ # check to ensure the input is an array given that the attribute
155
+ # is documented as an array but the input is not
156
+ if attributes[attribute_map[key]].is_a?(Array)
157
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
158
+ end
159
+ elsif !attributes[attribute_map[key]].nil?
160
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
161
+ end
162
+ end
163
+ new(transformed_hash)
164
+ end
165
+
166
+ # Deserializes the data based on type
167
+ # @param string type Data type
168
+ # @param string value Value to be deserialized
169
+ # @return [Object] Deserialized data
170
+ def self._deserialize(type, value)
171
+ case type.to_sym
172
+ when :Time
173
+ Time.parse(value)
174
+ when :Date
175
+ Date.parse(value)
176
+ when :String
177
+ value.to_s
178
+ when :Integer
179
+ value.to_i
180
+ when :Float
181
+ value.to_f
182
+ when :Boolean
183
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
184
+ true
185
+ else
186
+ false
187
+ end
188
+ when :Object
189
+ # generic object (usually a Hash), return directly
190
+ value
191
+ when /\AArray<(?<inner_type>.+)>\z/
192
+ inner_type = Regexp.last_match[:inner_type]
193
+ value.map { |v| _deserialize(inner_type, v) }
194
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
195
+ k_type = Regexp.last_match[:k_type]
196
+ v_type = Regexp.last_match[:v_type]
197
+ {}.tap do |hash|
198
+ value.each do |k, v|
199
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
200
+ end
201
+ end
202
+ else # model
203
+ # models (e.g. Pet) or oneOf
204
+ klass = Coinbase::Client.const_get(type)
205
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
206
+ end
207
+ end
208
+
209
+ # Returns the string representation of the object
210
+ # @return [String] String presentation of the object
211
+ def to_s
212
+ to_hash.to_s
213
+ end
214
+
215
+ # to_body is an alias to to_hash (backward compatibility)
216
+ # @return [Hash] Returns the object in the form of hash
217
+ def to_body
218
+ to_hash
219
+ end
220
+
221
+ # Returns the object in the form of hash
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_hash
224
+ hash = {}
225
+ self.class.attribute_map.each_pair do |attr, param|
226
+ value = self.send(attr)
227
+ if value.nil?
228
+ is_nullable = self.class.openapi_nullable.include?(attr)
229
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
230
+ end
231
+
232
+ hash[param] = _to_hash(value)
233
+ end
234
+ hash
235
+ end
236
+
237
+ # Outputs non-array value in the form of hash
238
+ # For object, use to_hash. Otherwise, just return the value
239
+ # @param [Object] value Any valid value
240
+ # @return [Hash] Returns the value in the form of hash
241
+ def _to_hash(value)
242
+ if value.is_a?(Array)
243
+ value.compact.map { |v| _to_hash(v) }
244
+ elsif value.is_a?(Hash)
245
+ {}.tap do |hash|
246
+ value.each { |k, v| hash[k] = _to_hash(v) }
247
+ end
248
+ elsif value.respond_to? :to_hash
249
+ value.to_hash
250
+ else
251
+ value
252
+ end
253
+ end
254
+
255
+ end
256
+
257
+ end
@@ -19,6 +19,7 @@ module Coinbase::Client
19
19
  # List of class defined in oneOf (OpenAPI v3)
20
20
  def openapi_one_of
21
21
  [
22
+ :'NativeEthStakingContext',
22
23
  :'PartialEthStakingContext'
23
24
  ]
24
25
  end
@@ -14,15 +14,56 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module Coinbase::Client
17
- # An onchain transaction to help realize a staking action.
17
+ # A list of onchain transactions to help realize a staking action.
18
18
  class StakingOperation
19
+ # The unique ID of the staking operation.
20
+ attr_accessor :id
21
+
22
+ # The ID of the blockchain network.
23
+ attr_accessor :network_id
24
+
25
+ # The onchain address orchestrating the staking operation.
26
+ attr_accessor :address_id
27
+
28
+ # The status of the staking operation
29
+ attr_accessor :status
30
+
19
31
  # The transaction(s) that will execute the staking operation onchain
20
32
  attr_accessor :transactions
21
33
 
34
+ attr_accessor :metadata
35
+
36
+ class EnumAttributeValidator
37
+ attr_reader :datatype
38
+ attr_reader :allowable_values
39
+
40
+ def initialize(datatype, allowable_values)
41
+ @allowable_values = allowable_values.map do |value|
42
+ case datatype.to_s
43
+ when /Integer/i
44
+ value.to_i
45
+ when /Float/i
46
+ value.to_f
47
+ else
48
+ value
49
+ end
50
+ end
51
+ end
52
+
53
+ def valid?(value)
54
+ !value || allowable_values.include?(value)
55
+ end
56
+ end
57
+
22
58
  # Attribute mapping from ruby-style variable name to JSON key.
23
59
  def self.attribute_map
24
60
  {
25
- :'transactions' => :'transactions'
61
+ :'id' => :'id',
62
+ :'network_id' => :'network_id',
63
+ :'address_id' => :'address_id',
64
+ :'status' => :'status',
65
+ :'transactions' => :'transactions',
66
+ :'metadata' => :'metadata'
26
67
  }
27
68
  end
28
69
 
@@ -34,7 +75,12 @@ module Coinbase::Client
34
75
  # Attribute type mapping.
35
76
  def self.openapi_types
36
77
  {
37
- :'transactions' => :'Array<Transaction>'
78
+ :'id' => :'String',
79
+ :'network_id' => :'String',
80
+ :'address_id' => :'String',
81
+ :'status' => :'String',
82
+ :'transactions' => :'Array<Transaction>',
83
+ :'metadata' => :'StakingOperationMetadata'
38
84
  }
39
85
  end
40
86
 
@@ -59,6 +105,30 @@ module Coinbase::Client
59
105
  h[k.to_sym] = v
60
106
  }
61
107
 
108
+ if attributes.key?(:'id')
109
+ self.id = attributes[:'id']
110
+ else
111
+ self.id = nil
112
+ end
113
+
114
+ if attributes.key?(:'network_id')
115
+ self.network_id = attributes[:'network_id']
116
+ else
117
+ self.network_id = nil
118
+ end
119
+
120
+ if attributes.key?(:'address_id')
121
+ self.address_id = attributes[:'address_id']
122
+ else
123
+ self.address_id = nil
124
+ end
125
+
126
+ if attributes.key?(:'status')
127
+ self.status = attributes[:'status']
128
+ else
129
+ self.status = nil
130
+ end
131
+
62
132
  if attributes.key?(:'transactions')
63
133
  if (value = attributes[:'transactions']).is_a?(Array)
64
134
  self.transactions = value
@@ -66,6 +136,10 @@ module Coinbase::Client
66
136
  else
67
137
  self.transactions = nil
68
138
  end
139
+
140
+ if attributes.key?(:'metadata')
141
+ self.metadata = attributes[:'metadata']
142
+ end
69
143
  end
70
144
 
71
145
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -73,6 +147,22 @@ module Coinbase::Client
73
147
  def list_invalid_properties
74
148
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
75
149
  invalid_properties = Array.new
150
+ if @id.nil?
151
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
152
+ end
153
+
154
+ if @network_id.nil?
155
+ invalid_properties.push('invalid value for "network_id", network_id cannot be nil.')
156
+ end
157
+
158
+ if @address_id.nil?
159
+ invalid_properties.push('invalid value for "address_id", address_id cannot be nil.')
160
+ end
161
+
162
+ if @status.nil?
163
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
164
+ end
165
+
76
166
  if @transactions.nil?
77
167
  invalid_properties.push('invalid value for "transactions", transactions cannot be nil.')
78
168
  end
@@ -84,16 +174,37 @@ module Coinbase::Client
84
174
  # @return true if the model is valid
85
175
  def valid?
86
176
  warn '[DEPRECATED] the `valid?` method is obsolete'
177
+ return false if @id.nil?
178
+ return false if @network_id.nil?
179
+ return false if @address_id.nil?
180
+ return false if @status.nil?
181
+ status_validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed"])
182
+ return false unless status_validator.valid?(@status)
87
183
  return false if @transactions.nil?
88
184
  true
89
185
  end
90
186
 
187
+ # Custom attribute writer method checking allowed values (enum).
188
+ # @param [Object] status Object to be assigned
189
+ def status=(status)
190
+ validator = EnumAttributeValidator.new('String', ["initialized", "pending", "complete", "failed"])
191
+ unless validator.valid?(status)
192
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
193
+ end
194
+ @status = status
195
+ end
196
+
91
197
  # Checks equality by comparing each attribute.
92
198
  # @param [Object] Object to be compared
93
199
  def ==(o)
94
200
  return true if self.equal?(o)
95
201
  self.class == o.class &&
96
- transactions == o.transactions
202
+ id == o.id &&
203
+ network_id == o.network_id &&
204
+ address_id == o.address_id &&
205
+ status == o.status &&
206
+ transactions == o.transactions &&
207
+ metadata == o.metadata
97
208
  end
98
209
 
99
210
  # @see the `==` method
@@ -105,7 +216,7 @@ module Coinbase::Client
105
216
  # Calculates hash code according to all attributes.
106
217
  # @return [Integer] Hash code
107
218
  def hash
108
- [transactions].hash
219
+ [id, network_id, address_id, status, transactions, metadata].hash
109
220
  end
110
221
 
111
222
  # Builds the object from hash
@@ -0,0 +1,104 @@
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.6.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ module StakingOperationMetadata
18
+ class << self
19
+ # List of class defined in oneOf (OpenAPI v3)
20
+ def openapi_one_of
21
+ [
22
+ :'Array<SignedVoluntaryExitMessageMetadata>'
23
+ ]
24
+ end
25
+
26
+ # Builds the object
27
+ # @param [Mixed] Data to be matched against the list of oneOf items
28
+ # @return [Object] Returns the model or the data itself
29
+ def build(data)
30
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
31
+ # Note:
32
+ # - We do not attempt to check whether exactly one item matches.
33
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
34
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
35
+ # - TODO: scalar values are de facto behaving as if they were nullable.
36
+ # - TODO: logging when debugging is set.
37
+ openapi_one_of.each do |klass|
38
+ begin
39
+ next if klass == :AnyType # "nullable: true"
40
+ typed_data = find_and_cast_into_type(klass, data)
41
+ return typed_data if typed_data
42
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
43
+ end
44
+ end
45
+
46
+ openapi_one_of.include?(:AnyType) ? data : nil
47
+ end
48
+
49
+ private
50
+
51
+ SchemaMismatchError = Class.new(StandardError)
52
+
53
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
54
+ def find_and_cast_into_type(klass, data)
55
+ return if data.nil?
56
+
57
+ case klass.to_s
58
+ when 'Boolean'
59
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
60
+ when 'Float'
61
+ return data if data.instance_of?(Float)
62
+ when 'Integer'
63
+ return data if data.instance_of?(Integer)
64
+ when 'Time'
65
+ return Time.parse(data)
66
+ when 'Date'
67
+ return Date.parse(data)
68
+ when 'String'
69
+ return data if data.instance_of?(String)
70
+ when 'Object' # "type: object"
71
+ return data if data.instance_of?(Hash)
72
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
73
+ if data.instance_of?(Array)
74
+ sub_type = Regexp.last_match[:sub_type]
75
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
76
+ end
77
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
78
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
79
+ sub_type = Regexp.last_match[:sub_type]
80
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
81
+ end
82
+ else # model
83
+ const = Coinbase::Client.const_get(klass)
84
+ if const
85
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
86
+ model = const.build(data)
87
+ return model if model
88
+ else
89
+ # raise if data contains keys that are not known to the model
90
+ raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
91
+ model = const.build_from_hash(data)
92
+ return model if model
93
+ end
94
+ end
95
+ end
96
+
97
+ raise # if no match by now, raise
98
+ rescue
99
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
100
+ end
101
+ end
102
+ end
103
+
104
+ end
@@ -14,9 +14,9 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module Coinbase::Client
17
- # The staking rewards for an address
17
+ # The staking rewards for an address.
18
18
  class StakingReward
19
- # The onchain address for which the staking rewards are being fetched
19
+ # The onchain address for which the staking rewards are being fetched.
20
20
  attr_accessor :address_id
21
21
 
22
22
  # The date of the reward in format 'YYYY-MM-DD' in UTC.
@@ -25,7 +25,7 @@ module Coinbase::Client
25
25
  # The reward amount in requested \"format\". Default is USD.
26
26
  attr_accessor :amount
27
27
 
28
- # The state of the reward
28
+ # The state of the reward.
29
29
  attr_accessor :state
30
30
 
31
31
  attr_accessor :format
@@ -180,7 +180,7 @@ module Coinbase::Client
180
180
  return false if @from_address_id.nil?
181
181
  return false if @unsigned_payload.nil?
182
182
  return false if @status.nil?
183
- status_validator = EnumAttributeValidator.new('String', ["pending", "broadcast", "complete", "failed"])
183
+ status_validator = EnumAttributeValidator.new('String', ["pending", "signed", "broadcast", "complete", "failed"])
184
184
  return false unless status_validator.valid?(@status)
185
185
  true
186
186
  end
@@ -188,7 +188,7 @@ module Coinbase::Client
188
188
  # Custom attribute writer method checking allowed values (enum).
189
189
  # @param [Object] status Object to be assigned
190
190
  def status=(status)
191
- validator = EnumAttributeValidator.new('String', ["pending", "broadcast", "complete", "failed"])
191
+ validator = EnumAttributeValidator.new('String', ["pending", "signed", "broadcast", "complete", "failed"])
192
192
  unless validator.valid?(status)
193
193
  fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
194
194
  end