coinbase-sdk 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coinbase/address.rb +64 -10
- data/lib/coinbase/asset.rb +18 -4
- data/lib/coinbase/client/api/server_signers_api.rb +13 -3
- data/lib/coinbase/client/api/stake_api.rb +86 -0
- data/lib/coinbase/client/models/broadcast_trade_request.rb +14 -4
- data/lib/coinbase/client/models/build_staking_operation_request.rb +291 -0
- data/lib/coinbase/client/models/feature.rb +42 -0
- data/lib/coinbase/client/models/request_faucet_funds200_response.rb +222 -0
- data/lib/coinbase/client/models/server_signer_list.rb +275 -0
- data/lib/coinbase/client/models/staking_operation.rb +222 -0
- data/lib/coinbase/client/models/trade.rb +13 -4
- data/lib/coinbase/client/models/transaction.rb +45 -1
- data/lib/coinbase/client/models/transfer.rb +33 -1
- data/lib/coinbase/client/models/wallet.rb +20 -1
- data/lib/coinbase/client.rb +5 -0
- data/lib/coinbase/errors.rb +3 -0
- data/lib/coinbase/server_signer.rb +57 -0
- data/lib/coinbase/trade.rb +147 -0
- data/lib/coinbase/transaction.rb +125 -0
- data/lib/coinbase/transfer.rb +22 -55
- data/lib/coinbase/wallet.rb +12 -1
- data/lib/coinbase.rb +3 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ed68757d7f8c6d946fed0b3220fe8657d07926bef5f90c50bb279ebb035087
|
4
|
+
data.tar.gz: 3b1df1f99ac447f197d0b636ca3d617c670142a42159a42f12a9c60fb2982c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d943a6ff62431d82b72f58ed48fa13f48297c57ef39e7d9efc3afe45141a8d85ffc327f5fbaba9f250c366d398e1961cc61ec2619f3ae7cdaff8012664b6f18
|
7
|
+
data.tar.gz: 391942f2797f2c5e8bed4adeff0cfb159f5f8bea90ad4bdebc61a5904929687bbcf73006e14ad1c5f5d9e3d8fb4ee57cbd33ac84af21928fd7b6685004aed63b
|
data/lib/coinbase/address.rb
CHANGED
@@ -77,7 +77,7 @@ module Coinbase
|
|
77
77
|
# @param asset_id [Symbol] The ID of the Asset to send. For Ether, :eth, :gwei, and :wei are supported.
|
78
78
|
# @param destination [Wallet | Address | String] The destination of the transfer. If a Wallet, sends to the Wallet's
|
79
79
|
# default address. If a String, interprets it as the address ID.
|
80
|
-
# @return [
|
80
|
+
# @return [Coinbase::Transfer] The Transfer object.
|
81
81
|
def transfer(amount, asset_id, destination)
|
82
82
|
destination_address, destination_network = destination_address_and_network(destination)
|
83
83
|
|
@@ -88,9 +88,27 @@ module Coinbase
|
|
88
88
|
# If a server signer is managing keys, it will sign and broadcast the underlying transfer transaction out of band.
|
89
89
|
return transfer if Coinbase.use_server_signer?
|
90
90
|
|
91
|
-
|
91
|
+
broadcast_transfer(transfer, transfer.transaction.sign(@key))
|
92
|
+
end
|
93
|
+
|
94
|
+
# Trades the given amount of the given Asset for another Asset.
|
95
|
+
# Only same-network Trades are supported.
|
96
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to send.
|
97
|
+
# @param from_asset_id [Symbol] The ID of the Asset to trade from. For Ether, :eth, :gwei, and :wei are supported.
|
98
|
+
# @param to_asset_id [Symbol] The ID of the Asset to trade to. For Ether, :eth, :gwei, and :wei are supported.
|
99
|
+
# @return [Coinbase::Trade] The Trade object.
|
100
|
+
def trade(amount, from_asset_id, to_asset_id)
|
101
|
+
validate_can_trade!(amount, from_asset_id, to_asset_id)
|
102
|
+
|
103
|
+
trade = create_trade(amount, from_asset_id, to_asset_id)
|
92
104
|
|
93
|
-
|
105
|
+
# NOTE: Trading does not yet support server signers at this point.
|
106
|
+
|
107
|
+
payloads = { signed_payload: trade.transaction.sign(@key) }
|
108
|
+
|
109
|
+
payloads[:approve_tx_signed_payload] = trade.approve_transaction.sign(@key) unless trade.approve_transaction.nil?
|
110
|
+
|
111
|
+
broadcast_trade(trade, **payloads)
|
94
112
|
end
|
95
113
|
|
96
114
|
# Returns whether the Address has a private key backing it to sign transactions.
|
@@ -163,6 +181,10 @@ module Coinbase
|
|
163
181
|
@transfers_api ||= Coinbase::Client::TransfersApi.new(Coinbase.configuration.api_client)
|
164
182
|
end
|
165
183
|
|
184
|
+
def trades_api
|
185
|
+
@trades_api ||= Coinbase::Client::TradesApi.new(Coinbase.configuration.api_client)
|
186
|
+
end
|
187
|
+
|
166
188
|
def destination_address_and_network(destination)
|
167
189
|
return [destination.default_address.id, destination.network_id] if destination.is_a?(Wallet)
|
168
190
|
return [destination.id, destination.network_id] if destination.is_a?(Address)
|
@@ -199,13 +221,6 @@ module Coinbase
|
|
199
221
|
Coinbase::Transfer.new(transfer_model)
|
200
222
|
end
|
201
223
|
|
202
|
-
def sign_transfer(transfer)
|
203
|
-
transaction = transfer.transaction
|
204
|
-
transaction.sign(@key)
|
205
|
-
|
206
|
-
transaction.hex
|
207
|
-
end
|
208
|
-
|
209
224
|
def broadcast_transfer(transfer, signed_payload)
|
210
225
|
transfer_model = Coinbase.call_api do
|
211
226
|
transfers_api.broadcast_transfer(wallet_id, id, transfer.id, { signed_payload: signed_payload })
|
@@ -213,5 +228,44 @@ module Coinbase
|
|
213
228
|
|
214
229
|
Coinbase::Transfer.new(transfer_model)
|
215
230
|
end
|
231
|
+
|
232
|
+
def validate_can_trade!(amount, from_asset_id, to_asset_id)
|
233
|
+
raise 'Cannot trade from address without private key loaded' unless can_sign?
|
234
|
+
|
235
|
+
raise ArgumentError, "Unsupported from asset: #{from_asset_id}" unless Coinbase::Asset.supported?(from_asset_id)
|
236
|
+
raise ArgumentError, "Unsupported to asset: #{to_asset_id}" unless Coinbase::Asset.supported?(to_asset_id)
|
237
|
+
|
238
|
+
current_balance = balance(from_asset_id)
|
239
|
+
|
240
|
+
return unless current_balance < amount
|
241
|
+
|
242
|
+
raise ArgumentError, "Insufficient funds: #{amount} requested, but only #{current_balance} available"
|
243
|
+
end
|
244
|
+
|
245
|
+
def create_trade(amount, from_asset_id, to_asset_id)
|
246
|
+
create_trade_request = {
|
247
|
+
amount: Coinbase::Asset.to_atomic_amount(amount, from_asset_id).to_i.to_s,
|
248
|
+
from_asset_id: Coinbase::Asset.primary_denomination(from_asset_id).to_s,
|
249
|
+
to_asset_id: Coinbase::Asset.primary_denomination(to_asset_id).to_s
|
250
|
+
}
|
251
|
+
|
252
|
+
trade_model = Coinbase.call_api do
|
253
|
+
trades_api.create_trade(wallet_id, id, create_trade_request)
|
254
|
+
end
|
255
|
+
|
256
|
+
Coinbase::Trade.new(trade_model)
|
257
|
+
end
|
258
|
+
|
259
|
+
def broadcast_trade(trade, signed_payload:, approve_tx_signed_payload: nil)
|
260
|
+
req = { signed_payload: signed_payload }
|
261
|
+
|
262
|
+
req[:approve_transaction_signed_payload] = approve_tx_signed_payload unless approve_tx_signed_payload.nil?
|
263
|
+
|
264
|
+
trade_model = Coinbase.call_api do
|
265
|
+
trades_api.broadcast_trade(wallet_id, id, trade.id, req)
|
266
|
+
end
|
267
|
+
|
268
|
+
Coinbase::Trade.new(trade_model)
|
269
|
+
end
|
216
270
|
end
|
217
271
|
end
|
data/lib/coinbase/asset.rb
CHANGED
@@ -61,26 +61,40 @@ module Coinbase
|
|
61
61
|
asset_id
|
62
62
|
end
|
63
63
|
|
64
|
+
def self.from_model(asset_model)
|
65
|
+
raise unless asset_model.is_a?(Coinbase::Client::Asset)
|
66
|
+
|
67
|
+
new(
|
68
|
+
network_id: Coinbase.to_sym(asset_model.network_id),
|
69
|
+
asset_id: Coinbase.to_sym(asset_model.asset_id),
|
70
|
+
address_id: asset_model.contract_address,
|
71
|
+
decimals: asset_model.decimals
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
64
75
|
# Returns a new Asset object. Do not use this method. Instead, use the Asset constants defined in
|
65
76
|
# the Coinbase module.
|
66
77
|
# @param network_id [Symbol] The ID of the Network to which the Asset belongs
|
67
78
|
# @param asset_id [Symbol] The Asset ID
|
68
|
-
# @param display_name [String] The Asset's display name
|
79
|
+
# @param display_name [String] (Optional) The Asset's display name
|
69
80
|
# @param address_id [String] (Optional) The Asset's address ID, if one exists
|
70
|
-
|
81
|
+
# @param decimals [Integer] (Optional) The number of decimal places the Asset uses
|
82
|
+
def initialize(network_id:, asset_id:, display_name: nil, address_id: nil, decimals: nil)
|
71
83
|
@network_id = network_id
|
72
84
|
@asset_id = asset_id
|
73
85
|
@display_name = display_name
|
74
86
|
@address_id = address_id
|
87
|
+
@decimals = decimals
|
75
88
|
end
|
76
89
|
|
77
|
-
attr_reader :network_id, :asset_id, :display_name, :address_id
|
90
|
+
attr_reader :network_id, :asset_id, :display_name, :address_id, :decimals
|
78
91
|
|
79
92
|
# Returns a string representation of the Asset.
|
80
93
|
# @return [String] a string representation of the Asset
|
81
94
|
def to_s
|
82
95
|
"Coinbase::Asset{network_id: '#{network_id}', asset_id: '#{asset_id}', display_name: '#{display_name}'" +
|
83
|
-
(address_id.nil? ? '}' : ", address_id: '#{address_id}'}")
|
96
|
+
(address_id.nil? ? '}' : ", address_id: '#{address_id}'}") +
|
97
|
+
(decimals.nil? ? '}' : ", decimals: '#{decimals}'}")
|
84
98
|
end
|
85
99
|
|
86
100
|
# Same as to_s.
|
@@ -222,7 +222,9 @@ module Coinbase::Client
|
|
222
222
|
# List server signers for the current project
|
223
223
|
# List server signers for the current project
|
224
224
|
# @param [Hash] opts the optional parameters
|
225
|
-
# @
|
225
|
+
# @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.
|
226
|
+
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
|
227
|
+
# @return [ServerSignerList]
|
226
228
|
def list_server_signers(opts = {})
|
227
229
|
data, _status_code, _headers = list_server_signers_with_http_info(opts)
|
228
230
|
data
|
@@ -231,16 +233,24 @@ module Coinbase::Client
|
|
231
233
|
# List server signers for the current project
|
232
234
|
# List server signers for the current project
|
233
235
|
# @param [Hash] opts the optional parameters
|
234
|
-
# @
|
236
|
+
# @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.
|
237
|
+
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
|
238
|
+
# @return [Array<(ServerSignerList, Integer, Hash)>] ServerSignerList data, response status code and response headers
|
235
239
|
def list_server_signers_with_http_info(opts = {})
|
236
240
|
if @api_client.config.debugging
|
237
241
|
@api_client.config.logger.debug 'Calling API: ServerSignersApi.list_server_signers ...'
|
238
242
|
end
|
243
|
+
if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
|
244
|
+
fail ArgumentError, 'invalid value for "opts[:"page"]" when calling ServerSignersApi.list_server_signers, the character length must be smaller than or equal to 5000.'
|
245
|
+
end
|
246
|
+
|
239
247
|
# resource path
|
240
248
|
local_var_path = '/v1/server_signers'
|
241
249
|
|
242
250
|
# query parameters
|
243
251
|
query_params = opts[:query_params] || {}
|
252
|
+
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
|
253
|
+
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
|
244
254
|
|
245
255
|
# header parameters
|
246
256
|
header_params = opts[:header_params] || {}
|
@@ -254,7 +264,7 @@ module Coinbase::Client
|
|
254
264
|
post_body = opts[:debug_body]
|
255
265
|
|
256
266
|
# return_type
|
257
|
-
return_type = opts[:debug_return_type] || '
|
267
|
+
return_type = opts[:debug_return_type] || 'ServerSignerList'
|
258
268
|
|
259
269
|
# auth_names
|
260
270
|
auth_names = opts[:debug_auth_names] || []
|
@@ -0,0 +1,86 @@
|
|
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 StakeApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# Build a new staking operation
|
23
|
+
# Build a new staking operation
|
24
|
+
# @param [Hash] opts the optional parameters
|
25
|
+
# @option opts [BuildStakingOperationRequest] :build_staking_operation_request
|
26
|
+
# @return [StakingOperation]
|
27
|
+
def build_staking_operation(opts = {})
|
28
|
+
data, _status_code, _headers = build_staking_operation_with_http_info(opts)
|
29
|
+
data
|
30
|
+
end
|
31
|
+
|
32
|
+
# Build a new staking operation
|
33
|
+
# Build a new staking operation
|
34
|
+
# @param [Hash] opts the optional parameters
|
35
|
+
# @option opts [BuildStakingOperationRequest] :build_staking_operation_request
|
36
|
+
# @return [Array<(StakingOperation, Integer, Hash)>] StakingOperation data, response status code and response headers
|
37
|
+
def build_staking_operation_with_http_info(opts = {})
|
38
|
+
if @api_client.config.debugging
|
39
|
+
@api_client.config.logger.debug 'Calling API: StakeApi.build_staking_operation ...'
|
40
|
+
end
|
41
|
+
# resource path
|
42
|
+
local_var_path = '/v1/stake/build'
|
43
|
+
|
44
|
+
# query parameters
|
45
|
+
query_params = opts[:query_params] || {}
|
46
|
+
|
47
|
+
# header parameters
|
48
|
+
header_params = opts[:header_params] || {}
|
49
|
+
# HTTP header 'Accept' (if needed)
|
50
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
51
|
+
# HTTP header 'Content-Type'
|
52
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
53
|
+
if !content_type.nil?
|
54
|
+
header_params['Content-Type'] = content_type
|
55
|
+
end
|
56
|
+
|
57
|
+
# form parameters
|
58
|
+
form_params = opts[:form_params] || {}
|
59
|
+
|
60
|
+
# http body (model)
|
61
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'build_staking_operation_request'])
|
62
|
+
|
63
|
+
# return_type
|
64
|
+
return_type = opts[:debug_return_type] || 'StakingOperation'
|
65
|
+
|
66
|
+
# auth_names
|
67
|
+
auth_names = opts[:debug_auth_names] || []
|
68
|
+
|
69
|
+
new_options = opts.merge(
|
70
|
+
:operation => :"StakeApi.build_staking_operation",
|
71
|
+
:header_params => header_params,
|
72
|
+
:query_params => query_params,
|
73
|
+
:form_params => form_params,
|
74
|
+
:body => post_body,
|
75
|
+
:auth_names => auth_names,
|
76
|
+
:return_type => return_type
|
77
|
+
)
|
78
|
+
|
79
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
80
|
+
if @api_client.config.debugging
|
81
|
+
@api_client.config.logger.debug "API called: StakeApi#build_staking_operation\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
82
|
+
end
|
83
|
+
return data, status_code, headers
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -18,10 +18,14 @@ module Coinbase::Client
|
|
18
18
|
# The hex-encoded signed payload of the trade
|
19
19
|
attr_accessor :signed_payload
|
20
20
|
|
21
|
+
# The hex-encoded signed payload of the approval transaction
|
22
|
+
attr_accessor :approve_transaction_signed_payload
|
23
|
+
|
21
24
|
# Attribute mapping from ruby-style variable name to JSON key.
|
22
25
|
def self.attribute_map
|
23
26
|
{
|
24
|
-
:'signed_payload' => :'signed_payload'
|
27
|
+
:'signed_payload' => :'signed_payload',
|
28
|
+
:'approve_transaction_signed_payload' => :'approve_transaction_signed_payload'
|
25
29
|
}
|
26
30
|
end
|
27
31
|
|
@@ -33,7 +37,8 @@ module Coinbase::Client
|
|
33
37
|
# Attribute type mapping.
|
34
38
|
def self.openapi_types
|
35
39
|
{
|
36
|
-
:'signed_payload' => :'String'
|
40
|
+
:'signed_payload' => :'String',
|
41
|
+
:'approve_transaction_signed_payload' => :'String'
|
37
42
|
}
|
38
43
|
end
|
39
44
|
|
@@ -63,6 +68,10 @@ module Coinbase::Client
|
|
63
68
|
else
|
64
69
|
self.signed_payload = nil
|
65
70
|
end
|
71
|
+
|
72
|
+
if attributes.key?(:'approve_transaction_signed_payload')
|
73
|
+
self.approve_transaction_signed_payload = attributes[:'approve_transaction_signed_payload']
|
74
|
+
end
|
66
75
|
end
|
67
76
|
|
68
77
|
# Show invalid properties with the reasons. Usually used together with valid?
|
@@ -90,7 +99,8 @@ module Coinbase::Client
|
|
90
99
|
def ==(o)
|
91
100
|
return true if self.equal?(o)
|
92
101
|
self.class == o.class &&
|
93
|
-
signed_payload == o.signed_payload
|
102
|
+
signed_payload == o.signed_payload &&
|
103
|
+
approve_transaction_signed_payload == o.approve_transaction_signed_payload
|
94
104
|
end
|
95
105
|
|
96
106
|
# @see the `==` method
|
@@ -102,7 +112,7 @@ module Coinbase::Client
|
|
102
112
|
# Calculates hash code according to all attributes.
|
103
113
|
# @return [Integer] Hash code
|
104
114
|
def hash
|
105
|
-
[signed_payload].hash
|
115
|
+
[signed_payload, approve_transaction_signed_payload].hash
|
106
116
|
end
|
107
117
|
|
108
118
|
# Builds the object from hash
|
@@ -0,0 +1,291 @@
|
|
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 BuildStakingOperationRequest
|
18
|
+
# The ID of the blockchain network
|
19
|
+
attr_accessor :network_id
|
20
|
+
|
21
|
+
# The ID of the asset being staked
|
22
|
+
attr_accessor :asset_id
|
23
|
+
|
24
|
+
# The onchain address from which the staking transaction originates and is responsible for signing the transaction.
|
25
|
+
attr_accessor :address_id
|
26
|
+
|
27
|
+
# The type of staking operation
|
28
|
+
attr_accessor :action
|
29
|
+
|
30
|
+
attr_accessor :options
|
31
|
+
|
32
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
33
|
+
def self.attribute_map
|
34
|
+
{
|
35
|
+
:'network_id' => :'network_id',
|
36
|
+
:'asset_id' => :'asset_id',
|
37
|
+
:'address_id' => :'address_id',
|
38
|
+
:'action' => :'action',
|
39
|
+
:'options' => :'options'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns all the JSON keys this model knows about
|
44
|
+
def self.acceptable_attributes
|
45
|
+
attribute_map.values
|
46
|
+
end
|
47
|
+
|
48
|
+
# Attribute type mapping.
|
49
|
+
def self.openapi_types
|
50
|
+
{
|
51
|
+
:'network_id' => :'String',
|
52
|
+
:'asset_id' => :'String',
|
53
|
+
:'address_id' => :'String',
|
54
|
+
:'action' => :'String',
|
55
|
+
:'options' => :'Hash<String, String>'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
# List of attributes with nullable: true
|
60
|
+
def self.openapi_nullable
|
61
|
+
Set.new([
|
62
|
+
])
|
63
|
+
end
|
64
|
+
|
65
|
+
# Initializes the object
|
66
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
67
|
+
def initialize(attributes = {})
|
68
|
+
if (!attributes.is_a?(Hash))
|
69
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::BuildStakingOperationRequest` initialize method"
|
70
|
+
end
|
71
|
+
|
72
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
73
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
74
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
75
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::BuildStakingOperationRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
76
|
+
end
|
77
|
+
h[k.to_sym] = v
|
78
|
+
}
|
79
|
+
|
80
|
+
if attributes.key?(:'network_id')
|
81
|
+
self.network_id = attributes[:'network_id']
|
82
|
+
else
|
83
|
+
self.network_id = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
if attributes.key?(:'asset_id')
|
87
|
+
self.asset_id = attributes[:'asset_id']
|
88
|
+
else
|
89
|
+
self.asset_id = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
if attributes.key?(:'address_id')
|
93
|
+
self.address_id = attributes[:'address_id']
|
94
|
+
else
|
95
|
+
self.address_id = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
if attributes.key?(:'action')
|
99
|
+
self.action = attributes[:'action']
|
100
|
+
else
|
101
|
+
self.action = nil
|
102
|
+
end
|
103
|
+
|
104
|
+
if attributes.key?(:'options')
|
105
|
+
if (value = attributes[:'options']).is_a?(Hash)
|
106
|
+
self.options = value
|
107
|
+
end
|
108
|
+
else
|
109
|
+
self.options = nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
114
|
+
# @return Array for valid properties with the reasons
|
115
|
+
def list_invalid_properties
|
116
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
117
|
+
invalid_properties = Array.new
|
118
|
+
if @network_id.nil?
|
119
|
+
invalid_properties.push('invalid value for "network_id", network_id cannot be nil.')
|
120
|
+
end
|
121
|
+
|
122
|
+
if @asset_id.nil?
|
123
|
+
invalid_properties.push('invalid value for "asset_id", asset_id cannot be nil.')
|
124
|
+
end
|
125
|
+
|
126
|
+
if @address_id.nil?
|
127
|
+
invalid_properties.push('invalid value for "address_id", address_id cannot be nil.')
|
128
|
+
end
|
129
|
+
|
130
|
+
if @action.nil?
|
131
|
+
invalid_properties.push('invalid value for "action", action cannot be nil.')
|
132
|
+
end
|
133
|
+
|
134
|
+
if @options.nil?
|
135
|
+
invalid_properties.push('invalid value for "options", options cannot be nil.')
|
136
|
+
end
|
137
|
+
|
138
|
+
invalid_properties
|
139
|
+
end
|
140
|
+
|
141
|
+
# Check to see if the all the properties in the model are valid
|
142
|
+
# @return true if the model is valid
|
143
|
+
def valid?
|
144
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
145
|
+
return false if @network_id.nil?
|
146
|
+
return false if @asset_id.nil?
|
147
|
+
return false if @address_id.nil?
|
148
|
+
return false if @action.nil?
|
149
|
+
return false if @options.nil?
|
150
|
+
true
|
151
|
+
end
|
152
|
+
|
153
|
+
# Checks equality by comparing each attribute.
|
154
|
+
# @param [Object] Object to be compared
|
155
|
+
def ==(o)
|
156
|
+
return true if self.equal?(o)
|
157
|
+
self.class == o.class &&
|
158
|
+
network_id == o.network_id &&
|
159
|
+
asset_id == o.asset_id &&
|
160
|
+
address_id == o.address_id &&
|
161
|
+
action == o.action &&
|
162
|
+
options == o.options
|
163
|
+
end
|
164
|
+
|
165
|
+
# @see the `==` method
|
166
|
+
# @param [Object] Object to be compared
|
167
|
+
def eql?(o)
|
168
|
+
self == o
|
169
|
+
end
|
170
|
+
|
171
|
+
# Calculates hash code according to all attributes.
|
172
|
+
# @return [Integer] Hash code
|
173
|
+
def hash
|
174
|
+
[network_id, asset_id, address_id, action, options].hash
|
175
|
+
end
|
176
|
+
|
177
|
+
# Builds the object from hash
|
178
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
179
|
+
# @return [Object] Returns the model itself
|
180
|
+
def self.build_from_hash(attributes)
|
181
|
+
return nil unless attributes.is_a?(Hash)
|
182
|
+
attributes = attributes.transform_keys(&:to_sym)
|
183
|
+
transformed_hash = {}
|
184
|
+
openapi_types.each_pair do |key, type|
|
185
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
186
|
+
transformed_hash["#{key}"] = nil
|
187
|
+
elsif type =~ /\AArray<(.*)>/i
|
188
|
+
# check to ensure the input is an array given that the attribute
|
189
|
+
# is documented as an array but the input is not
|
190
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
191
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
192
|
+
end
|
193
|
+
elsif !attributes[attribute_map[key]].nil?
|
194
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
195
|
+
end
|
196
|
+
end
|
197
|
+
new(transformed_hash)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Deserializes the data based on type
|
201
|
+
# @param string type Data type
|
202
|
+
# @param string value Value to be deserialized
|
203
|
+
# @return [Object] Deserialized data
|
204
|
+
def self._deserialize(type, value)
|
205
|
+
case type.to_sym
|
206
|
+
when :Time
|
207
|
+
Time.parse(value)
|
208
|
+
when :Date
|
209
|
+
Date.parse(value)
|
210
|
+
when :String
|
211
|
+
value.to_s
|
212
|
+
when :Integer
|
213
|
+
value.to_i
|
214
|
+
when :Float
|
215
|
+
value.to_f
|
216
|
+
when :Boolean
|
217
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
218
|
+
true
|
219
|
+
else
|
220
|
+
false
|
221
|
+
end
|
222
|
+
when :Object
|
223
|
+
# generic object (usually a Hash), return directly
|
224
|
+
value
|
225
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
226
|
+
inner_type = Regexp.last_match[:inner_type]
|
227
|
+
value.map { |v| _deserialize(inner_type, v) }
|
228
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
229
|
+
k_type = Regexp.last_match[:k_type]
|
230
|
+
v_type = Regexp.last_match[:v_type]
|
231
|
+
{}.tap do |hash|
|
232
|
+
value.each do |k, v|
|
233
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
else # model
|
237
|
+
# models (e.g. Pet) or oneOf
|
238
|
+
klass = Coinbase::Client.const_get(type)
|
239
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Returns the string representation of the object
|
244
|
+
# @return [String] String presentation of the object
|
245
|
+
def to_s
|
246
|
+
to_hash.to_s
|
247
|
+
end
|
248
|
+
|
249
|
+
# to_body is an alias to to_hash (backward compatibility)
|
250
|
+
# @return [Hash] Returns the object in the form of hash
|
251
|
+
def to_body
|
252
|
+
to_hash
|
253
|
+
end
|
254
|
+
|
255
|
+
# Returns the object in the form of hash
|
256
|
+
# @return [Hash] Returns the object in the form of hash
|
257
|
+
def to_hash
|
258
|
+
hash = {}
|
259
|
+
self.class.attribute_map.each_pair do |attr, param|
|
260
|
+
value = self.send(attr)
|
261
|
+
if value.nil?
|
262
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
263
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
264
|
+
end
|
265
|
+
|
266
|
+
hash[param] = _to_hash(value)
|
267
|
+
end
|
268
|
+
hash
|
269
|
+
end
|
270
|
+
|
271
|
+
# Outputs non-array value in the form of hash
|
272
|
+
# For object, use to_hash. Otherwise, just return the value
|
273
|
+
# @param [Object] value Any valid value
|
274
|
+
# @return [Hash] Returns the value in the form of hash
|
275
|
+
def _to_hash(value)
|
276
|
+
if value.is_a?(Array)
|
277
|
+
value.compact.map { |v| _to_hash(v) }
|
278
|
+
elsif value.is_a?(Hash)
|
279
|
+
{}.tap do |hash|
|
280
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
281
|
+
end
|
282
|
+
elsif value.respond_to? :to_hash
|
283
|
+
value.to_hash
|
284
|
+
else
|
285
|
+
value
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 Feature
|
18
|
+
TRANSFER = "transfer".freeze
|
19
|
+
TRADE = "trade".freeze
|
20
|
+
FAUCET = "faucet".freeze
|
21
|
+
SERVER_SIGNER = "server_signer".freeze
|
22
|
+
|
23
|
+
def self.all_vars
|
24
|
+
@all_vars ||= [TRANSFER, TRADE, FAUCET, SERVER_SIGNER].freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
# Builds the enum from string
|
28
|
+
# @param [String] The enum value in the form of the string
|
29
|
+
# @return [String] The enum value
|
30
|
+
def self.build_from_hash(value)
|
31
|
+
new.build_from_hash(value)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Builds the enum from string
|
35
|
+
# @param [String] The enum value in the form of the string
|
36
|
+
# @return [String] The enum value
|
37
|
+
def build_from_hash(value)
|
38
|
+
return value if Feature.all_vars.include?(value)
|
39
|
+
raise "Invalid ENUM value #{value} for class #Feature"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|