coinbase-sdk 0.0.14 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +31 -21
  3. data/lib/coinbase/address.rb +51 -17
  4. data/lib/coinbase/asset.rb +11 -8
  5. data/lib/coinbase/client/api/contract_events_api.rb +17 -9
  6. data/lib/coinbase/client/api/external_addresses_api.rb +85 -0
  7. data/lib/coinbase/client/api/networks_api.rb +85 -0
  8. data/lib/coinbase/client/api/stake_api.rb +74 -195
  9. data/lib/coinbase/client/api/validators_api.rb +2 -2
  10. data/lib/coinbase/client/api/wallet_stake_api.rb +263 -0
  11. data/lib/coinbase/client/models/address.rb +21 -4
  12. data/lib/coinbase/client/models/{native_eth_staking_context.rb → address_historical_balance_list.rb} +39 -35
  13. data/lib/coinbase/client/models/contract_event.rb +99 -8
  14. data/lib/coinbase/client/models/create_address_request.rb +14 -4
  15. data/lib/coinbase/client/models/create_transfer_request.rb +14 -4
  16. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +11 -11
  17. data/lib/coinbase/client/models/feature.rb +2 -1
  18. data/lib/coinbase/client/models/feature_set.rb +307 -0
  19. data/lib/coinbase/client/models/{partial_eth_staking_context.rb → fetch_historical_staking_balances200_response.rb} +39 -35
  20. data/lib/coinbase/client/models/historical_balance.rb +273 -0
  21. data/lib/coinbase/client/models/network.rb +365 -0
  22. data/lib/coinbase/client/models/network_identifier.rb +44 -0
  23. data/lib/coinbase/client/models/sponsored_send.rb +338 -0
  24. data/lib/coinbase/client/models/staking_balance.rb +289 -0
  25. data/lib/coinbase/client/models/staking_context_context.rb +222 -74
  26. data/lib/coinbase/client/models/staking_operation.rb +2 -2
  27. data/lib/coinbase/client/models/staking_reward.rb +22 -6
  28. data/lib/coinbase/client/models/staking_reward_format.rb +2 -1
  29. data/lib/coinbase/client/models/staking_reward_usd_value.rb +257 -0
  30. data/lib/coinbase/client/models/transaction.rb +17 -7
  31. data/lib/coinbase/client/models/transaction_type.rb +2 -1
  32. data/lib/coinbase/client/models/transfer.rb +101 -8
  33. data/lib/coinbase/client/models/validator.rb +23 -2
  34. data/lib/coinbase/client/models/validator_status.rb +52 -0
  35. data/lib/coinbase/client/models/wallet.rb +13 -16
  36. data/lib/coinbase/client/models/webhook_event_type.rb +2 -1
  37. data/lib/coinbase/client.rb +12 -3
  38. data/lib/coinbase/constants.rb +0 -10
  39. data/lib/coinbase/contract_event.rb +104 -0
  40. data/lib/coinbase/correlation.rb +30 -0
  41. data/lib/coinbase/destination.rb +11 -9
  42. data/lib/coinbase/errors.rb +14 -0
  43. data/lib/coinbase/historical_balance.rb +53 -0
  44. data/lib/coinbase/middleware.rb +2 -0
  45. data/lib/coinbase/network.rb +103 -20
  46. data/lib/coinbase/server_signer.rb +14 -3
  47. data/lib/coinbase/smart_contract.rb +106 -0
  48. data/lib/coinbase/sponsored_send.rb +110 -0
  49. data/lib/coinbase/staking_balance.rb +92 -0
  50. data/lib/coinbase/staking_operation.rb +134 -36
  51. data/lib/coinbase/staking_reward.rb +18 -0
  52. data/lib/coinbase/trade.rb +10 -9
  53. data/lib/coinbase/transaction.rb +13 -3
  54. data/lib/coinbase/transfer.rb +65 -36
  55. data/lib/coinbase/validator.rb +18 -10
  56. data/lib/coinbase/version.rb +5 -0
  57. data/lib/coinbase/wallet/data.rb +31 -0
  58. data/lib/coinbase/wallet.rb +143 -182
  59. data/lib/coinbase/webhook.rb +181 -0
  60. data/lib/coinbase.rb +64 -21
  61. metadata +51 -5
  62. data/lib/coinbase/user.rb +0 -65
@@ -23,8 +23,7 @@ module Coinbase::Client
23
23
 
24
24
  attr_accessor :default_address
25
25
 
26
- # The features enabled for the wallet
27
- attr_accessor :enabled_features
26
+ attr_accessor :feature_set
28
27
 
29
28
  # The status of the Server-Signer for the wallet if present.
30
29
  attr_accessor :server_signer_status
@@ -57,7 +56,7 @@ module Coinbase::Client
57
56
  :'id' => :'id',
58
57
  :'network_id' => :'network_id',
59
58
  :'default_address' => :'default_address',
60
- :'enabled_features' => :'enabled_features',
59
+ :'feature_set' => :'feature_set',
61
60
  :'server_signer_status' => :'server_signer_status'
62
61
  }
63
62
  end
@@ -73,7 +72,7 @@ module Coinbase::Client
73
72
  :'id' => :'String',
74
73
  :'network_id' => :'String',
75
74
  :'default_address' => :'Address',
76
- :'enabled_features' => :'Array<Feature>',
75
+ :'feature_set' => :'FeatureSet',
77
76
  :'server_signer_status' => :'String'
78
77
  }
79
78
  end
@@ -115,12 +114,10 @@ module Coinbase::Client
115
114
  self.default_address = attributes[:'default_address']
116
115
  end
117
116
 
118
- if attributes.key?(:'enabled_features')
119
- if (value = attributes[:'enabled_features']).is_a?(Array)
120
- self.enabled_features = value
121
- end
117
+ if attributes.key?(:'feature_set')
118
+ self.feature_set = attributes[:'feature_set']
122
119
  else
123
- self.enabled_features = nil
120
+ self.feature_set = nil
124
121
  end
125
122
 
126
123
  if attributes.key?(:'server_signer_status')
@@ -141,8 +138,8 @@ module Coinbase::Client
141
138
  invalid_properties.push('invalid value for "network_id", network_id cannot be nil.')
142
139
  end
143
140
 
144
- if @enabled_features.nil?
145
- invalid_properties.push('invalid value for "enabled_features", enabled_features cannot be nil.')
141
+ if @feature_set.nil?
142
+ invalid_properties.push('invalid value for "feature_set", feature_set cannot be nil.')
146
143
  end
147
144
 
148
145
  invalid_properties
@@ -154,8 +151,8 @@ module Coinbase::Client
154
151
  warn '[DEPRECATED] the `valid?` method is obsolete'
155
152
  return false if @id.nil?
156
153
  return false if @network_id.nil?
157
- return false if @enabled_features.nil?
158
- server_signer_status_validator = EnumAttributeValidator.new('String', ["pending_seed_creation", "active_seed"])
154
+ return false if @feature_set.nil?
155
+ server_signer_status_validator = EnumAttributeValidator.new('String', ["pending_seed_creation", "active_seed", "unknown_default_open_api"])
159
156
  return false unless server_signer_status_validator.valid?(@server_signer_status)
160
157
  true
161
158
  end
@@ -163,7 +160,7 @@ module Coinbase::Client
163
160
  # Custom attribute writer method checking allowed values (enum).
164
161
  # @param [Object] server_signer_status Object to be assigned
165
162
  def server_signer_status=(server_signer_status)
166
- validator = EnumAttributeValidator.new('String', ["pending_seed_creation", "active_seed"])
163
+ validator = EnumAttributeValidator.new('String', ["pending_seed_creation", "active_seed", "unknown_default_open_api"])
167
164
  unless validator.valid?(server_signer_status)
168
165
  fail ArgumentError, "invalid value for \"server_signer_status\", must be one of #{validator.allowable_values}."
169
166
  end
@@ -178,7 +175,7 @@ module Coinbase::Client
178
175
  id == o.id &&
179
176
  network_id == o.network_id &&
180
177
  default_address == o.default_address &&
181
- enabled_features == o.enabled_features &&
178
+ feature_set == o.feature_set &&
182
179
  server_signer_status == o.server_signer_status
183
180
  end
184
181
 
@@ -191,7 +188,7 @@ module Coinbase::Client
191
188
  # Calculates hash code according to all attributes.
192
189
  # @return [Integer] Hash code
193
190
  def hash
194
- [id, network_id, default_address, enabled_features, server_signer_status].hash
191
+ [id, network_id, default_address, feature_set, server_signer_status].hash
195
192
  end
196
193
 
197
194
  # Builds the object from hash
@@ -18,9 +18,10 @@ module Coinbase::Client
18
18
  UNSPECIFIED = "unspecified".freeze
19
19
  ERC20_TRANSFER = "erc20_transfer".freeze
20
20
  ERC721_TRANSFER = "erc721_transfer".freeze
21
+ UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze
21
22
 
22
23
  def self.all_vars
23
- @all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER].freeze
24
+ @all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER, UNKNOWN_DEFAULT_OPEN_API].freeze
24
25
  end
25
26
 
26
27
  # Builds the enum from string
@@ -19,6 +19,7 @@ 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'
@@ -39,12 +40,14 @@ Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_
39
40
  Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
40
41
  Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
41
42
  Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
42
- 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'
43
45
  Coinbase::Client.autoload :FetchStakingRewards200Response, 'coinbase/client/models/fetch_staking_rewards200_response'
44
46
  Coinbase::Client.autoload :FetchStakingRewardsRequest, 'coinbase/client/models/fetch_staking_rewards_request'
45
47
  Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get_staking_context_request'
46
- Coinbase::Client.autoload :NativeEthStakingContext, 'coinbase/client/models/native_eth_staking_context'
47
- 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'
48
51
  Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
49
52
  Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
50
53
  Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
@@ -55,12 +58,15 @@ Coinbase::Client.autoload :ServerSignerList, 'coinbase/client/models/server_sign
55
58
  Coinbase::Client.autoload :SignatureCreationEvent, 'coinbase/client/models/signature_creation_event'
56
59
  Coinbase::Client.autoload :SignatureCreationEventResult, 'coinbase/client/models/signature_creation_event_result'
57
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'
58
63
  Coinbase::Client.autoload :StakingContext, 'coinbase/client/models/staking_context'
59
64
  Coinbase::Client.autoload :StakingContextContext, 'coinbase/client/models/staking_context_context'
60
65
  Coinbase::Client.autoload :StakingOperation, 'coinbase/client/models/staking_operation'
61
66
  Coinbase::Client.autoload :StakingOperationMetadata, 'coinbase/client/models/staking_operation_metadata'
62
67
  Coinbase::Client.autoload :StakingReward, 'coinbase/client/models/staking_reward'
63
68
  Coinbase::Client.autoload :StakingRewardFormat, 'coinbase/client/models/staking_reward_format'
69
+ Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/staking_reward_usd_value'
64
70
  Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
65
71
  Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
66
72
  Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
@@ -72,6 +78,7 @@ Coinbase::Client.autoload :User, 'coinbase/client/models/user'
72
78
  Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
73
79
  Coinbase::Client.autoload :ValidatorDetails, 'coinbase/client/models/validator_details'
74
80
  Coinbase::Client.autoload :ValidatorList, 'coinbase/client/models/validator_list'
81
+ Coinbase::Client.autoload :ValidatorStatus, 'coinbase/client/models/validator_status'
75
82
  Coinbase::Client.autoload :Wallet, 'coinbase/client/models/wallet'
76
83
  Coinbase::Client.autoload :WalletList, 'coinbase/client/models/wallet_list'
77
84
  Coinbase::Client.autoload :Webhook, 'coinbase/client/models/webhook'
@@ -84,12 +91,14 @@ Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
84
91
  Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
85
92
  Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
86
93
  Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
94
+ Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
87
95
  Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
88
96
  Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
89
97
  Coinbase::Client.autoload :TradesApi, 'coinbase/client/api/trades_api'
90
98
  Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
91
99
  Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
92
100
  Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
101
+ Coinbase::Client.autoload :WalletStakeApi, 'coinbase/client/api/wallet_stake_api'
93
102
  Coinbase::Client.autoload :WalletsApi, 'coinbase/client/api/wallets_api'
94
103
  Coinbase::Client.autoload :WebhooksApi, 'coinbase/client/api/webhooks_api'
95
104
 
@@ -4,16 +4,6 @@ require_relative 'asset'
4
4
  require_relative 'network'
5
5
 
6
6
  module Coinbase
7
- # The Base Sepolia Network.
8
- BASE_SEPOLIA = Network.new(
9
- network_id: :base_sepolia,
10
- display_name: 'Base Sepolia',
11
- protocol_family: :evm,
12
- is_testnet: true,
13
- native_asset_id: :eth,
14
- chain_id: 84_532
15
- )
16
-
17
7
  # The number of decimal places in Gwei.
18
8
  GWEI_DECIMALS = 9
19
9
 
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Represents a single contract event
5
+ class ContractEvent
6
+ # Returns a new ContractEvent object.
7
+ # @param model [Coinbase::Client::ContractEvent] The underlying ContractEvent object
8
+ def initialize(model)
9
+ @model = model
10
+ end
11
+
12
+ # Returns the network ID of the ContractEvent.
13
+ # @return [String] The network ID
14
+ def network_id
15
+ @model.network_id
16
+ end
17
+
18
+ # Returns the protocol name of the ContractEvent.
19
+ # @return [String] The protocol name
20
+ def protocol_name
21
+ @model.protocol_name
22
+ end
23
+
24
+ # Returns the contract name of the ContractEvent.
25
+ # @return [String] The contract name
26
+ def contract_name
27
+ @model.contract_name
28
+ end
29
+
30
+ # Returns the event name of the ContractEvent.
31
+ # @return [String] The event name
32
+ def event_name
33
+ @model.event_name
34
+ end
35
+
36
+ # Returns the signature of the ContractEvent.
37
+ # @return [String] The event signature
38
+ def sig
39
+ @model.sig
40
+ end
41
+
42
+ # Returns the four bytes of the Keccak hash of the event signature.
43
+ # @return [String] The four bytes of the event signature hash
44
+ def four_bytes
45
+ @model.four_bytes
46
+ end
47
+
48
+ # Returns the contract address of the ContractEvent.
49
+ # @return [String] The contract address
50
+ def contract_address
51
+ @model.contract_address
52
+ end
53
+
54
+ # Returns the block time of the ContractEvent.
55
+ # @return [Time] The block time
56
+ def block_time
57
+ Time.parse(@model.block_time)
58
+ end
59
+
60
+ # Returns the block height of the ContractEvent.
61
+ # @return [Integer] The block height
62
+ def block_height
63
+ @model.block_height
64
+ end
65
+
66
+ # Returns the transaction hash of the ContractEvent.
67
+ # @return [String] The transaction hash
68
+ def tx_hash
69
+ @model.tx_hash
70
+ end
71
+
72
+ # Returns the transaction index of the ContractEvent.
73
+ # @return [Integer] The transaction index
74
+ def tx_index
75
+ @model.tx_index
76
+ end
77
+
78
+ # Returns the event index of the ContractEvent.
79
+ # @return [Integer] The event index
80
+ def event_index
81
+ @model.event_index
82
+ end
83
+
84
+ # Returns the event data of the ContractEvent.
85
+ # @return [String] The event data
86
+ def data
87
+ @model.data
88
+ end
89
+
90
+ # Returns a string representation of the ContractEvent.
91
+ # @return [String] a string representation of the ContractEvent
92
+ def to_s
93
+ "Coinbase::ContractEvent{network_id: '#{network_id}', protocol_name: '#{protocol_name}', " \
94
+ "contract_name: '#{contract_name}', event_name: '#{event_name}', contract_address: '#{contract_address}', " \
95
+ "block_height: #{block_height}, tx_hash: '#{tx_hash}', data: '#{data}'}"
96
+ end
97
+
98
+ # Same as to_s.
99
+ # @return [String] a string representation of the ContractEvent
100
+ def inspect
101
+ to_s
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'securerandom'
5
+
6
+ module Coinbase
7
+ # A middleware that injects correlation data into the request headers.
8
+ class Correlation < Faraday::Middleware
9
+ # Initializes the Correlation middleware.
10
+ # @param app [Faraday::Connection] The Faraday connection
11
+ def initialize(app)
12
+ super(app)
13
+ @app = app
14
+ end
15
+
16
+ # Processes the request by adding the Correlation Data to the request headers.
17
+ # @param env [Faraday::Env] The Faraday request environment
18
+ def call(env)
19
+ env.request_headers['Correlation-Context'] = correlation_data
20
+ @app.call(env)
21
+ end
22
+
23
+ def correlation_data
24
+ @correlation_data ||= {
25
+ sdk_version: Coinbase::VERSION,
26
+ sdk_language: 'ruby'
27
+ }.map { |key, val| "#{key}=#{CGI.escape(val)}" }.join(',')
28
+ end
29
+ end
30
+ end
@@ -20,32 +20,34 @@ module Coinbase
20
20
  # If the destination is a String, it uses it as the Address ID.
21
21
  # @param network_id [Symbol] The ID of the Network to which the Destination belongs
22
22
  # @return [Destination] The Destination object
23
- def initialize(model, network_id: nil)
23
+ def initialize(model, network:)
24
+ network = Coinbase::Network.from_id(network)
25
+
24
26
  case model
25
27
  when Coinbase::Destination
26
- raise ArgumentError, 'destination network must match destination' unless model.network_id == network_id
28
+ raise ArgumentError, 'destination network must match destination' unless model.network == network
27
29
 
28
30
  @address_id = model.address_id
29
- @network_id = model.network_id
31
+ @network = model.network
30
32
  when Coinbase::Wallet
31
- raise ArgumentError, 'destination network must match wallet' unless model.network_id == network_id
33
+ raise ArgumentError, 'destination network must match wallet' unless model.network == network
32
34
  raise ArgumentError, 'destination wallet must have default address' if model.default_address.nil?
33
35
 
34
36
  @address_id = model.default_address.id
35
- @network_id = model.network_id
37
+ @network = model.network
36
38
  when Coinbase::Address
37
- raise ArgumentError, 'destination network must match address' unless model.network_id == network_id
39
+ raise ArgumentError, 'destination network must match address' unless model.network == network
38
40
 
39
41
  @address_id = model.id
40
- @network_id = model.network_id
42
+ @network = model.network
41
43
  when String
42
44
  @address_id = model
43
- @network_id = network_id
45
+ @network = network
44
46
  else
45
47
  raise ArgumentError, "unsupported destination type: #{model.class}"
46
48
  end
47
49
  end
48
50
 
49
- attr_reader :address_id, :network_id
51
+ attr_reader :address_id, :network
50
52
  end
51
53
  end
@@ -56,6 +56,13 @@ module Coinbase
56
56
  end
57
57
  end
58
58
 
59
+ # An error raised when an operation is attempted with insufficient funds.
60
+ class NetworkUnsupportedError < StandardError
61
+ def initialize(network_id)
62
+ super("Network #{network_id} is not supported")
63
+ end
64
+ end
65
+
59
66
  # An error raised when an operation is attempted with insufficient funds.
60
67
  class InsufficientFundsError < StandardError
61
68
  def initialize(expected, exact, msg = 'Insufficient funds')
@@ -63,6 +70,13 @@ module Coinbase
63
70
  end
64
71
  end
65
72
 
73
+ # An error raised when a resource is already signed.
74
+ class AlreadySignedError < StandardError
75
+ def initialize(msg = 'Resource already signed')
76
+ super(msg)
77
+ end
78
+ end
79
+
66
80
  # An error raised when a transaction is not signed.
67
81
  class TransactionNotSignedError < StandardError
68
82
  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
@@ -9,6 +9,7 @@ module Coinbase
9
9
  # A module for middleware that can be used with Faraday.
10
10
  module Middleware
11
11
  Faraday::Request.register_middleware authenticator: -> { Coinbase::Authenticator }
12
+ Faraday::Request.register_middleware correlation: -> { Coinbase::Correlation }
12
13
 
13
14
  # Returns the default middleware configuration for the Coinbase SDK.
14
15
  def self.config
@@ -19,6 +20,7 @@ module Coinbase
19
20
  config.host = uri.host + (uri.port ? ":#{uri.port}" : '')
20
21
  config.scheme = uri.scheme if uri.scheme
21
22
  config.request(:authenticator)
23
+ config.request(:correlation)
22
24
  retry_options = {
23
25
  max: Coinbase.configuration.max_network_tries,
24
26
  interval: 0.05,
@@ -3,39 +3,122 @@
3
3
  module Coinbase
4
4
  # A blockchain network.
5
5
  class Network
6
- attr_reader :chain_id
6
+ # Returns the Network object for the given ID, if supported.
7
+ # @param network_id [Symbol, String] The ID of the network
8
+ # @return [Network] The network object
9
+ def self.from_id(network_id)
10
+ return network_id if network_id.is_a?(Network)
7
11
 
8
- # Returns a new Network object. Do not use this method directly. Instead, use the Network constants defined in
12
+ network = NETWORK_MAP.fetch(Coinbase.to_sym(network_id), nil)
13
+
14
+ return network unless network.nil?
15
+
16
+ raise NetworkUnsupportedError, network_id
17
+ end
18
+
19
+ # Constructs a new Network object. Do not use this method directly. Instead, use the Network constants defined in
9
20
  # the Coinbase module.
10
- # @param network_id [Symbol] The Network ID
11
- # @param display_name [String] The Network's display name
12
- # @param protocol_family [String] The protocol family to which the Network belongs
13
- # (e.g., "evm")
14
- # @param is_testnet [Boolean] Whether the Network is a testnet
15
- # @param native_asset_id [String] The ID of the Network's native Asset
16
- # @param chain_id [Integer] The Chain ID of the Network
17
- def initialize(network_id:, display_name:, protocol_family:, is_testnet:, native_asset_id:, chain_id:)
18
- @network_id = network_id
19
- @display_name = display_name
20
- @protocol_family = protocol_family
21
- @is_testnet = is_testnet
22
- @native_asset_id = native_asset_id
23
- @chain_id = chain_id
21
+ # @param id [Symbol, String] The Network ID
22
+ # @return [Network] The new Network object
23
+ def initialize(id)
24
+ @id = ::Coinbase.to_sym(id)
25
+ end
26
+
27
+ # Returns the equality of the Network object with another Network object by ID.
28
+ # @param other [Coinbase::Network] The network object to compare
29
+ # @return [Boolean] Whether the Network objects are equal
30
+ def ==(other)
31
+ return false unless other.is_a?(Network)
32
+
33
+ id == other.id
34
+ end
35
+
36
+ attr_reader :id
37
+
38
+ def normalized_id
39
+ id.to_s.gsub('_', '-')
40
+ end
41
+
42
+ # The Chain ID of the Network.
43
+ # @return [Integer] The Chain ID of the Network
44
+ # @example
45
+ # network.chain_id #=> 84_532
46
+ def chain_id
47
+ model.chain_id
48
+ end
49
+
50
+ # Whether the Network is a testnet.
51
+ # @return [Boolean] Whether the Network is a testnet
52
+ # @example
53
+ # network.testnet? #=> true
54
+ def testnet?
55
+ model.is_testnet
56
+ end
57
+
58
+ # The display name of the Network.
59
+ # @return [String] The display name of the Network
60
+ # @example
61
+ # network.display_name #=> "Base Sepolia"
62
+ def display_name
63
+ model.display_name
64
+ end
65
+
66
+ # The protocol family to which the Network belongs. Example: `evm`.
67
+ # @return [String] The protocol family to which the Network belongs.
68
+ # @example
69
+ # network.protocol_family #=> "evm"
70
+ def protocol_family
71
+ model.protocol_family
72
+ end
73
+
74
+ # The address path prefix of the Network.
75
+ # @return [String] The address path prefix of the Network
76
+ # @example
77
+ # network.address_path_prefix #=> "m/44'/60'/0'/0"
78
+ def address_path_prefix
79
+ model.address_path_prefix
24
80
  end
25
81
 
26
82
  # Gets the Asset with the given ID.
27
- #
28
83
  # @param asset_id [Symbol] The ID of the Asset
29
84
  # @return [Asset] The Asset with the given ID
30
85
  def get_asset(asset_id)
31
- Asset.fetch(@network_id, asset_id)
86
+ Asset.fetch(@id, asset_id)
32
87
  end
33
88
 
34
89
  # Gets the native Asset of the Network.
35
- #
36
90
  # @return [Asset] The native Asset of the Network
37
91
  def native_asset
38
- @native_asset ||= get_asset(@native_asset_id)
92
+ @native_asset ||= Coinbase::Asset.from_model(model.native_asset)
93
+ end
94
+
95
+ def to_s
96
+ details = { id: id }
97
+
98
+ # Only include optional details if the model is already fetched.
99
+ unless @model.nil?
100
+ Coinbase::Client::Network.attribute_map.each_key do |attr|
101
+ details[attr] = @model.send(attr)
102
+ end
103
+ end
104
+
105
+ Coinbase.pretty_print_object(self.class, **details)
106
+ end
107
+
108
+ def inspect
109
+ to_s
110
+ end
111
+
112
+ private
113
+
114
+ def networks_api
115
+ @networks_api ||= Coinbase::Client::NetworksApi.new(Coinbase.configuration.api_client)
116
+ end
117
+
118
+ def model
119
+ @model ||= Coinbase.call_api do
120
+ networks_api.get_network(Coinbase.normalize_network(id))
121
+ end
39
122
  end
40
123
  end
41
124
  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