Skip to content
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.13.0] - 2024-12-19

### Added
- Add support for fetching address reputation.
- Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function
- Add support for registering, updating, and listing smart contracts that are deployed external to CDP.

## [0.12.0] - Skipped

## [0.11.0] - 2024-11-27

### Added
Expand Down
3 changes: 2 additions & 1 deletion lib/coinbase.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

require_relative 'coinbase/client'
require_relative 'coinbase/address'
require_relative 'coinbase/address/wallet_address'
require_relative 'coinbase/address/external_address'
require_relative 'coinbase/address_reputation'
require_relative 'coinbase/asset'
require_relative 'coinbase/authenticator'
require_relative 'coinbase/correlation'
require_relative 'coinbase/balance'
require_relative 'coinbase/balance_map'
require_relative 'coinbase/historical_balance'
require_relative 'coinbase/client'
require_relative 'coinbase/constants'
require_relative 'coinbase/contract_event'
require_relative 'coinbase/contract_invocation'
Expand Down
25 changes: 22 additions & 3 deletions lib/coinbase/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ def initialize(network, id)
# Returns a String representation of the Address.
# @return [String] a String representation of the Address
def to_s
Coinbase.pretty_print_object(self.class, id: id, network_id: network.id)
Coinbase.pretty_print_object(
self.class,
**{
id: id,
network_id: network.id,
reputation_score: @reputation.nil? ? nil : reputation.score
}.compact
)
end

# Same as to_s.
Expand All @@ -32,6 +39,18 @@ def can_sign?
false
end

# Returns the reputation of the Address.
# @return [Coinbase::AddressReputation] The reputation of the Address
def reputation
@reputation ||= Coinbase::AddressReputation.fetch(network: network, address_id: id)
end

# Returns wheth the Address's reputation is risky.
# @return [Boolean] true if the Address's reputation is risky
def risky?
reputation.risky?
end

# Returns the balances of the Address.
# @return [BalanceMap] The balances of the Address, keyed by asset ID. Ether balances are denominated
# in ETH.
Expand Down Expand Up @@ -66,7 +85,7 @@ def balance(asset_id)
# @return [Enumerable<Coinbase::HistoricalBalance>] Enumerator that returns historical_balance
def historical_balances(asset_id)
Coinbase::Pagination.enumerate(
->(page) { list_page(asset_id, page) }
->(page) { list_historical_balance_page(asset_id, page) }
) do |historical_balance|
Coinbase::HistoricalBalance.from_model(historical_balance)
end
Expand Down Expand Up @@ -265,7 +284,7 @@ def stake_api
@stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
end

def list_page(asset_id, page)
def list_historical_balance_page(asset_id, page)
balance_history_api.list_address_historical_balance(
network.normalized_id,
id,
Expand Down
67 changes: 67 additions & 0 deletions lib/coinbase/address_reputation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

module Coinbase
# A representation of the reputation of a blockchain address.
class AddressReputation
# A metadata object associated with an address reputation.
Metadata = Struct.new(
*Client::AddressReputationMetadata.attribute_map.keys.map(&:to_sym),
keyword_init: true
) do
def to_s
Coinbase.pretty_print_object(
self.class,
**to_h
)
end
end

class << self
def fetch(address_id:, network: Coinbase.default_network)
network = Coinbase::Network.from_id(network)

model = Coinbase.call_api do
reputation_api.get_address_reputation(network.normalized_id, address_id)
end

new(model)
end

private

def reputation_api
Coinbase::Client::ReputationApi.new(Coinbase.configuration.api_client)
end
end

def initialize(model)
raise ArgumentError, 'must be an AddressReputation object' unless model.is_a?(Coinbase::Client::AddressReputation)

@model = model
end

def score
@model.score
end

def metadata
@metadata ||= Metadata.new(**@model.metadata)
end

def risky?
score.negative?
end

def to_s
Coinbase.pretty_print_object(
self.class,
score: score,
**metadata.to_h
)
end

def inspect
to_s
end
end
end
10 changes: 7 additions & 3 deletions lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.9.0
Generator version: 7.10.0

=end

Expand All @@ -23,21 +23,21 @@
Coinbase::Client.autoload :AddressList, 'coinbase/client/models/address_list'
Coinbase::Client.autoload :AddressReputation, 'coinbase/client/models/address_reputation'
Coinbase::Client.autoload :AddressReputationMetadata, 'coinbase/client/models/address_reputation_metadata'
Coinbase::Client.autoload :AddressRisk, 'coinbase/client/models/address_risk'
Coinbase::Client.autoload :AddressTransactionList, 'coinbase/client/models/address_transaction_list'
Coinbase::Client.autoload :Asset, 'coinbase/client/models/asset'
Coinbase::Client.autoload :Balance, 'coinbase/client/models/balance'
Coinbase::Client.autoload :BroadcastContractInvocationRequest, 'coinbase/client/models/broadcast_contract_invocation_request'
Coinbase::Client.autoload :BroadcastExternalTransferRequest, 'coinbase/client/models/broadcast_external_transfer_request'
Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
Coinbase::Client.autoload :ContractInvocation, 'coinbase/client/models/contract_invocation'
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 :CreateExternalTransferRequest, 'coinbase/client/models/create_external_transfer_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'
Expand Down Expand Up @@ -82,6 +82,7 @@
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'
Coinbase::Client.autoload :RegisterSmartContractRequest, 'coinbase/client/models/register_smart_contract_request'
Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
Expand All @@ -93,6 +94,7 @@
Coinbase::Client.autoload :SignatureCreationEventResult, 'coinbase/client/models/signature_creation_event_result'
Coinbase::Client.autoload :SignedVoluntaryExitMessageMetadata, 'coinbase/client/models/signed_voluntary_exit_message_metadata'
Coinbase::Client.autoload :SmartContract, 'coinbase/client/models/smart_contract'
Coinbase::Client.autoload :SmartContractActivityEvent, 'coinbase/client/models/smart_contract_activity_event'
Coinbase::Client.autoload :SmartContractList, 'coinbase/client/models/smart_contract_list'
Coinbase::Client.autoload :SmartContractOptions, 'coinbase/client/models/smart_contract_options'
Coinbase::Client.autoload :SmartContractType, 'coinbase/client/models/smart_contract_type'
Expand All @@ -115,6 +117,7 @@
Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
Coinbase::Client.autoload :UpdateSmartContractRequest, 'coinbase/client/models/update_smart_contract_request'
Coinbase::Client.autoload :UpdateWebhookRequest, 'coinbase/client/models/update_webhook_request'
Coinbase::Client.autoload :User, 'coinbase/client/models/user'
Coinbase::Client.autoload :Validator, 'coinbase/client/models/validator'
Expand All @@ -128,6 +131,7 @@
Coinbase::Client.autoload :WebhookEventType, 'coinbase/client/models/webhook_event_type'
Coinbase::Client.autoload :WebhookEventTypeFilter, 'coinbase/client/models/webhook_event_type_filter'
Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
Coinbase::Client.autoload :WebhookSmartContractEventFilter, 'coinbase/client/models/webhook_smart_contract_event_filter'
Coinbase::Client.autoload :WebhookWalletActivityFilter, 'coinbase/client/models/webhook_wallet_activity_filter'

# APIs
Expand Down
20 changes: 10 additions & 10 deletions lib/coinbase/client/api/addresses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.9.0
Generator version: 7.10.0

=end

Expand Down Expand Up @@ -70,7 +70,7 @@ def create_address_with_http_info(wallet_id, opts = {})
return_type = opts[:debug_return_type] || 'Address'

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

new_options = opts.merge(
:operation => :"AddressesApi.create_address",
Expand Down Expand Up @@ -146,7 +146,7 @@ def create_payload_signature_with_http_info(wallet_id, address_id, opts = {})
return_type = opts[:debug_return_type] || 'PayloadSignature'

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

new_options = opts.merge(
:operation => :"AddressesApi.create_payload_signature",
Expand Down Expand Up @@ -215,7 +215,7 @@ def get_address_with_http_info(wallet_id, address_id, opts = {})
return_type = opts[:debug_return_type] || 'Address'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.get_address",
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_address_balance_with_http_info(wallet_id, address_id, asset_id, opts = {
return_type = opts[:debug_return_type] || 'Balance'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.get_address_balance",
Expand Down Expand Up @@ -365,7 +365,7 @@ def get_payload_signature_with_http_info(wallet_id, address_id, payload_signatur
return_type = opts[:debug_return_type] || 'PayloadSignature'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.get_payload_signature",
Expand Down Expand Up @@ -441,7 +441,7 @@ def list_address_balances_with_http_info(wallet_id, address_id, opts = {})
return_type = opts[:debug_return_type] || 'AddressBalanceList'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.list_address_balances",
Expand Down Expand Up @@ -514,7 +514,7 @@ def list_addresses_with_http_info(wallet_id, opts = {})
return_type = opts[:debug_return_type] || 'AddressList'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.list_addresses",
Expand Down Expand Up @@ -593,7 +593,7 @@ def list_payload_signatures_with_http_info(wallet_id, address_id, opts = {})
return_type = opts[:debug_return_type] || 'PayloadSignatureList'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AddressesApi.list_payload_signatures",
Expand Down Expand Up @@ -665,7 +665,7 @@ def request_faucet_funds_with_http_info(wallet_id, address_id, opts = {})
return_type = opts[:debug_return_type] || 'FaucetTransaction'

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

new_options = opts.merge(
:operation => :"AddressesApi.request_faucet_funds",
Expand Down
4 changes: 2 additions & 2 deletions lib/coinbase/client/api/assets_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.9.0
Generator version: 7.10.0

=end

Expand Down Expand Up @@ -69,7 +69,7 @@ def get_asset_with_http_info(network_id, asset_id, opts = {})
return_type = opts[:debug_return_type] || 'Asset'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"AssetsApi.get_asset",
Expand Down
4 changes: 2 additions & 2 deletions lib/coinbase/client/api/balance_history_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.9.0
Generator version: 7.10.0

=end

Expand Down Expand Up @@ -85,7 +85,7 @@ def list_address_historical_balance_with_http_info(network_id, address_id, asset
return_type = opts[:debug_return_type] || 'AddressHistoricalBalanceList'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"BalanceHistoryApi.list_address_historical_balance",
Expand Down
4 changes: 2 additions & 2 deletions lib/coinbase/client/api/contract_events_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha

Generated by: https://openapi-generator.tech
Generator version: 7.9.0
Generator version: 7.10.0

=end

Expand Down Expand Up @@ -107,7 +107,7 @@ def list_contract_events_with_http_info(network_id, protocol_name, contract_addr
return_type = opts[:debug_return_type] || 'ContractEventList'

# auth_names
auth_names = opts[:debug_auth_names] || []
auth_names = opts[:debug_auth_names] || ['apiKey', 'session']

new_options = opts.merge(
:operation => :"ContractEventsApi.list_contract_events",
Expand Down
Loading
Loading