Skip to content
Closed
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
128 changes: 128 additions & 0 deletions sdk/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# RustChain Python SDK

A pip-installable Python SDK for interacting with the RustChain blockchain network.

## What is RustChain?

RustChain is a Proof-of-Antiquity blockchain that rewards vintage hardware (PowerPC G4/G5, 68K Macs, SPARC, etc.) with higher mining multipliers than modern machines.

## Installation

### From GitHub (Recommended for development)
```bash
pip install git+https://github.com/sososonia-cyber/RustChain.git
```

### From PyPI (coming soon)
```bash
pip install rustchain-sdk
```

### For async support
```bash
pip install rustchain-sdk[async]
```

## Quick Start

```python
from rustchain_sdk import RustChainClient

# Create client (self-signed SSL certs handled automatically)
client = RustChainClient("https://50.28.86.131")

# Check node health
health = client.health()
print(f"Node OK: {health['ok']}")
print(f"Version: {health['version']}")

# Get active miners
miners = client.get_miners()
print(f"Active miners: {len(miners)}")

# Check epoch info
epoch = client.get_epoch()
print(f"Current epoch: {epoch['epoch']}")

# Check lottery eligibility
eligibility = client.check_eligibility("my-wallet")
print(f"Eligible: {eligibility['eligible']}")
```

## API Reference

### Client Configuration

```python
# Default configuration
client = RustChainClient()

# Custom configuration
client = RustChainClient(
base_url="https://50.28.86.131", # Node URL
verify_ssl=False, # Set True to verify SSL (for production)
timeout=30, # Request timeout in seconds
retry_count=3, # Number of retries on failure
retry_delay=1.0 # Delay between retries
)
```

### Available Methods

| Method | Description |
|--------|-------------|
| `client.health()` | Get node health status |
| `client.get_miners()` | Get list of active miners |
| `client.get_balance(miner_id)` | Get wallet balance |
| `client.get_epoch()` | Get current epoch info |
| `client.check_eligibility(miner_id)` | Check lottery eligibility |
| `client.submit_attestation(payload)` | Submit attestation |
| `client.transfer(from, to, amount, private_key)` | Transfer RTC |

### Async Support

```python
import asyncio
from rustchain_sdk import RustChainClient

async def main():
client = RustChainClient()

# Use async methods
health = await client.async_health()
miners = await client.async_get_miners()

print(f"Miners: {len(miners)}")

asyncio.run(main())
```

## Command Line Interface

```bash
# Check node health
rustchain-cli health

# List miners
rustchain-cli miners

# Check balance
rustchain-cli balance my-wallet

# Check epoch
rustchain-cli epoch
```

## Requirements

- Python 3.8+
- requests >= 2.28.0
- aiohttp >= 3.8.0 (optional, for async support)

## License

MIT License

## Author

Built by Atlas (AI Agent) for RustChain Bounty #36
5 changes: 5 additions & 0 deletions sdk/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# RustChain SDK Dependencies
requests>=2.28.0

# Optional: for async support
aiohttp>=3.8.0
19 changes: 19 additions & 0 deletions sdk/python/rustchain_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
RustChain Python SDK
A pip-installable API client for the RustChain blockchain network.

Author: sososonia-cyber (Atlas AI Agent)
License: MIT
"""

__version__ = "0.1.0"

from .client import RustChainClient
from .exceptions import RustChainError, AuthenticationError, APIError

__all__ = [
"RustChainError",
"AuthenticationError",
"APIError",
"RustChainClient",
]
94 changes: 94 additions & 0 deletions sdk/python/rustchain_sdk/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
"""
RustChain CLI - Command-line interface for RustChain
"""

import argparse
import sys
from rustchain_sdk import RustChainClient


def main():
parser = argparse.ArgumentParser(
description="RustChain CLI - Manage RTC tokens from command line"
)
parser.add_argument(
"--url",
default="https://50.28.86.131",
help="RustChain node URL"
)

subparsers = parser.add_subparsers(dest="command", help="Commands")

# Health command
subparsers.add_parser("health", help="Check node health")

# Miners command
miners_parser = subparsers.add_parser("miners", help="List active miners")
miners_parser.add_argument("--limit", type=int, default=10, help="Number of miners to show")

# Epoch command
subparsers.add_parser("epoch", help="Show current epoch info")

# Balance command
balance_parser = subparsers.add_parser("balance", help="Check wallet balance")
balance_parser.add_argument("miner_id", help="Miner wallet ID")

# Eligibility command
eligibility_parser = subparsers.add_parser("eligibility", help="Check lottery eligibility")
eligibility_parser.add_argument("miner_id", help="Miner wallet ID")

args = parser.parse_args()

if not args.command:
parser.print_help()
return

client = RustChainClient(args.url)

try:
if args.command == "health":
health = client.health()
print(f"Node Status: {'OK' if health['ok'] else 'ERROR'}")
print(f"Version: {health['version']}")
print(f"Uptime: {health['uptime_s']} seconds")
print(f"Backup Age: {health.get('backup_age_hours', 'N/A')} hours")

elif args.command == "miners":
miners = client.get_miners()
print(f"Active Miners: {len(miners)}")
print("-" * 60)
for i, m in enumerate(miners[:args.limit], 1):
print(f"{i:2}. {m['miner']}")
print(f" Hardware: {m['hardware_type']}")
print(f" Multiplier: x{m['antiquity_multiplier']}")
print(f" Last Attest: {m.get('last_attest', 'Never')}")
print()

elif args.command == "epoch":
epoch = client.get_epoch()
print(f"Epoch: {epoch['epoch']}")
print(f"Slot: {epoch['slot']}/{epoch['blocks_per_epoch']}")
print(f"Epoch Pot: {epoch['epoch_pot']} RTC")
print(f"Enrolled Miners: {epoch['enrolled_miners']}")
print(f"Total Supply: {epoch['total_supply_rtc']} RTC")

elif args.command == "balance":
balance = client.get_balance(args.miner_id)
print(f"Miner: {args.miner_id}")
print(f"Balance: {balance.get('balance', 'N/A')} RTC")

elif args.command == "eligibility":
eligibility = client.check_eligibility(args.miner_id)
print(f"Miner: {args.miner_id}")
print(f"Eligible: {'YES' if eligibility['eligible'] else 'NO'}")
print(f"Reason: {eligibility.get('reason', 'N/A')}")
print(f"Slot: {eligibility.get('slot', 'N/A')}")

except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
main()
Loading
Loading