Skip to main content

A Python SDK for interacting with the Tranquillo API

Project description

Tranquillo Staking Python SDK

Welcome to the Tranquillo Staking Python SDK - your definitive toolkit for staking and delegation. This SDK provides a streamlined experience for initiating staking flows, handling delegation, and managing signed transactions, ensuring seamless and secure integration the POS networks.


Build the Tranquillo SDK Application

Prerequisites for Tranquillo SDK

  • Python: Version 3.11 or higher.
  • Poetry: Dependency management tool for Python.

Installing Tranquillo SDK Dependencies

Before building the program, ensure you have the following prerequisites:

  1. Navigate to the project directory:

    cd python_sdk
    
  2. Setup Environment:

    Create a virtual environment and activate it:

    python3.11 -m venv venv
    source venv/bin/activate
    
  3. Install the necessary dependencies using Poetry:

    poetry install
    

Running the Tranquillo SDK Application

Starting the Tranquillo API Server

To start the server and import validator keys using mnemonics, use the following command:

poetry run python python_sdk/endpoint_server.py

Running SDK Testing Tool

poetry run python python_sdk/tester.py

Understanding SDK Output Data

poetry run python python_sdk/tester.py

Flow ID: ['2d514903-2a09-41d6-938d-65965c0d7507']
Delegated State: delegated
Transaction State: broadcasted

SDK Testing Procedures

TTesting Tranquillo SDK Server with curl Commands

To test the API endpoints, you can use the curl command-line tool. Here are some example commands:

  1. Test the Create Staking Flow Endpoint:

    curl -X POST -H "Content-Type: application/json" \
      -d '{"flow": {"network_code": "cosmos", "chain_code": "testnet", "operation": "staking"}}' \
      http://127.0.0.1:5000/api/v1/flows
    
  2. Test the Delegate Endpoint (Replace {flow_id} with the actual flow ID):

    curl -X PUT -H "Content-Type: application/json" \
      -d '{"name": "create_delegate_tx", "inputs": {"delegator_address": "your_address", "validator_address": "validator_address", "amount": 100}}' \
      http://127.0.0.1:5000/api/v1/flows/{flow_id}/next
    
  3. Test the Signed Delegate Endpoint (Replace {flow_id} with the actual flow ID):

    curl -X PUT -H "Content-Type: application/json" \
      -d '{"name": "sign_delegate_tx", "inputs": {"transaction_payload": "your_payload"}, "signatures": ["signature1", "signature2"]}' \
      http://127.0.0.1:5000/api/v1/flows/{flow_id}/next
    

Replace placeholders like your_address, validator_address, your_payload, etc., with actual values when executing the commands.


Executing Automated Tests for the SDK

To execute your tests, you can use the following command:

poetry run pytest

# or

poetry run pytest tests/test_tranquillo_client.py

Or, if you are using unittest and your test files are named in the pattern test_*.py, you can use:

poetry run python -m unittest discover

Running a Single Test File

To run a specific test file, simply provide the path to the file. For example:

poetry run pytest tests/test_my_feature.py

Performing Coverage Analysis for SDK Tests

Run tests with coverage using the following command:

poetry run pytest --cov=python_sdk/.

Generating Test Coverage Reports for the SDK

Terminal Report:

poetry run pytest --cov=python_sdk/. --cov-report=term

Create HTML Report:

poetry run pytest --cov=python_sdk/. --cov-report=xml

XML Report:

poetry run pytest --cov=your_package_name --cov-report=xml

MongoDB Command Reference for Staking Data Management

This section outlines the MongoDB commands used for querying the staking database, specifically within the flows collection.

Accessing and Querying the Staking Database

First, Start mongo cli:

./mongosh

Switch to the staking database:

use staking

Retrieve and Display All Documents in flows Collection

This command fetches all documents from the flows collection and displays them in a formatted manner.

db.flows.find().pretty()

Find a Specific Document by Flow ID

Replace your_flow_id with the actual ID of the flow you want to query.

db.flows.find({"flow_id": "your_flow_id"}).pretty()

Example using a specific flow ID:

db.flows.find({"flow_id": "b2c4c9c9-a6ef-46f7-b1a4-e3aebd9ba84b"}).pretty()

Drop the Collection

Example to drop the flows collection:

db.flows.drop()

Building and Deploying the Tranquillo SDK

Configuring pyproject.toml for Tranquillo SDK

Ensure your pyproject.toml file is correctly set up with all necessary information. This includes the package name, version, description, dependencies, and any other relevant metadata. Here's an example template:

[tool.poetry]
name = "tranquillo-sdk"
version = "0.1.0"
description = "A Python SDK for interacting with the Tranquillo API"
authors = ["Your Name <youremail@example.com>"]

[tool.poetry.dependencies]
python = "^3.11"

[tool.poetry.dev-dependencies]
pytest = "^7.4.3"

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

Building the Tranquillo SDK Package

To build the package, execute the following command:

poetry build

This command will generate a .tar.gz archive and a .whl file in the dist directory.

Publishing the Tranquillo SDK to PyPI

To publish your package to PyPI (Python Package Index), create a account on PyPI.

Once the account is created, publish your package using:

poetry publish

This command will prompt you for your PyPI username and password. If you are using a CI/CD pipeline, you can also automate this step using API tokens.

Version Control Tagging for SDK Releases

After deploying your package, tag the commit and push the tag to your remote repository:

git tag -a v0.1.0 -m "Release 0.1.0"
git push origin v0.1.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tranquillo_staking_api-0.1.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tranquillo_staking_api-0.1.3-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file tranquillo_staking_api-0.1.3.tar.gz.

File metadata

  • Download URL: tranquillo_staking_api-0.1.3.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Darwin/23.0.0

File hashes

Hashes for tranquillo_staking_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 734ce55407a767fdd5b3a27b38f7415c40abb55f2ef815fcc115ae75f8123d75
MD5 39f5d20db0fd5de2605c06cf11be1c33
BLAKE2b-256 49225e59cf5a925c0aab5c9de43b6969335b6a45c1502ad32bf0cd782875d208

See more details on using hashes here.

File details

Details for the file tranquillo_staking_api-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for tranquillo_staking_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 36113a2c8527c75efdd2898e11576676c885327acc685bfb9329aeb4ff70caa5
MD5 14758ca20b82bb5367c817c15acb532e
BLAKE2b-256 a618bf51a7661942858887bb1f52520ad2b7ee029f3712de19f56c78d4d7402a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page