Skip to content

Commit

Permalink
Implement python client
Browse files Browse the repository at this point in the history
  • Loading branch information
yeehan-crypto-com committed Oct 18, 2024
1 parent 33d5472 commit c54384f
Show file tree
Hide file tree
Showing 20 changed files with 899 additions and 132 deletions.
23 changes: 23 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Pull Request Template

## Description
Please include a summary of the change and which issue is fixed. Include the context and motivations behind your changes.

## Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## Checklist:
Before you submit the pull request, please review the following checklist:
- [ ] I have performed a self-review of my own code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have made corresponding changes to the documentation.
- [ ] My changes generate no new warnings.
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] New and existing unit tests pass locally with my changes.
- [ ] Any dependent changes have been merged and published in downstream modules.

## Linked Issues
Mention the issues that are addressed by this PR. You can use the `#` symbol to link an issue.
24 changes: 24 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: upload

on:
push:
tags:
- 'v*.*.*'

permissions:
contents: write

jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install dependencies
run: python3 -m pip install --user --upgrade poetry
- name: build
run: poetry build
- name: release
uses: softprops/action-gh-release@v1
with:
files: |
dist/*
187 changes: 74 additions & 113 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,137 +26,98 @@ share/python-wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
# Virtual environments
venv/
ENV/
env/
.venv/
*.venv

# PyBuilder
.pybuilder/
target/
# Poetry virtual environments
poetry.lock
.pdm.toml

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py
# PyCharm
.idea/

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# VS Code
.vscode/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# pyenv
.python-version

# Celery stuff
# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
# dotenv
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject
.env.*

# Rope project settings
.ropeproject

# mkdocs documentation
/site
# pyre type checker
.pyre/

# mypy
# mypy type checker
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
# pytest
.cache/
*.pytest_cache/

# pytype static type analyzer
.pytype/
# Coverage reports
htmlcov/
.coverage
.coverage.*
.cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Cython debug symbols
cython_debug/
# pylint
pylint.log

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Sphinx documentation
docs/_build/

# Cython
*.c
*.cpp
*.cxx
*.h

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
coverage.xml
*.cover
*.py,cover
.cache

# Miscellaneous
*.log
*.pot
*.log.*
*.out
*.pid
*.pid.lock
*.pid.txt

# Logs and databases
*.log
*.sql
*.sqlite3

# Editors
*.sublime*
*~
*~
.*.swp
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
24 changes: 5 additions & 19 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
MIT License
Copyright 2024 Crypto.com

Copyright (c) 2024 Crypto.com
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This project is powered by OpenAI (www.openai.com).
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[tool.poetry]
name = "developer-platform-client-py"
version = "1.0.2-beta"
description = "A python client to interact with @cryptocom/developer-platform-service"
authors = ["Ric Arcifa <[email protected]>"]
license = "MIT"
keywords = ["agent", "blockchain", "crypto.com", "AI", "CDC"]
readme = "README.md"
homepage = "https://github.com/crypto-com/developer-platform-client-py"
repository = "https://github.com/crypto-com/developer-platform-client-py"
documentation = "https://github.com/crypto-com/developer-platform-client-py"

[tool.poetry.dependencies]
python = "^3.8.1"
requests = "^2.32.3"

[tool.poetry.dev-dependencies]
pytest = "^8.3.3"
flake8 = "^7.1.1"
black = "^24.8.0"
isort = "^5.13.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 88
target-version = ['py39']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
| \.git
| \.tox
| \.venv
| build
| dist
)/
)
'''

[tool.isort]
profile = "black"

[tool.poetry.scripts]
cdc-ai-agent-client = "developer-platform-client-py.cli:main"
18 changes: 18 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .block import Block
from .client import Client
from .contract import Contract
from .interfaces.chain_interfaces import CronosEvm, CronosZkEvm
from .token import Token
from .transaction import Transaction
from .wallet import Wallet

__all__ = [
"Client",
"Contract",
"Wallet",
"Block",
"Transaction",
"Token",
"CronosEvm",
"CronosZkEvm",
]
35 changes: 35 additions & 0 deletions src/block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from .client import Client
from .integrations.api_interfaces import ApiResponse
from .integrations.block_api import get_block_by_tag


class Block:
"""
Block class for fetching block data.
"""
_client: Client

@classmethod
def init(cls, client: Client) -> None:
"""
Initialize the Block class with a Client instance.
:param client: An instance of the Client class.
"""
cls._client = client

@classmethod
def get_by_tag(cls, tag: str, tx_detail: str = "false") -> ApiResponse:
"""
Get block data by tag.
:param tag: Integer of a block number in hex, or the string "earliest", "latest" or "pending", as in https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block
:param tx_detail: If true it returns the full transaction objects, if false only the hashes of the transactions.
:return: The block data.
"""
return get_block_by_tag(
cls._client.get_chain_id(),
cls._client.get_api_key(),
tag,
tx_detail
)
Loading

0 comments on commit c54384f

Please sign in to comment.