coinbase-sdk 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +53 -0
  3. data/lib/coinbase/address.rb +20 -0
  4. data/lib/coinbase/client/api/addresses_api.rb +231 -1
  5. data/lib/coinbase/client/api/assets_api.rb +1 -1
  6. data/lib/coinbase/client/api/contract_events_api.rb +1 -1
  7. data/lib/coinbase/client/api/contract_invocations_api.rb +342 -0
  8. data/lib/coinbase/client/api/external_addresses_api.rb +81 -2
  9. data/lib/coinbase/client/api/networks_api.rb +1 -1
  10. data/lib/coinbase/client/api/server_signers_api.rb +1 -1
  11. data/lib/coinbase/client/api/stake_api.rb +1 -1
  12. data/lib/coinbase/client/api/trades_api.rb +1 -1
  13. data/lib/coinbase/client/api/transfers_api.rb +1 -1
  14. data/lib/coinbase/client/api/users_api.rb +1 -1
  15. data/lib/coinbase/client/api/validators_api.rb +1 -1
  16. data/lib/coinbase/client/api/wallet_stake_api.rb +1 -1
  17. data/lib/coinbase/client/api/wallets_api.rb +1 -1
  18. data/lib/coinbase/client/api/webhooks_api.rb +1 -1
  19. data/lib/coinbase/client/api_client.rb +1 -1
  20. data/lib/coinbase/client/api_error.rb +1 -1
  21. data/lib/coinbase/client/configuration.rb +1 -1
  22. data/lib/coinbase/client/models/address.rb +1 -1
  23. data/lib/coinbase/client/models/address_balance_list.rb +1 -1
  24. data/lib/coinbase/client/models/address_historical_balance_list.rb +1 -1
  25. data/lib/coinbase/client/models/address_list.rb +1 -1
  26. data/lib/coinbase/client/models/address_transaction_list.rb +258 -0
  27. data/lib/coinbase/client/models/asset.rb +1 -1
  28. data/lib/coinbase/client/models/balance.rb +1 -1
  29. data/lib/coinbase/client/models/broadcast_contract_invocation_request.rb +222 -0
  30. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
  31. data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
  32. data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
  33. data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
  34. data/lib/coinbase/client/models/contract_event.rb +1 -1
  35. data/lib/coinbase/client/models/contract_event_list.rb +1 -1
  36. data/lib/coinbase/client/models/contract_invocation.rb +351 -0
  37. data/lib/coinbase/client/models/contract_invocation_list.rb +274 -0
  38. data/lib/coinbase/client/models/create_address_request.rb +1 -1
  39. data/lib/coinbase/client/models/create_contract_invocation_request.rb +266 -0
  40. data/lib/coinbase/client/models/create_payload_signature_request.rb +232 -0
  41. data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
  42. data/lib/coinbase/client/models/create_staking_operation_request.rb +1 -1
  43. data/lib/coinbase/client/models/create_trade_request.rb +1 -1
  44. data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
  45. data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
  46. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
  47. data/lib/coinbase/client/models/create_webhook_request.rb +29 -5
  48. data/lib/coinbase/client/models/error.rb +1 -1
  49. data/lib/coinbase/client/models/ethereum_transaction.rb +389 -0
  50. data/lib/coinbase/client/models/ethereum_transaction_access.rb +225 -0
  51. data/lib/coinbase/client/models/ethereum_transaction_access_list.rb +216 -0
  52. data/lib/coinbase/client/models/ethereum_transaction_flattened_trace.rb +378 -0
  53. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
  54. data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
  55. data/lib/coinbase/client/models/feature_set.rb +1 -1
  56. data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +1 -1
  57. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
  58. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
  59. data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
  60. data/lib/coinbase/client/models/historical_balance.rb +1 -1
  61. data/lib/coinbase/client/models/network.rb +3 -3
  62. data/lib/coinbase/client/models/network_identifier.rb +3 -2
  63. data/lib/coinbase/client/models/payload_signature.rb +335 -0
  64. data/lib/coinbase/client/models/payload_signature_list.rb +275 -0
  65. data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
  66. data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
  67. data/lib/coinbase/client/models/server_signer.rb +1 -1
  68. data/lib/coinbase/client/models/server_signer_event.rb +1 -1
  69. data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
  70. data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
  71. data/lib/coinbase/client/models/server_signer_list.rb +1 -1
  72. data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
  73. data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
  74. data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
  75. data/lib/coinbase/client/models/sponsored_send.rb +1 -1
  76. data/lib/coinbase/client/models/staking_balance.rb +1 -1
  77. data/lib/coinbase/client/models/staking_context.rb +1 -1
  78. data/lib/coinbase/client/models/staking_context_context.rb +1 -1
  79. data/lib/coinbase/client/models/staking_operation.rb +1 -1
  80. data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
  81. data/lib/coinbase/client/models/staking_reward.rb +1 -1
  82. data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
  83. data/lib/coinbase/client/models/staking_reward_usd_value.rb +1 -1
  84. data/lib/coinbase/client/models/trade.rb +1 -1
  85. data/lib/coinbase/client/models/trade_list.rb +1 -1
  86. data/lib/coinbase/client/models/transaction.rb +36 -7
  87. data/lib/coinbase/client/models/transaction_content.rb +104 -0
  88. data/lib/coinbase/client/models/transaction_type.rb +1 -1
  89. data/lib/coinbase/client/models/transfer.rb +1 -1
  90. data/lib/coinbase/client/models/transfer_list.rb +1 -1
  91. data/lib/coinbase/client/models/update_webhook_request.rb +2 -50
  92. data/lib/coinbase/client/models/user.rb +1 -1
  93. data/lib/coinbase/client/models/validator.rb +1 -1
  94. data/lib/coinbase/client/models/validator_details.rb +1 -1
  95. data/lib/coinbase/client/models/validator_list.rb +1 -1
  96. data/lib/coinbase/client/models/validator_status.rb +1 -1
  97. data/lib/coinbase/client/models/wallet.rb +1 -1
  98. data/lib/coinbase/client/models/wallet_list.rb +1 -1
  99. data/lib/coinbase/client/models/webhook.rb +15 -5
  100. data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
  101. data/lib/coinbase/client/models/webhook_event_type.rb +1 -1
  102. data/lib/coinbase/client/models/webhook_list.rb +1 -1
  103. data/lib/coinbase/client/version.rb +1 -1
  104. data/lib/coinbase/client.rb +15 -1
  105. data/lib/coinbase/constants.rb +3 -0
  106. data/lib/coinbase/contract_invocation.rb +234 -0
  107. data/lib/coinbase/payload_signature.rb +181 -0
  108. data/lib/coinbase/transaction.rb +21 -0
  109. data/lib/coinbase/version.rb +1 -1
  110. data/lib/coinbase/wallet.rb +11 -1
  111. data/lib/coinbase/webhook.rb +17 -6
  112. data/lib/coinbase.rb +2 -0
  113. metadata +18 -2
@@ -4,7 +4,7 @@
4
4
  #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
5
 
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
- Contact: yuga.cohler@coinbase.com
7
+
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.7.0
10
10
 
@@ -4,7 +4,7 @@
4
4
  #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
5
 
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
- Contact: yuga.cohler@coinbase.com
7
+
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.7.0
10
10
 
@@ -4,7 +4,7 @@
4
4
  #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
5
 
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
- Contact: yuga.cohler@coinbase.com
7
+
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.7.0
10
10
 
@@ -4,7 +4,7 @@
4
4
  #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
5
 
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
- Contact: yuga.cohler@coinbase.com
7
+
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.7.0
10
10
 
@@ -4,7 +4,7 @@
4
4
  #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
5
 
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
- Contact: yuga.cohler@coinbase.com
7
+
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.7.0
10
10
 
@@ -21,15 +21,21 @@ Coinbase::Client.autoload :Address, 'coinbase/client/models/address'
21
21
  Coinbase::Client.autoload :AddressBalanceList, 'coinbase/client/models/address_balance_list'
22
22
  Coinbase::Client.autoload :AddressHistoricalBalanceList, 'coinbase/client/models/address_historical_balance_list'
23
23
  Coinbase::Client.autoload :AddressList, 'coinbase/client/models/address_list'
24
+ Coinbase::Client.autoload :AddressTransactionList, 'coinbase/client/models/address_transaction_list'
24
25
  Coinbase::Client.autoload :Asset, 'coinbase/client/models/asset'
25
26
  Coinbase::Client.autoload :Balance, 'coinbase/client/models/balance'
27
+ Coinbase::Client.autoload :BroadcastContractInvocationRequest, 'coinbase/client/models/broadcast_contract_invocation_request'
26
28
  Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
27
29
  Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
28
30
  Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
29
31
  Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
30
32
  Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
31
33
  Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
34
+ Coinbase::Client.autoload :ContractInvocation, 'coinbase/client/models/contract_invocation'
35
+ Coinbase::Client.autoload :ContractInvocationList, 'coinbase/client/models/contract_invocation_list'
32
36
  Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_address_request'
37
+ Coinbase::Client.autoload :CreateContractInvocationRequest, 'coinbase/client/models/create_contract_invocation_request'
38
+ Coinbase::Client.autoload :CreatePayloadSignatureRequest, 'coinbase/client/models/create_payload_signature_request'
33
39
  Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
34
40
  Coinbase::Client.autoload :CreateStakingOperationRequest, 'coinbase/client/models/create_staking_operation_request'
35
41
  Coinbase::Client.autoload :CreateTradeRequest, 'coinbase/client/models/create_trade_request'
@@ -38,6 +44,10 @@ Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_w
38
44
  Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
39
45
  Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
40
46
  Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
47
+ Coinbase::Client.autoload :EthereumTransaction, 'coinbase/client/models/ethereum_transaction'
48
+ Coinbase::Client.autoload :EthereumTransactionAccess, 'coinbase/client/models/ethereum_transaction_access'
49
+ Coinbase::Client.autoload :EthereumTransactionAccessList, 'coinbase/client/models/ethereum_transaction_access_list'
50
+ Coinbase::Client.autoload :EthereumTransactionFlattenedTrace, 'coinbase/client/models/ethereum_transaction_flattened_trace'
41
51
  Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
42
52
  Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
43
53
  Coinbase::Client.autoload :FeatureSet, 'coinbase/client/models/feature_set'
@@ -48,6 +58,8 @@ Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get
48
58
  Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
49
59
  Coinbase::Client.autoload :Network, 'coinbase/client/models/network'
50
60
  Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
61
+ Coinbase::Client.autoload :PayloadSignature, 'coinbase/client/models/payload_signature'
62
+ Coinbase::Client.autoload :PayloadSignatureList, 'coinbase/client/models/payload_signature_list'
51
63
  Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
52
64
  Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
53
65
  Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
@@ -70,6 +82,7 @@ Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/stakin
70
82
  Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
71
83
  Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
72
84
  Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
85
+ Coinbase::Client.autoload :TransactionContent, 'coinbase/client/models/transaction_content'
73
86
  Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
74
87
  Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
75
88
  Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
@@ -90,6 +103,7 @@ Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
90
103
  Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
91
104
  Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
92
105
  Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
106
+ Coinbase::Client.autoload :ContractInvocationsApi, 'coinbase/client/api/contract_invocations_api'
93
107
  Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
94
108
  Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
95
109
  Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
@@ -9,4 +9,7 @@ module Coinbase
9
9
 
10
10
  # The default page limit for paginated API requests.
11
11
  DEFAULT_PAGE_LIMIT = 100
12
+
13
+ # The default page limit for transaction paginated API request.
14
+ DEFAULT_TRANSACTION_PAGE_LIMIT = 10
12
15
  end
@@ -0,0 +1,234 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # A representation of a Contract Invocation.
5
+ class ContractInvocation
6
+ class << self
7
+ # Creates a new ContractInvocation object.
8
+ # @param address_id [String] The Address ID of the signing Address
9
+ # @param wallet_id [String] The Wallet ID associated with the signing Address
10
+ # @param contract_address [String] The contract address
11
+ # @param abi [Array<Hash>] The contract ABI
12
+ # @param method [String] The contract method
13
+ # @param args [Hash] The arguments to pass to the contract method.
14
+ # The keys should be the argument names, and the values should be the argument values.
15
+ # @return [ContractInvocation] The new Contract Invocation object
16
+ # @raise [Coinbase::ApiError] If the request to create the Contract Invocation fails
17
+ def create(
18
+ address_id:,
19
+ wallet_id:,
20
+ contract_address:,
21
+ abi:,
22
+ method:,
23
+ args: {}
24
+ )
25
+ model = Coinbase.call_api do
26
+ contract_invocation_api.create_contract_invocation(
27
+ wallet_id,
28
+ address_id,
29
+ contract_address: contract_address,
30
+ abi: abi.to_json,
31
+ method: method,
32
+ args: args.to_json
33
+ )
34
+ end
35
+
36
+ new(model)
37
+ end
38
+
39
+ # Enumerates the payload signatures for a given address belonging to a wallet.
40
+ # The result is an enumerator that lazily fetches from the server, and can be iterated over,
41
+ # converted an array, etc...
42
+ # @return [Enumerable<Coinbase::ContractInvocation>] Enumerator that returns payload signatures
43
+ def list(wallet_id:, address_id:)
44
+ Coinbase::Pagination.enumerate(
45
+ ->(page) { fetch_page(wallet_id, address_id, page) }
46
+ ) do |contract_invocation|
47
+ new(contract_invocation)
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def contract_invocation_api
54
+ Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
55
+ end
56
+
57
+ def fetch_page(wallet_id, address_id, page)
58
+ contract_invocation_api.list_contract_invocations(
59
+ wallet_id,
60
+ address_id,
61
+ limit: DEFAULT_PAGE_LIMIT,
62
+ page: page
63
+ )
64
+ end
65
+ end
66
+
67
+ # Returns a new ContractInvocation object. Do not use this method directly.
68
+ # Instead use Coinbase::ContractInvocation.create.
69
+ # @param model [Coinbase::Client::ContractInvocation] The underlying Contract Invocation obejct
70
+ def initialize(model)
71
+ raise unless model.is_a?(Coinbase::Client::ContractInvocation)
72
+
73
+ @model = model
74
+ end
75
+
76
+ # Returns the Contract Invocation ID.
77
+ # @return [String] The Contract Invocation ID
78
+ def id
79
+ @model.contract_invocation_id
80
+ end
81
+
82
+ # Returns the Wallet ID of the Contract Invocation.
83
+ # @return [String] The Wallet ID
84
+ def wallet_id
85
+ @model.wallet_id
86
+ end
87
+
88
+ # Returns the Address ID of the Contract Invocation.
89
+ # @return [String] The Address ID
90
+ def address_id
91
+ @model.address_id
92
+ end
93
+
94
+ # Returns the Network of the Contract Invocation.
95
+ # @return [Coinbase::Network] The Network
96
+ def network
97
+ @network ||= Coinbase::Network.from_id(@model.network_id)
98
+ end
99
+
100
+ # Returns the Contract Address of the Contract Invocation.
101
+ # @return [String] The Contract Address
102
+ def contract_address
103
+ @model.contract_address
104
+ end
105
+
106
+ # Returns the ABI of the Contract Invocation.
107
+ # @return [Array<Hash>] The ABI
108
+ def abi
109
+ JSON.parse(@model.abi)
110
+ end
111
+
112
+ # Returns the method of the Contract Invocation.
113
+ # @return [String] The method
114
+ def method
115
+ @model.method
116
+ end
117
+
118
+ # Returns the arguments of the Contract Invocation.
119
+ # @return [Hash] The arguments
120
+ def args
121
+ JSON.parse(@model.args).transform_keys(&:to_sym)
122
+ end
123
+
124
+ # Returns the transaction.
125
+ # @return [Coinbase::Transaction] The Transfer transaction
126
+ def transaction
127
+ @transaction ||= Coinbase::Transaction.new(@model.transaction)
128
+ end
129
+
130
+ # Returns the status of the Contract Invocation.
131
+ # @return [String] The status
132
+ def status
133
+ transaction.status
134
+ end
135
+
136
+ # Signs the Contract Invocation transaction with the given key.
137
+ # This is required before broadcasting the Contract Invocation when not using
138
+ # a Server-Signer.
139
+ # @param key [Eth::Key] The key to sign the ContractInvocation with
140
+ # @raise [RuntimeError] If the key is not an Eth::Key
141
+ # @return [ContractInvocation] The ContractInvocation object
142
+ def sign(key)
143
+ raise unless key.is_a?(Eth::Key)
144
+
145
+ transaction.sign(key)
146
+
147
+ self
148
+ end
149
+
150
+ # Broadcasts the ContractInvocation to the Network.
151
+ # @raise [RuntimeError] If the ContractInvocation is not signed
152
+ # @return [ContractInvocation] The ContractInvocation object
153
+ def broadcast!
154
+ raise TransactionNotSignedError unless transaction.signed?
155
+
156
+ @model = Coinbase.call_api do
157
+ contract_invocation_api.broadcast_contract_invocation(
158
+ wallet_id,
159
+ address_id,
160
+ id,
161
+ { signed_payload: transaction.signature }
162
+ )
163
+ end
164
+
165
+ @transaction = Coinbase::Transaction.new(@model.transaction)
166
+
167
+ self
168
+ end
169
+
170
+ # # Reload reloads the Contract Invocation model with the latest version from the server side.
171
+ # @return [ContractInvocation] The most recent version of Contract Invocation from the server
172
+ def reload
173
+ @model = Coinbase.call_api do
174
+ contract_invocation_api.get_contract_invocation(wallet_id, address_id, id)
175
+ end
176
+
177
+ @transaction = Coinbase::Transaction.new(@model.transaction)
178
+
179
+ self
180
+ end
181
+
182
+ # Waits until the Contract Invocation is signed or failed by polling the server at the given interval. Raises a
183
+ # Timeout::Error if the Contract Invocation takes longer than the given timeout.
184
+ # @param interval_seconds [Integer] The interval at which to poll the server, in seconds
185
+ # @param timeout_seconds [Integer] The maximum amount of time to wait for the Contract Invocation to be signed,
186
+ # in seconds.
187
+ # @return [ContractInvocation] The completed Contract Invocation object
188
+ def wait!(interval_seconds = 0.2, timeout_seconds = 20)
189
+ start_time = Time.now
190
+
191
+ loop do
192
+ reload
193
+
194
+ return self if transaction.terminal_state?
195
+
196
+ raise Timeout::Error, 'Contract Invocation timed out' if Time.now - start_time > timeout_seconds
197
+
198
+ self.sleep interval_seconds
199
+ end
200
+
201
+ self
202
+ end
203
+
204
+ # Returns a String representation of the Contract Invocation.
205
+ # @return [String] a String representation of the Contract Invocation
206
+ def to_s
207
+ Coinbase.pretty_print_object(
208
+ self.class,
209
+ id: id,
210
+ wallet_id: wallet_id,
211
+ address_id: address_id,
212
+ network_id: network.id,
213
+ status: status,
214
+ abi: abi.to_json,
215
+ method: method,
216
+ args: args.to_json,
217
+ transaction_hash: transaction.transaction_hash,
218
+ transaction_link: transaction.transaction_link
219
+ )
220
+ end
221
+
222
+ # Same as to_s.
223
+ # @return [String] a String representation of the ContractInvocation
224
+ def inspect
225
+ to_s
226
+ end
227
+
228
+ private
229
+
230
+ def contract_invocation_api
231
+ @contract_invocation_api ||= Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+
5
+ module Coinbase
6
+ # A representation of a Payload Signature.
7
+ class PayloadSignature
8
+ # A representation of a Payload Signature status.
9
+ module Status
10
+ # The Payload Signature is pending signing.
11
+ # At this point, the Signature is not available yet.
12
+ PENDING = 'pending'
13
+
14
+ # The Payload Signature has been signed.
15
+ SIGNED = 'signed'
16
+
17
+ # The Payload Signature has failed.
18
+ FAILED = 'failed'
19
+
20
+ # The states that are considered terminal.
21
+ TERMINAL_STATES = [SIGNED, FAILED].freeze
22
+ end
23
+
24
+ class << self
25
+ # Creates a new PayloadSignature object.
26
+ # @param wallet_id [String] The Wallet ID associated with the signing Address
27
+ # @param address_id [String] The Address ID of the signing Address
28
+ # @param unsigned_payload [String] The hex-encoded Unsigned Payload
29
+ # @param signature [String] (Optional) The Signature if the Wallet is not using an MPC Server-Signer
30
+ # @return [PayloadSignature] The new Payload Signature object
31
+ # @raise [Coinbase::ApiError] If the request to create the Payload Signature fails
32
+ def create(wallet_id:, address_id:, unsigned_payload:, signature: nil)
33
+ create_payload_signature_request = {
34
+ unsigned_payload: unsigned_payload,
35
+ signature: signature
36
+ }.compact
37
+
38
+ model = Coinbase.call_api do
39
+ addresses_api.create_payload_signature(
40
+ wallet_id,
41
+ address_id,
42
+ create_payload_signature_request: create_payload_signature_request
43
+ )
44
+ end
45
+
46
+ new(model)
47
+ end
48
+
49
+ # Enumerates the payload signatures for a given address belonging to a wallet.
50
+ # The result is an enumerator that lazily fetches from the server, and can be iterated over,
51
+ # converted an array, etc...
52
+ # @return [Enumerable<Coinbase::PayloadSignature>] Enumerator that returns payload signatures
53
+ def list(wallet_id:, address_id:)
54
+ Coinbase::Pagination.enumerate(
55
+ ->(page) { fetch_page(wallet_id, address_id, page) }
56
+ ) do |payload_signature|
57
+ new(payload_signature)
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def addresses_api
64
+ Coinbase::Client::AddressesApi.new(Coinbase.configuration.api_client)
65
+ end
66
+
67
+ def fetch_page(wallet_id, address_id, page)
68
+ addresses_api.list_payload_signatures(wallet_id, address_id, { limit: DEFAULT_PAGE_LIMIT, page: page })
69
+ end
70
+ end
71
+
72
+ # Returns a new PayloadSignature object. Do not use this method directly.
73
+ # Instead use Coinbase::PayloadSignature.create.
74
+ # @param model [Coinbase::Client::PayloadSignature] The underlying Payload Signature obejct
75
+ def initialize(model)
76
+ raise unless model.is_a?(Coinbase::Client::PayloadSignature)
77
+
78
+ @model = model
79
+ end
80
+
81
+ # Returns the Payload Signature ID.
82
+ # @return [String] The Payload Signature ID
83
+ def id
84
+ @model.payload_signature_id
85
+ end
86
+
87
+ # Returns the Wallet ID of the Payload Signature.
88
+ # @return [String] The Wallet ID
89
+ def wallet_id
90
+ @model.wallet_id
91
+ end
92
+
93
+ # Returns the Address ID of the Payload Signature.
94
+ # @return [String] The Address ID
95
+ def address_id
96
+ @model.address_id
97
+ end
98
+
99
+ # Returns the Unsigned Payload of the Payload Signature.
100
+ # @return [String] The Unsigned Payload
101
+ def unsigned_payload
102
+ @model.unsigned_payload
103
+ end
104
+
105
+ # Returns the Signature of the Payload Signature.
106
+ # @return [String] The Signature
107
+ def signature
108
+ @model.signature
109
+ end
110
+
111
+ # Returns the status of the Payload Signature.
112
+ # @return [Symbol] The status
113
+ def status
114
+ @model.status
115
+ end
116
+
117
+ # Returns whether the Payload Signature is in a terminal state.
118
+ # @return [Boolean] Whether the Payload Signature is in a terminal state
119
+ def terminal_state?
120
+ Status::TERMINAL_STATES.include?(status)
121
+ end
122
+
123
+ # # Reload reloads the Payload Signature model with the latest version from the server side.
124
+ # @return [PayloadSignature] The most recent version of Payload Signature from the server
125
+ def reload
126
+ @model = Coinbase.call_api do
127
+ addresses_api.get_payload_signature(wallet_id, address_id, id)
128
+ end
129
+
130
+ self
131
+ end
132
+
133
+ # Waits until the Payload Signature is signed or failed by polling the server at the given interval. Raises a
134
+ # Timeout::Error if the Payload Signature takes longer than the given timeout.
135
+ # @param interval_seconds [Integer] The interval at which to poll the server, in seconds
136
+ # @param timeout_seconds [Integer] The maximum amount of time to wait for the Payload Signature to be signed,
137
+ # in seconds.
138
+ # @return [PayloadSignature] The completed Payload Signature object
139
+ def wait!(interval_seconds = 0.2, timeout_seconds = 20)
140
+ start_time = Time.now
141
+
142
+ loop do
143
+ reload
144
+
145
+ return self if terminal_state?
146
+
147
+ raise Timeout::Error, 'Payload Signature timed out' if Time.now - start_time > timeout_seconds
148
+
149
+ self.sleep interval_seconds
150
+ end
151
+
152
+ self
153
+ end
154
+
155
+ # Returns a String representation of the Payload Signature.
156
+ # @return [String] a String representation of the Payload Signature
157
+ def to_s
158
+ Coinbase.pretty_print_object(
159
+ self.class,
160
+ id: id,
161
+ wallet_id: wallet_id,
162
+ address_id: address_id,
163
+ status: status,
164
+ unsigned_payload: unsigned_payload,
165
+ signature: signature
166
+ )
167
+ end
168
+
169
+ # Same as to_s.
170
+ # @return [String] a String representation of the PayloadSignature
171
+ def inspect
172
+ to_s
173
+ end
174
+
175
+ private
176
+
177
+ def addresses_api
178
+ Coinbase::Client::AddressesApi.new(Coinbase.configuration.api_client)
179
+ end
180
+ end
181
+ end
@@ -26,6 +26,9 @@ module Coinbase
26
26
  # The Transaction has failed for some reason.
27
27
  FAILED = 'failed'
28
28
 
29
+ # The Transaction isn't specified it's status in Receipt.
30
+ UNSPECIFIED = 'unspecified'
31
+
29
32
  # The states that are considered terminal on-chain.
30
33
  TERMINAL_STATES = [COMPLETE, FAILED].freeze
31
34
  end
@@ -80,12 +83,30 @@ module Coinbase
80
83
  Status::TERMINAL_STATES.include?(status)
81
84
  end
82
85
 
86
+ # Returns the block hash of which the Transaction is recorded.
87
+ # @return [String] The to block_hash
88
+ def block_hash
89
+ @model.block_hash
90
+ end
91
+
92
+ # Returns the block height of which the Transaction is recorded.
93
+ # @return [String] The to block_height
94
+ def block_height
95
+ @model.block_height
96
+ end
97
+
83
98
  # Returns the link to the transaction on the blockchain explorer.
84
99
  # @return [String] The link to the transaction on the blockchain explorer
85
100
  def transaction_link
86
101
  @model.transaction_link
87
102
  end
88
103
 
104
+ # Returns the block height of which the Transaction is recorded.
105
+ # @return [String] The to block_height
106
+ def content
107
+ @model.content
108
+ end
109
+
89
110
  # Returns the underlying raw transaction.
90
111
  # @return [Eth::Tx::Eip1559] The raw transaction
91
112
  def raw
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coinbase
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -226,8 +226,18 @@ module Coinbase
226
226
  # @param options [Hash] Additional options for the staking operation
227
227
  # @return [BigDecimal] The claimable balance
228
228
 
229
+ # @!method sign_payload
230
+ # Signs the given unsigned payload.
231
+ # @param unsigned_payload [String] The hex-encoded hashed unsigned payload for the Address to sign.
232
+ # @return [Coinbase::PayloadSignature] The payload signature
233
+
234
+ # @!method invoke_contract
235
+ # Invokes a contract with the given ABI, method, and arguments.
236
+ # @param abi [Array<Hash>] The ABI of the contract
237
+ #
238
+
229
239
  def_delegators :default_address, :transfer, :trade, :faucet, :stake, :unstake, :claim_stake, :staking_balances,
230
- :stakeable_balance, :unstakeable_balance, :claimable_balance
240
+ :stakeable_balance, :unstakeable_balance, :claimable_balance, :sign_payload, :invoke_contract
231
241
 
232
242
  # Returns the addresses belonging to the Wallet.
233
243
  # @return [Array<Coinbase::WalletAddress>] The addresses belonging to the Wallet
@@ -22,6 +22,8 @@ module Coinbase
22
22
  # @param event_filters [Array<Hash>] Filters applied to the events that determine
23
23
  # which specific events trigger the webhook. Each filter should be a hash that
24
24
  # can include keys like `contract_address`, `from_address`, or `to_address`.
25
+ # @param signature_header [String] The custom header to be used for x-webhook-signature header on callbacks,
26
+ # so developers can verify the requests are coming from Coinbase.
25
27
  # @return [Coinbase::Webhook] A new instance of Webhook.
26
28
  #
27
29
  # @example Create a new webhook
@@ -29,16 +31,18 @@ module Coinbase
29
31
  # network_id: :ethereum_mainnet,
30
32
  # notification_uri: 'https://example.com/callback',
31
33
  # event_type: 'transaction',
32
- # event_filters: [{ 'contract_address' => '0x...', 'from_address' => '0x...', 'to_address' => '0x...' }]
34
+ # event_filters: [{ 'contract_address' => '0x...', 'from_address' => '0x...', 'to_address' => '0x...' }],
35
+ # signature_header: 'example_header'
33
36
  # )
34
- def create(network_id:, notification_uri:, event_type:, event_filters:)
37
+ def create(network_id:, notification_uri:, event_type:, event_filters:, signature_header: '')
35
38
  model = Coinbase.call_api do
36
39
  webhooks_api.create_webhook(
37
40
  create_webhook_request: {
38
41
  network_id: Coinbase.normalize_network(network_id),
39
42
  notification_uri: notification_uri,
40
43
  event_type: event_type,
41
- event_filters: event_filters
44
+ event_filters: event_filters,
45
+ signature_header: signature_header
42
46
  }
43
47
  )
44
48
  end
@@ -112,6 +116,14 @@ module Coinbase
112
116
  @model.event_filters
113
117
  end
114
118
 
119
+ # Returns the signature header for the webhook. It is used as the value of callback header
120
+ # with key 'x-webhook-signature'.
121
+ #
122
+ # @return [String] The signature header value.
123
+ def signature_header
124
+ @model.signature_header
125
+ end
126
+
115
127
  # Updates the webhook with a new notification URI.
116
128
  #
117
129
  # @param notification_uri [String] The new URI for webhook notifications.
@@ -124,9 +136,7 @@ module Coinbase
124
136
  webhooks_api.update_webhook(
125
137
  id,
126
138
  update_webhook_request: {
127
- network_id: network_id,
128
139
  notification_uri: notification_uri,
129
- event_type: event_type,
130
140
  event_filters: event_filters.map(&:to_hash)
131
141
  }
132
142
  )
@@ -162,7 +172,8 @@ module Coinbase
162
172
  network_id: @model.network_id,
163
173
  event_type: @model.event_type,
164
174
  notification_uri: @model.notification_uri,
165
- event_filters: @model.event_filters.map(&:to_hash).to_json
175
+ event_filters: @model.event_filters.map(&:to_hash).to_json,
176
+ signature_header: @model.signature_header
166
177
  )
167
178
  end
168
179
 
data/lib/coinbase.rb CHANGED
@@ -12,12 +12,14 @@ require_relative 'coinbase/historical_balance'
12
12
  require_relative 'coinbase/client'
13
13
  require_relative 'coinbase/constants'
14
14
  require_relative 'coinbase/contract_event'
15
+ require_relative 'coinbase/contract_invocation'
15
16
  require_relative 'coinbase/destination'
16
17
  require_relative 'coinbase/errors'
17
18
  require_relative 'coinbase/faucet_transaction'
18
19
  require_relative 'coinbase/middleware'
19
20
  require_relative 'coinbase/network'
20
21
  require_relative 'coinbase/pagination'
22
+ require_relative 'coinbase/payload_signature'
21
23
  require_relative 'coinbase/trade'
22
24
  require_relative 'coinbase/transfer'
23
25
  require_relative 'coinbase/transaction'