Skip to content

Commit b5bb568

Browse files
authored
Merge pull request #69 from coinbase/v0.13.0
Release v0.13.0
2 parents df98abb + a6cbe88 commit b5bb568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1539
-390
lines changed

CHANGELOG.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
# CDP Python SDK Changelog
22

3-
## Unreleased
3+
## [0.13.0] - 2024-12-19
44

5-
### [0.12.1] - 2024-12-10
5+
### Added
6+
- Add support for fetching address reputation
7+
- Add `reputation` method to `Address` to fetch the reputation of the address.
8+
- Add support for registering, updating, and listing smart contracts that are
9+
deployed external to CDP.
10+
- Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function
11+
- Add ability to import external wallets into CDP via a BIP-39 mnemonic phrase, as a 1-of-1 wallet
12+
- Add ability to import WalletData files exported by the NodeJS CDP SDK
13+
14+
### Deprecated
15+
- Deprecate `Wallet.load_seed` method in favor of `Wallet.load_seed_from_file`
16+
- Deprecate `Wallet.save_seed` method in favor of `Wallet.save_seed_to_file`
17+
18+
## [0.12.1] - 2024-12-10
619

720
### Added
821

922
- Wallet address contract invocation input validation for payable contracts.
1023

11-
### [0.12.0] - 2024-12-06
24+
## [0.12.0] - 2024-12-06
1225

1326
### Added
1427

1528
- Use Poetry as the dependency manager
1629
- Relax dependency version constraints
1730

18-
### [0.11.0] - 2024-11-27
31+
## [0.11.0] - 2024-11-27
1932

2033
### Added
2134

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ list(address.trades())
189189
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.
190190

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

cdp/__init__.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from cdp.contract_invocation import ContractInvocation
88
from cdp.faucet_transaction import FaucetTransaction
99
from cdp.hash_utils import hash_message, hash_typed_data_message
10+
from cdp.mnemonic_seed_phrase import MnemonicSeedPhrase
1011
from cdp.payload_signature import PayloadSignature
1112
from cdp.smart_contract import SmartContract
1213
from cdp.sponsored_send import SponsoredSend
@@ -19,24 +20,25 @@
1920
from cdp.webhook import Webhook
2021

2122
__all__ = [
22-
"__version__",
23-
"Cdp",
24-
"ContractInvocation",
25-
"Wallet",
26-
"WalletAddress",
27-
"WalletData",
28-
"Webhook",
29-
"Asset",
30-
"Transfer",
3123
"Address",
32-
"Transaction",
24+
"Asset",
3325
"Balance",
3426
"BalanceMap",
27+
"Cdp",
28+
"ContractInvocation",
3529
"FaucetTransaction",
36-
"Trade",
37-
"SponsoredSend",
30+
"MnemonicSeedPhrase",
3831
"PayloadSignature",
3932
"SmartContract",
33+
"SponsoredSend",
34+
"Trade",
35+
"Transaction",
36+
"Transfer",
37+
"Wallet",
38+
"WalletAddress",
39+
"WalletData",
40+
"Webhook",
41+
"__version__",
4042
"hash_message",
4143
"hash_typed_data_message",
4244
]

cdp/address.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Iterator
22
from decimal import Decimal
33

4+
from cdp.address_reputation import AddressReputation
45
from cdp.asset import Asset
56
from cdp.balance import Balance
67
from cdp.balance_map import BalanceMap
@@ -23,6 +24,7 @@ def __init__(self, network_id: str, address_id: str) -> None:
2324
"""
2425
self._network_id = network_id
2526
self._id = address_id
27+
self._reputation: AddressReputation | None = None
2628

2729
@property
2830
def address_id(self) -> str:
@@ -133,6 +135,22 @@ def transactions(self) -> Iterator[Transaction]:
133135
"""
134136
return Transaction.list(network_id=self.network_id, address_id=self.address_id)
135137

138+
def reputation(self) -> AddressReputation:
139+
"""Get the reputation of the address.
140+
141+
Returns:
142+
AddressReputation: The reputation of the address.
143+
144+
"""
145+
if self._reputation is not None:
146+
return self._reputation
147+
148+
response = Cdp.api_clients.reputation.get_address_reputation(
149+
network_id=self.network_id, address_id=self.address_id
150+
)
151+
self._reputation = AddressReputation(response)
152+
return self._reputation
153+
136154
def __str__(self) -> str:
137155
"""Return a string representation of the Address."""
138156
return f"Address: (address_id: {self.address_id}, network_id: {self.network_id})"

cdp/address_reputation.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from cdp.client import AddressReputationMetadata
2+
from cdp.client.models.address_reputation import AddressReputation as AddressReputationModel
3+
4+
5+
class AddressReputation:
6+
"""A representation of the reputation of a blockchain address."""
7+
8+
def __init__(self, model: AddressReputationModel) -> None:
9+
"""Initialize the AddressReputation class."""
10+
if not model:
11+
raise ValueError("model is required")
12+
13+
self._score = model.score
14+
self._metadata = model.metadata
15+
16+
@property
17+
def metadata(self) -> AddressReputationMetadata:
18+
"""Return the metadata of the address."""
19+
return self._metadata
20+
21+
@property
22+
def score(self) -> int:
23+
"""Return the score of the address."""
24+
return self._score
25+
26+
@property
27+
def risky(self) -> bool:
28+
"""Return whether the address is risky."""
29+
return self.score < 0
30+
31+
def __str__(self) -> str:
32+
"""Return a string representation of the AddressReputation."""
33+
metadata = ", ".join(f"{key}={getattr(self.metadata, key)}" for key in vars(self.metadata))
34+
return f"Address Reputation: (score={self.score}, metadata=({metadata}))"
35+
36+
def __repr__(self) -> str:
37+
"""Return a string representation of the AddressReputation."""
38+
return str(self)

cdp/api_clients.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from cdp.cdp_api_client import CdpApiClient
2+
from cdp.client import ReputationApi
23
from cdp.client.api.addresses_api import AddressesApi
34
from cdp.client.api.assets_api import AssetsApi
45
from cdp.client.api.balance_history_api import BalanceHistoryApi
@@ -55,6 +56,7 @@ def __init__(self, cdp_client: CdpApiClient) -> None:
5556
self._balance_history: BalanceHistoryApi | None = None
5657
self._transaction_history: TransactionHistoryApi | None = None
5758
self._fund: FundApi | None = None
59+
self._reputation: ReputationApi | None = None
5860

5961
@property
6062
def wallets(self) -> WalletsApi:
@@ -250,3 +252,18 @@ def fund(self) -> FundApi:
250252
if self._fund is None:
251253
self._fund = FundApi(api_client=self._cdp_client)
252254
return self._fund
255+
256+
@property
257+
def reputation(self) -> ReputationApi:
258+
"""Get the ReputationApi client instance.
259+
260+
Returns:
261+
ReputationApi: The ReputationApi client instance.
262+
263+
Note:
264+
This property lazily initializes the ReputationApi client on first access.
265+
266+
"""
267+
if self._reputation is None:
268+
self._reputation = ReputationApi(api_client=self._cdp_client)
269+
return self._reputation

cdp/client/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@
5050
from cdp.client.exceptions import ApiException
5151

5252
# import models into sdk package
53-
from cdp.client.models.abi import ABI
5453
from cdp.client.models.address import Address
5554
from cdp.client.models.address_balance_list import AddressBalanceList
5655
from cdp.client.models.address_historical_balance_list import AddressHistoricalBalanceList
5756
from cdp.client.models.address_list import AddressList
5857
from cdp.client.models.address_reputation import AddressReputation
5958
from cdp.client.models.address_reputation_metadata import AddressReputationMetadata
60-
from cdp.client.models.address_risk import AddressRisk
6159
from cdp.client.models.address_transaction_list import AddressTransactionList
6260
from cdp.client.models.asset import Asset
6361
from cdp.client.models.balance import Balance
@@ -116,6 +114,7 @@
116114
from cdp.client.models.payload_signature import PayloadSignature
117115
from cdp.client.models.payload_signature_list import PayloadSignatureList
118116
from cdp.client.models.read_contract_request import ReadContractRequest
117+
from cdp.client.models.register_smart_contract_request import RegisterSmartContractRequest
119118
from cdp.client.models.seed_creation_event import SeedCreationEvent
120119
from cdp.client.models.seed_creation_event_result import SeedCreationEventResult
121120
from cdp.client.models.server_signer import ServerSigner
@@ -150,6 +149,7 @@
150149
from cdp.client.models.transaction_type import TransactionType
151150
from cdp.client.models.transfer import Transfer
152151
from cdp.client.models.transfer_list import TransferList
152+
from cdp.client.models.update_smart_contract_request import UpdateSmartContractRequest
153153
from cdp.client.models.update_webhook_request import UpdateWebhookRequest
154154
from cdp.client.models.user import User
155155
from cdp.client.models.validator import Validator

cdp/client/api/addresses_api.py

+15
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def _create_address_serialize(
315315

316316
# authentication setting
317317
_auth_settings: List[str] = [
318+
'apiKey'
318319
]
319320

320321
return self.api_client.param_serialize(
@@ -618,6 +619,7 @@ def _create_payload_signature_serialize(
618619

619620
# authentication setting
620621
_auth_settings: List[str] = [
622+
'apiKey'
621623
]
622624

623625
return self.api_client.param_serialize(
@@ -893,6 +895,8 @@ def _get_address_serialize(
893895

894896
# authentication setting
895897
_auth_settings: List[str] = [
898+
'apiKey',
899+
'session'
896900
]
897901

898902
return self.api_client.param_serialize(
@@ -1183,6 +1187,8 @@ def _get_address_balance_serialize(
11831187

11841188
# authentication setting
11851189
_auth_settings: List[str] = [
1190+
'apiKey',
1191+
'session'
11861192
]
11871193

11881194
return self.api_client.param_serialize(
@@ -1473,6 +1479,8 @@ def _get_payload_signature_serialize(
14731479

14741480
# authentication setting
14751481
_auth_settings: List[str] = [
1482+
'apiKey',
1483+
'session'
14761484
]
14771485

14781486
return self.api_client.param_serialize(
@@ -1765,6 +1773,8 @@ def _list_address_balances_serialize(
17651773

17661774
# authentication setting
17671775
_auth_settings: List[str] = [
1776+
'apiKey',
1777+
'session'
17681778
]
17691779

17701780
return self.api_client.param_serialize(
@@ -2059,6 +2069,8 @@ def _list_addresses_serialize(
20592069

20602070
# authentication setting
20612071
_auth_settings: List[str] = [
2072+
'apiKey',
2073+
'session'
20622074
]
20632075

20642076
return self.api_client.param_serialize(
@@ -2368,6 +2380,8 @@ def _list_payload_signatures_serialize(
23682380

23692381
# authentication setting
23702382
_auth_settings: List[str] = [
2383+
'apiKey',
2384+
'session'
23712385
]
23722386

23732387
return self.api_client.param_serialize(
@@ -2663,6 +2677,7 @@ def _request_faucet_funds_serialize(
26632677

26642678
# authentication setting
26652679
_auth_settings: List[str] = [
2680+
'apiKey'
26662681
]
26672682

26682683
return self.api_client.param_serialize(

cdp/client/api/assets_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ def _get_asset_serialize(
293293

294294
# authentication setting
295295
_auth_settings: List[str] = [
296+
'apiKey',
297+
'session'
296298
]
297299

298300
return self.api_client.param_serialize(

cdp/client/api/balance_history_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def _list_address_historical_balance_serialize(
343343

344344
# authentication setting
345345
_auth_settings: List[str] = [
346+
'apiKey',
347+
'session'
346348
]
347349

348350
return self.api_client.param_serialize(

cdp/client/api/contract_events_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ def _list_contract_events_serialize(
396396

397397
# authentication setting
398398
_auth_settings: List[str] = [
399+
'apiKey',
400+
'session'
399401
]
400402

401403
return self.api_client.param_serialize(

cdp/client/api/contract_invocations_api.py

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ def _broadcast_contract_invocation_serialize(
340340

341341
# authentication setting
342342
_auth_settings: List[str] = [
343+
'apiKey'
343344
]
344345

345346
return self.api_client.param_serialize(
@@ -643,6 +644,7 @@ def _create_contract_invocation_serialize(
643644

644645
# authentication setting
645646
_auth_settings: List[str] = [
647+
'apiKey'
646648
]
647649

648650
return self.api_client.param_serialize(
@@ -933,6 +935,8 @@ def _get_contract_invocation_serialize(
933935

934936
# authentication setting
935937
_auth_settings: List[str] = [
938+
'apiKey',
939+
'session'
936940
]
937941

938942
return self.api_client.param_serialize(
@@ -1242,6 +1246,8 @@ def _list_contract_invocations_serialize(
12421246

12431247
# authentication setting
12441248
_auth_settings: List[str] = [
1249+
'apiKey',
1250+
'session'
12451251
]
12461252

12471253
return self.api_client.param_serialize(

0 commit comments

Comments
 (0)