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
@@ -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.6.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
@@ -19,27 +19,35 @@ require 'coinbase/client/configuration'
19
19
  # Models
20
20
  Coinbase::Client.autoload :Address, 'coinbase/client/models/address'
21
21
  Coinbase::Client.autoload :AddressBalanceList, 'coinbase/client/models/address_balance_list'
22
+ Coinbase::Client.autoload :AddressHistoricalBalanceList, 'coinbase/client/models/address_historical_balance_list'
22
23
  Coinbase::Client.autoload :AddressList, 'coinbase/client/models/address_list'
23
24
  Coinbase::Client.autoload :Asset, 'coinbase/client/models/asset'
24
25
  Coinbase::Client.autoload :Balance, 'coinbase/client/models/balance'
26
+ Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
25
27
  Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
26
28
  Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
27
29
  Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
30
+ Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
31
+ Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
28
32
  Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_address_request'
29
33
  Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
34
+ Coinbase::Client.autoload :CreateStakingOperationRequest, 'coinbase/client/models/create_staking_operation_request'
30
35
  Coinbase::Client.autoload :CreateTradeRequest, 'coinbase/client/models/create_trade_request'
31
36
  Coinbase::Client.autoload :CreateTransferRequest, 'coinbase/client/models/create_transfer_request'
32
37
  Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_wallet_request'
33
38
  Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
39
+ Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
34
40
  Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
35
41
  Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
36
42
  Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
37
- Coinbase::Client.autoload :Feature, 'coinbase/client/models/feature'
43
+ Coinbase::Client.autoload :FeatureSet, 'coinbase/client/models/feature_set'
44
+ Coinbase::Client.autoload :FetchHistoricalStakingBalances200Response, 'coinbase/client/models/fetch_historical_staking_balances200_response'
38
45
  Coinbase::Client.autoload :FetchStakingRewards200Response, 'coinbase/client/models/fetch_staking_rewards200_response'
39
46
  Coinbase::Client.autoload :FetchStakingRewardsRequest, 'coinbase/client/models/fetch_staking_rewards_request'
40
47
  Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get_staking_context_request'
41
- Coinbase::Client.autoload :NativeEthStakingContext, 'coinbase/client/models/native_eth_staking_context'
42
- Coinbase::Client.autoload :PartialEthStakingContext, 'coinbase/client/models/partial_eth_staking_context'
48
+ Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
49
+ Coinbase::Client.autoload :Network, 'coinbase/client/models/network'
50
+ Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
43
51
  Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
44
52
  Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
45
53
  Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
@@ -50,29 +58,39 @@ Coinbase::Client.autoload :ServerSignerList, 'coinbase/client/models/server_sign
50
58
  Coinbase::Client.autoload :SignatureCreationEvent, 'coinbase/client/models/signature_creation_event'
51
59
  Coinbase::Client.autoload :SignatureCreationEventResult, 'coinbase/client/models/signature_creation_event_result'
52
60
  Coinbase::Client.autoload :SignedVoluntaryExitMessageMetadata, 'coinbase/client/models/signed_voluntary_exit_message_metadata'
61
+ Coinbase::Client.autoload :SponsoredSend, 'coinbase/client/models/sponsored_send'
62
+ Coinbase::Client.autoload :StakingBalance, 'coinbase/client/models/staking_balance'
53
63
  Coinbase::Client.autoload :StakingContext, 'coinbase/client/models/staking_context'
54
64
  Coinbase::Client.autoload :StakingContextContext, 'coinbase/client/models/staking_context_context'
55
65
  Coinbase::Client.autoload :StakingOperation, 'coinbase/client/models/staking_operation'
56
66
  Coinbase::Client.autoload :StakingOperationMetadata, 'coinbase/client/models/staking_operation_metadata'
57
67
  Coinbase::Client.autoload :StakingReward, 'coinbase/client/models/staking_reward'
58
68
  Coinbase::Client.autoload :StakingRewardFormat, 'coinbase/client/models/staking_reward_format'
69
+ Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/staking_reward_usd_value'
59
70
  Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
60
71
  Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
61
72
  Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
62
73
  Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
63
74
  Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
64
75
  Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
76
+ Coinbase::Client.autoload :UpdateWebhookRequest, 'coinbase/client/models/update_webhook_request'
65
77
  Coinbase::Client.autoload :User, 'coinbase/client/models/user'
66
78
  Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
67
79
  Coinbase::Client.autoload :ValidatorDetails, 'coinbase/client/models/validator_details'
68
80
  Coinbase::Client.autoload :ValidatorList, 'coinbase/client/models/validator_list'
69
81
  Coinbase::Client.autoload :Wallet, 'coinbase/client/models/wallet'
70
82
  Coinbase::Client.autoload :WalletList, 'coinbase/client/models/wallet_list'
83
+ Coinbase::Client.autoload :Webhook, 'coinbase/client/models/webhook'
84
+ Coinbase::Client.autoload :WebhookEventFilter, 'coinbase/client/models/webhook_event_filter'
85
+ Coinbase::Client.autoload :WebhookEventType, 'coinbase/client/models/webhook_event_type'
86
+ Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
71
87
 
72
88
  # APIs
73
89
  Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
74
90
  Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
91
+ Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
75
92
  Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
93
+ Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
76
94
  Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
77
95
  Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
78
96
  Coinbase::Client.autoload :TradesApi, 'coinbase/client/api/trades_api'
@@ -80,6 +98,7 @@ Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
80
98
  Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
81
99
  Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
82
100
  Coinbase::Client.autoload :WalletsApi, 'coinbase/client/api/wallets_api'
101
+ Coinbase::Client.autoload :WebhooksApi, 'coinbase/client/api/webhooks_api'
83
102
 
84
103
  module Coinbase::Client
85
104
  class << self
@@ -63,6 +63,13 @@ module Coinbase
63
63
  end
64
64
  end
65
65
 
66
+ # An error raised when a resource is already signed.
67
+ class AlreadySignedError < StandardError
68
+ def initialize(msg = 'Resource already signed')
69
+ super(msg)
70
+ end
71
+ end
72
+
66
73
  # An error raised when a transaction is not signed.
67
74
  class TransactionNotSignedError < StandardError
68
75
  def initialize(msg = 'Transaction must be signed')
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # A representation of an HistoricalBalance.
5
+ class HistoricalBalance
6
+ # Converts a Coinbase::Client::HistoricalBalance model to a Coinbase::HistoricalBalance
7
+ # @param historical_balance_model [Coinbase::Client::HistoricalBalance] The historical balance fetched from the API.
8
+ # @return [HistoricalBalance] The converted HistoricalBalance object.
9
+ def self.from_model(historical_balance_model)
10
+ asset = Coinbase::Asset.from_model(historical_balance_model.asset)
11
+
12
+ new(
13
+ amount: asset.from_atomic_amount(historical_balance_model.amount),
14
+ block_height: BigDecimal(historical_balance_model.block_height),
15
+ block_hash: historical_balance_model.block_hash,
16
+ asset: asset
17
+ )
18
+ end
19
+
20
+ # Returns a new HistoricalBalance object. Do not use this method. Instead, use Balance.from_model or
21
+ # Balance.from_model_and_asset_id.
22
+ # @param amount [BigDecimal] The amount of the Asset
23
+ # @param block_height [BigDecimal] The block height at which the balance was recorded
24
+ # @param block_hash [String] The block hash at which the balance was recorded
25
+ # @param asset [Asset] The asset we want to fetch
26
+ def initialize(amount:, block_height:, block_hash:, asset:)
27
+ @amount = amount
28
+ @block_height = block_height
29
+ @block_hash = block_hash
30
+ @asset = asset
31
+ end
32
+
33
+ attr_reader :amount, :block_height, :block_hash, :asset
34
+
35
+ # Returns a string representation of the HistoricalBalance.
36
+ # @return [String] a string representation of the HistoricalBalance
37
+ def to_s
38
+ Coinbase.pretty_print_object(
39
+ self.class,
40
+ amount: amount.to_i,
41
+ block_height: block_height.to_i,
42
+ block_hash: block_hash,
43
+ asset: asset
44
+ )
45
+ end
46
+
47
+ # Same as to_s.
48
+ # @return [String] a string representation of the HistoricalBalance
49
+ def inspect
50
+ to_s
51
+ end
52
+ end
53
+ end
@@ -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
@@ -5,9 +5,15 @@ require_relative 'client'
5
5
  module Coinbase
6
6
  # A representation of a Server-Signer. Server-Signers are assigned to sign transactions for a Wallet.
7
7
  class ServerSigner
8
- # Returns a new Server-Signer object. Do not use this method directly. Instead, use ServerSigner.default.
9
- def initialize(model)
10
- @model = model
8
+ # A representation of ServerSigner status in a Wallet.
9
+ module Status
10
+ # The Wallet is awaiting seed creation by the ServerSigner. At this point,
11
+ # the Wallet cannot create addresses or sign transactions.
12
+ PENDING = 'pending_seed_creation'
13
+
14
+ # The Wallet has an associated seed created by the ServerSigner. It is ready
15
+ # to create addresses and sign transactions.
16
+ ACTIVE = 'active_seed'
11
17
  end
12
18
 
13
19
  class << self
@@ -30,6 +36,11 @@ module Coinbase
30
36
  end
31
37
  end
32
38
 
39
+ # Returns a new Server-Signer object. Do not use this method directly. Instead, use ServerSigner.default.
40
+ def initialize(model)
41
+ @model = model
42
+ end
43
+
33
44
  # Returns the Server-Signer ID.
34
45
  # @return [String] the Server-Signer ID
35
46
  def id
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eth'
4
+
5
+ module Coinbase
6
+ # A representation of an onchain Sponsored Send.
7
+ # Sponsored Sends should be constructed via higher level abstractions like Transfer.
8
+ class SponsoredSend
9
+ # A representation of a Transaction status.
10
+ module Status
11
+ # The SponsoredSend is awaiting being signed.
12
+ PENDING = 'pending'
13
+
14
+ # The Sponsored Send has been signed, but has not been submitted to be
15
+ # built into a transaction yet.
16
+ SIGNED = 'signed'
17
+
18
+ # The Sponsored Send has been submitted to be built into a transaction,
19
+ # that the sponsor will sign and submit to the network.
20
+ # At this point, transaction hashes may not yet be assigned.
21
+ SUBMITTED = 'submitted'
22
+
23
+ # The Sponsored Send's corresponding transaction is complete and has
24
+ # confirmed on the Network.
25
+ COMPLETE = 'complete'
26
+
27
+ # The Sponsored Send has failed for some reason.
28
+ FAILED = 'failed'
29
+
30
+ # The states that are considered terminal on-chain.
31
+ TERMINAL_STATES = [COMPLETE, FAILED].freeze
32
+ end
33
+
34
+ # Returns a new SponsoredSend object. Do not use this method directly.
35
+ # @param model [Coinbase::Client::SponsoredSend] The underlying SponsoredSend object
36
+ def initialize(model)
37
+ raise unless model.is_a?(Coinbase::Client::SponsoredSend)
38
+
39
+ @model = model
40
+ end
41
+
42
+ # Returns the Keccak256 hash of the typed data. This payload must be signed
43
+ # by the sender to be used as an approval in the EIP-3009 transaction.
44
+ # @return [String] The Keccak256 hash of the typed data
45
+ def typed_data_hash
46
+ @model.typed_data_hash
47
+ end
48
+
49
+ # Returns the signature of the typed data.
50
+ def signature
51
+ @signature ||= @model.signature
52
+ end
53
+
54
+ # Signs the Transaction with the provided key and returns the hex signing payload.
55
+ # @return [String] The hex-encoded signed payload
56
+ def sign(key)
57
+ raise unless key.is_a?(Eth::Key)
58
+ raise Coinbase::AlreadySignedError if signed?
59
+
60
+ @signature = Eth::Util.prefix_hex(key.sign(Eth::Util.hex_to_bin(typed_data_hash)))
61
+ end
62
+
63
+ # Returns whether the Transaction has been signed.
64
+ # @return [Boolean] Whether the Transaction has been signed
65
+ def signed?
66
+ !signature.nil?
67
+ end
68
+
69
+ # Returns the status of the Transaction.
70
+ # @return [Symbol] The status
71
+ def status
72
+ @model.status
73
+ end
74
+
75
+ # Returns whether the Sponsored Send is in a terminal state.
76
+ # @return [Boolean] Whether the Transaction is in a terminal state
77
+ def terminal_state?
78
+ Status::TERMINAL_STATES.include?(status)
79
+ end
80
+
81
+ # Returns the Transaction Hash of the Transaction.
82
+ # @return [String] The Transaction Hash
83
+ def transaction_hash
84
+ @model.transaction_hash
85
+ end
86
+
87
+ # Returns the link to the transaction on the blockchain explorer.
88
+ # @return [String] The link to the transaction on the blockchain explorer
89
+ def transaction_link
90
+ @model.transaction_link
91
+ end
92
+
93
+ # Returns a String representation of the SponsoredSend.
94
+ # @return [String] a String representation of the SponsoredSend
95
+ def to_s
96
+ Coinbase.pretty_print_object(
97
+ self.class,
98
+ status: status,
99
+ transaction_hash: transaction_hash,
100
+ transaction_link: transaction_link
101
+ )
102
+ end
103
+
104
+ # Same as to_s.
105
+ # @return [String] a String representation of the SponsoredSend
106
+ def inspect
107
+ to_s
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Coinbase
6
+ # A representation of a staking balance on a network for a given asset.
7
+ class StakingBalance
8
+ # Returns a list of StakingBalance for the provided network, asset, and addresses.
9
+ # @param network_id [Symbol] The network ID
10
+ # @param asset_id [Symbol] The asset ID
11
+ # @param address_id [String] The address ID
12
+ # @param start_time [Time] The start time. Defaults to one month ago.
13
+ # @param end_time [Time] The end time. Defaults to the current time.
14
+ # @return [Enumerable<Coinbase::StakingBalance>] The staking balances
15
+ def self.list(network_id, asset_id, address_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now)
16
+ Coinbase::Pagination.enumerate(
17
+ ->(page) { list_page(network_id, asset_id, address_id, start_time, end_time, page) }
18
+ ) do |staking_balance|
19
+ new(staking_balance)
20
+ end
21
+ end
22
+
23
+ # Returns a new StakingBalance object.
24
+ # @param model [Coinbase::Client::StakingBalance] The underlying StakingBalance object
25
+ def initialize(model)
26
+ @model = model
27
+ end
28
+
29
+ # Returns the date of the StakingBalance.
30
+ # @return [Time] The date
31
+ def date
32
+ @model.date
33
+ end
34
+
35
+ # Returns the onchain address of the StakingBalance.
36
+ # @return [Time] The onchain address
37
+ def address
38
+ @model.address
39
+ end
40
+
41
+ # Returns the bonded stake as a Balance
42
+ # @return [Balance] The bonded stake
43
+ def bonded_stake
44
+ @bonded_stake ||= Balance.from_model(@model.bonded_stake)
45
+ end
46
+
47
+ # Returns the unbonded balance as a Balance
48
+ # @return [Balance] The unbonded balance
49
+ def unbonded_balance
50
+ @unbonded_balance ||= Balance.from_model(@model.unbonded_balance)
51
+ end
52
+
53
+ # Returns the participant type of the StakingBalance.
54
+ # @return [String] The participant type
55
+ def participant_type
56
+ @model.participant_type
57
+ end
58
+
59
+ # Returns a string representation of the StakingBalance.
60
+ # @return [String] a string representation of the StakingBalance
61
+ def to_s
62
+ "Coinbase::StakingBalance{date: '#{date}' address: '#{address}'}"
63
+ end
64
+
65
+ # Same as to_s.
66
+ # @return [String] a string representation of the StakingBalance
67
+ def inspect
68
+ to_s
69
+ end
70
+
71
+ def self.stake_api
72
+ Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
73
+ end
74
+
75
+ def self.list_page(network_id, asset_id, address_id, start_time, end_time, page)
76
+ stake_api.fetch_historical_staking_balances(
77
+ Coinbase.normalize_network(network_id),
78
+ asset_id,
79
+ address_id,
80
+ start_time.iso8601,
81
+ end_time.iso8601,
82
+ { next_page: page }
83
+ )
84
+ end
85
+ end
86
+ end