forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python dict type for RPC method arg/return values (kaspanet#60)
* Python dictionary for request and response * readme update * to_keypair block moves
- Loading branch information
Showing
11 changed files
with
105 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Python bindings for Rusty Kaspa | ||
Rusty-Kaspa/Rust bindings for Python, using [PyO3](https://pyo3.rs/v0.20.0/) and [Maturin](https://www.maturin.rs). The result is a Python package that exposes rusty-kaspa/rust source for use in Python programs. | ||
|
||
# Building from Source | ||
1. Ensure Python 3.8 or higher (`python --version`) is installed. [*TODO validate 3.8 or higher is correct*]. Python installers can be found on [python.org](https://www.python.org). | ||
2. `cd ./python` | ||
3. Create Python virtual environment: `python -m venv env` | ||
4. Activate Python virtual env: | ||
- Unix-based systems: `source env/bin/activate` | ||
- Windows: `env/scripts/activate.bat` | ||
5. Install `maturin` build tool: `pip install maturin` | ||
6. Build Python package with Maturin: | ||
- For local development, build and install in active Python virtual env: `maturin develop --release --features py-sdk` | ||
- To build source and built (wheel) distributions: `maturin build --release --strip --sdist --features py-sdk` | ||
|
||
# Usage from Python | ||
See Python files in `./python/examples`. | ||
|
||
# Project Layout | ||
The Python package `kaspapy` is built from the `kaspa-python` crate, which is located at `./python`. | ||
|
||
As such, the `kaspapy` function in `./python/src/lib.rs` is a good starting point. This function uses PyO3 to add functionality to the package. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
import json | ||
import time | ||
|
||
from kaspapy import RpcClient | ||
|
||
|
||
async def main(): | ||
client = await RpcClient.connect(url = "ws://localhost:17110") | ||
print(f'Client is connected: {client.is_connected()}') | ||
|
||
get_server_info_response = await client.get_server_info() | ||
print(get_server_info_response) | ||
|
||
block_dag_info_response = await client.get_block_dag_info() | ||
print(block_dag_info_response) | ||
|
||
tip_hash = block_dag_info_response['tipHashes'][0] | ||
get_block_request = {'hash': tip_hash, 'includeTransactions': True} | ||
get_block_response = await client.get_block_call(get_block_request) | ||
print(get_block_response) | ||
|
||
get_balances_by_addresses_request = {'addresses': ['kaspa:qqxn4k5dchwk3m207cmh9ewagzlwwvfesngkc8l90tj44mufcgmujpav8hakt', 'kaspa:qr5ekyld6j4zn0ngennj9nx5gpt3254fzs77ygh6zzkvyy8scmp97de4ln8v5']} | ||
get_balances_by_addresses_response = await client.get_balances_by_addresses_call(get_balances_by_addresses_request) | ||
print(get_balances_by_addresses_response) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters