coinbase-sdk 0.0.14 → 0.1.0
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.
- checksums.yaml +4 -4
- data/lib/coinbase/address/wallet_address.rb +31 -21
- data/lib/coinbase/address.rb +51 -17
- data/lib/coinbase/asset.rb +11 -8
- data/lib/coinbase/client/api/contract_events_api.rb +17 -9
- data/lib/coinbase/client/api/external_addresses_api.rb +85 -0
- data/lib/coinbase/client/api/networks_api.rb +85 -0
- data/lib/coinbase/client/api/stake_api.rb +74 -195
- data/lib/coinbase/client/api/validators_api.rb +2 -2
- data/lib/coinbase/client/api/wallet_stake_api.rb +263 -0
- data/lib/coinbase/client/models/address.rb +21 -4
- data/lib/coinbase/client/models/{native_eth_staking_context.rb → address_historical_balance_list.rb} +39 -35
- data/lib/coinbase/client/models/contract_event.rb +99 -8
- data/lib/coinbase/client/models/create_address_request.rb +14 -4
- data/lib/coinbase/client/models/create_transfer_request.rb +14 -4
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +11 -11
- data/lib/coinbase/client/models/feature.rb +2 -1
- data/lib/coinbase/client/models/feature_set.rb +307 -0
- data/lib/coinbase/client/models/{partial_eth_staking_context.rb → fetch_historical_staking_balances200_response.rb} +39 -35
- data/lib/coinbase/client/models/historical_balance.rb +273 -0
- data/lib/coinbase/client/models/network.rb +365 -0
- data/lib/coinbase/client/models/network_identifier.rb +44 -0
- data/lib/coinbase/client/models/sponsored_send.rb +338 -0
- data/lib/coinbase/client/models/staking_balance.rb +289 -0
- data/lib/coinbase/client/models/staking_context_context.rb +222 -74
- data/lib/coinbase/client/models/staking_operation.rb +2 -2
- data/lib/coinbase/client/models/staking_reward.rb +22 -6
- data/lib/coinbase/client/models/staking_reward_format.rb +2 -1
- data/lib/coinbase/client/models/staking_reward_usd_value.rb +257 -0
- data/lib/coinbase/client/models/transaction.rb +17 -7
- data/lib/coinbase/client/models/transaction_type.rb +2 -1
- data/lib/coinbase/client/models/transfer.rb +101 -8
- data/lib/coinbase/client/models/validator.rb +23 -2
- data/lib/coinbase/client/models/validator_status.rb +52 -0
- data/lib/coinbase/client/models/wallet.rb +13 -16
- data/lib/coinbase/client/models/webhook_event_type.rb +2 -1
- data/lib/coinbase/client.rb +12 -3
- data/lib/coinbase/constants.rb +0 -10
- data/lib/coinbase/contract_event.rb +104 -0
- data/lib/coinbase/correlation.rb +30 -0
- data/lib/coinbase/destination.rb +11 -9
- data/lib/coinbase/errors.rb +14 -0
- data/lib/coinbase/historical_balance.rb +53 -0
- data/lib/coinbase/middleware.rb +2 -0
- data/lib/coinbase/network.rb +103 -20
- data/lib/coinbase/server_signer.rb +14 -3
- data/lib/coinbase/smart_contract.rb +106 -0
- data/lib/coinbase/sponsored_send.rb +110 -0
- data/lib/coinbase/staking_balance.rb +92 -0
- data/lib/coinbase/staking_operation.rb +134 -36
- data/lib/coinbase/staking_reward.rb +18 -0
- data/lib/coinbase/trade.rb +10 -9
- data/lib/coinbase/transaction.rb +13 -3
- data/lib/coinbase/transfer.rb +65 -36
- data/lib/coinbase/validator.rb +18 -10
- data/lib/coinbase/version.rb +5 -0
- data/lib/coinbase/wallet/data.rb +31 -0
- data/lib/coinbase/wallet.rb +143 -182
- data/lib/coinbase/webhook.rb +181 -0
- data/lib/coinbase.rb +64 -21
- metadata +51 -5
- data/lib/coinbase/user.rb +0 -65
data/lib/coinbase/transaction.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'constants'
|
4
|
-
require 'bigdecimal'
|
5
3
|
require 'eth'
|
6
4
|
require 'json'
|
7
5
|
|
@@ -70,6 +68,12 @@ module Coinbase
|
|
70
68
|
@model.from_address_id
|
71
69
|
end
|
72
70
|
|
71
|
+
# Returns the to address for the Transaction.
|
72
|
+
# @return [String] The to address
|
73
|
+
def to_address_id
|
74
|
+
@model.to_address_id
|
75
|
+
end
|
76
|
+
|
73
77
|
# Returns whether the Transaction is in a terminal state.
|
74
78
|
# @return [Boolean] Whether the Transaction is in a terminal state
|
75
79
|
def terminal_state?
|
@@ -113,12 +117,18 @@ module Coinbase
|
|
113
117
|
@raw = Eth::Tx::Eip1559.new(Eth::Tx.validate_eip1559_params(params))
|
114
118
|
end
|
115
119
|
|
120
|
+
# Returns the signature of the Transaction.
|
121
|
+
# @return [String] The hex-encode signature
|
122
|
+
def signature
|
123
|
+
raw.hex
|
124
|
+
end
|
125
|
+
|
116
126
|
# Signs the Transaction with the provided key and returns the hex signing payload.
|
117
127
|
# @return [String] The hex-encoded signed payload
|
118
128
|
def sign(key)
|
119
129
|
raw.sign(key)
|
120
130
|
|
121
|
-
|
131
|
+
signature
|
122
132
|
end
|
123
133
|
|
124
134
|
# Returns whether the Transaction has been signed.
|
data/lib/coinbase/transfer.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require_relative 'constants'
|
4
4
|
require 'bigdecimal'
|
5
5
|
require 'eth'
|
6
|
-
require 'json'
|
7
6
|
|
8
7
|
module Coinbase
|
9
8
|
# A representation of a Transfer, which moves an amount of an Asset from
|
@@ -21,12 +20,13 @@ module Coinbase
|
|
21
20
|
# If the destination is a Wallet, it uses the default Address of the Wallet.
|
22
21
|
# If the destination is an Address, it uses the Address's ID.
|
23
22
|
# If the destination is a String, it uses it as the Address ID.
|
24
|
-
# @param
|
23
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
25
24
|
# @param wallet_id [String] The Wallet ID of the sending Wallet
|
26
25
|
# @return [Transfer] The new pending Transfer object
|
27
26
|
# @raise [Coinbase::ApiError] If the Transfer fails
|
28
|
-
def create(address_id:, amount:, asset_id:, destination:,
|
29
|
-
|
27
|
+
def create(address_id:, amount:, asset_id:, destination:, network:, wallet_id:, gasless: false)
|
28
|
+
network = Coinbase::Network.from_id(network)
|
29
|
+
asset = network.get_asset(asset_id)
|
30
30
|
|
31
31
|
model = Coinbase.call_api do
|
32
32
|
transfers_api.create_transfer(
|
@@ -35,8 +35,9 @@ module Coinbase
|
|
35
35
|
{
|
36
36
|
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
37
37
|
asset_id: asset.primary_denomination.to_s,
|
38
|
-
destination: Coinbase::Destination.new(destination,
|
39
|
-
network_id:
|
38
|
+
destination: Coinbase::Destination.new(destination, network: network).address_id,
|
39
|
+
network_id: network.normalized_id,
|
40
|
+
gasless: gasless
|
40
41
|
}
|
41
42
|
)
|
42
43
|
end
|
@@ -82,10 +83,10 @@ module Coinbase
|
|
82
83
|
@model.transfer_id
|
83
84
|
end
|
84
85
|
|
85
|
-
# Returns the Network
|
86
|
-
# @return [Symbol] The Network
|
87
|
-
def
|
88
|
-
Coinbase.
|
86
|
+
# Returns the Network of the Transfer.
|
87
|
+
# @return [Symbol] The Network
|
88
|
+
def network
|
89
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
89
90
|
end
|
90
91
|
|
91
92
|
# Returns the Wallet ID of the Transfer.
|
@@ -122,40 +123,52 @@ module Coinbase
|
|
122
123
|
BigDecimal(@model.amount) / BigDecimal(10).power(@model.asset.decimals)
|
123
124
|
end
|
124
125
|
|
125
|
-
#
|
126
|
-
# @
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
# Signs the Transfer with the given key. This is required before broadcasting the Transfer.
|
127
|
+
# @param key [Eth::Key] The key to sign the Transfer with
|
128
|
+
# @raise [RuntimeError] If the key is not an Eth::Key
|
129
|
+
# @return [Transfer] The Transfer object
|
130
|
+
def sign(key)
|
131
|
+
raise unless key.is_a?(Eth::Key)
|
130
132
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
unless sponsored_send.nil?
|
134
|
+
sponsored_send.sign(key)
|
135
|
+
|
136
|
+
return
|
137
|
+
end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
transaction.signed_payload
|
139
|
+
transaction.sign(key)
|
140
|
+
|
141
|
+
self
|
141
142
|
end
|
142
143
|
|
143
144
|
# Returns the Transfer transaction.
|
144
145
|
# @return [Coinbase::Transaction] The Transfer transaction
|
145
146
|
def transaction
|
146
|
-
@transaction ||= Coinbase::Transaction.new(@model.transaction)
|
147
|
+
@transaction ||= @model.transaction.nil? ? nil : Coinbase::Transaction.new(@model.transaction)
|
147
148
|
end
|
148
149
|
|
149
|
-
# Returns the
|
150
|
-
# @return [
|
151
|
-
def
|
152
|
-
|
150
|
+
# Returns the SponsoredSend of the Transfer, if the transfer is gasless.
|
151
|
+
# @return [Coinbase::SponsoredSend] The SponsoredSend object
|
152
|
+
def sponsored_send
|
153
|
+
@sponsored_send ||= @model.sponsored_send.nil? ? nil : Coinbase::SponsoredSend.new(@model.sponsored_send)
|
153
154
|
end
|
154
155
|
|
155
156
|
# Returns the status of the Transfer.
|
156
157
|
# @return [Symbol] The status
|
157
158
|
def status
|
158
|
-
|
159
|
+
send_tx_delegate.status
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the link to the transaction on the blockchain explorer.
|
163
|
+
# @return [String] The link to the transaction on the blockchain explorer
|
164
|
+
def transaction_link
|
165
|
+
send_tx_delegate.transaction_link
|
166
|
+
end
|
167
|
+
|
168
|
+
# Returns the Transaction Hash of the Transfer.
|
169
|
+
# @return [String] The Transaction Hash
|
170
|
+
def transaction_hash
|
171
|
+
send_tx_delegate.transaction_hash
|
159
172
|
end
|
160
173
|
|
161
174
|
# Broadcasts the Transfer to the Network.
|
@@ -163,18 +176,19 @@ module Coinbase
|
|
163
176
|
# @raise [RuntimeError] If the Transfer is not signed
|
164
177
|
# @return [Transfer] The Transfer object
|
165
178
|
def broadcast!
|
166
|
-
raise TransactionNotSignedError unless
|
179
|
+
raise TransactionNotSignedError unless send_tx_delegate.signed?
|
167
180
|
|
168
181
|
@model = Coinbase.call_api do
|
169
182
|
transfers_api.broadcast_transfer(
|
170
183
|
wallet_id,
|
171
184
|
from_address_id,
|
172
185
|
id,
|
173
|
-
{ signed_payload:
|
186
|
+
{ signed_payload: send_tx_delegate.signature }
|
174
187
|
)
|
175
188
|
end
|
176
189
|
|
177
|
-
update_transaction(@model)
|
190
|
+
update_transaction(@model) unless @model.transaction.nil?
|
191
|
+
update_sponsored_send(@model) unless @model.sponsored_send.nil?
|
178
192
|
|
179
193
|
self
|
180
194
|
end
|
@@ -186,7 +200,8 @@ module Coinbase
|
|
186
200
|
transfers_api.get_transfer(wallet_id, from_address_id, id)
|
187
201
|
end
|
188
202
|
|
189
|
-
update_transaction(@model)
|
203
|
+
update_transaction(@model) unless @model.transaction.nil?
|
204
|
+
update_sponsored_send(@model) unless @model.sponsored_send.nil?
|
190
205
|
|
191
206
|
self
|
192
207
|
end
|
@@ -202,7 +217,7 @@ module Coinbase
|
|
202
217
|
loop do
|
203
218
|
reload
|
204
219
|
|
205
|
-
return self if
|
220
|
+
return self if terminal_state?
|
206
221
|
|
207
222
|
raise Timeout::Error, 'Transfer timed out' if Time.now - start_time > timeout_seconds
|
208
223
|
|
@@ -215,7 +230,7 @@ module Coinbase
|
|
215
230
|
# Returns a String representation of the Transfer.
|
216
231
|
# @return [String] a String representation of the Transfer
|
217
232
|
def to_s
|
218
|
-
"Coinbase::Transfer{transfer_id: '#{id}', network_id: '#{
|
233
|
+
"Coinbase::Transfer{transfer_id: '#{id}', network_id: '#{network.id}', " \
|
219
234
|
"from_address_id: '#{from_address_id}', destination_address_id: '#{destination_address_id}', " \
|
220
235
|
"asset_id: '#{asset_id}', amount: '#{amount}', transaction_link: '#{transaction_link}', " \
|
221
236
|
"status: '#{status}'}"
|
@@ -229,6 +244,16 @@ module Coinbase
|
|
229
244
|
|
230
245
|
private
|
231
246
|
|
247
|
+
def terminal_state?
|
248
|
+
send_tx_delegate.terminal_state?
|
249
|
+
end
|
250
|
+
|
251
|
+
def send_tx_delegate
|
252
|
+
return sponsored_send unless sponsored_send.nil?
|
253
|
+
|
254
|
+
transaction
|
255
|
+
end
|
256
|
+
|
232
257
|
def transfers_api
|
233
258
|
@transfers_api ||= Coinbase::Client::TransfersApi.new(Coinbase.configuration.api_client)
|
234
259
|
end
|
@@ -236,5 +261,9 @@ module Coinbase
|
|
236
261
|
def update_transaction(model)
|
237
262
|
@transaction = Coinbase::Transaction.new(model.transaction)
|
238
263
|
end
|
264
|
+
|
265
|
+
def update_sponsored_send(model)
|
266
|
+
@sponsored_send = Coinbase::SponsoredSend.new(model.sponsored_send)
|
267
|
+
end
|
239
268
|
end
|
240
269
|
end
|
data/lib/coinbase/validator.rb
CHANGED
@@ -10,27 +10,31 @@ module Coinbase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns a list of Validators for the provided network and asset.
|
13
|
-
# @param
|
13
|
+
# @param network [Coinbase::Nework, Symbol] The Network or Network ID
|
14
14
|
# @param asset_id [Symbol] The asset ID
|
15
15
|
# @param status [Symbol] The status of the validator. Defaults to nil.
|
16
16
|
# @return [Enumerable<Coinbase::Validator>] The validators
|
17
|
-
def self.list(
|
18
|
-
Coinbase::
|
19
|
-
|
20
|
-
|
17
|
+
def self.list(network, asset_id, status: nil)
|
18
|
+
network = Coinbase::Network.from_id(network)
|
19
|
+
|
20
|
+
Coinbase::Pagination.enumerate(lambda { |page|
|
21
|
+
list_page(network, asset_id, status, page)
|
22
|
+
}) do |validator|
|
21
23
|
new(validator)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
# Returns a Validator for the provided network, asset, and validator.
|
26
|
-
# @param
|
28
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID
|
27
29
|
# @param asset_id [Symbol] The asset ID
|
28
30
|
# @param validator_id [String] The validator ID
|
29
31
|
# @return [Coinbase::Validator] The validator
|
30
|
-
def self.fetch(
|
32
|
+
def self.fetch(network, asset_id, validator_id)
|
33
|
+
network = Coinbase::Network.from_id(network)
|
34
|
+
|
31
35
|
validator = Coinbase.call_api do
|
32
36
|
validators_api.get_validator(
|
33
|
-
|
37
|
+
network.normalized_id,
|
34
38
|
asset_id,
|
35
39
|
validator_id
|
36
40
|
)
|
@@ -62,10 +66,10 @@ module Coinbase
|
|
62
66
|
to_s
|
63
67
|
end
|
64
68
|
|
65
|
-
def self.list_page(
|
69
|
+
def self.list_page(network, asset_id, status, page)
|
66
70
|
Coinbase.call_api do
|
67
71
|
validators_api.list_validators(
|
68
|
-
|
72
|
+
network.normalized_id,
|
69
73
|
asset_id,
|
70
74
|
{
|
71
75
|
status: status,
|
@@ -75,8 +79,12 @@ module Coinbase
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
82
|
+
private_class_method :list_page
|
83
|
+
|
78
84
|
def self.validators_api
|
79
85
|
Coinbase::Client::ValidatorsApi.new(Coinbase.configuration.api_client)
|
80
86
|
end
|
87
|
+
|
88
|
+
private_class_method :validators_api
|
81
89
|
end
|
82
90
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coinbase
|
4
|
+
class Wallet
|
5
|
+
# The data required to recreate a Wallet.
|
6
|
+
class Data
|
7
|
+
attr_reader :wallet_id, :seed
|
8
|
+
|
9
|
+
# Returns a new Data object.
|
10
|
+
# @param wallet_id [String] The ID of the Wallet
|
11
|
+
# @param seed [String] The seed of the Wallet
|
12
|
+
def initialize(wallet_id:, seed:)
|
13
|
+
@wallet_id = wallet_id
|
14
|
+
@seed = seed
|
15
|
+
end
|
16
|
+
|
17
|
+
# Converts the Data object to a Hash.
|
18
|
+
# @return [Hash] The Hash representation of the Data object
|
19
|
+
def to_hash
|
20
|
+
{ wallet_id: wallet_id, seed: seed }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a Data object from the given Hash.
|
24
|
+
# @param data [Hash] The Hash to create the Data object from
|
25
|
+
# @return [Data] The new Data object
|
26
|
+
def self.from_hash(data)
|
27
|
+
Data.new(wallet_id: data['wallet_id'], seed: data['seed'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|