Skip to content
Merged
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
71 changes: 71 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Publish to crates.io

on:
release:
types: [published]

env:
CARGO_TERM_COLOR: always

jobs:
publish:
name: Publish bittensor-rs
runs-on: ubuntu-latest
# Only run if this is a bittensor-rs release
if: startsWith(github.event.release.tag_name, 'bittensor-rs-v')
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-action@stable
with:
components: rustfmt, clippy
Comment on lines +20 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

dtolnay rust-toolchain github action

💡 Result:

dtolnay/rust-toolchain is a concise GitHub Action that installs a Rust toolchain via rustup. Key points:

  • Repo/README: usage example (one-line use like uses: dtolnay/rust-toolchain@stable or @nightly), inputs (toolchain, targets, components), and outputs (cachekey, name). [1]
  • Action selects toolchain from the action ref by default (e.g. @nightly or @1.89.0); to override with an explicit toolchain input use @master. [1]
  • Marketplace entry and related actions (actions-rust-lang/setup-rust-toolchain) show alternatives with extra features (caching, problem matchers). [2][3]

Sources:
[1] dtolnay/rust-toolchain (README & action.yml).
[2] GitHub Marketplace: Setup Rust Toolchain for GitHub CI (actions-rust-lang).
[3] dtolnay/rust-toolchain repository Actions page.


🌐 Web query:

dtolnay/rust-action github

💡 Result:

You likely mean dtolnay/rust-toolchain — a concise GitHub Action that installs a Rust toolchain via rustup (usage: e.g. uses: dtolnay/rust-toolchain@stable). (github.com)

Citations:


🏁 Script executed:

cat -n .github/workflows/publish.yml | sed -n '20,23p'

Repository: one-covenant/bittensor-rs

Length of output: 226


Invalid GitHub Action reference - workflow will fail.

The action dtolnay/rust-action@stable does not exist. The correct action is dtolnay/rust-toolchain@stable.

       - name: Install Rust toolchain
-        uses: dtolnay/rust-action@stable
+        uses: dtolnay/rust-toolchain@stable
         with:
           components: rustfmt, clippy
🤖 Prompt for AI Agents
In .github/workflows/publish.yml around lines 20 to 23 the workflow references a
non-existent action `dtolnay/rust-action@stable`; replace that reference with
the correct action `dtolnay/rust-toolchain@stable` so the step becomes `uses:
dtolnay/rust-toolchain@stable` and keep the existing `with: components: rustfmt,
clippy` configuration intact.


- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-publish-

- name: Verify package
working-directory: bittensor-rs
run: |
cargo publish --dry-run

- name: Publish to crates.io
working-directory: bittensor-rs
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo publish --no-verify

# Notify on failure
notify-failure:
name: Notify on Failure
runs-on: ubuntu-latest
needs: publish
if: failure()
steps:
- name: Create issue on failure
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Failed to publish ${context.payload.release.tag_name} to crates.io`,
body: `The publish workflow failed for release ${context.payload.release.tag_name}.\n\nPlease check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.`,
labels: ['bug', 'ci']
})

26 changes: 26 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release Please

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
bittensor-rs--release_created: ${{ steps.release.outputs['bittensor-rs--release_created'] }}
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json

4 changes: 4 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bittensor-rs": "0.1.0"
}

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 distributedstatemachine
Copyright (c) 2024 covenant.ai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Bittensor Rust SDK

[![CI](https://github.com/one-covenant/bittensor-rs/workflows/CI/badge.svg)](https://github.com/one-covenant/bittensor-rs/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A collection of Rust crates for interacting with the [Bittensor](https://bittensor.com) blockchain network.

## Workspace Structure

This monorepo contains the following crates:

| Crate | Description | Crates.io |
|-------|-------------|-----------|
| [`bittensor-rs`](./bittensor-rs) | Core SDK for Bittensor chain interactions | [![Crates.io](https://img.shields.io/crates/v/bittensor-rs.svg)](https://crates.io/crates/bittensor-rs) |
| [`bittensor-wallet`](./bittensor-wallet) | Wallet management with Python bindings | - |
| [`lightning-tensor`](./lightning-tensor) | Terminal UI for Bittensor | - |

## Quick Start

### Using bittensor-rs

Add to your `Cargo.toml`:

```toml
[dependencies]
bittensor-rs = "0.1"
```

```rust
use bittensor::{config::BittensorConfig, Service};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Finney mainnet
let config = BittensorConfig::finney("my_wallet", "my_hotkey", 1);
let service = Service::new(config).await?;

// Query metagraph
let metagraph = service.get_metagraph(1).await?;
println!("Found {} neurons", metagraph.hotkeys.len());

Ok(())
}
```
Comment on lines +29 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Import path inconsistency with crate name.

The example shows use bittensor::{config::BittensorConfig, Service}; but the Cargo.toml dependency specifies bittensor-rs = "0.1". This means the import should be use bittensor_rs::{config::BittensorConfig, Service}; (with underscore, not hyphen).

This inconsistency will cause compilation errors for users following the Quick Start guide.

🔎 Proposed fix
-use bittensor::{config::BittensorConfig, Service};
+use bittensor_rs::{config::BittensorConfig, Service};
🤖 Prompt for AI Agents
In README.md around lines 29 to 44 the example imports "bittensor::{...}" but
the crate in Cargo.toml is declared as "bittensor-rs", causing a compile-time
import error; update the import to use the actual crate identifier (replace the
hyphenated crate name with the valid Rust identifier form) and ensure any other
README examples and import references match the crate name in Cargo.toml (or
alternatively update Cargo.toml to expose the intended crate name).


## Development

### Prerequisites

- Rust 1.70 or later
- Protocol Buffers compiler (`protoc`)

### Building

```bash
# Build all crates
cargo build --workspace

# Build with all features
cargo build --workspace --all-features

# Run tests
cargo test --workspace

# Run specific crate tests
cargo test -p bittensor-rs
```

### Using Just (Recommended)

This project includes a [justfile](./justfile) for common tasks:

```bash
# Install just: https://github.com/casey/just
cargo install just

# See available commands
just --list
```

## Documentation

- [bittensor-rs API docs](https://docs.rs/bittensor-rs) - Full API documentation on docs.rs
- [bittensor-wallet README](./bittensor-wallet/README.md) - Wallet crate documentation

## Contributing

Contributions are welcome! Please follow these guidelines:

1. **Conventional Commits**: Use [conventional commit](https://www.conventionalcommits.org/) format:
- `feat: add new feature`
- `fix: resolve bug`
- `docs: update documentation`
- `chore: maintenance task`

2. **Pull Requests**: All changes should go through PR review

3. **Testing**: Add tests for new functionality

## Release Process

This repository uses [release-please](https://github.com/googleapis/release-please) for automated releases:

1. Merge PRs with conventional commits to `main`
2. Release-please automatically creates/updates a release PR with changelog
3. Merge the release PR to trigger a GitHub release
4. The publish workflow automatically publishes to crates.io

## License

MIT License - see [LICENSE](LICENSE) for details.

## Related Projects

- [Bittensor](https://github.com/opentensor/bittensor) - Python SDK and CLI
- [Subtensor](https://github.com/opentensor/subtensor) - Bittensor blockchain node

61 changes: 61 additions & 0 deletions bittensor-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - Initial Release

### Features

- **Connection Management**
- Connection pooling with configurable pool size
- Automatic health checks and connection monitoring
- Circuit breaker pattern for cascade failure prevention
- Exponential backoff retry logic with jitter

- **Chain Queries**
- `get_metagraph` / `get_selective_metagraph` - Subnet metagraph data
- `get_neuron` / `get_neuron_lite` - Neuron information
- `get_balance` / `get_stake` - Account balances and stake
- `get_subnet_info` / `get_subnet_hyperparameters` - Subnet configuration
- `get_total_subnets` / `subnet_exists` - Subnet enumeration

- **Extrinsics (Transactions)**
- Staking: `add_stake`, `remove_stake`, `delegate_stake`, `undelegate_stake`
- Weights: `set_weights`, `commit_weights`, `reveal_weights`
- Transfer: `transfer`, `transfer_keep_alive`, `transfer_all`
- Registration: `serve_axon`, `serve_prometheus`, `burned_register`
- Subnet: `register_network`, `set_subnet_identity`
- Children: `set_children`, `set_childkey_take`, `revoke_children`
- Root: `root_register`, `set_root_weights`

- **Wallet Management**
- Load wallets from Bittensor CLI format (`~/.bittensor/wallets`)
- Create wallets from mnemonic or hex seed
- Sign and verify messages
- Subxt-compatible signer for transactions

- **Error Handling**
- Comprehensive error types with categories
- Retry configuration per error category
- Detailed error messages with context

- **Configuration**
- Network presets: Finney, Testnet, Local
- Custom endpoint configuration
- Connection pool settings
- Read-only mode support

### Dependencies

- `subxt` 0.44.0 for Substrate interactions
- `tokio` for async runtime
- `sp-core` / `sp-runtime` for cryptography

[Unreleased]: https://github.com/one-covenant/bittensor-rs/compare/bittensor-rs-v0.1.0...HEAD
[0.1.0]: https://github.com/one-covenant/bittensor-rs/releases/tag/bittensor-rs-v0.1.0

16 changes: 13 additions & 3 deletions bittensor-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
name = "bittensor-rs"
version = "0.1.0"
edition = "2021"
authors = ["covenant.ai"]
description = "Standalone Rust SDK for Bittensor blockchain interactions"
rust-version = "1.70"
documentation = "https://docs.rs/bittensor-rs"
homepage = "https://github.com/one-covenant/bittensor-rs"
repository = "https://github.com/one-covenant/bittensor-rs"
readme = "README.md"
license = "MIT"
repository = "https://github.com/opentensor/bittensor-rust-sdk"
keywords = ["bittensor", "blockchain", "substrate", "cryptocurrency", "decentralized"]
rust-version = "1.70"
keywords = [
"bittensor",
"blockchain",
"substrate",
"cryptocurrency",
"decentralized",
]
categories = ["cryptography::cryptocurrencies", "api-bindings"]

[features]
Expand Down
21 changes: 21 additions & 0 deletions bittensor-rs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 covenant.ai

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.
Loading
Loading