coinbase-sdk 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +61 -0
  3. data/lib/coinbase/address.rb +25 -1
  4. data/lib/coinbase/client/api/addresses_api.rb +238 -8
  5. data/lib/coinbase/client/api/assets_api.rb +3 -3
  6. data/lib/coinbase/client/api/balance_history_api.rb +107 -0
  7. data/lib/coinbase/client/api/contract_events_api.rb +5 -5
  8. data/lib/coinbase/client/api/contract_invocations_api.rb +342 -0
  9. data/lib/coinbase/client/api/external_addresses_api.rb +24 -30
  10. data/lib/coinbase/client/api/networks_api.rb +3 -3
  11. data/lib/coinbase/client/api/server_signers_api.rb +8 -8
  12. data/lib/coinbase/client/api/stake_api.rb +7 -7
  13. data/lib/coinbase/client/api/trades_api.rb +6 -6
  14. data/lib/coinbase/client/api/transfers_api.rb +6 -6
  15. data/lib/coinbase/client/api/validators_api.rb +8 -8
  16. data/lib/coinbase/client/api/wallet_stake_api.rb +5 -5
  17. data/lib/coinbase/client/api/wallets_api.rb +11 -11
  18. data/lib/coinbase/client/api/webhooks_api.rb +6 -6
  19. data/lib/coinbase/client/api_client.rb +31 -25
  20. data/lib/coinbase/client/api_error.rb +2 -2
  21. data/lib/coinbase/client/configuration.rb +2 -2
  22. data/lib/coinbase/client/models/address.rb +2 -2
  23. data/lib/coinbase/client/models/address_balance_list.rb +2 -2
  24. data/lib/coinbase/client/models/address_historical_balance_list.rb +2 -2
  25. data/lib/coinbase/client/models/address_list.rb +2 -2
  26. data/lib/coinbase/client/models/address_transaction_list.rb +258 -0
  27. data/lib/coinbase/client/models/asset.rb +2 -2
  28. data/lib/coinbase/client/models/balance.rb +2 -2
  29. data/lib/coinbase/client/models/{user.rb → broadcast_contract_invocation_request.rb} +17 -26
  30. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +2 -2
  31. data/lib/coinbase/client/models/broadcast_trade_request.rb +2 -2
  32. data/lib/coinbase/client/models/broadcast_transfer_request.rb +2 -2
  33. data/lib/coinbase/client/models/build_staking_operation_request.rb +2 -2
  34. data/lib/coinbase/client/models/contract_event.rb +2 -2
  35. data/lib/coinbase/client/models/contract_event_list.rb +2 -2
  36. data/lib/coinbase/client/models/contract_invocation.rb +368 -0
  37. data/lib/coinbase/client/models/contract_invocation_list.rb +274 -0
  38. data/lib/coinbase/client/models/create_address_request.rb +2 -2
  39. data/lib/coinbase/client/models/create_contract_invocation_request.rb +276 -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 +2 -2
  42. data/lib/coinbase/client/models/create_staking_operation_request.rb +2 -2
  43. data/lib/coinbase/client/models/create_trade_request.rb +2 -2
  44. data/lib/coinbase/client/models/create_transfer_request.rb +3 -3
  45. data/lib/coinbase/client/models/create_wallet_request.rb +2 -2
  46. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +2 -2
  47. data/lib/coinbase/client/models/create_webhook_request.rb +30 -6
  48. data/lib/coinbase/client/models/erc20_transfer_event.rb +336 -0
  49. data/lib/coinbase/client/models/erc721_transfer_event.rb +336 -0
  50. data/lib/coinbase/client/models/error.rb +16 -6
  51. data/lib/coinbase/client/models/ethereum_transaction.rb +389 -0
  52. data/lib/coinbase/client/models/ethereum_transaction_access.rb +225 -0
  53. data/lib/coinbase/client/models/ethereum_transaction_access_list.rb +216 -0
  54. data/lib/coinbase/client/models/ethereum_transaction_flattened_trace.rb +378 -0
  55. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +2 -2
  56. data/lib/coinbase/client/models/faucet_transaction.rb +2 -2
  57. data/lib/coinbase/client/models/feature_set.rb +2 -2
  58. data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +2 -2
  59. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +2 -2
  60. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +2 -2
  61. data/lib/coinbase/client/models/get_staking_context_request.rb +2 -2
  62. data/lib/coinbase/client/models/historical_balance.rb +2 -2
  63. data/lib/coinbase/client/models/network.rb +4 -4
  64. data/lib/coinbase/client/models/network_identifier.rb +5 -3
  65. data/lib/coinbase/client/models/payload_signature.rb +335 -0
  66. data/lib/coinbase/client/models/payload_signature_list.rb +275 -0
  67. data/lib/coinbase/client/models/seed_creation_event.rb +2 -2
  68. data/lib/coinbase/client/models/seed_creation_event_result.rb +2 -2
  69. data/lib/coinbase/client/models/server_signer.rb +2 -2
  70. data/lib/coinbase/client/models/server_signer_event.rb +2 -2
  71. data/lib/coinbase/client/models/server_signer_event_event.rb +2 -2
  72. data/lib/coinbase/client/models/server_signer_event_list.rb +2 -2
  73. data/lib/coinbase/client/models/server_signer_list.rb +2 -2
  74. data/lib/coinbase/client/models/signature_creation_event.rb +2 -2
  75. data/lib/coinbase/client/models/signature_creation_event_result.rb +2 -2
  76. data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +2 -2
  77. data/lib/coinbase/client/models/sponsored_send.rb +2 -2
  78. data/lib/coinbase/client/models/staking_balance.rb +2 -2
  79. data/lib/coinbase/client/models/staking_context.rb +2 -2
  80. data/lib/coinbase/client/models/staking_context_context.rb +2 -2
  81. data/lib/coinbase/client/models/staking_operation.rb +2 -2
  82. data/lib/coinbase/client/models/staking_operation_metadata.rb +2 -2
  83. data/lib/coinbase/client/models/staking_reward.rb +2 -2
  84. data/lib/coinbase/client/models/staking_reward_format.rb +2 -2
  85. data/lib/coinbase/client/models/staking_reward_usd_value.rb +2 -2
  86. data/lib/coinbase/client/models/trade.rb +2 -2
  87. data/lib/coinbase/client/models/trade_list.rb +2 -2
  88. data/lib/coinbase/client/models/transaction.rb +37 -8
  89. data/lib/coinbase/client/models/transaction_content.rb +104 -0
  90. data/lib/coinbase/client/models/transaction_type.rb +2 -2
  91. data/lib/coinbase/client/models/transfer.rb +2 -2
  92. data/lib/coinbase/client/models/transfer_list.rb +2 -2
  93. data/lib/coinbase/client/models/update_webhook_request.rb +3 -51
  94. data/lib/coinbase/client/models/validator.rb +2 -2
  95. data/lib/coinbase/client/models/validator_details.rb +2 -2
  96. data/lib/coinbase/client/models/validator_list.rb +2 -2
  97. data/lib/coinbase/client/models/validator_status.rb +2 -2
  98. data/lib/coinbase/client/models/wallet.rb +2 -2
  99. data/lib/coinbase/client/models/wallet_list.rb +2 -2
  100. data/lib/coinbase/client/models/webhook.rb +16 -6
  101. data/lib/coinbase/client/models/webhook_event_filter.rb +5 -5
  102. data/lib/coinbase/client/models/webhook_event_type.rb +2 -2
  103. data/lib/coinbase/client/models/webhook_list.rb +2 -2
  104. data/lib/coinbase/client/version.rb +2 -2
  105. data/lib/coinbase/client.rb +19 -4
  106. data/lib/coinbase/constants.rb +3 -0
  107. data/lib/coinbase/contract_invocation.rb +259 -0
  108. data/lib/coinbase/payload_signature.rb +181 -0
  109. data/lib/coinbase/transaction.rb +21 -0
  110. data/lib/coinbase/version.rb +1 -1
  111. data/lib/coinbase/wallet.rb +11 -1
  112. data/lib/coinbase/webhook.rb +17 -6
  113. data/lib/coinbase.rb +2 -0
  114. metadata +21 -5
  115. data/lib/coinbase/client/api/users_api.rb +0 -79
  116. data/lib/coinbase/client/models/feature.rb +0 -43
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -36,6 +36,9 @@ module Coinbase::Client
36
36
  # The date and time the webhook was last updated.
37
37
  attr_accessor :updated_at
38
38
 
39
+ # The header that will contain the signature of the webhook payload.
40
+ attr_accessor :signature_header
41
+
39
42
  class EnumAttributeValidator
40
43
  attr_reader :datatype
41
44
  attr_reader :allowable_values
@@ -67,7 +70,8 @@ module Coinbase::Client
67
70
  :'event_filters' => :'event_filters',
68
71
  :'notification_uri' => :'notification_uri',
69
72
  :'created_at' => :'created_at',
70
- :'updated_at' => :'updated_at'
73
+ :'updated_at' => :'updated_at',
74
+ :'signature_header' => :'signature_header'
71
75
  }
72
76
  end
73
77
 
@@ -85,7 +89,8 @@ module Coinbase::Client
85
89
  :'event_filters' => :'Array<WebhookEventFilter>',
86
90
  :'notification_uri' => :'String',
87
91
  :'created_at' => :'Time',
88
- :'updated_at' => :'Time'
92
+ :'updated_at' => :'Time',
93
+ :'signature_header' => :'String'
89
94
  }
90
95
  end
91
96
 
@@ -139,6 +144,10 @@ module Coinbase::Client
139
144
  if attributes.key?(:'updated_at')
140
145
  self.updated_at = attributes[:'updated_at']
141
146
  end
147
+
148
+ if attributes.key?(:'signature_header')
149
+ self.signature_header = attributes[:'signature_header']
150
+ end
142
151
  end
143
152
 
144
153
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -167,7 +176,8 @@ module Coinbase::Client
167
176
  event_filters == o.event_filters &&
168
177
  notification_uri == o.notification_uri &&
169
178
  created_at == o.created_at &&
170
- updated_at == o.updated_at
179
+ updated_at == o.updated_at &&
180
+ signature_header == o.signature_header
171
181
  end
172
182
 
173
183
  # @see the `==` method
@@ -179,7 +189,7 @@ module Coinbase::Client
179
189
  # Calculates hash code according to all attributes.
180
190
  # @return [Integer] Hash code
181
191
  def hash
182
- [id, network_id, event_type, event_filters, notification_uri, created_at, updated_at].hash
192
+ [id, network_id, event_type, event_filters, notification_uri, created_at, updated_at, signature_header].hash
183
193
  end
184
194
 
185
195
  # Builds the object from hash
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -16,13 +16,13 @@ require 'time'
16
16
  module Coinbase::Client
17
17
  # The event_filter parameter specifies the criteria to filter events from the blockchain. It allows filtering events by contract address, sender address and receiver address. For a single event filter, not all of the properties need to be presented.
18
18
  class WebhookEventFilter
19
- # The onchain contract address of the token being transferred.
19
+ # The onchain contract address of the token for which the events should be tracked.
20
20
  attr_accessor :contract_address
21
21
 
22
- # The onchain address of the sender.
22
+ # The onchain address of the sender. Set this filter to track all transfer events originating from your address.
23
23
  attr_accessor :from_address
24
24
 
25
- # The onchain address of the receiver.
25
+ # The onchain address of the receiver. Set this filter to track all transfer events sent to your address.
26
26
  attr_accessor :to_address
27
27
 
28
28
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -4,9 +4,9 @@
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
- Generator version: 7.7.0
9
+ Generator version: 7.8.0
10
10
 
11
11
  =end
12
12
 
@@ -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'
@@ -37,7 +43,13 @@ Coinbase::Client.autoload :CreateTransferRequest, 'coinbase/client/models/create
37
43
  Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_wallet_request'
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'
46
+ Coinbase::Client.autoload :ERC20TransferEvent, 'coinbase/client/models/erc20_transfer_event'
47
+ Coinbase::Client.autoload :ERC721TransferEvent, 'coinbase/client/models/erc721_transfer_event'
40
48
  Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
49
+ Coinbase::Client.autoload :EthereumTransaction, 'coinbase/client/models/ethereum_transaction'
50
+ Coinbase::Client.autoload :EthereumTransactionAccess, 'coinbase/client/models/ethereum_transaction_access'
51
+ Coinbase::Client.autoload :EthereumTransactionAccessList, 'coinbase/client/models/ethereum_transaction_access_list'
52
+ Coinbase::Client.autoload :EthereumTransactionFlattenedTrace, 'coinbase/client/models/ethereum_transaction_flattened_trace'
41
53
  Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
42
54
  Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
43
55
  Coinbase::Client.autoload :FeatureSet, 'coinbase/client/models/feature_set'
@@ -48,6 +60,8 @@ Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get
48
60
  Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
49
61
  Coinbase::Client.autoload :Network, 'coinbase/client/models/network'
50
62
  Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
63
+ Coinbase::Client.autoload :PayloadSignature, 'coinbase/client/models/payload_signature'
64
+ Coinbase::Client.autoload :PayloadSignatureList, 'coinbase/client/models/payload_signature_list'
51
65
  Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
52
66
  Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
53
67
  Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
@@ -70,11 +84,11 @@ Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/stakin
70
84
  Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
71
85
  Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
72
86
  Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
87
+ Coinbase::Client.autoload :TransactionContent, 'coinbase/client/models/transaction_content'
73
88
  Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
74
89
  Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
75
90
  Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
76
91
  Coinbase::Client.autoload :UpdateWebhookRequest, 'coinbase/client/models/update_webhook_request'
77
- Coinbase::Client.autoload :User, 'coinbase/client/models/user'
78
92
  Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
79
93
  Coinbase::Client.autoload :ValidatorDetails, 'coinbase/client/models/validator_details'
80
94
  Coinbase::Client.autoload :ValidatorList, 'coinbase/client/models/validator_list'
@@ -89,14 +103,15 @@ Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
89
103
  # APIs
90
104
  Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
91
105
  Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
106
+ Coinbase::Client.autoload :BalanceHistoryApi, 'coinbase/client/api/balance_history_api'
92
107
  Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
108
+ Coinbase::Client.autoload :ContractInvocationsApi, 'coinbase/client/api/contract_invocations_api'
93
109
  Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
94
110
  Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
95
111
  Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
96
112
  Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
97
113
  Coinbase::Client.autoload :TradesApi, 'coinbase/client/api/trades_api'
98
114
  Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
99
- Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
100
115
  Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
101
116
  Coinbase::Client.autoload :WalletStakeApi, 'coinbase/client/api/wallet_stake_api'
102
117
  Coinbase::Client.autoload :WalletsApi, 'coinbase/client/api/wallets_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,259 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+
5
+ module Coinbase
6
+ # A representation of a Contract Invocation.
7
+ class ContractInvocation
8
+ class << self
9
+ # Creates a new ContractInvocation object.
10
+ # @param address_id [String] The Address ID of the signing Address
11
+ # @param wallet_id [String] The Wallet ID associated with the signing Address
12
+ # @param contract_address [String] The contract address
13
+ # @param abi [Array<Hash>] The contract ABI
14
+ # @param method [String] The contract method
15
+ # @param amount [Integer, Float, BigDecimal] The amount of the native Asset
16
+ # to send to a payable contract method.
17
+ # @param asset_id [Symbol] The ID of the Asset to send to a payable contract method.
18
+ # The Asset must be a denomination of the native Asset. For Ethereum, :eth, :gwei, and :wei are supported.
19
+ # @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
20
+ # @param args [Hash] The arguments to pass to the contract method.
21
+ # The keys should be the argument names, and the values should be the argument values.
22
+ # @return [ContractInvocation] The new Contract Invocation object
23
+ # @raise [Coinbase::ApiError] If the request to create the Contract Invocation fails
24
+ def create(
25
+ address_id:,
26
+ wallet_id:,
27
+ contract_address:,
28
+ abi:,
29
+ method:,
30
+ amount:,
31
+ asset_id:,
32
+ network:,
33
+ args: {}
34
+ )
35
+ atomic_amount = nil
36
+
37
+ if amount && asset_id && network
38
+ network = Coinbase::Network.from_id(network)
39
+ asset = network.get_asset(asset_id)
40
+ atomic_amount = asset.to_atomic_amount(amount).to_i_to_s
41
+ end
42
+
43
+ model = Coinbase.call_api do
44
+ contract_invocation_api.create_contract_invocation(
45
+ wallet_id,
46
+ address_id,
47
+ contract_address: contract_address,
48
+ abi: abi.to_json,
49
+ method: method,
50
+ args: args.to_json,
51
+ amount: atomic_amount
52
+ )
53
+ end
54
+
55
+ new(model)
56
+ end
57
+
58
+ # Enumerates the payload signatures for a given address belonging to a wallet.
59
+ # The result is an enumerator that lazily fetches from the server, and can be iterated over,
60
+ # converted an array, etc...
61
+ # @return [Enumerable<Coinbase::ContractInvocation>] Enumerator that returns payload signatures
62
+ def list(wallet_id:, address_id:)
63
+ Coinbase::Pagination.enumerate(
64
+ ->(page) { fetch_page(wallet_id, address_id, page) }
65
+ ) do |contract_invocation|
66
+ new(contract_invocation)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def contract_invocation_api
73
+ Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
74
+ end
75
+
76
+ def fetch_page(wallet_id, address_id, page)
77
+ contract_invocation_api.list_contract_invocations(
78
+ wallet_id,
79
+ address_id,
80
+ limit: DEFAULT_PAGE_LIMIT,
81
+ page: page
82
+ )
83
+ end
84
+ end
85
+
86
+ # Returns a new ContractInvocation object. Do not use this method directly.
87
+ # Instead use Coinbase::ContractInvocation.create.
88
+ # @param model [Coinbase::Client::ContractInvocation] The underlying Contract Invocation obejct
89
+ def initialize(model)
90
+ raise unless model.is_a?(Coinbase::Client::ContractInvocation)
91
+
92
+ @model = model
93
+ end
94
+
95
+ # Returns the Contract Invocation ID.
96
+ # @return [String] The Contract Invocation ID
97
+ def id
98
+ @model.contract_invocation_id
99
+ end
100
+
101
+ # Returns the Wallet ID of the Contract Invocation.
102
+ # @return [String] The Wallet ID
103
+ def wallet_id
104
+ @model.wallet_id
105
+ end
106
+
107
+ # Returns the Address ID of the Contract Invocation.
108
+ # @return [String] The Address ID
109
+ def address_id
110
+ @model.address_id
111
+ end
112
+
113
+ # Returns the Network of the Contract Invocation.
114
+ # @return [Coinbase::Network] The Network
115
+ def network
116
+ @network ||= Coinbase::Network.from_id(@model.network_id)
117
+ end
118
+
119
+ # Returns the Contract Address of the Contract Invocation.
120
+ # @return [String] The Contract Address
121
+ def contract_address
122
+ @model.contract_address
123
+ end
124
+
125
+ # Returns the ABI of the Contract Invocation.
126
+ # @return [Array<Hash>] The ABI
127
+ def abi
128
+ JSON.parse(@model.abi)
129
+ end
130
+
131
+ # Returns the method of the Contract Invocation.
132
+ # @return [String] The method
133
+ def method
134
+ @model.method
135
+ end
136
+
137
+ # Returns the arguments of the Contract Invocation.
138
+ # @return [Hash] The arguments
139
+ def args
140
+ JSON.parse(@model.args).transform_keys(&:to_sym)
141
+ end
142
+
143
+ # Returns the amount of the native asset sent to a payable contract method, if applicable.
144
+ # @return [BigDecimal] The amount in atomic units of the native asset
145
+ def amount
146
+ BigDecimal(@model.amount)
147
+ end
148
+
149
+ # Returns the transaction.
150
+ # @return [Coinbase::Transaction] The Transfer transaction
151
+ def transaction
152
+ @transaction ||= Coinbase::Transaction.new(@model.transaction)
153
+ end
154
+
155
+ # Returns the status of the Contract Invocation.
156
+ # @return [String] The status
157
+ def status
158
+ transaction.status
159
+ end
160
+
161
+ # Signs the Contract Invocation transaction with the given key.
162
+ # This is required before broadcasting the Contract Invocation when not using
163
+ # a Server-Signer.
164
+ # @param key [Eth::Key] The key to sign the ContractInvocation with
165
+ # @raise [RuntimeError] If the key is not an Eth::Key
166
+ # @return [ContractInvocation] The ContractInvocation object
167
+ def sign(key)
168
+ raise unless key.is_a?(Eth::Key)
169
+
170
+ transaction.sign(key)
171
+
172
+ self
173
+ end
174
+
175
+ # Broadcasts the ContractInvocation to the Network.
176
+ # @raise [RuntimeError] If the ContractInvocation is not signed
177
+ # @return [ContractInvocation] The ContractInvocation object
178
+ def broadcast!
179
+ raise TransactionNotSignedError unless transaction.signed?
180
+
181
+ @model = Coinbase.call_api do
182
+ contract_invocation_api.broadcast_contract_invocation(
183
+ wallet_id,
184
+ address_id,
185
+ id,
186
+ { signed_payload: transaction.signature }
187
+ )
188
+ end
189
+
190
+ @transaction = Coinbase::Transaction.new(@model.transaction)
191
+
192
+ self
193
+ end
194
+
195
+ # # Reload reloads the Contract Invocation model with the latest version from the server side.
196
+ # @return [ContractInvocation] The most recent version of Contract Invocation from the server
197
+ def reload
198
+ @model = Coinbase.call_api do
199
+ contract_invocation_api.get_contract_invocation(wallet_id, address_id, id)
200
+ end
201
+
202
+ @transaction = Coinbase::Transaction.new(@model.transaction)
203
+
204
+ self
205
+ end
206
+
207
+ # Waits until the Contract Invocation is signed or failed by polling the server at the given interval. Raises a
208
+ # Timeout::Error if the Contract Invocation takes longer than the given timeout.
209
+ # @param interval_seconds [Integer] The interval at which to poll the server, in seconds
210
+ # @param timeout_seconds [Integer] The maximum amount of time to wait for the Contract Invocation to be signed,
211
+ # in seconds.
212
+ # @return [ContractInvocation] The completed Contract Invocation object
213
+ def wait!(interval_seconds = 0.2, timeout_seconds = 20)
214
+ start_time = Time.now
215
+
216
+ loop do
217
+ reload
218
+
219
+ return self if transaction.terminal_state?
220
+
221
+ raise Timeout::Error, 'Contract Invocation timed out' if Time.now - start_time > timeout_seconds
222
+
223
+ self.sleep interval_seconds
224
+ end
225
+
226
+ self
227
+ end
228
+
229
+ # Returns a String representation of the Contract Invocation.
230
+ # @return [String] a String representation of the Contract Invocation
231
+ def to_s
232
+ Coinbase.pretty_print_object(
233
+ self.class,
234
+ id: id,
235
+ wallet_id: wallet_id,
236
+ address_id: address_id,
237
+ network_id: network.id,
238
+ status: status,
239
+ abi: abi.to_json,
240
+ method: method,
241
+ args: args.to_json,
242
+ transaction_hash: transaction.transaction_hash,
243
+ transaction_link: transaction.transaction_link
244
+ )
245
+ end
246
+
247
+ # Same as to_s.
248
+ # @return [String] a String representation of the ContractInvocation
249
+ def inspect
250
+ to_s
251
+ end
252
+
253
+ private
254
+
255
+ def contract_invocation_api
256
+ @contract_invocation_api ||= Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
257
+ end
258
+ end
259
+ end