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

Release v0.13.0 #69

Merged
merged 6 commits into from
Dec 19, 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
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
# CDP Python SDK Changelog

## Unreleased
## [0.13.0] - 2024-12-19

### [0.12.1] - 2024-12-10
### Added
- Add support for fetching address reputation
- Add `reputation` method to `Address` to fetch the reputation of the address.
- Add support for registering, updating, and listing smart contracts that are
deployed external to CDP.
- Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function
- Add ability to import external wallets into CDP via a BIP-39 mnemonic phrase, as a 1-of-1 wallet
- Add ability to import WalletData files exported by the NodeJS CDP SDK

### Deprecated
- Deprecate `Wallet.load_seed` method in favor of `Wallet.load_seed_from_file`
- Deprecate `Wallet.save_seed` method in favor of `Wallet.save_seed_to_file`

## [0.12.1] - 2024-12-10

### Added

- Wallet address contract invocation input validation for payable contracts.

### [0.12.0] - 2024-12-06
## [0.12.0] - 2024-12-06

### Added

- Use Poetry as the dependency manager
- Relax dependency version constraints

### [0.11.0] - 2024-11-27
## [0.11.0] - 2024-11-27

### Added

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ list(address.trades())
The SDK creates wallets with [Developer-Managed (1-1)](https://docs.cdp.coinbase.com/mpc-wallet/docs/wallets#developer-managed-wallets) keys by default, which means you are responsible for securely storing the keys required to re-instantiate wallets. The below code walks you through how to export a wallet and store it in a secure location.

```python
# Export the data required to re-instantiate the wallet. The data contains the seed and the ID of the wallet.
# Export the data required to re-instantiate the wallet. The data contains the seed, the ID of the wallet, and the network ID.
data = wallet.export_data()
```

Expand Down
26 changes: 14 additions & 12 deletions cdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cdp.contract_invocation import ContractInvocation
from cdp.faucet_transaction import FaucetTransaction
from cdp.hash_utils import hash_message, hash_typed_data_message
from cdp.mnemonic_seed_phrase import MnemonicSeedPhrase
from cdp.payload_signature import PayloadSignature
from cdp.smart_contract import SmartContract
from cdp.sponsored_send import SponsoredSend
Expand All @@ -19,24 +20,25 @@
from cdp.webhook import Webhook

__all__ = [
"__version__",
"Cdp",
"ContractInvocation",
"Wallet",
"WalletAddress",
"WalletData",
"Webhook",
"Asset",
"Transfer",
"Address",
"Transaction",
"Asset",
"Balance",
"BalanceMap",
"Cdp",
"ContractInvocation",
"FaucetTransaction",
"Trade",
"SponsoredSend",
"MnemonicSeedPhrase",
"PayloadSignature",
"SmartContract",
"SponsoredSend",
"Trade",
"Transaction",
"Transfer",
"Wallet",
"WalletAddress",
"WalletData",
"Webhook",
"__version__",
"hash_message",
"hash_typed_data_message",
]
18 changes: 18 additions & 0 deletions cdp/address.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Iterator
from decimal import Decimal

from cdp.address_reputation import AddressReputation
from cdp.asset import Asset
from cdp.balance import Balance
from cdp.balance_map import BalanceMap
Expand All @@ -23,6 +24,7 @@ def __init__(self, network_id: str, address_id: str) -> None:
"""
self._network_id = network_id
self._id = address_id
self._reputation: AddressReputation | None = None

@property
def address_id(self) -> str:
Expand Down Expand Up @@ -133,6 +135,22 @@ def transactions(self) -> Iterator[Transaction]:
"""
return Transaction.list(network_id=self.network_id, address_id=self.address_id)

def reputation(self) -> AddressReputation:
"""Get the reputation of the address.

Returns:
AddressReputation: The reputation of the address.

"""
if self._reputation is not None:
return self._reputation

response = Cdp.api_clients.reputation.get_address_reputation(
network_id=self.network_id, address_id=self.address_id
)
self._reputation = AddressReputation(response)
return self._reputation

def __str__(self) -> str:
"""Return a string representation of the Address."""
return f"Address: (address_id: {self.address_id}, network_id: {self.network_id})"
Expand Down
38 changes: 38 additions & 0 deletions cdp/address_reputation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from cdp.client import AddressReputationMetadata
from cdp.client.models.address_reputation import AddressReputation as AddressReputationModel


class AddressReputation:
"""A representation of the reputation of a blockchain address."""

def __init__(self, model: AddressReputationModel) -> None:
"""Initialize the AddressReputation class."""
if not model:
raise ValueError("model is required")

self._score = model.score
self._metadata = model.metadata

@property
def metadata(self) -> AddressReputationMetadata:
"""Return the metadata of the address."""
return self._metadata

@property
def score(self) -> int:
"""Return the score of the address."""
return self._score

@property
def risky(self) -> bool:
"""Return whether the address is risky."""
return self.score < 0

def __str__(self) -> str:
"""Return a string representation of the AddressReputation."""
metadata = ", ".join(f"{key}={getattr(self.metadata, key)}" for key in vars(self.metadata))
return f"Address Reputation: (score={self.score}, metadata=({metadata}))"

def __repr__(self) -> str:
"""Return a string representation of the AddressReputation."""
return str(self)
17 changes: 17 additions & 0 deletions cdp/api_clients.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cdp.cdp_api_client import CdpApiClient
from cdp.client import ReputationApi
from cdp.client.api.addresses_api import AddressesApi
from cdp.client.api.assets_api import AssetsApi
from cdp.client.api.balance_history_api import BalanceHistoryApi
Expand Down Expand Up @@ -55,6 +56,7 @@ def __init__(self, cdp_client: CdpApiClient) -> None:
self._balance_history: BalanceHistoryApi | None = None
self._transaction_history: TransactionHistoryApi | None = None
self._fund: FundApi | None = None
self._reputation: ReputationApi | None = None

@property
def wallets(self) -> WalletsApi:
Expand Down Expand Up @@ -250,3 +252,18 @@ def fund(self) -> FundApi:
if self._fund is None:
self._fund = FundApi(api_client=self._cdp_client)
return self._fund

@property
def reputation(self) -> ReputationApi:
"""Get the ReputationApi client instance.

Returns:
ReputationApi: The ReputationApi client instance.

Note:
This property lazily initializes the ReputationApi client on first access.

"""
if self._reputation is None:
self._reputation = ReputationApi(api_client=self._cdp_client)
return self._reputation
4 changes: 2 additions & 2 deletions cdp/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@
from cdp.client.exceptions import ApiException

# import models into sdk package
from cdp.client.models.abi import ABI
from cdp.client.models.address import Address
from cdp.client.models.address_balance_list import AddressBalanceList
from cdp.client.models.address_historical_balance_list import AddressHistoricalBalanceList
from cdp.client.models.address_list import AddressList
from cdp.client.models.address_reputation import AddressReputation
from cdp.client.models.address_reputation_metadata import AddressReputationMetadata
from cdp.client.models.address_risk import AddressRisk
from cdp.client.models.address_transaction_list import AddressTransactionList
from cdp.client.models.asset import Asset
from cdp.client.models.balance import Balance
Expand Down Expand Up @@ -116,6 +114,7 @@
from cdp.client.models.payload_signature import PayloadSignature
from cdp.client.models.payload_signature_list import PayloadSignatureList
from cdp.client.models.read_contract_request import ReadContractRequest
from cdp.client.models.register_smart_contract_request import RegisterSmartContractRequest
from cdp.client.models.seed_creation_event import SeedCreationEvent
from cdp.client.models.seed_creation_event_result import SeedCreationEventResult
from cdp.client.models.server_signer import ServerSigner
Expand Down Expand Up @@ -150,6 +149,7 @@
from cdp.client.models.transaction_type import TransactionType
from cdp.client.models.transfer import Transfer
from cdp.client.models.transfer_list import TransferList
from cdp.client.models.update_smart_contract_request import UpdateSmartContractRequest
from cdp.client.models.update_webhook_request import UpdateWebhookRequest
from cdp.client.models.user import User
from cdp.client.models.validator import Validator
Expand Down
15 changes: 15 additions & 0 deletions cdp/client/api/addresses_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def _create_address_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -618,6 +619,7 @@ def _create_payload_signature_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -893,6 +895,8 @@ def _get_address_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -1183,6 +1187,8 @@ def _get_address_balance_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -1473,6 +1479,8 @@ def _get_payload_signature_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -1765,6 +1773,8 @@ def _list_address_balances_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -2059,6 +2069,8 @@ def _list_addresses_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -2368,6 +2380,8 @@ def _list_payload_signatures_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -2663,6 +2677,7 @@ def _request_faucet_funds_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey'
]

return self.api_client.param_serialize(
Expand Down
2 changes: 2 additions & 0 deletions cdp/client/api/assets_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def _get_asset_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down
2 changes: 2 additions & 0 deletions cdp/client/api/balance_history_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ def _list_address_historical_balance_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down
2 changes: 2 additions & 0 deletions cdp/client/api/contract_events_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ def _list_contract_events_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down
6 changes: 6 additions & 0 deletions cdp/client/api/contract_invocations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def _broadcast_contract_invocation_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -643,6 +644,7 @@ def _create_contract_invocation_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -933,6 +935,8 @@ def _get_contract_invocation_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down Expand Up @@ -1242,6 +1246,8 @@ def _list_contract_invocations_serialize(

# authentication setting
_auth_settings: List[str] = [
'apiKey',
'session'
]

return self.api_client.param_serialize(
Expand Down
Loading
Loading