Skip to content

Commit

Permalink
update SDK's listAddressTransaction (#199)
Browse files Browse the repository at this point in the history
### What changed? Why?


#### Qualified Impact
<!-- Please evaluate what components could be affected and what the
impact would be if there was an
error. How would this error be resolved, e.g. rollback a deploy, push a
new fix, disable a feature
flag, etc... -->
  • Loading branch information
howard-at-cb authored Sep 20, 2024
1 parent 3b5de66 commit 2667f5f
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 128 deletions.
6 changes: 5 additions & 1 deletion lib/coinbase/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def balance_history_api
@balance_history_api ||= Coinbase::Client::BalanceHistoryApi.new(Coinbase.configuration.api_client)
end

def transaction_history_api
@transaction_history_api ||= Coinbase::Client::TransactionHistoryApi.new(Coinbase.configuration.api_client)
end

def stake_api
@stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
end
Expand All @@ -266,7 +270,7 @@ def list_page(asset_id, page)
end

def list_transaction_page(page)
addresses_api.list_address_transactions(
transaction_history_api.list_address_transactions(
network.normalized_id,
id,
{ limit: DEFAULT_TRANSACTION_PAGE_LIMIT, page: page }
Expand Down
1 change: 1 addition & 0 deletions lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
Coinbase::Client.autoload :SmartContractsApi, 'coinbase/client/api/smart_contracts_api'
Coinbase::Client.autoload :StakeApi, 'coinbase/client/api/stake_api'
Coinbase::Client.autoload :TradesApi, 'coinbase/client/api/trades_api'
Coinbase::Client.autoload :TransactionHistoryApi, 'coinbase/client/api/transaction_history_api'
Coinbase::Client.autoload :TransfersApi, 'coinbase/client/api/transfers_api'
Coinbase::Client.autoload :UsersApi, 'coinbase/client/api/users_api'
Coinbase::Client.autoload :ValidatorsApi, 'coinbase/client/api/validators_api'
Expand Down
79 changes: 0 additions & 79 deletions lib/coinbase/client/api/external_addresses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,85 +94,6 @@ def get_external_address_balance_with_http_info(network_id, address_id, asset_id
return data, status_code, headers
end

# List transactions for an address.
# List all transactions that interact with the address.
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the transactions for.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
# @return [AddressTransactionList]
def list_address_transactions(network_id, address_id, opts = {})
data, _status_code, _headers = list_address_transactions_with_http_info(network_id, address_id, opts)
data
end

# List transactions for an address.
# List all transactions that interact with the address.
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the transactions for.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
# @return [Array<(AddressTransactionList, Integer, Hash)>] AddressTransactionList data, response status code and response headers
def list_address_transactions_with_http_info(network_id, address_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ExternalAddressesApi.list_address_transactions ...'
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.list_address_transactions"
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.list_address_transactions"
end
if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
fail ArgumentError, 'invalid value for "opts[:"page"]" when calling ExternalAddressesApi.list_address_transactions, the character length must be smaller than or equal to 5000.'
end

# resource path
local_var_path = '/v1/networks/{network_id}/addresses/{address_id}/transactions'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))

# query parameters
query_params = opts[:query_params] || {}
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?

# 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] || 'AddressTransactionList'

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

new_options = opts.merge(
:operation => :"ExternalAddressesApi.list_address_transactions",
: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#list_address_transactions\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
101 changes: 101 additions & 0 deletions lib/coinbase/client/api/transaction_history_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
=begin
#Coinbase Platform API
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.8.0
=end

require 'cgi'

module Coinbase::Client
class TransactionHistoryApi
attr_accessor :api_client

def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# List transactions for an address.
# List all transactions that interact with the address.
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the transactions for.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
# @return [AddressTransactionList]
def list_address_transactions(network_id, address_id, opts = {})
data, _status_code, _headers = list_address_transactions_with_http_info(network_id, address_id, opts)
data
end

# List transactions for an address.
# List all transactions that interact with the address.
# @param network_id [String] The ID of the blockchain network
# @param address_id [String] The ID of the address to fetch the transactions for.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
# @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
# @return [Array<(AddressTransactionList, Integer, Hash)>] AddressTransactionList data, response status code and response headers
def list_address_transactions_with_http_info(network_id, address_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: TransactionHistoryApi.list_address_transactions ...'
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 TransactionHistoryApi.list_address_transactions"
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 TransactionHistoryApi.list_address_transactions"
end
if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
fail ArgumentError, 'invalid value for "opts[:"page"]" when calling TransactionHistoryApi.list_address_transactions, the character length must be smaller than or equal to 5000.'
end

# resource path
local_var_path = '/v1/networks/{network_id}/addresses/{address_id}/transactions'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))

# query parameters
query_params = opts[:query_params] || {}
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?

# 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] || 'AddressTransactionList'

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

new_options = opts.merge(
:operation => :"TransactionHistoryApi.list_address_transactions",
: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: TransactionHistoryApi#list_address_transactions\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end
43 changes: 0 additions & 43 deletions lib/coinbase/client/models/feature.rb

This file was deleted.

3 changes: 2 additions & 1 deletion lib/coinbase/client/models/network_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class NetworkIdentifier
ETHEREUM_MAINNET = "ethereum-mainnet".freeze
POLYGON_MAINNET = "polygon-mainnet".freeze
SOLANA_DEVNET = "solana-devnet".freeze
SOLANA_MAINNET = "solana-mainnet".freeze
ARBITRUM_MAINNET = "arbitrum-mainnet".freeze
UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze

def self.all_vars
@all_vars ||= [BASE_SEPOLIA, BASE_MAINNET, ETHEREUM_HOLESKY, ETHEREUM_MAINNET, POLYGON_MAINNET, SOLANA_DEVNET, ARBITRUM_MAINNET, UNKNOWN_DEFAULT_OPEN_API].freeze
@all_vars ||= [BASE_SEPOLIA, BASE_MAINNET, ETHEREUM_HOLESKY, ETHEREUM_MAINNET, POLYGON_MAINNET, SOLANA_DEVNET, SOLANA_MAINNET, ARBITRUM_MAINNET, UNKNOWN_DEFAULT_OPEN_API].freeze
end

# Builds the enum from string
Expand Down
8 changes: 4 additions & 4 deletions spec/support/shared_examples/address_transactions.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

shared_examples 'an address that supports transaction queries' do |_operation|
let(:external_addresses_api) { instance_double(Coinbase::Client::ExternalAddressesApi) }
let(:transaction_history_api) { instance_double(Coinbase::Client::TransactionHistoryApi) }

before do
allow(Coinbase::Client::ExternalAddressesApi).to receive(:new).and_return(external_addresses_api)
allow(Coinbase::Client::TransactionHistoryApi).to receive(:new).and_return(transaction_history_api)
end

describe '#transactions' do
Expand All @@ -18,7 +18,7 @@
end

before do
allow(external_addresses_api)
allow(transaction_history_api)
.to receive(:list_address_transactions)
.with(normalized_network_id, address_id, { limit: 10, page: nil })
.and_return(response)
Expand All @@ -35,7 +35,7 @@
address.transactions
end

let(:api) { external_addresses_api }
let(:api) { transaction_history_api }
let(:fetch_params) { ->(page) { [normalized_network_id, address_id, { limit: 10, page: page }] } }
let(:resource_list_klass) { Coinbase::Client::AddressTransactionList }
let(:item_klass) { Coinbase::Transaction }
Expand Down

0 comments on commit 2667f5f

Please sign in to comment.