diff --git a/CHANGELOG.md b/CHANGELOG.md index 861dbcfd..a9643f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ 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). +## Unreleased +* Add support for fetching address reputation. + +## [0.12.0] - Skipped + ## [0.11.0] - 2024-11-27 ### Added diff --git a/lib/coinbase.rb b/lib/coinbase.rb index 559695a0..a3472c87 100644 --- a/lib/coinbase.rb +++ b/lib/coinbase.rb @@ -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' diff --git a/lib/coinbase/address.rb b/lib/coinbase/address.rb index d5837abd..552ed122 100644 --- a/lib/coinbase/address.rb +++ b/lib/coinbase/address.rb @@ -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. @@ -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. @@ -66,7 +85,7 @@ def balance(asset_id) # @return [Enumerable] 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 @@ -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, diff --git a/lib/coinbase/address_reputation.rb b/lib/coinbase/address_reputation.rb new file mode 100644 index 00000000..7e8b7e69 --- /dev/null +++ b/lib/coinbase/address_reputation.rb @@ -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 diff --git a/lib/coinbase/client.rb b/lib/coinbase/client.rb index d0a11450..04f31ee7 100644 --- a/lib/coinbase/client.rb +++ b/lib/coinbase/client.rb @@ -23,7 +23,6 @@ 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' @@ -82,6 +81,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' @@ -93,6 +93,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' @@ -128,6 +129,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 diff --git a/lib/coinbase/client/api/reputation_api.rb b/lib/coinbase/client/api/reputation_api.rb index 748f13a2..c88936d8 100644 --- a/lib/coinbase/client/api/reputation_api.rb +++ b/lib/coinbase/client/api/reputation_api.rb @@ -87,74 +87,5 @@ def get_address_reputation_with_http_info(network_id, address_id, opts = {}) end return data, status_code, headers end - - # Get the risk of an address - # Get the risk of an address - # @param network_id [String] The ID of the blockchain network. - # @param address_id [String] The ID of the address to fetch the risk for. - # @param [Hash] opts the optional parameters - # @return [AddressRisk] - def get_address_risk(network_id, address_id, opts = {}) - data, _status_code, _headers = get_address_risk_with_http_info(network_id, address_id, opts) - data - end - - # Get the risk of an address - # Get the risk of an address - # @param network_id [String] The ID of the blockchain network. - # @param address_id [String] The ID of the address to fetch the risk for. - # @param [Hash] opts the optional parameters - # @return [Array<(AddressRisk, Integer, Hash)>] AddressRisk data, response status code and response headers - def get_address_risk_with_http_info(network_id, address_id, opts = {}) - if @api_client.config.debugging - @api_client.config.logger.debug 'Calling API: ReputationApi.get_address_risk ...' - 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 ReputationApi.get_address_risk" - 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 ReputationApi.get_address_risk" - end - # resource path - local_var_path = '/v1/networks/{network_id}/addresses/{address_id}/risk'.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] || {} - - # 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] || 'AddressRisk' - - # auth_names - auth_names = opts[:debug_auth_names] || [] - - new_options = opts.merge( - :operation => :"ReputationApi.get_address_risk", - :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: ReputationApi#get_address_risk\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" - end - return data, status_code, headers - end end end diff --git a/lib/coinbase/client/api/smart_contracts_api.rb b/lib/coinbase/client/api/smart_contracts_api.rb index b5bbba7d..e6e5f6b3 100644 --- a/lib/coinbase/client/api/smart_contracts_api.rb +++ b/lib/coinbase/client/api/smart_contracts_api.rb @@ -260,40 +260,31 @@ def get_smart_contract_with_http_info(wallet_id, address_id, smart_contract_id, return data, status_code, headers end - # List smart contracts deployed by address - # List all smart contracts deployed by address. - # @param wallet_id [String] The ID of the wallet the address belongs to. - # @param address_id [String] The ID of the address to fetch the smart contracts for. + # List smart contracts + # List smart contracts # @param [Hash] opts the optional parameters + # @option opts [String] :page Pagination token for retrieving the next set of results # @return [SmartContractList] - def list_smart_contracts(wallet_id, address_id, opts = {}) - data, _status_code, _headers = list_smart_contracts_with_http_info(wallet_id, address_id, opts) + def list_smart_contracts(opts = {}) + data, _status_code, _headers = list_smart_contracts_with_http_info(opts) data end - # List smart contracts deployed by address - # List all smart contracts deployed by address. - # @param wallet_id [String] The ID of the wallet the address belongs to. - # @param address_id [String] The ID of the address to fetch the smart contracts for. + # List smart contracts + # List smart contracts # @param [Hash] opts the optional parameters + # @option opts [String] :page Pagination token for retrieving the next set of results # @return [Array<(SmartContractList, Integer, Hash)>] SmartContractList data, response status code and response headers - def list_smart_contracts_with_http_info(wallet_id, address_id, opts = {}) + def list_smart_contracts_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: SmartContractsApi.list_smart_contracts ...' end - # verify the required parameter 'wallet_id' is set - if @api_client.config.client_side_validation && wallet_id.nil? - fail ArgumentError, "Missing the required parameter 'wallet_id' when calling SmartContractsApi.list_smart_contracts" - 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 SmartContractsApi.list_smart_contracts" - end # resource path - local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/smart_contracts'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)) + local_var_path = '/v1/smart_contracts' # query parameters query_params = opts[:query_params] || {} + query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil? # header parameters header_params = opts[:header_params] || {} @@ -408,5 +399,81 @@ def read_contract_with_http_info(network_id, contract_address, read_contract_req end return data, status_code, headers end + + # Register a smart contract + # Register a smart contract + # @param network_id [String] The ID of the network to fetch. + # @param contract_address [String] EVM address of the smart contract (42 characters, including '0x', in lowercase) + # @param [Hash] opts the optional parameters + # @option opts [RegisterSmartContractRequest] :register_smart_contract_request + # @return [SmartContract] + def register_smart_contract(network_id, contract_address, opts = {}) + data, _status_code, _headers = register_smart_contract_with_http_info(network_id, contract_address, opts) + data + end + + # Register a smart contract + # Register a smart contract + # @param network_id [String] The ID of the network to fetch. + # @param contract_address [String] EVM address of the smart contract (42 characters, including '0x', in lowercase) + # @param [Hash] opts the optional parameters + # @option opts [RegisterSmartContractRequest] :register_smart_contract_request + # @return [Array<(SmartContract, Integer, Hash)>] SmartContract data, response status code and response headers + def register_smart_contract_with_http_info(network_id, contract_address, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: SmartContractsApi.register_smart_contract ...' + 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 SmartContractsApi.register_smart_contract" + end + # verify the required parameter 'contract_address' is set + if @api_client.config.client_side_validation && contract_address.nil? + fail ArgumentError, "Missing the required parameter 'contract_address' when calling SmartContractsApi.register_smart_contract" + end + # resource path + local_var_path = '/v1/networks/{network_id}/smart_contracts/{contract_address}/register'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'contract_address' + '}', CGI.escape(contract_address.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'] + # HTTP header 'Content-Type' + content_type = @api_client.select_header_content_type(['application/json']) + if !content_type.nil? + header_params['Content-Type'] = content_type + end + + # form parameters + form_params = opts[:form_params] || {} + + # http body (model) + post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'register_smart_contract_request']) + + # return_type + return_type = opts[:debug_return_type] || 'SmartContract' + + # auth_names + auth_names = opts[:debug_auth_names] || [] + + new_options = opts.merge( + :operation => :"SmartContractsApi.register_smart_contract", + :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(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: SmartContractsApi#register_smart_contract\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end end end diff --git a/lib/coinbase/client/models/address_reputation.rb b/lib/coinbase/client/models/address_reputation.rb index a8a6b7de..6adb2ad1 100644 --- a/lib/coinbase/client/models/address_reputation.rb +++ b/lib/coinbase/client/models/address_reputation.rb @@ -16,15 +16,15 @@ module Coinbase::Client # The reputation score with metadata of a blockchain address. class AddressReputation - # The reputation score of a wallet address which lie between 0 to 100. - attr_accessor :reputation_score + # The score of a wallet address, ranging from -100 to 100. A negative score indicates a bad reputation, while a positive score indicates a good reputation. + attr_accessor :score attr_accessor :metadata # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'reputation_score' => :'reputation_score', + :'score' => :'score', :'metadata' => :'metadata' } end @@ -37,7 +37,7 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { - :'reputation_score' => :'Integer', + :'score' => :'Integer', :'metadata' => :'AddressReputationMetadata' } end @@ -63,8 +63,10 @@ def initialize(attributes = {}) h[k.to_sym] = v } - if attributes.key?(:'reputation_score') - self.reputation_score = attributes[:'reputation_score'] + if attributes.key?(:'score') + self.score = attributes[:'score'] + else + self.score = nil end if attributes.key?(:'metadata') @@ -79,6 +81,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if @score.nil? + invalid_properties.push('invalid value for "score", score cannot be nil.') + end + if @metadata.nil? invalid_properties.push('invalid value for "metadata", metadata cannot be nil.') end @@ -90,6 +96,7 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @score.nil? return false if @metadata.nil? true end @@ -99,7 +106,7 @@ def valid? def ==(o) return true if self.equal?(o) self.class == o.class && - reputation_score == o.reputation_score && + score == o.score && metadata == o.metadata end @@ -112,7 +119,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [reputation_score, metadata].hash + [score, metadata].hash end # Builds the object from hash diff --git a/lib/coinbase/client/models/ethereum_transaction.rb b/lib/coinbase/client/models/ethereum_transaction.rb index d426fa76..2132eae1 100644 --- a/lib/coinbase/client/models/ethereum_transaction.rb +++ b/lib/coinbase/client/models/ethereum_transaction.rb @@ -66,6 +66,9 @@ class EthereumTransaction # This is for handling optimism rollup specific EIP-2718 transaction type field. attr_accessor :mint + # RLP encoded transaction as a hex string (prefixed with 0x) for native compatibility with popular eth clients such as etherjs, viem etc. + attr_accessor :rlp_encoded_tx + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { @@ -86,7 +89,8 @@ def self.attribute_map :'token_transfers' => :'token_transfers', :'flattened_traces' => :'flattened_traces', :'block_timestamp' => :'block_timestamp', - :'mint' => :'mint' + :'mint' => :'mint', + :'rlp_encoded_tx' => :'rlp_encoded_tx' } end @@ -115,7 +119,8 @@ def self.openapi_types :'token_transfers' => :'Array', :'flattened_traces' => :'Array', :'block_timestamp' => :'Time', - :'mint' => :'String' + :'mint' => :'String', + :'rlp_encoded_tx' => :'String' } end @@ -219,6 +224,10 @@ def initialize(attributes = {}) if attributes.key?(:'mint') self.mint = attributes[:'mint'] end + + if attributes.key?(:'rlp_encoded_tx') + self.rlp_encoded_tx = attributes[:'rlp_encoded_tx'] + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -268,7 +277,8 @@ def ==(o) token_transfers == o.token_transfers && flattened_traces == o.flattened_traces && block_timestamp == o.block_timestamp && - mint == o.mint + mint == o.mint && + rlp_encoded_tx == o.rlp_encoded_tx end # @see the `==` method @@ -280,7 +290,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [from, gas, gas_price, hash, input, nonce, to, index, value, type, max_fee_per_gas, max_priority_fee_per_gas, priority_fee_per_gas, transaction_access_list, token_transfers, flattened_traces, block_timestamp, mint].hash + [from, gas, gas_price, hash, input, nonce, to, index, value, type, max_fee_per_gas, max_priority_fee_per_gas, priority_fee_per_gas, transaction_access_list, token_transfers, flattened_traces, block_timestamp, mint, rlp_encoded_tx].hash end # Builds the object from hash diff --git a/lib/coinbase/client/models/register_smart_contract_request.rb b/lib/coinbase/client/models/register_smart_contract_request.rb new file mode 100644 index 00000000..73c9f7ca --- /dev/null +++ b/lib/coinbase/client/models/register_smart_contract_request.rb @@ -0,0 +1,240 @@ +=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.9.0 + +=end + +require 'date' +require 'time' + +module Coinbase::Client + # Smart Contract data to be registered + class RegisterSmartContractRequest + # ABI of the smart contract + attr_accessor :abi + + # Name of the smart contract + attr_accessor :contract_name + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'abi' => :'abi', + :'contract_name' => :'contract_name' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'abi' => :'String', + :'contract_name' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::RegisterSmartContractRequest` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::RegisterSmartContractRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'abi') + self.abi = attributes[:'abi'] + else + self.abi = nil + end + + if attributes.key?(:'contract_name') + self.contract_name = attributes[:'contract_name'] + else + self.contract_name = nil + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if @abi.nil? + invalid_properties.push('invalid value for "abi", abi cannot be nil.') + end + + if @contract_name.nil? + invalid_properties.push('invalid value for "contract_name", contract_name cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @abi.nil? + return false if @contract_name.nil? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + abi == o.abi && + contract_name == o.contract_name + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [abi, contract_name].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Coinbase::Client.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/lib/coinbase/client/models/smart_contract.rb b/lib/coinbase/client/models/smart_contract.rb index 9c8a3621..fac28e4e 100644 --- a/lib/coinbase/client/models/smart_contract.rb +++ b/lib/coinbase/client/models/smart_contract.rb @@ -16,19 +16,22 @@ module Coinbase::Client # Represents a smart contract on the blockchain class SmartContract - # The unique identifier of the smart contract + # The unique identifier of the smart contract. attr_accessor :smart_contract_id # The name of the blockchain network attr_accessor :network_id - # The ID of the wallet that deployed the smart contract + # The ID of the wallet that deployed the smart contract. If this smart contract was deployed externally, this will be omitted. attr_accessor :wallet_id # The EVM address of the smart contract attr_accessor :contract_address - # The EVM address of the account that deployed the smart contract + # The name of the smart contract + attr_accessor :contract_name + + # The EVM address of the account that deployed the smart contract. If this smart contract was deployed externally, this will be omitted. attr_accessor :deployer_address attr_accessor :type @@ -40,6 +43,9 @@ class SmartContract attr_accessor :transaction + # Whether the smart contract was deployed externally. If true, the deployer_address and transaction will be omitted. + attr_accessor :is_external + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -69,11 +75,13 @@ def self.attribute_map :'network_id' => :'network_id', :'wallet_id' => :'wallet_id', :'contract_address' => :'contract_address', + :'contract_name' => :'contract_name', :'deployer_address' => :'deployer_address', :'type' => :'type', :'options' => :'options', :'abi' => :'abi', - :'transaction' => :'transaction' + :'transaction' => :'transaction', + :'is_external' => :'is_external' } end @@ -89,11 +97,13 @@ def self.openapi_types :'network_id' => :'String', :'wallet_id' => :'String', :'contract_address' => :'String', + :'contract_name' => :'String', :'deployer_address' => :'String', :'type' => :'SmartContractType', :'options' => :'SmartContractOptions', :'abi' => :'String', - :'transaction' => :'Transaction' + :'transaction' => :'Transaction', + :'is_external' => :'Boolean' } end @@ -132,8 +142,6 @@ def initialize(attributes = {}) if attributes.key?(:'wallet_id') self.wallet_id = attributes[:'wallet_id'] - else - self.wallet_id = nil end if attributes.key?(:'contract_address') @@ -142,10 +150,14 @@ def initialize(attributes = {}) self.contract_address = nil end + if attributes.key?(:'contract_name') + self.contract_name = attributes[:'contract_name'] + else + self.contract_name = nil + end + if attributes.key?(:'deployer_address') self.deployer_address = attributes[:'deployer_address'] - else - self.deployer_address = nil end if attributes.key?(:'type') @@ -156,8 +168,6 @@ def initialize(attributes = {}) if attributes.key?(:'options') self.options = attributes[:'options'] - else - self.options = nil end if attributes.key?(:'abi') @@ -168,8 +178,12 @@ def initialize(attributes = {}) if attributes.key?(:'transaction') self.transaction = attributes[:'transaction'] + end + + if attributes.key?(:'is_external') + self.is_external = attributes[:'is_external'] else - self.transaction = nil + self.is_external = nil end end @@ -186,32 +200,24 @@ def list_invalid_properties invalid_properties.push('invalid value for "network_id", network_id cannot be nil.') end - if @wallet_id.nil? - invalid_properties.push('invalid value for "wallet_id", wallet_id cannot be nil.') - end - if @contract_address.nil? invalid_properties.push('invalid value for "contract_address", contract_address cannot be nil.') end - if @deployer_address.nil? - invalid_properties.push('invalid value for "deployer_address", deployer_address cannot be nil.') + if @contract_name.nil? + invalid_properties.push('invalid value for "contract_name", contract_name cannot be nil.') end if @type.nil? invalid_properties.push('invalid value for "type", type cannot be nil.') end - if @options.nil? - invalid_properties.push('invalid value for "options", options cannot be nil.') - end - if @abi.nil? invalid_properties.push('invalid value for "abi", abi cannot be nil.') end - if @transaction.nil? - invalid_properties.push('invalid value for "transaction", transaction cannot be nil.') + if @is_external.nil? + invalid_properties.push('invalid value for "is_external", is_external cannot be nil.') end invalid_properties @@ -223,13 +229,11 @@ def valid? warn '[DEPRECATED] the `valid?` method is obsolete' return false if @smart_contract_id.nil? return false if @network_id.nil? - return false if @wallet_id.nil? return false if @contract_address.nil? - return false if @deployer_address.nil? + return false if @contract_name.nil? return false if @type.nil? - return false if @options.nil? return false if @abi.nil? - return false if @transaction.nil? + return false if @is_external.nil? true end @@ -242,11 +246,13 @@ def ==(o) network_id == o.network_id && wallet_id == o.wallet_id && contract_address == o.contract_address && + contract_name == o.contract_name && deployer_address == o.deployer_address && type == o.type && options == o.options && abi == o.abi && - transaction == o.transaction + transaction == o.transaction && + is_external == o.is_external end # @see the `==` method @@ -258,7 +264,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [smart_contract_id, network_id, wallet_id, contract_address, deployer_address, type, options, abi, transaction].hash + [smart_contract_id, network_id, wallet_id, contract_address, contract_name, deployer_address, type, options, abi, transaction, is_external].hash end # Builds the object from hash diff --git a/lib/coinbase/client/models/smart_contract_activity_event.rb b/lib/coinbase/client/models/smart_contract_activity_event.rb new file mode 100644 index 00000000..1dba2a07 --- /dev/null +++ b/lib/coinbase/client/models/smart_contract_activity_event.rb @@ -0,0 +1,386 @@ +=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.9.0 + +=end + +require 'date' +require 'time' + +module Coinbase::Client + # Represents an event triggered by a smart contract activity on the blockchain. Contains information about the function, transaction, block, and involved addresses. + class SmartContractActivityEvent + # Unique identifier for the webhook that triggered this event. + attr_accessor :webhook_id + + # Type of event, in this case, an ERC-721 token transfer. + attr_accessor :event_type + + # Blockchain network where the event occurred. + attr_accessor :network + + # Name of the project this smart contract belongs to. + attr_accessor :project_name + + # Name of the contract. + attr_accessor :contract_name + + # Name of the function. + attr_accessor :func + + # Signature of the function. + attr_accessor :sig + + # First 4 bytes of the Transaction, a unique ID. + attr_accessor :four_bytes + + # Address of the smart contract. + attr_accessor :contract_address + + # Hash of the block containing the transaction. + attr_accessor :block_hash + + # Number of the block containing the transaction. + attr_accessor :block_number + + # Timestamp when the block was mined. + attr_accessor :block_time + + # Hash of the transaction that triggered the event. + attr_accessor :transaction_hash + + # Position of the transaction within the block. + attr_accessor :transaction_index + + # Position of the event log within the transaction. + attr_accessor :log_index + + # Address of the initiator in the transfer. + attr_accessor :from + + # Address of the recipient in the transfer. + attr_accessor :to + + # Amount of tokens transferred, typically in the smallest unit (e.g., wei for Ethereum). + attr_accessor :value + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'webhook_id' => :'webhookId', + :'event_type' => :'eventType', + :'network' => :'network', + :'project_name' => :'projectName', + :'contract_name' => :'contractName', + :'func' => :'func', + :'sig' => :'sig', + :'four_bytes' => :'fourBytes', + :'contract_address' => :'contractAddress', + :'block_hash' => :'blockHash', + :'block_number' => :'blockNumber', + :'block_time' => :'blockTime', + :'transaction_hash' => :'transactionHash', + :'transaction_index' => :'transactionIndex', + :'log_index' => :'logIndex', + :'from' => :'from', + :'to' => :'to', + :'value' => :'value' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'webhook_id' => :'String', + :'event_type' => :'String', + :'network' => :'String', + :'project_name' => :'String', + :'contract_name' => :'String', + :'func' => :'String', + :'sig' => :'String', + :'four_bytes' => :'String', + :'contract_address' => :'String', + :'block_hash' => :'String', + :'block_number' => :'Integer', + :'block_time' => :'Time', + :'transaction_hash' => :'String', + :'transaction_index' => :'Integer', + :'log_index' => :'Integer', + :'from' => :'String', + :'to' => :'String', + :'value' => :'Integer' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::SmartContractActivityEvent` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::SmartContractActivityEvent`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'webhook_id') + self.webhook_id = attributes[:'webhook_id'] + end + + if attributes.key?(:'event_type') + self.event_type = attributes[:'event_type'] + end + + if attributes.key?(:'network') + self.network = attributes[:'network'] + end + + if attributes.key?(:'project_name') + self.project_name = attributes[:'project_name'] + end + + if attributes.key?(:'contract_name') + self.contract_name = attributes[:'contract_name'] + end + + if attributes.key?(:'func') + self.func = attributes[:'func'] + end + + if attributes.key?(:'sig') + self.sig = attributes[:'sig'] + end + + if attributes.key?(:'four_bytes') + self.four_bytes = attributes[:'four_bytes'] + end + + if attributes.key?(:'contract_address') + self.contract_address = attributes[:'contract_address'] + end + + if attributes.key?(:'block_hash') + self.block_hash = attributes[:'block_hash'] + end + + if attributes.key?(:'block_number') + self.block_number = attributes[:'block_number'] + end + + if attributes.key?(:'block_time') + self.block_time = attributes[:'block_time'] + end + + if attributes.key?(:'transaction_hash') + self.transaction_hash = attributes[:'transaction_hash'] + end + + if attributes.key?(:'transaction_index') + self.transaction_index = attributes[:'transaction_index'] + end + + if attributes.key?(:'log_index') + self.log_index = attributes[:'log_index'] + end + + if attributes.key?(:'from') + self.from = attributes[:'from'] + end + + if attributes.key?(:'to') + self.to = attributes[:'to'] + end + + if attributes.key?(:'value') + self.value = attributes[:'value'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + webhook_id == o.webhook_id && + event_type == o.event_type && + network == o.network && + project_name == o.project_name && + contract_name == o.contract_name && + func == o.func && + sig == o.sig && + four_bytes == o.four_bytes && + contract_address == o.contract_address && + block_hash == o.block_hash && + block_number == o.block_number && + block_time == o.block_time && + transaction_hash == o.transaction_hash && + transaction_index == o.transaction_index && + log_index == o.log_index && + from == o.from && + to == o.to && + value == o.value + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [webhook_id, event_type, network, project_name, contract_name, func, sig, four_bytes, contract_address, block_hash, block_number, block_time, transaction_hash, transaction_index, log_index, from, to, value].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Coinbase::Client.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/lib/coinbase/client/models/smart_contract_type.rb b/lib/coinbase/client/models/smart_contract_type.rb index 3d0f0bfd..f41bbd72 100644 --- a/lib/coinbase/client/models/smart_contract_type.rb +++ b/lib/coinbase/client/models/smart_contract_type.rb @@ -18,10 +18,11 @@ class SmartContractType ERC20 = "erc20".freeze ERC721 = "erc721".freeze ERC1155 = "erc1155".freeze + CUSTOM = "custom".freeze UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze def self.all_vars - @all_vars ||= [ERC20, ERC721, ERC1155, UNKNOWN_DEFAULT_OPEN_API].freeze + @all_vars ||= [ERC20, ERC721, ERC1155, CUSTOM, UNKNOWN_DEFAULT_OPEN_API].freeze end # Builds the enum from string diff --git a/lib/coinbase/client/models/webhook_event_type.rb b/lib/coinbase/client/models/webhook_event_type.rb index df57b98c..9ab7ffad 100644 --- a/lib/coinbase/client/models/webhook_event_type.rb +++ b/lib/coinbase/client/models/webhook_event_type.rb @@ -19,10 +19,11 @@ class WebhookEventType ERC20_TRANSFER = "erc20_transfer".freeze ERC721_TRANSFER = "erc721_transfer".freeze WALLET_ACTIVITY = "wallet_activity".freeze + SMART_CONTRACT_EVENT_ACTIVITY = "smart_contract_event_activity".freeze UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze def self.all_vars - @all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER, WALLET_ACTIVITY, UNKNOWN_DEFAULT_OPEN_API].freeze + @all_vars ||= [UNSPECIFIED, ERC20_TRANSFER, ERC721_TRANSFER, WALLET_ACTIVITY, SMART_CONTRACT_EVENT_ACTIVITY, UNKNOWN_DEFAULT_OPEN_API].freeze end # Builds the enum from string diff --git a/lib/coinbase/client/models/webhook_event_type_filter.rb b/lib/coinbase/client/models/webhook_event_type_filter.rb index 7e6dcbd2..c8dd017b 100644 --- a/lib/coinbase/client/models/webhook_event_type_filter.rb +++ b/lib/coinbase/client/models/webhook_event_type_filter.rb @@ -20,6 +20,7 @@ class << self # List of class defined in oneOf (OpenAPI v3) def openapi_one_of [ + :'WebhookSmartContractEventFilter', :'WebhookWalletActivityFilter' ] end diff --git a/lib/coinbase/client/models/address_risk.rb b/lib/coinbase/client/models/webhook_smart_contract_event_filter.rb similarity index 84% rename from lib/coinbase/client/models/address_risk.rb rename to lib/coinbase/client/models/webhook_smart_contract_event_filter.rb index 570f4385..b0e54e18 100644 --- a/lib/coinbase/client/models/address_risk.rb +++ b/lib/coinbase/client/models/webhook_smart_contract_event_filter.rb @@ -14,15 +14,15 @@ require 'time' module Coinbase::Client - # The risk score of a blockchain address. - class AddressRisk - # The lower the score is, the higher the risk is. The score lies between -100 to 0. - attr_accessor :risk_score + # Filter for smart contract events. This filter allows the client to specify smart contract addresses to monitor for activities such as contract function calls. + class WebhookSmartContractEventFilter + # A list of smart contract addresses to filter on. + attr_accessor :contract_addresses # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'risk_score' => :'risk_score' + :'contract_addresses' => :'contract_addresses' } end @@ -34,7 +34,7 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { - :'risk_score' => :'Integer' + :'contract_addresses' => :'Array' } end @@ -48,21 +48,23 @@ def self.openapi_nullable # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) if (!attributes.is_a?(Hash)) - fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::AddressRisk` initialize method" + fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::WebhookSmartContractEventFilter` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| if (!self.class.attribute_map.key?(k.to_sym)) - fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::AddressRisk`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::WebhookSmartContractEventFilter`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v } - if attributes.key?(:'risk_score') - self.risk_score = attributes[:'risk_score'] + if attributes.key?(:'contract_addresses') + if (value = attributes[:'contract_addresses']).is_a?(Array) + self.contract_addresses = value + end else - self.risk_score = nil + self.contract_addresses = nil end end @@ -71,8 +73,8 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new - if @risk_score.nil? - invalid_properties.push('invalid value for "risk_score", risk_score cannot be nil.') + if @contract_addresses.nil? + invalid_properties.push('invalid value for "contract_addresses", contract_addresses cannot be nil.') end invalid_properties @@ -82,7 +84,7 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' - return false if @risk_score.nil? + return false if @contract_addresses.nil? true end @@ -91,7 +93,7 @@ def valid? def ==(o) return true if self.equal?(o) self.class == o.class && - risk_score == o.risk_score + contract_addresses == o.contract_addresses end # @see the `==` method @@ -103,7 +105,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [risk_score].hash + [contract_addresses].hash end # Builds the object from hash diff --git a/lib/coinbase/client/models/webhook_wallet_activity_filter.rb b/lib/coinbase/client/models/webhook_wallet_activity_filter.rb index 1f70afa4..7d200d5f 100644 --- a/lib/coinbase/client/models/webhook_wallet_activity_filter.rb +++ b/lib/coinbase/client/models/webhook_wallet_activity_filter.rb @@ -72,6 +72,8 @@ def initialize(attributes = {}) if attributes.key?(:'wallet_id') self.wallet_id = attributes[:'wallet_id'] + else + self.wallet_id = nil end end @@ -80,6 +82,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if @wallet_id.nil? + invalid_properties.push('invalid value for "wallet_id", wallet_id cannot be nil.') + end + invalid_properties end @@ -87,6 +93,7 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @wallet_id.nil? true end diff --git a/spec/factories/address_reputation.rb b/spec/factories/address_reputation.rb new file mode 100644 index 00000000..449ed48e --- /dev/null +++ b/spec/factories/address_reputation.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :address_reputation_model, class: Coinbase::Client::AddressReputation do + score { 50 } + metadata do + { + total_transactions: 1, + unique_days_active: 1, + longest_active_streak: 1, + current_active_streak: 2, + activity_period_days: 3, + bridge_transactions_performed: 4, + lend_borrow_stake_transactions: 5, + ens_contract_interactions: 6, + smart_contract_deployments: 7, + token_swaps_performed: 8 + } + end + + initialize_with { new(attributes) } + end + + factory :address_reputation, class: Coinbase::AddressReputation do + transient do + score { nil } + metadata { nil } + + model do + build( + :address_reputation_model, + { score: score, metadata: metadata }.compact + ) + end + end + + initialize_with { Coinbase::AddressReputation.new(model) } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5bb1b8a3..ab95d768 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,7 @@ require_relative 'support/shared_examples/address_staking' require_relative 'support/shared_examples/address_transactions' require_relative 'support/shared_examples/pagination' +require_relative 'support/shared_examples/address_reputation' # Networks and Asset symbols used in our test factories. NETWORK_TRAITS = %i[base_mainnet base_sepolia ethereum_holesky ethereum_mainnet].freeze diff --git a/spec/support/shared_examples/address_reputation.rb b/spec/support/shared_examples/address_reputation.rb new file mode 100644 index 00000000..ce62c7a2 --- /dev/null +++ b/spec/support/shared_examples/address_reputation.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +shared_examples 'an address that supports reputation' do + let(:score) { 50 } + let(:metadata) { { total_transactions: 10, unique_days_active: 42 } } + let(:address_reputation) { build(:address_reputation, score: score, metadata: metadata) } + + before do + allow(Coinbase::AddressReputation).to receive(:fetch).and_return(address_reputation) + end + + it 'fetches the address reputation from the API' do + expect(address.reputation).to be_a(Coinbase::AddressReputation) + end + + it 'returns the reputation score' do + expect(address_reputation.score).to eq(score) + end + + it 'returns metadata as a Metadata object' do + expect(address_reputation.metadata).to be_a(Coinbase::AddressReputation::Metadata) + end + + it 'has correct metadata values for total transactions' do + expect(address_reputation.metadata.total_transactions).to eq(metadata[:total_transactions]) + end + + it 'has correct metadata values for unique days active' do + expect(address_reputation.metadata.unique_days_active).to eq(metadata[:unique_days_active]) + end +end diff --git a/spec/unit/coinbase/address/external_address_spec.rb b/spec/unit/coinbase/address/external_address_spec.rb index 24d003cc..5b8af3b8 100644 --- a/spec/unit/coinbase/address/external_address_spec.rb +++ b/spec/unit/coinbase/address/external_address_spec.rb @@ -34,4 +34,5 @@ it_behaves_like 'an address that supports requesting faucet funds' it_behaves_like 'an address that supports transaction queries' it_behaves_like 'an address that supports staking' + it_behaves_like 'an address that supports reputation' end diff --git a/spec/unit/coinbase/address/wallet_address_spec.rb b/spec/unit/coinbase/address/wallet_address_spec.rb index 382591e8..5bc9d461 100644 --- a/spec/unit/coinbase/address/wallet_address_spec.rb +++ b/spec/unit/coinbase/address/wallet_address_spec.rb @@ -101,6 +101,7 @@ it_behaves_like 'an address that supports balance queries' it_behaves_like 'an address that supports requesting faucet funds' it_behaves_like 'an address that supports staking' + it_behaves_like 'an address that supports reputation' describe '#invoke_contract' do subject(:contract_invocation) do diff --git a/spec/unit/coinbase/address_reputation_spec.rb b/spec/unit/coinbase/address_reputation_spec.rb new file mode 100644 index 00000000..133e81a8 --- /dev/null +++ b/spec/unit/coinbase/address_reputation_spec.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +describe Coinbase::AddressReputation do + subject(:address_reputation) { described_class.new(model) } + + let(:address_id) { '0x123456789abcdef' } + let(:network) { 'ethereum-mainnet' } + let(:score) { 50 } + let(:model) { build(:address_reputation_model, score: score) } + + describe '.fetch' do + subject(:address_reputation) { described_class.fetch(address_id: address_id, network: network) } + + let(:api_instance) { instance_double(Coinbase::Client::ReputationApi) } + + before do + allow(Coinbase::Client::ReputationApi).to receive(:new).and_return(api_instance) + allow(api_instance).to receive(:get_address_reputation).and_return(model) + + address_reputation + end + + it 'fetches address reputation for the given network and address' do + expect(api_instance).to have_received(:get_address_reputation).with(network, address_id) + end + + it 'returns an AddressReputation object' do + expect(address_reputation).to be_a(described_class) + end + + it 'returns an object initialized with the correct model' do + expect(address_reputation.instance_variable_get(:@model)).to eq(model) + end + + it 'raises an error if the API returns an invalid model' do + allow(api_instance).to receive(:get_address_reputation).and_return(nil) + + expect do + described_class.fetch(address_id: address_id, network: network) + end.to raise_error(ArgumentError, 'must be an AddressReputation object') + end + end + + describe '#score' do + it 'returns the reputation score' do + expect(address_reputation.score).to eq(score) + end + end + + describe '#metadata' do + it 'returns a Metadata object' do + expect(address_reputation.metadata).to be_a(described_class::Metadata) + end + + it 'initalizes the metadata object properly' do + model.metadata.all? do |key, value| + expect(address_reputation.metadata.send(key)).to eq(value) + end + end + end + + describe '#risky?' do + context 'when the score is positive' do + let(:score) { 42 } + + it 'returns false' do + expect(address_reputation).not_to be_risky + end + end + + context 'when the score is negative' do + let(:score) { -10 } + + it 'returns true' do + expect(address_reputation).to be_risky + end + end + end + + describe '#to_s' do + it 'includes the score and the metadata details' do + expect(address_reputation.inspect).to include( + score.to_s, + *address_reputation.metadata.to_h.values.map(&:to_s) + ) + end + end + + describe '#inspect' do + it 'matches the output of #to_s' do + expect(address_reputation.inspect).to eq(address_reputation.to_s) + end + end +end diff --git a/spec/unit/coinbase/address_spec.rb b/spec/unit/coinbase/address_spec.rb index dba93986..b6c432b4 100644 --- a/spec/unit/coinbase/address_spec.rb +++ b/spec/unit/coinbase/address_spec.rb @@ -28,6 +28,21 @@ subject { address.to_s } it { is_expected.to include(network_id.to_s, address_id) } + + context 'when the address reputation is not loaded' do + it { is_expected.not_to include('reputation_score') } + end + + context 'when the address reputation is loaded' do + let(:score) { 37 } + let(:reputation) { build(:address_reputation, score: score) } + + before do + address.instance_variable_set(:@reputation, reputation) + end + + it { is_expected.to include('reputation_score', score.to_s) } + end end describe '#inspect' do @@ -45,4 +60,5 @@ it_behaves_like 'an address that supports balance queries' it_behaves_like 'an address that supports requesting faucet funds' it_behaves_like 'an address that supports transaction queries' + it_behaves_like 'an address that supports reputation' end