Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support async faucet transactions #213

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ testnet ETH. You are allowed one faucet claim per 24-hour window.
# Fund the wallet with a faucet transaction.
faucet_tx = wallet1.faucet

# Wait for the faucet transaction to complete.
faucet_tx.wait!

puts "Faucet transaction successfully completed: #{faucet_tx}"
```

Expand Down
11 changes: 8 additions & 3 deletions lib/coinbase/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ def transactions
# @raise [Coinbase::FaucetLimitReachedError] If the faucet limit has been reached for the address or user.
# @raise [Coinbase::Client::ApiError] If an unexpected error occurs while requesting faucet funds.
def faucet(asset_id: nil)
opts = { asset_id: asset_id }.compact

Coinbase.call_api do
Coinbase::FaucetTransaction.new(
addresses_api.request_external_faucet_funds(network.normalized_id, id, opts)
addresses_api.request_external_faucet_funds(
network.normalized_id,
id,
{
asset_id: asset_id,
skip_wait: true
}.compact
)
)
end
end
Expand Down
10 changes: 9 additions & 1 deletion lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
Coinbase::Client.autoload :ContractInvocationList, 'coinbase/client/models/contract_invocation_list'
Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_address_request'
Coinbase::Client.autoload :CreateContractInvocationRequest, 'coinbase/client/models/create_contract_invocation_request'
Coinbase::Client.autoload :CreateFundOperationRequest, 'coinbase/client/models/create_fund_operation_request'
Coinbase::Client.autoload :CreateFundQuoteRequest, 'coinbase/client/models/create_fund_quote_request'
Coinbase::Client.autoload :CreatePayloadSignatureRequest, 'coinbase/client/models/create_payload_signature_request'
Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
Coinbase::Client.autoload :CreateSmartContractRequest, 'coinbase/client/models/create_smart_contract_request'
Expand All @@ -45,6 +47,7 @@
Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
Coinbase::Client.autoload :CreateWalletWebhookRequest, 'coinbase/client/models/create_wallet_webhook_request'
Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
Coinbase::Client.autoload :CryptoAmount, 'coinbase/client/models/crypto_amount'
Coinbase::Client.autoload :DeploySmartContractRequest, 'coinbase/client/models/deploy_smart_contract_request'
Coinbase::Client.autoload :ERC20TransferEvent, 'coinbase/client/models/erc20_transfer_event'
Coinbase::Client.autoload :ERC721TransferEvent, 'coinbase/client/models/erc721_transfer_event'
Expand All @@ -60,6 +63,11 @@
Coinbase::Client.autoload :FetchHistoricalStakingBalances200Response, 'coinbase/client/models/fetch_historical_staking_balances200_response'
Coinbase::Client.autoload :FetchStakingRewards200Response, 'coinbase/client/models/fetch_staking_rewards200_response'
Coinbase::Client.autoload :FetchStakingRewardsRequest, 'coinbase/client/models/fetch_staking_rewards_request'
Coinbase::Client.autoload :FiatAmount, 'coinbase/client/models/fiat_amount'
Coinbase::Client.autoload :FundOperation, 'coinbase/client/models/fund_operation'
Coinbase::Client.autoload :FundOperationFees, 'coinbase/client/models/fund_operation_fees'
Coinbase::Client.autoload :FundOperationList, 'coinbase/client/models/fund_operation_list'
Coinbase::Client.autoload :FundQuote, 'coinbase/client/models/fund_quote'
Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get_staking_context_request'
Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
Coinbase::Client.autoload :MultiTokenContractOptions, 'coinbase/client/models/multi_token_contract_options'
Expand All @@ -68,7 +76,6 @@
Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
Coinbase::Client.autoload :OnchainName, 'coinbase/client/models/onchain_name'
Coinbase::Client.autoload :OnchainNameList, 'coinbase/client/models/onchain_name_list'
Coinbase::Client.autoload :OnchainNameTextRecordsInner, 'coinbase/client/models/onchain_name_text_records_inner'
Coinbase::Client.autoload :PayloadSignature, 'coinbase/client/models/payload_signature'
Coinbase::Client.autoload :PayloadSignatureList, 'coinbase/client/models/payload_signature_list'
Coinbase::Client.autoload :ReadContractRequest, 'coinbase/client/models/read_contract_request'
Expand Down Expand Up @@ -127,6 +134,7 @@
Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
Coinbase::Client.autoload :ContractInvocationsApi, 'coinbase/client/api/contract_invocations_api'
Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
Coinbase::Client.autoload :FundApi, 'coinbase/client/api/fund_api'
Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
Coinbase::Client.autoload :OnchainIdentityApi, 'coinbase/client/api/onchain_identity_api'
Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
Expand Down
78 changes: 78 additions & 0 deletions lib/coinbase/client/api/external_addresses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,81 @@ def get_external_address_balance_with_http_info(network_id, address_id, asset_id
return data, status_code, headers
end

# Get the status of a faucet transaction
# Get the status of a faucet transaction
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the faucet transaction for
# @param tx_hash [String] The hash of the faucet transaction
# @param [Hash] opts the optional parameters
# @return [FaucetTransaction]
def get_faucet_transaction(network_id, address_id, tx_hash, opts = {})
data, _status_code, _headers = get_faucet_transaction_with_http_info(network_id, address_id, tx_hash, opts)
data
end

# Get the status of a faucet transaction
# Get the status of a faucet transaction
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the faucet transaction for
# @param tx_hash [String] The hash of the faucet transaction
# @param [Hash] opts the optional parameters
# @return [Array<(FaucetTransaction, Integer, Hash)>] FaucetTransaction data, response status code and response headers
def get_faucet_transaction_with_http_info(network_id, address_id, tx_hash, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ExternalAddressesApi.get_faucet_transaction ...'
end
# verify the required parameter 'network_id' is set
if @api_client.config.client_side_validation && network_id.nil?
fail ArgumentError, "Missing the required parameter 'network_id' when calling ExternalAddressesApi.get_faucet_transaction"
end
# verify the required parameter 'address_id' is set
if @api_client.config.client_side_validation && address_id.nil?
fail ArgumentError, "Missing the required parameter 'address_id' when calling ExternalAddressesApi.get_faucet_transaction"
end
# verify the required parameter 'tx_hash' is set
if @api_client.config.client_side_validation && tx_hash.nil?
fail ArgumentError, "Missing the required parameter 'tx_hash' when calling ExternalAddressesApi.get_faucet_transaction"
end
# resource path
local_var_path = '/v1/networks/{network_id}/addresses/{address_id}/faucet/{tx_hash}'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'tx_hash' + '}', CGI.escape(tx_hash.to_s))

# query parameters
query_params = opts[:query_params] || {}

# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

# form parameters
form_params = opts[:form_params] || {}

# http body (model)
post_body = opts[:debug_body]

# return_type
return_type = opts[:debug_return_type] || 'FaucetTransaction'

# auth_names
auth_names = opts[:debug_auth_names] || []

new_options = opts.merge(
:operation => :"ExternalAddressesApi.get_faucet_transaction",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)

data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: ExternalAddressesApi#get_faucet_transaction\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end

# Get the balances of an external address
# List all of the balances of an external address
# @param network_id [String] The ID of the blockchain network
Expand Down Expand Up @@ -176,6 +251,7 @@ def list_external_address_balances_with_http_info(network_id, address_id, opts =
# @param address_id [String] The onchain address of the address that is being fetched.
# @param [Hash] opts the optional parameters
# @option opts [String] :asset_id The ID of the asset to transfer from the faucet.
# @option opts [Boolean] :skip_wait Whether to skip waiting for the transaction to be mined. This will become the default behavior in the future.
# @return [FaucetTransaction]
def request_external_faucet_funds(network_id, address_id, opts = {})
data, _status_code, _headers = request_external_faucet_funds_with_http_info(network_id, address_id, opts)
Expand All @@ -188,6 +264,7 @@ def request_external_faucet_funds(network_id, address_id, opts = {})
# @param address_id [String] The onchain address of the address that is being fetched.
# @param [Hash] opts the optional parameters
# @option opts [String] :asset_id The ID of the asset to transfer from the faucet.
# @option opts [Boolean] :skip_wait Whether to skip waiting for the transaction to be mined. This will become the default behavior in the future.
# @return [Array<(FaucetTransaction, Integer, Hash)>] FaucetTransaction data, response status code and response headers
def request_external_faucet_funds_with_http_info(network_id, address_id, opts = {})
if @api_client.config.debugging
Expand All @@ -207,6 +284,7 @@ def request_external_faucet_funds_with_http_info(network_id, address_id, opts =
# query parameters
query_params = opts[:query_params] || {}
query_params[:'asset_id'] = opts[:'asset_id'] if !opts[:'asset_id'].nil?
query_params[:'skip_wait'] = opts[:'skip_wait'] if !opts[:'skip_wait'].nil?

# header parameters
header_params = opts[:header_params] || {}
Expand Down
Loading
Loading