coinbase-sdk 0.5.0 → 0.7.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 +70 -1
- data/lib/coinbase/address.rb +5 -1
- data/lib/coinbase/client/api/external_addresses_api.rb +0 -79
- data/lib/coinbase/client/api/smart_contracts_api.rb +332 -0
- data/lib/coinbase/client/api/stake_api.rb +0 -8
- data/lib/coinbase/client/api/transaction_history_api.rb +101 -0
- data/lib/coinbase/client/api/users_api.rb +79 -0
- data/lib/coinbase/client/api/validators_api.rb +4 -4
- data/lib/coinbase/client/api/wallets_api.rb +4 -4
- data/lib/coinbase/client/api/webhooks_api.rb +72 -2
- data/lib/coinbase/client/models/create_smart_contract_request.rb +259 -0
- data/lib/coinbase/client/models/create_wallet_webhook_request.rb +232 -0
- data/lib/coinbase/client/models/create_webhook_request.rb +10 -8
- data/lib/coinbase/client/models/deploy_smart_contract_request.rb +222 -0
- data/lib/coinbase/client/models/multi_token_contract_options.rb +223 -0
- data/lib/coinbase/client/models/network_identifier.rb +2 -1
- data/lib/coinbase/client/models/nft_contract_options.rb +257 -0
- data/lib/coinbase/client/models/smart_contract.rb +378 -0
- data/lib/coinbase/client/models/smart_contract_list.rb +257 -0
- data/lib/coinbase/client/models/smart_contract_options.rb +107 -0
- data/lib/coinbase/client/models/smart_contract_type.rb +42 -0
- data/lib/coinbase/client/models/staking_balance.rb +2 -2
- data/lib/coinbase/client/models/staking_reward.rb +2 -2
- data/lib/coinbase/client/models/token_contract_options.rb +257 -0
- data/lib/coinbase/client/models/update_webhook_request.rb +10 -8
- data/lib/coinbase/client/models/user.rb +231 -0
- data/lib/coinbase/client/models/webhook.rb +10 -1
- data/lib/coinbase/client/models/webhook_event_type.rb +2 -1
- data/lib/coinbase/client/models/webhook_event_type_filter.rb +105 -0
- data/lib/coinbase/client/models/webhook_wallet_activity_filter.rb +228 -0
- data/lib/coinbase/client.rb +15 -0
- data/lib/coinbase/contract_invocation.rb +16 -17
- data/lib/coinbase/smart_contract.rb +264 -39
- data/lib/coinbase/transaction.rb +3 -0
- data/lib/coinbase/transfer.rb +1 -1
- data/lib/coinbase/version.rb +1 -1
- data/lib/coinbase/wallet.rb +45 -2
- data/lib/coinbase/webhook.rb +3 -7
- metadata +18 -2
data/lib/coinbase/client.rb
CHANGED
@@ -37,12 +37,14 @@ Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_
|
|
37
37
|
Coinbase::Client.autoload :CreateContractInvocationRequest, 'coinbase/client/models/create_contract_invocation_request'
|
38
38
|
Coinbase::Client.autoload :CreatePayloadSignatureRequest, 'coinbase/client/models/create_payload_signature_request'
|
39
39
|
Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
|
40
|
+
Coinbase::Client.autoload :CreateSmartContractRequest, 'coinbase/client/models/create_smart_contract_request'
|
40
41
|
Coinbase::Client.autoload :CreateStakingOperationRequest, 'coinbase/client/models/create_staking_operation_request'
|
41
42
|
Coinbase::Client.autoload :CreateTradeRequest, 'coinbase/client/models/create_trade_request'
|
42
43
|
Coinbase::Client.autoload :CreateTransferRequest, 'coinbase/client/models/create_transfer_request'
|
43
44
|
Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_wallet_request'
|
44
45
|
Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
|
45
46
|
Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
|
47
|
+
Coinbase::Client.autoload :DeploySmartContractRequest, 'coinbase/client/models/deploy_smart_contract_request'
|
46
48
|
Coinbase::Client.autoload :ERC20TransferEvent, 'coinbase/client/models/erc20_transfer_event'
|
47
49
|
Coinbase::Client.autoload :ERC721TransferEvent, 'coinbase/client/models/erc721_transfer_event'
|
48
50
|
Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
|
@@ -58,6 +60,8 @@ Coinbase::Client.autoload :FetchStakingRewards200Response, 'coinbase/client/mode
|
|
58
60
|
Coinbase::Client.autoload :FetchStakingRewardsRequest, 'coinbase/client/models/fetch_staking_rewards_request'
|
59
61
|
Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get_staking_context_request'
|
60
62
|
Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
|
63
|
+
Coinbase::Client.autoload :MultiTokenContractOptions, 'coinbase/client/models/multi_token_contract_options'
|
64
|
+
Coinbase::Client.autoload :NFTContractOptions, 'coinbase/client/models/nft_contract_options'
|
61
65
|
Coinbase::Client.autoload :Network, 'coinbase/client/models/network'
|
62
66
|
Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
|
63
67
|
Coinbase::Client.autoload :PayloadSignature, 'coinbase/client/models/payload_signature'
|
@@ -72,6 +76,10 @@ Coinbase::Client.autoload :ServerSignerList, 'coinbase/client/models/server_sign
|
|
72
76
|
Coinbase::Client.autoload :SignatureCreationEvent, 'coinbase/client/models/signature_creation_event'
|
73
77
|
Coinbase::Client.autoload :SignatureCreationEventResult, 'coinbase/client/models/signature_creation_event_result'
|
74
78
|
Coinbase::Client.autoload :SignedVoluntaryExitMessageMetadata, 'coinbase/client/models/signed_voluntary_exit_message_metadata'
|
79
|
+
Coinbase::Client.autoload :SmartContract, 'coinbase/client/models/smart_contract'
|
80
|
+
Coinbase::Client.autoload :SmartContractList, 'coinbase/client/models/smart_contract_list'
|
81
|
+
Coinbase::Client.autoload :SmartContractOptions, 'coinbase/client/models/smart_contract_options'
|
82
|
+
Coinbase::Client.autoload :SmartContractType, 'coinbase/client/models/smart_contract_type'
|
75
83
|
Coinbase::Client.autoload :SponsoredSend, 'coinbase/client/models/sponsored_send'
|
76
84
|
Coinbase::Client.autoload :StakingBalance, 'coinbase/client/models/staking_balance'
|
77
85
|
Coinbase::Client.autoload :StakingContext, 'coinbase/client/models/staking_context'
|
@@ -81,6 +89,7 @@ Coinbase::Client.autoload :StakingOperationMetadata, 'coinbase/client/models/sta
|
|
81
89
|
Coinbase::Client.autoload :StakingReward, 'coinbase/client/models/staking_reward'
|
82
90
|
Coinbase::Client.autoload :StakingRewardFormat, 'coinbase/client/models/staking_reward_format'
|
83
91
|
Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/staking_reward_usd_value'
|
92
|
+
Coinbase::Client.autoload :TokenContractOptions, 'coinbase/client/models/token_contract_options'
|
84
93
|
Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
|
85
94
|
Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
|
86
95
|
Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
|
@@ -89,6 +98,7 @@ Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_
|
|
89
98
|
Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
|
90
99
|
Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
|
91
100
|
Coinbase::Client.autoload :UpdateWebhookRequest, 'coinbase/client/models/update_webhook_request'
|
101
|
+
Coinbase::Client.autoload :User, 'coinbase/client/models/user'
|
92
102
|
Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
|
93
103
|
Coinbase::Client.autoload :ValidatorDetails, 'coinbase/client/models/validator_details'
|
94
104
|
Coinbase::Client.autoload :ValidatorList, 'coinbase/client/models/validator_list'
|
@@ -98,7 +108,9 @@ Coinbase::Client.autoload :WalletList, 'coinbase/client/models/wallet_list'
|
|
98
108
|
Coinbase::Client.autoload :Webhook, 'coinbase/client/models/webhook'
|
99
109
|
Coinbase::Client.autoload :WebhookEventFilter, 'coinbase/client/models/webhook_event_filter'
|
100
110
|
Coinbase::Client.autoload :WebhookEventType, 'coinbase/client/models/webhook_event_type'
|
111
|
+
Coinbase::Client.autoload :WebhookEventTypeFilter, 'coinbase/client/models/webhook_event_type_filter'
|
101
112
|
Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
|
113
|
+
Coinbase::Client.autoload :WebhookWalletActivityFilter, 'coinbase/client/models/webhook_wallet_activity_filter'
|
102
114
|
|
103
115
|
# APIs
|
104
116
|
Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
|
@@ -109,9 +121,12 @@ Coinbase::Client.autoload :ContractInvocationsApi, 'coinbase/client/api/contract
|
|
109
121
|
Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
|
110
122
|
Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
|
111
123
|
Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
|
124
|
+
Coinbase::Client.autoload :SmartContractsApi, 'coinbase/client/api/smart_contracts_api'
|
112
125
|
Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
|
113
126
|
Coinbase::Client.autoload :TradesApi, 'coinbase/client/api/trades_api'
|
127
|
+
Coinbase::Client.autoload :TransactionHistoryApi, 'coinbase/client/api/transaction_history_api'
|
114
128
|
Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
|
129
|
+
Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
|
115
130
|
Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
|
116
131
|
Coinbase::Client.autoload :WalletStakeApi, 'coinbase/client/api/wallet_stake_api'
|
117
132
|
Coinbase::Client.autoload :WalletsApi, 'coinbase/client/api/wallets_api'
|
@@ -25,31 +25,30 @@ module Coinbase
|
|
25
25
|
address_id:,
|
26
26
|
wallet_id:,
|
27
27
|
contract_address:,
|
28
|
-
abi:,
|
29
28
|
method:,
|
30
|
-
amount:,
|
31
|
-
asset_id:,
|
32
29
|
network:,
|
33
|
-
args: {}
|
30
|
+
args: {},
|
31
|
+
amount: nil,
|
32
|
+
abi: nil,
|
33
|
+
asset_id: nil
|
34
34
|
)
|
35
|
-
|
35
|
+
req = {
|
36
|
+
method: method,
|
37
|
+
args: args.to_json,
|
38
|
+
contract_address: contract_address
|
39
|
+
}
|
36
40
|
|
41
|
+
req[:abi] = abi.to_json unless abi.nil?
|
42
|
+
|
43
|
+
# For payable contract invocations, convert the amount to atomic units of specified asset.
|
37
44
|
if amount && asset_id && network
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
asset = Coinbase::Asset.fetch(network, asset_id)
|
46
|
+
|
47
|
+
req[:amount] = asset.to_atomic_amount(amount).to_i.to_s
|
41
48
|
end
|
42
49
|
|
43
50
|
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
|
-
)
|
51
|
+
contract_invocation_api.create_contract_invocation(wallet_id, address_id, **req)
|
53
52
|
end
|
54
53
|
|
55
54
|
new(model)
|
@@ -23,63 +23,118 @@ module Coinbase
|
|
23
23
|
)
|
24
24
|
Coinbase::Pagination.enumerate(
|
25
25
|
lambda { |page|
|
26
|
-
list_events_page(
|
27
|
-
|
26
|
+
list_events_page(
|
27
|
+
network_id,
|
28
|
+
protocol_name,
|
29
|
+
contract_address,
|
30
|
+
contract_name,
|
31
|
+
event_name,
|
32
|
+
from_block_height,
|
33
|
+
to_block_height,
|
34
|
+
page
|
35
|
+
)
|
28
36
|
}
|
29
37
|
) do |contract_event|
|
30
38
|
Coinbase::ContractEvent.new(contract_event)
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
# Creates a new ERC20 token contract, that can subsequently be deployed to
|
43
|
+
# the blockchain.
|
44
|
+
# @param address_id [String] The address ID of deployer
|
45
|
+
# @param wallet_id [String] The wallet ID of the deployer
|
46
|
+
# @param name [String] The name of the token
|
47
|
+
# @param symbol [String] The symbol of the token
|
48
|
+
# @param total_supply [String] The total supply of the token, denominate in whole units.
|
49
|
+
# @return [SmartContract] The new ERC20 Token SmartContract object
|
50
|
+
def self.create_token_contract(
|
51
|
+
address_id:,
|
52
|
+
wallet_id:,
|
53
|
+
name:,
|
54
|
+
symbol:,
|
55
|
+
total_supply:
|
56
|
+
)
|
57
|
+
contract = Coinbase.call_api do
|
58
|
+
smart_contracts_api.create_smart_contract(
|
59
|
+
wallet_id,
|
60
|
+
address_id,
|
61
|
+
{
|
62
|
+
type: Coinbase::Client::SmartContractType::ERC20,
|
63
|
+
options: Coinbase::Client::TokenContractOptions.new(
|
64
|
+
name: name,
|
65
|
+
symbol: symbol,
|
66
|
+
total_supply: BigDecimal(total_supply).to_i.to_s
|
67
|
+
).to_body
|
68
|
+
}
|
69
|
+
)
|
70
|
+
end
|
39
71
|
|
40
|
-
|
41
|
-
# @return [String] The network ID
|
42
|
-
def network_id
|
43
|
-
Coinbase.to_sym(@model.network_id)
|
72
|
+
new(contract)
|
44
73
|
end
|
45
74
|
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
75
|
+
# Creates a new ERC721 token contract, that can subsequently be deployed to
|
76
|
+
# the blockchain.
|
77
|
+
# @param address_id [String] The address ID of deployer
|
78
|
+
# @param wallet_id [String] The wallet ID of the deployer
|
79
|
+
# @param name [String] The name of the token
|
80
|
+
# @param symbol [String] The symbol of the token
|
81
|
+
# @param base_uri [String] The base URI for the token metadata
|
82
|
+
# @return [SmartContract] The new ERC721 Token SmartContract object
|
83
|
+
def self.create_nft_contract(
|
84
|
+
address_id:,
|
85
|
+
wallet_id:,
|
86
|
+
name:,
|
87
|
+
symbol:,
|
88
|
+
base_uri:
|
89
|
+
)
|
90
|
+
contract = Coinbase.call_api do
|
91
|
+
smart_contracts_api.create_smart_contract(
|
92
|
+
wallet_id,
|
93
|
+
address_id,
|
94
|
+
{
|
95
|
+
type: Coinbase::Client::SmartContractType::ERC721,
|
96
|
+
options: Coinbase::Client::NFTContractOptions.new(
|
97
|
+
name: name,
|
98
|
+
symbol: symbol,
|
99
|
+
base_uri: base_uri
|
100
|
+
).to_body
|
101
|
+
}
|
102
|
+
)
|
103
|
+
end
|
51
104
|
|
52
|
-
|
53
|
-
# @return [String] The contract name
|
54
|
-
def contract_name
|
55
|
-
@model.contract_name
|
105
|
+
new(contract)
|
56
106
|
end
|
57
107
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
108
|
+
def self.create_multi_token_contract(
|
109
|
+
address_id:,
|
110
|
+
wallet_id:,
|
111
|
+
uri:
|
112
|
+
)
|
113
|
+
contract = Coinbase.call_api do
|
114
|
+
smart_contracts_api.create_smart_contract(
|
115
|
+
wallet_id,
|
116
|
+
address_id,
|
117
|
+
{
|
118
|
+
type: Coinbase::Client::SmartContractType::ERC1155,
|
119
|
+
options: Coinbase::Client::MultiTokenContractOptions.new(
|
120
|
+
uri: uri
|
121
|
+
).to_body
|
122
|
+
}
|
123
|
+
)
|
124
|
+
end
|
73
125
|
|
74
|
-
|
75
|
-
# @return [String] a string representation of the SmartContract
|
76
|
-
def inspect
|
77
|
-
to_s
|
126
|
+
new(contract)
|
78
127
|
end
|
79
128
|
|
80
129
|
def self.contract_events_api
|
81
130
|
Coinbase::Client::ContractEventsApi.new(Coinbase.configuration.api_client)
|
82
131
|
end
|
132
|
+
private_class_method :contract_events_api
|
133
|
+
|
134
|
+
def self.smart_contracts_api
|
135
|
+
Coinbase::Client::SmartContractsApi.new(Coinbase.configuration.api_client)
|
136
|
+
end
|
137
|
+
private_class_method :smart_contracts_api
|
83
138
|
|
84
139
|
def self.list_events_page(
|
85
140
|
network_id,
|
@@ -102,5 +157,175 @@ module Coinbase
|
|
102
157
|
{ next_page: page }
|
103
158
|
)
|
104
159
|
end
|
160
|
+
private_class_method :list_events_page
|
161
|
+
|
162
|
+
# Returns a new SmartContract object.
|
163
|
+
# @param model [Coinbase::Client::SmartContract] The underlying SmartContract object
|
164
|
+
def initialize(model)
|
165
|
+
raise unless model.is_a?(Coinbase::Client::SmartContract)
|
166
|
+
|
167
|
+
@model = model
|
168
|
+
end
|
169
|
+
|
170
|
+
# Returns the SmartContract ID.
|
171
|
+
# NOTE: This is not the contract address and is primarily used before
|
172
|
+
# the contract is deployed.
|
173
|
+
# @return [String] The SmartContract ID
|
174
|
+
def id
|
175
|
+
@model.smart_contract_id
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns the Network of the SmartContract.
|
179
|
+
# @return [Coinbase::Network] The Network
|
180
|
+
def network
|
181
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Returns the contract address of the SmartContract.
|
185
|
+
# @return [String] The contract address
|
186
|
+
def contract_address
|
187
|
+
@model.contract_address
|
188
|
+
end
|
189
|
+
|
190
|
+
# Returns the address of the deployer of the SmartContract.
|
191
|
+
# @return [String] The deployer address
|
192
|
+
def deployer_address
|
193
|
+
@model.deployer_address
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the ABI of the Smart Contract.
|
197
|
+
# @return [Array<Hash>] The ABI
|
198
|
+
def abi
|
199
|
+
JSON.parse(@model.abi)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Returns the ID of the wallet that deployed the SmartContract.
|
203
|
+
# @return [String] The wallet ID
|
204
|
+
def wallet_id
|
205
|
+
@model.wallet_id
|
206
|
+
end
|
207
|
+
|
208
|
+
# Returns the type of the SmartContract.
|
209
|
+
# @return [Coinbase::Client::SmartContractType] The SmartContract type
|
210
|
+
def type
|
211
|
+
@model.type
|
212
|
+
end
|
213
|
+
|
214
|
+
# Returns the options of the SmartContract.
|
215
|
+
# @return [Coinbase::Client::SmartContractOptions] The SmartContract options
|
216
|
+
def options
|
217
|
+
@model.options
|
218
|
+
end
|
219
|
+
|
220
|
+
# Returns the transaction.
|
221
|
+
# @return [Coinbase::Transaction] The SmartContracy deployment transaction
|
222
|
+
def transaction
|
223
|
+
@transaction ||= Coinbase::Transaction.new(@model.transaction)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Returns the status of the SmartContract.
|
227
|
+
# @return [String] The status
|
228
|
+
def status
|
229
|
+
transaction.status
|
230
|
+
end
|
231
|
+
|
232
|
+
# Signs the SmartContract deployment transaction with the given key.
|
233
|
+
# This is required before broadcasting the SmartContract.
|
234
|
+
# @param key [Eth::Key] The key to sign the SmartContract with
|
235
|
+
# @return [SmartContract] The SmartContract object
|
236
|
+
# @raise [RuntimeError] If the key is not an Eth::Key
|
237
|
+
# @raise [Coinbase::AlreadySignedError] If the SmartContract has already been signed
|
238
|
+
def sign(key)
|
239
|
+
raise unless key.is_a?(Eth::Key)
|
240
|
+
|
241
|
+
transaction.sign(key)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Deploys the signed SmartContract to the blockchain.
|
245
|
+
# @return [SmartContract] The SmartContract object
|
246
|
+
# @raise [Coinbase::TransactionNotSignedError] If the SmartContract has not been signed
|
247
|
+
def deploy!
|
248
|
+
raise TransactionNotSignedError unless transaction.signed?
|
249
|
+
|
250
|
+
@model = Coinbase.call_api do
|
251
|
+
smart_contracts_api.deploy_smart_contract(
|
252
|
+
wallet_id,
|
253
|
+
deployer_address,
|
254
|
+
id,
|
255
|
+
{ signed_payload: transaction.signature }
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
@transaction = Coinbase::Transaction.new(@model.transaction)
|
260
|
+
|
261
|
+
self
|
262
|
+
end
|
263
|
+
|
264
|
+
# Reloads the Smart Contract model with the latest version from the server side.
|
265
|
+
# @return [SmartContract] The most recent version of Smart Contract from the server
|
266
|
+
def reload
|
267
|
+
@model = Coinbase.call_api do
|
268
|
+
smart_contracts_api.get_smart_contract(
|
269
|
+
wallet_id,
|
270
|
+
deployer_address,
|
271
|
+
id
|
272
|
+
)
|
273
|
+
end
|
274
|
+
|
275
|
+
@transaction = Coinbase::Transaction.new(@model.transaction)
|
276
|
+
|
277
|
+
self
|
278
|
+
end
|
279
|
+
|
280
|
+
# Waits until the Smart Contract deployment is signed or failed by polling the server at the given interval.
|
281
|
+
# @param interval_seconds [Integer] The interval at which to poll the server, in seconds
|
282
|
+
# @param timeout_seconds [Integer] The maximum amount of time to wait for the Smart Contract,
|
283
|
+
# deployment to land on-chain, in seconds
|
284
|
+
# @return [SmartContract] The completed Smart Contract object
|
285
|
+
# @raise [Timeout::Error] if the Contract Invocation takes longer than the given timeout
|
286
|
+
def wait!(interval_seconds = 0.2, timeout_seconds = 20)
|
287
|
+
start_time = Time.now
|
288
|
+
|
289
|
+
loop do
|
290
|
+
reload
|
291
|
+
|
292
|
+
return self if transaction.terminal_state?
|
293
|
+
|
294
|
+
if Time.now - start_time > timeout_seconds
|
295
|
+
raise Timeout::Error,
|
296
|
+
'SmartContract deployment timed out. Try waiting again.'
|
297
|
+
end
|
298
|
+
|
299
|
+
self.sleep interval_seconds
|
300
|
+
end
|
301
|
+
|
302
|
+
self
|
303
|
+
end
|
304
|
+
|
305
|
+
# Same as to_s.
|
306
|
+
# @return [String] a string representation of the SmartContract
|
307
|
+
def inspect
|
308
|
+
to_s
|
309
|
+
end
|
310
|
+
|
311
|
+
# Returns a string representation of the SmartContract.
|
312
|
+
# @return [String] a string representation of the SmartContract
|
313
|
+
def to_s
|
314
|
+
Coinbase.pretty_print_object(
|
315
|
+
self.class,
|
316
|
+
network: network.id,
|
317
|
+
contract_address: contract_address,
|
318
|
+
deployer_address: deployer_address,
|
319
|
+
type: type,
|
320
|
+
status: status,
|
321
|
+
options: Coinbase.pretty_print_object('Options', **options)
|
322
|
+
)
|
323
|
+
end
|
324
|
+
|
325
|
+
private
|
326
|
+
|
327
|
+
def smart_contracts_api
|
328
|
+
@smart_contracts_api ||= Coinbase::Client::SmartContractsApi.new(Coinbase.configuration.api_client)
|
329
|
+
end
|
105
330
|
end
|
106
331
|
end
|
data/lib/coinbase/transaction.rb
CHANGED
@@ -147,6 +147,9 @@ module Coinbase
|
|
147
147
|
# Signs the Transaction with the provided key and returns the hex signing payload.
|
148
148
|
# @return [String] The hex-encoded signed payload
|
149
149
|
def sign(key)
|
150
|
+
raise 'Invalid key type' unless key.is_a?(Eth::Key)
|
151
|
+
raise Coinbase::AlreadySignedError if signed?
|
152
|
+
|
150
153
|
raw.sign(key)
|
151
154
|
|
152
155
|
signature
|
data/lib/coinbase/transfer.rb
CHANGED
data/lib/coinbase/version.rb
CHANGED
data/lib/coinbase/wallet.rb
CHANGED
@@ -234,10 +234,33 @@ module Coinbase
|
|
234
234
|
# @!method invoke_contract
|
235
235
|
# Invokes a contract with the given ABI, method, and arguments.
|
236
236
|
# @param abi [Array<Hash>] The ABI of the contract
|
237
|
-
|
237
|
+
|
238
|
+
# @!method deploy_token
|
239
|
+
# Deploys a new ERC20 token contract with the given name, symbol, and total supply.
|
240
|
+
# @param name [String] The name of the token.
|
241
|
+
# @param symbol [String] The symbol of the token.
|
242
|
+
# @param total_supply [Integer, BigDecimal] The total supply of the token, denominated in
|
243
|
+
# whole units.
|
244
|
+
# @return [Coinbase::SmartContract] The deployed token contract.
|
245
|
+
# @raise [AddressCannotSignError] if the Address does not have a private key backing it.
|
246
|
+
|
247
|
+
# @!method deploy_nft
|
248
|
+
# Deploys a new ERC721 NFT contract with the given name, symbol, and base URI.
|
249
|
+
# @param name [String] The name of the NFT contract.
|
250
|
+
# @param symbol [String] The symbol of the NFT contract.
|
251
|
+
# @param base_uri [String] The base URI for the NFT contract.
|
252
|
+
# @return [Coinbase::SmartContract] The deployed NFT contract.
|
253
|
+
# @raise [AddressCannotSignError] if the Address does not have a private key backing it.
|
254
|
+
|
255
|
+
# @!method deploy_multi_token
|
256
|
+
# Deploys a new ERC1155 multi-token contract with the given URI.
|
257
|
+
# @param uri [String] The URI for the token metadata, where {id} will be replaced with the token ID.
|
258
|
+
# @return [Coinbase::SmartContract] The deployed multi-token contract.
|
259
|
+
# @raise [AddressCannotSignError] if the Address does not have a private key backing it.
|
238
260
|
|
239
261
|
def_delegators :default_address, :transfer, :trade, :faucet, :stake, :unstake, :claim_stake, :staking_balances,
|
240
|
-
:stakeable_balance, :unstakeable_balance, :claimable_balance, :sign_payload, :invoke_contract
|
262
|
+
:stakeable_balance, :unstakeable_balance, :claimable_balance, :sign_payload, :invoke_contract,
|
263
|
+
:deploy_token, :deploy_nft, :deploy_multi_token
|
241
264
|
|
242
265
|
# Returns the addresses belonging to the Wallet.
|
243
266
|
# @return [Array<Coinbase::WalletAddress>] The addresses belonging to the Wallet
|
@@ -459,6 +482,22 @@ module Coinbase
|
|
459
482
|
"Successfully loaded seed for wallet #{id} from #{file_path}."
|
460
483
|
end
|
461
484
|
|
485
|
+
# Creates a new webhook on the current wallet for tracking wallet activity events.
|
486
|
+
#
|
487
|
+
# @param notification_uri [String] The URI to which the webhook notifications will be sent.
|
488
|
+
#
|
489
|
+
# @return [Coinbase::Client::Webhook] The newly created webhook instance.
|
490
|
+
def create_webhook(notification_uri:)
|
491
|
+
Coinbase.call_api do
|
492
|
+
webhooks_api.create_wallet_webhook(
|
493
|
+
id,
|
494
|
+
create_wallet_webhook_request: {
|
495
|
+
notification_uri: notification_uri
|
496
|
+
}
|
497
|
+
)
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
462
501
|
# Returns a String representation of the Wallet.
|
463
502
|
# @return [String] a String representation of the Wallet
|
464
503
|
def to_s
|
@@ -583,6 +622,10 @@ module Coinbase
|
|
583
622
|
@wallets_api ||= Coinbase::Client::WalletsApi.new(Coinbase.configuration.api_client)
|
584
623
|
end
|
585
624
|
|
625
|
+
def webhooks_api
|
626
|
+
@webhooks_api ||= Coinbase::Client::WebhooksApi.new(Coinbase.configuration.api_client)
|
627
|
+
end
|
628
|
+
|
586
629
|
def set_addresses
|
587
630
|
address_list = Coinbase.call_api do
|
588
631
|
addresses_api.list_addresses(@model.id, { limit: MAX_ADDRESSES })
|
data/lib/coinbase/webhook.rb
CHANGED
@@ -22,8 +22,6 @@ 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.
|
27
25
|
# @return [Coinbase::Webhook] A new instance of Webhook.
|
28
26
|
#
|
29
27
|
# @example Create a new webhook
|
@@ -31,18 +29,16 @@ module Coinbase
|
|
31
29
|
# network_id: :ethereum_mainnet,
|
32
30
|
# notification_uri: 'https://example.com/callback',
|
33
31
|
# event_type: 'transaction',
|
34
|
-
# event_filters: [{ 'contract_address' => '0x...', 'from_address' => '0x...', 'to_address' => '0x...' }]
|
35
|
-
# signature_header: 'example_header'
|
32
|
+
# event_filters: [{ 'contract_address' => '0x...', 'from_address' => '0x...', 'to_address' => '0x...' }]
|
36
33
|
# )
|
37
|
-
def create(network_id:, notification_uri:, event_type:, event_filters
|
34
|
+
def create(network_id:, notification_uri:, event_type:, event_filters:)
|
38
35
|
model = Coinbase.call_api do
|
39
36
|
webhooks_api.create_webhook(
|
40
37
|
create_webhook_request: {
|
41
38
|
network_id: Coinbase.normalize_network(network_id),
|
42
39
|
notification_uri: notification_uri,
|
43
40
|
event_type: event_type,
|
44
|
-
event_filters: event_filters
|
45
|
-
signature_header: signature_header
|
41
|
+
event_filters: event_filters
|
46
42
|
}
|
47
43
|
)
|
48
44
|
end
|