Skip to content

Commit

Permalink
chore: Support listing smart contracts
Browse files Browse the repository at this point in the history
This adds support for listing smart contracts across the entire
CDP account.

We will eventually add support for listing these by network as
well
  • Loading branch information
alex-stone committed Dec 19, 2024
1 parent ca7ddf5 commit 7e9b7a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/coinbase/smart_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ def read(
convert_solidity_value(response)
end

def list
Coinbase::Pagination.enumerate(
lambda { |page|
smart_contracts_api.list_smart_contracts(page: page)
}
) do |smart_contract|
new(smart_contract)
end
end

# Normalizes an ABI from a String or Array of Hashes to an Array of Hashes.
# @param abi [String, Array] The ABI to normalize
# @return [Array<Hash>] The normalized ABI
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/coinbase/smart_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@
end
end

describe '.list' do
subject(:enumerator) { described_class.list }

let(:api) { smart_contracts_api }
let(:fetch_params) { ->(page) { [{ page: page }] } }
let(:resource_list_klass) { Coinbase::Client::SmartContractList }
let(:item_klass) { described_class }
let(:item_initialize_args) { nil }
let(:create_model) do
->(id) { Coinbase::Client::SmartContract.new(smart_contract_id: id, network_id: :base_sepolia) }
end

it_behaves_like 'it is a paginated enumerator', :smart_contracts
end

describe '.register' do
subject(:smart_contract) do
described_class.register(
Expand Down

0 comments on commit 7e9b7a1

Please sign in to comment.