coinbase-sdk 0.0.13 → 0.0.14
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/external_address.rb +3 -166
- data/lib/coinbase/address/wallet_address.rb +44 -0
- data/lib/coinbase/address.rb +128 -0
- data/lib/coinbase/client/api/addresses_api.rb +1 -1
- data/lib/coinbase/client/api/assets_api.rb +3 -3
- data/lib/coinbase/client/api/contract_events_api.rb +121 -0
- data/lib/coinbase/client/api/external_addresses_api.rb +1 -1
- data/lib/coinbase/client/api/server_signers_api.rb +1 -1
- data/lib/coinbase/client/api/stake_api.rb +242 -1
- data/lib/coinbase/client/api/trades_api.rb +1 -1
- data/lib/coinbase/client/api/transfers_api.rb +1 -1
- data/lib/coinbase/client/api/users_api.rb +1 -1
- data/lib/coinbase/client/api/validators_api.rb +1 -1
- data/lib/coinbase/client/api/wallets_api.rb +1 -1
- data/lib/coinbase/client/api/webhooks_api.rb +286 -0
- data/lib/coinbase/client/api_client.rb +1 -1
- data/lib/coinbase/client/api_error.rb +1 -1
- data/lib/coinbase/client/configuration.rb +11 -1
- data/lib/coinbase/client/models/address.rb +1 -1
- data/lib/coinbase/client/models/address_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_list.rb +1 -1
- data/lib/coinbase/client/models/asset.rb +1 -1
- data/lib/coinbase/client/models/balance.rb +1 -1
- data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +239 -0
- data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/contract_event.rb +336 -0
- data/lib/coinbase/client/models/contract_event_list.rb +259 -0
- data/lib/coinbase/client/models/create_address_request.rb +1 -1
- data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
- data/lib/coinbase/client/models/create_staking_operation_request.rb +274 -0
- data/lib/coinbase/client/models/create_trade_request.rb +1 -1
- data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
- data/lib/coinbase/client/models/create_webhook_request.rb +282 -0
- data/lib/coinbase/client/models/error.rb +1 -1
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
- data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
- data/lib/coinbase/client/models/feature.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
- data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
- data/lib/coinbase/client/models/native_eth_staking_context.rb +1 -1
- data/lib/coinbase/client/models/partial_eth_staking_context.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/server_signer.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
- data/lib/coinbase/client/models/server_signer_list.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
- data/lib/coinbase/client/models/staking_context.rb +1 -1
- data/lib/coinbase/client/models/staking_context_context.rb +1 -1
- data/lib/coinbase/client/models/staking_operation.rb +16 -6
- data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
- data/lib/coinbase/client/models/staking_reward.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
- data/lib/coinbase/client/models/trade.rb +1 -1
- data/lib/coinbase/client/models/trade_list.rb +1 -1
- data/lib/coinbase/client/models/transaction.rb +1 -1
- data/lib/coinbase/client/models/transaction_type.rb +1 -1
- data/lib/coinbase/client/models/transfer.rb +5 -93
- data/lib/coinbase/client/models/transfer_list.rb +1 -1
- data/lib/coinbase/client/models/update_webhook_request.rb +289 -0
- data/lib/coinbase/client/models/user.rb +1 -1
- data/lib/coinbase/client/models/validator.rb +1 -1
- data/lib/coinbase/client/models/validator_details.rb +1 -1
- data/lib/coinbase/client/models/validator_list.rb +1 -1
- data/lib/coinbase/client/models/wallet.rb +1 -1
- data/lib/coinbase/client/models/wallet_list.rb +1 -1
- data/lib/coinbase/client/models/webhook.rb +299 -0
- data/lib/coinbase/client/models/webhook_event_filter.rb +236 -0
- data/lib/coinbase/client/models/webhook_event_type.rb +41 -0
- data/lib/coinbase/client/models/webhook_list.rb +244 -0
- data/lib/coinbase/client/version.rb +1 -1
- data/lib/coinbase/client.rb +13 -1
- data/lib/coinbase/middleware.rb +12 -0
- data/lib/coinbase/staking_operation.rb +106 -5
- data/lib/coinbase/trade.rb +1 -1
- data/lib/coinbase/transfer.rb +4 -5
- data/lib/coinbase/wallet.rb +76 -0
- data/lib/coinbase.rb +2 -1
- metadata +28 -2
@@ -0,0 +1,244 @@
|
|
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.7.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module Coinbase::Client
|
17
|
+
#
|
18
|
+
class WebhookList
|
19
|
+
attr_accessor :data
|
20
|
+
|
21
|
+
# True if this list has another page of items after this one that can be fetched.
|
22
|
+
attr_accessor :has_more
|
23
|
+
|
24
|
+
# The page token to be used to fetch the next page.
|
25
|
+
attr_accessor :next_page
|
26
|
+
|
27
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
28
|
+
def self.attribute_map
|
29
|
+
{
|
30
|
+
:'data' => :'data',
|
31
|
+
:'has_more' => :'has_more',
|
32
|
+
:'next_page' => :'next_page'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns all the JSON keys this model knows about
|
37
|
+
def self.acceptable_attributes
|
38
|
+
attribute_map.values
|
39
|
+
end
|
40
|
+
|
41
|
+
# Attribute type mapping.
|
42
|
+
def self.openapi_types
|
43
|
+
{
|
44
|
+
:'data' => :'Array<Webhook>',
|
45
|
+
:'has_more' => :'Boolean',
|
46
|
+
:'next_page' => :'String'
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
# List of attributes with nullable: true
|
51
|
+
def self.openapi_nullable
|
52
|
+
Set.new([
|
53
|
+
])
|
54
|
+
end
|
55
|
+
|
56
|
+
# Initializes the object
|
57
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
58
|
+
def initialize(attributes = {})
|
59
|
+
if (!attributes.is_a?(Hash))
|
60
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::WebhookList` initialize method"
|
61
|
+
end
|
62
|
+
|
63
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
64
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
65
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
66
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::WebhookList`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
67
|
+
end
|
68
|
+
h[k.to_sym] = v
|
69
|
+
}
|
70
|
+
|
71
|
+
if attributes.key?(:'data')
|
72
|
+
if (value = attributes[:'data']).is_a?(Array)
|
73
|
+
self.data = value
|
74
|
+
end
|
75
|
+
else
|
76
|
+
self.data = nil
|
77
|
+
end
|
78
|
+
|
79
|
+
if attributes.key?(:'has_more')
|
80
|
+
self.has_more = attributes[:'has_more']
|
81
|
+
end
|
82
|
+
|
83
|
+
if attributes.key?(:'next_page')
|
84
|
+
self.next_page = attributes[:'next_page']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
89
|
+
# @return Array for valid properties with the reasons
|
90
|
+
def list_invalid_properties
|
91
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
92
|
+
invalid_properties = Array.new
|
93
|
+
if @data.nil?
|
94
|
+
invalid_properties.push('invalid value for "data", data cannot be nil.')
|
95
|
+
end
|
96
|
+
|
97
|
+
invalid_properties
|
98
|
+
end
|
99
|
+
|
100
|
+
# Check to see if the all the properties in the model are valid
|
101
|
+
# @return true if the model is valid
|
102
|
+
def valid?
|
103
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
104
|
+
return false if @data.nil?
|
105
|
+
true
|
106
|
+
end
|
107
|
+
|
108
|
+
# Checks equality by comparing each attribute.
|
109
|
+
# @param [Object] Object to be compared
|
110
|
+
def ==(o)
|
111
|
+
return true if self.equal?(o)
|
112
|
+
self.class == o.class &&
|
113
|
+
data == o.data &&
|
114
|
+
has_more == o.has_more &&
|
115
|
+
next_page == o.next_page
|
116
|
+
end
|
117
|
+
|
118
|
+
# @see the `==` method
|
119
|
+
# @param [Object] Object to be compared
|
120
|
+
def eql?(o)
|
121
|
+
self == o
|
122
|
+
end
|
123
|
+
|
124
|
+
# Calculates hash code according to all attributes.
|
125
|
+
# @return [Integer] Hash code
|
126
|
+
def hash
|
127
|
+
[data, has_more, next_page].hash
|
128
|
+
end
|
129
|
+
|
130
|
+
# Builds the object from hash
|
131
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
132
|
+
# @return [Object] Returns the model itself
|
133
|
+
def self.build_from_hash(attributes)
|
134
|
+
return nil unless attributes.is_a?(Hash)
|
135
|
+
attributes = attributes.transform_keys(&:to_sym)
|
136
|
+
transformed_hash = {}
|
137
|
+
openapi_types.each_pair do |key, type|
|
138
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
139
|
+
transformed_hash["#{key}"] = nil
|
140
|
+
elsif type =~ /\AArray<(.*)>/i
|
141
|
+
# check to ensure the input is an array given that the attribute
|
142
|
+
# is documented as an array but the input is not
|
143
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
144
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
145
|
+
end
|
146
|
+
elsif !attributes[attribute_map[key]].nil?
|
147
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
148
|
+
end
|
149
|
+
end
|
150
|
+
new(transformed_hash)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Deserializes the data based on type
|
154
|
+
# @param string type Data type
|
155
|
+
# @param string value Value to be deserialized
|
156
|
+
# @return [Object] Deserialized data
|
157
|
+
def self._deserialize(type, value)
|
158
|
+
case type.to_sym
|
159
|
+
when :Time
|
160
|
+
Time.parse(value)
|
161
|
+
when :Date
|
162
|
+
Date.parse(value)
|
163
|
+
when :String
|
164
|
+
value.to_s
|
165
|
+
when :Integer
|
166
|
+
value.to_i
|
167
|
+
when :Float
|
168
|
+
value.to_f
|
169
|
+
when :Boolean
|
170
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
171
|
+
true
|
172
|
+
else
|
173
|
+
false
|
174
|
+
end
|
175
|
+
when :Object
|
176
|
+
# generic object (usually a Hash), return directly
|
177
|
+
value
|
178
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
179
|
+
inner_type = Regexp.last_match[:inner_type]
|
180
|
+
value.map { |v| _deserialize(inner_type, v) }
|
181
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
182
|
+
k_type = Regexp.last_match[:k_type]
|
183
|
+
v_type = Regexp.last_match[:v_type]
|
184
|
+
{}.tap do |hash|
|
185
|
+
value.each do |k, v|
|
186
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
else # model
|
190
|
+
# models (e.g. Pet) or oneOf
|
191
|
+
klass = Coinbase::Client.const_get(type)
|
192
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the string representation of the object
|
197
|
+
# @return [String] String presentation of the object
|
198
|
+
def to_s
|
199
|
+
to_hash.to_s
|
200
|
+
end
|
201
|
+
|
202
|
+
# to_body is an alias to to_hash (backward compatibility)
|
203
|
+
# @return [Hash] Returns the object in the form of hash
|
204
|
+
def to_body
|
205
|
+
to_hash
|
206
|
+
end
|
207
|
+
|
208
|
+
# Returns the object in the form of hash
|
209
|
+
# @return [Hash] Returns the object in the form of hash
|
210
|
+
def to_hash
|
211
|
+
hash = {}
|
212
|
+
self.class.attribute_map.each_pair do |attr, param|
|
213
|
+
value = self.send(attr)
|
214
|
+
if value.nil?
|
215
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
216
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
217
|
+
end
|
218
|
+
|
219
|
+
hash[param] = _to_hash(value)
|
220
|
+
end
|
221
|
+
hash
|
222
|
+
end
|
223
|
+
|
224
|
+
# Outputs non-array value in the form of hash
|
225
|
+
# For object, use to_hash. Otherwise, just return the value
|
226
|
+
# @param [Object] value Any valid value
|
227
|
+
# @return [Hash] Returns the value in the form of hash
|
228
|
+
def _to_hash(value)
|
229
|
+
if value.is_a?(Array)
|
230
|
+
value.compact.map { |v| _to_hash(v) }
|
231
|
+
elsif value.is_a?(Hash)
|
232
|
+
{}.tap do |hash|
|
233
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
234
|
+
end
|
235
|
+
elsif value.respond_to? :to_hash
|
236
|
+
value.to_hash
|
237
|
+
else
|
238
|
+
value
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
data/lib/coinbase/client.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
7
|
Contact: yuga.cohler@coinbase.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
Generator version: 7.
|
9
|
+
Generator version: 7.7.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -22,15 +22,20 @@ Coinbase::Client.autoload :AddressBalanceList, 'coinbase/client/models/address_b
|
|
22
22
|
Coinbase::Client.autoload :AddressList, 'coinbase/client/models/address_list'
|
23
23
|
Coinbase::Client.autoload :Asset, 'coinbase/client/models/asset'
|
24
24
|
Coinbase::Client.autoload :Balance, 'coinbase/client/models/balance'
|
25
|
+
Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
|
25
26
|
Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
|
26
27
|
Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
|
27
28
|
Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
|
29
|
+
Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
|
30
|
+
Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
|
28
31
|
Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_address_request'
|
29
32
|
Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
|
33
|
+
Coinbase::Client.autoload :CreateStakingOperationRequest, 'coinbase/client/models/create_staking_operation_request'
|
30
34
|
Coinbase::Client.autoload :CreateTradeRequest, 'coinbase/client/models/create_trade_request'
|
31
35
|
Coinbase::Client.autoload :CreateTransferRequest, 'coinbase/client/models/create_transfer_request'
|
32
36
|
Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_wallet_request'
|
33
37
|
Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
|
38
|
+
Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
|
34
39
|
Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
|
35
40
|
Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
|
36
41
|
Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
|
@@ -62,16 +67,22 @@ Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
|
|
62
67
|
Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
|
63
68
|
Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
|
64
69
|
Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
|
70
|
+
Coinbase::Client.autoload :UpdateWebhookRequest, 'coinbase/client/models/update_webhook_request'
|
65
71
|
Coinbase::Client.autoload :User, 'coinbase/client/models/user'
|
66
72
|
Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
|
67
73
|
Coinbase::Client.autoload :ValidatorDetails, 'coinbase/client/models/validator_details'
|
68
74
|
Coinbase::Client.autoload :ValidatorList, 'coinbase/client/models/validator_list'
|
69
75
|
Coinbase::Client.autoload :Wallet, 'coinbase/client/models/wallet'
|
70
76
|
Coinbase::Client.autoload :WalletList, 'coinbase/client/models/wallet_list'
|
77
|
+
Coinbase::Client.autoload :Webhook, 'coinbase/client/models/webhook'
|
78
|
+
Coinbase::Client.autoload :WebhookEventFilter, 'coinbase/client/models/webhook_event_filter'
|
79
|
+
Coinbase::Client.autoload :WebhookEventType, 'coinbase/client/models/webhook_event_type'
|
80
|
+
Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
|
71
81
|
|
72
82
|
# APIs
|
73
83
|
Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
|
74
84
|
Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
|
85
|
+
Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
|
75
86
|
Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
|
76
87
|
Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
|
77
88
|
Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
|
@@ -80,6 +91,7 @@ Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
|
|
80
91
|
Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
|
81
92
|
Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
|
82
93
|
Coinbase::Client.autoload :WalletsApi, 'coinbase/client/api/wallets_api'
|
94
|
+
Coinbase::Client.autoload :WebhooksApi, 'coinbase/client/api/webhooks_api'
|
83
95
|
|
84
96
|
module Coinbase::Client
|
85
97
|
class << self
|
data/lib/coinbase/middleware.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'authenticator'
|
4
4
|
require_relative 'client/configuration'
|
5
5
|
require 'faraday'
|
6
|
+
require 'faraday/retry'
|
6
7
|
|
7
8
|
module Coinbase
|
8
9
|
# A module for middleware that can be used with Faraday.
|
@@ -18,6 +19,17 @@ module Coinbase
|
|
18
19
|
config.host = uri.host + (uri.port ? ":#{uri.port}" : '')
|
19
20
|
config.scheme = uri.scheme if uri.scheme
|
20
21
|
config.request(:authenticator)
|
22
|
+
retry_options = {
|
23
|
+
max: Coinbase.configuration.max_network_tries,
|
24
|
+
interval: 0.05,
|
25
|
+
interval_randomness: 0.5,
|
26
|
+
backoff_factor: 2,
|
27
|
+
methods: %i[get],
|
28
|
+
retry_statuses: [500, 502, 503, 504]
|
29
|
+
}
|
30
|
+
config.configure_faraday_connection do |conn|
|
31
|
+
conn.request :retry, retry_options
|
32
|
+
end
|
21
33
|
end
|
22
34
|
end
|
23
35
|
end
|
@@ -9,6 +9,67 @@ module Coinbase
|
|
9
9
|
class StakingOperation
|
10
10
|
attr_reader :transactions
|
11
11
|
|
12
|
+
# Builds an ephemeral staking operation this is intended to be called via an Address or Wallet.
|
13
|
+
# @param amount [BigDecimal] The amount to stake, in the primary denomination of the asset
|
14
|
+
# @param network_id [Symbol] The Network ID
|
15
|
+
# @param asset_id [Symbol] The Asset ID
|
16
|
+
# @param address_id [String] The Address ID
|
17
|
+
# @param action [Symbol] The action to perform
|
18
|
+
# @param mode [Symbol] The staking mode
|
19
|
+
# @param options [Hash] Additional options
|
20
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
21
|
+
def self.build(amount, network_id, asset_id, address_id, action, mode, options)
|
22
|
+
model = Coinbase.call_api do
|
23
|
+
asset = Coinbase::Asset.fetch(network_id, asset_id)
|
24
|
+
stake_api.build_staking_operation(
|
25
|
+
{
|
26
|
+
asset_id: asset.primary_denomination.to_s,
|
27
|
+
address_id: address_id,
|
28
|
+
action: action,
|
29
|
+
network_id: Coinbase.normalize_network(network_id),
|
30
|
+
options: {
|
31
|
+
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
32
|
+
mode: mode
|
33
|
+
}.merge(options)
|
34
|
+
}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
new(model)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates a persisted staking operation this is intended to be called via an Address or Wallet.
|
42
|
+
# @param amount [BigDecimal] The amount to stake, in the primary denomination of the asset
|
43
|
+
# @param network_id [Symbol] The Network ID
|
44
|
+
# @param asset_id [Symbol] The Asset ID
|
45
|
+
# @param address_id [String] The Address ID
|
46
|
+
# @param wallet_id [String] The Wallet ID
|
47
|
+
# @param action [Symbol] The action to perform
|
48
|
+
# @param mode [Symbol] The staking mode
|
49
|
+
# @param options [Hash] Additional options
|
50
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
51
|
+
def self.create(amount, network_id, asset_id, address_id, wallet_id, action, mode, options)
|
52
|
+
model = Coinbase.call_api do
|
53
|
+
asset = Coinbase::Asset.fetch(network_id, asset_id)
|
54
|
+
stake_api.create_staking_operation(
|
55
|
+
wallet_id,
|
56
|
+
address_id,
|
57
|
+
{
|
58
|
+
asset_id: asset.primary_denomination.to_s,
|
59
|
+
address_id: address_id,
|
60
|
+
action: action,
|
61
|
+
network_id: Coinbase.normalize_network(network_id),
|
62
|
+
options: {
|
63
|
+
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
64
|
+
mode: mode
|
65
|
+
}.merge(options)
|
66
|
+
}
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
new(model)
|
71
|
+
end
|
72
|
+
|
12
73
|
# Returns a new StakingOperation object.
|
13
74
|
# @param model [Coinbase::Client::StakingOperation] The underlying StakingOperation object
|
14
75
|
def initialize(model)
|
@@ -39,6 +100,12 @@ module Coinbase
|
|
39
100
|
@model.status
|
40
101
|
end
|
41
102
|
|
103
|
+
# Returns the Wallet ID of the Staking Operation.
|
104
|
+
# @return [String] The Wallet ID
|
105
|
+
def wallet_id
|
106
|
+
@model.wallet_id
|
107
|
+
end
|
108
|
+
|
42
109
|
# Waits until the Staking Operation is completed or failed by polling its status at the given interval. Raises a
|
43
110
|
# Timeout::Error if the Staking Operation takes longer than the given timeout.
|
44
111
|
# @param interval_seconds [Integer] The interval at which to poll, in seconds
|
@@ -66,13 +133,18 @@ module Coinbase
|
|
66
133
|
# @param network_id [Symbol] The Network ID
|
67
134
|
# @param address_id [Symbol] The Address ID
|
68
135
|
# @param id [String] The ID of the StakingOperation
|
136
|
+
# @param wallet_id [String] The optional Wallet ID
|
69
137
|
# @return [Coinbase::StakingOperation] The staking operation
|
70
|
-
def self.fetch(network_id, address_id, id)
|
138
|
+
def self.fetch(network_id, address_id, id, wallet_id: nil)
|
71
139
|
staking_operation_model = Coinbase.call_api do
|
72
|
-
|
140
|
+
if wallet_id.nil?
|
141
|
+
stake_api.get_external_staking_operation(network_id, address_id, id)
|
142
|
+
else
|
143
|
+
stake_api.get_staking_operation(wallet_id, address_id, id)
|
144
|
+
end
|
73
145
|
end
|
74
146
|
|
75
|
-
|
147
|
+
new(staking_operation_model)
|
76
148
|
end
|
77
149
|
|
78
150
|
# Signs the Open Transactions with the provided key
|
@@ -87,7 +159,11 @@ module Coinbase
|
|
87
159
|
# @return [Coinbase::StakingOperation] The updated staking operation
|
88
160
|
def reload
|
89
161
|
@model = Coinbase.call_api do
|
90
|
-
|
162
|
+
if wallet_id.nil?
|
163
|
+
stake_api.get_external_staking_operation(network_id, address_id, id)
|
164
|
+
else
|
165
|
+
stake_api.get_staking_operation(wallet_id, address_id, id)
|
166
|
+
end
|
91
167
|
end
|
92
168
|
|
93
169
|
from_model(@model)
|
@@ -108,10 +184,33 @@ module Coinbase
|
|
108
184
|
signed_voluntary_exit_messages
|
109
185
|
end
|
110
186
|
|
187
|
+
# Broadcasts the Staking Operation transactions to the network
|
188
|
+
# @return [Coinbase::StakingOperation]
|
189
|
+
def broadcast!
|
190
|
+
transactions.each_with_index do |transaction, i|
|
191
|
+
raise TransactionNotSignedError unless transaction.signed?
|
192
|
+
|
193
|
+
Coinbase.call_api do
|
194
|
+
stake_api.broadcast_staking_operation(
|
195
|
+
wallet_id,
|
196
|
+
address_id,
|
197
|
+
id,
|
198
|
+
{ signed_payload: transaction.raw.hex, transaction_index: i }
|
199
|
+
)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
self
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.stake_api
|
207
|
+
Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
208
|
+
end
|
209
|
+
|
111
210
|
private
|
112
211
|
|
113
212
|
def stake_api
|
114
|
-
@stake_api ||=
|
213
|
+
@stake_api ||= self.class.stake_api
|
115
214
|
end
|
116
215
|
|
117
216
|
def from_model(model)
|
@@ -120,6 +219,8 @@ module Coinbase
|
|
120
219
|
@transactions = model.transactions.map do |transaction_model|
|
121
220
|
Transaction.new(transaction_model)
|
122
221
|
end
|
222
|
+
|
223
|
+
self
|
123
224
|
end
|
124
225
|
end
|
125
226
|
end
|
data/lib/coinbase/trade.rb
CHANGED
@@ -147,7 +147,7 @@ module Coinbase
|
|
147
147
|
|
148
148
|
payloads = { signed_payload: transaction.raw.hex }
|
149
149
|
|
150
|
-
payloads[:
|
150
|
+
payloads[:approve_transaction_signed_payload] = approve_transaction.raw.hex unless approve_transaction.nil?
|
151
151
|
|
152
152
|
@model = Coinbase.call_api do
|
153
153
|
trades_api.broadcast_trade(wallet_id, address_id, id, payloads)
|
data/lib/coinbase/transfer.rb
CHANGED
@@ -125,20 +125,19 @@ module Coinbase
|
|
125
125
|
# Returns the link to the transaction on the blockchain explorer.
|
126
126
|
# @return [String] The link to the transaction on the blockchain explorer
|
127
127
|
def transaction_link
|
128
|
-
|
129
|
-
"https://sepolia.basescan.org/tx/#{transaction_hash}"
|
128
|
+
transaction.transaction_link
|
130
129
|
end
|
131
130
|
|
132
131
|
# Returns the Unsigned Payload of the Transfer.
|
133
132
|
# @return [String] The Unsigned Payload
|
134
133
|
def unsigned_payload
|
135
|
-
|
134
|
+
transaction.unsigned_payload
|
136
135
|
end
|
137
136
|
|
138
137
|
# Returns the Signed Payload of the Transfer.
|
139
138
|
# @return [String] The Signed Payload
|
140
139
|
def signed_payload
|
141
|
-
|
140
|
+
transaction.signed_payload
|
142
141
|
end
|
143
142
|
|
144
143
|
# Returns the Transfer transaction.
|
@@ -150,7 +149,7 @@ module Coinbase
|
|
150
149
|
# Returns the Transaction Hash of the Transfer.
|
151
150
|
# @return [String] The Transaction Hash
|
152
151
|
def transaction_hash
|
153
|
-
|
152
|
+
transaction.transaction_hash
|
154
153
|
end
|
155
154
|
|
156
155
|
# Returns the status of the Transfer.
|
data/lib/coinbase/wallet.rb
CHANGED
@@ -294,6 +294,82 @@ module Coinbase
|
|
294
294
|
default_address.trade(amount, from_asset_id, to_asset_id)
|
295
295
|
end
|
296
296
|
|
297
|
+
# Stakes the given amount of the given Asset.
|
298
|
+
# Currently only the default_address is used to source the Stake.
|
299
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to stake.
|
300
|
+
# @param asset_id [Symbol] The ID of the Asset to stake.
|
301
|
+
# @param mode [Symbol] (Optional) The staking mode. Defaults to :default.
|
302
|
+
# @param options [Hash] (Optional) Additional options for the staking operation.
|
303
|
+
# @return [Coinbase::StakingOperation] The stake operation
|
304
|
+
def stake(amount, asset_id, mode: :default, options: {})
|
305
|
+
default_address.stake(amount, asset_id, mode: mode, options: options)
|
306
|
+
end
|
307
|
+
|
308
|
+
# Unstakes the given amount of the given Asset.
|
309
|
+
# Currently only the default_address is used to source the Unstake.
|
310
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to unstake.
|
311
|
+
# @param asset_id [Symbol] The ID of the Asset to unstake.
|
312
|
+
# @param mode [Symbol] (Optional) The staking mode. Defaults to :default.
|
313
|
+
# @param options [Hash] (Optional) Additional options for the unstaking operation.
|
314
|
+
# @return [Coinbase::StakingOperation] The unstake operation
|
315
|
+
def unstake(amount, asset_id, mode: :default, options: {})
|
316
|
+
default_address.unstake(amount, asset_id, mode: mode, options: options)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Claims stake of the given amount of the given Asset.
|
320
|
+
# Currently only the default_address is used as the source for claim_stake.
|
321
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to claim_stake.
|
322
|
+
# @param asset_id [Symbol] The ID of the Asset to claim_stake.
|
323
|
+
# @param mode [Symbol] (Optional) The staking mode. Defaults to :default.
|
324
|
+
# @param options [Hash] (Optional) Additional options for the unstaking operation.
|
325
|
+
# @return [Coinbase::StakingOperation] The claim_stake operation
|
326
|
+
def claim_stake(amount, asset_id, mode: :default, options: {})
|
327
|
+
default_address.claim_stake(amount, asset_id, mode: mode, options: options)
|
328
|
+
end
|
329
|
+
|
330
|
+
# Retrieves the balances used for staking for the supplied asset.
|
331
|
+
# Currently only the default_address is used to source the staking balances.
|
332
|
+
# @param asset_id [Symbol] The asset to retrieve staking balances for
|
333
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
334
|
+
# @param options [Hash] Additional options for the staking operation
|
335
|
+
# @return [Hash] The staking balances
|
336
|
+
# @return [BigDecimal] :stakeable_balance The amount of the asset that can be staked
|
337
|
+
# @return [BigDecimal] :unstakeable_balance The amount of the asset that is currently staked and cannot be unstaked
|
338
|
+
# @return [BigDecimal] :claimable_balance The amount of the asset that can be claimed
|
339
|
+
def staking_balances(asset_id, mode: :default, options: {})
|
340
|
+
default_address.staking_balances(asset_id, mode: mode, options: options)
|
341
|
+
end
|
342
|
+
|
343
|
+
# Retrieves the stakeable balance for the supplied asset.
|
344
|
+
# Currently only the default_address is used to source the stakeable balance.
|
345
|
+
# @param asset_id [Symbol] The asset to retrieve the stakeable balance for
|
346
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
347
|
+
# @param options [Hash] Additional options for the staking operation
|
348
|
+
# @return [BigDecimal] The stakeable balance
|
349
|
+
def stakeable_balance(asset_id, mode: :default, options: {})
|
350
|
+
default_address.stakeable_balance(asset_id, mode: mode, options: options)
|
351
|
+
end
|
352
|
+
|
353
|
+
# Retrieves the unstakeable balance for the supplied asset.
|
354
|
+
# Currently only the default_address is used to source the unstakeable balance.
|
355
|
+
# @param asset_id [Symbol] The asset to retrieve the unstakeable balance for
|
356
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
357
|
+
# @param options [Hash] Additional options for the staking operation
|
358
|
+
# @return [BigDecimal] The unstakeable balance
|
359
|
+
def unstakeable_balance(asset_id, mode: :default, options: {})
|
360
|
+
default_address.unstakeable_balance(asset_id, mode: mode, options: options)
|
361
|
+
end
|
362
|
+
|
363
|
+
# Retrieves the claimable balance for the supplied asset.
|
364
|
+
# Currently only the default_address is used to source the claimable balance.
|
365
|
+
# @param asset_id [Symbol] The asset to retrieve the claimable balance for
|
366
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
367
|
+
# @param options [Hash] Additional options for the staking operation
|
368
|
+
# @return [BigDecimal] The claimable balance
|
369
|
+
def claimable_balance(asset_id, mode: :default, options: {})
|
370
|
+
default_address.claimable_balance(asset_id, mode: mode, options: options)
|
371
|
+
end
|
372
|
+
|
297
373
|
# Exports the Wallet's data to a Data object.
|
298
374
|
# @return [Data] The Wallet data
|
299
375
|
def export
|
data/lib/coinbase.rb
CHANGED
@@ -62,13 +62,14 @@ module Coinbase
|
|
62
62
|
|
63
63
|
# Configuration object for the Coinbase SDK.
|
64
64
|
class Configuration
|
65
|
-
attr_accessor :api_url, :api_key_name, :api_key_private_key, :debug_api, :use_server_signer
|
65
|
+
attr_accessor :api_url, :api_key_name, :api_key_private_key, :debug_api, :use_server_signer, :max_network_tries
|
66
66
|
|
67
67
|
# Initializes the configuration object.
|
68
68
|
def initialize
|
69
69
|
@api_url = 'https://api.cdp.coinbase.com'
|
70
70
|
@debug_api = false
|
71
71
|
@use_server_signer = false
|
72
|
+
@max_network_tries = 3
|
72
73
|
end
|
73
74
|
|
74
75
|
# Sets configuration values based on the provided CDP API Key JSON file.
|