The sn_node
directory provides the safenode
binary and Python bindings for the Safe Network node implementation. This directory contains the core logic for node operations, including API definitions, error handling, event management, and data validation.
Follow the main project's installation guide to set up the safenode
binary.
To install the Python bindings, you'll need:
- Python 3.8 or newer
- Rust toolchain
- maturin (
pip install maturin
)
Install the package using:
maturin develop
To run the safenode
binary, follow the instructions in the main project's usage guide.
The Python module provides a comprehensive interface to run and manage Safe Network nodes. Here's a complete overview:
from safenode import SafeNode
# Create and start a node
node = SafeNode()
node.run(
rewards_address="0x1234567890123456789012345678901234567890", # Your EVM wallet address
evm_network="arbitrum_sepolia", # or "arbitrum_one" for mainnet
ip="0.0.0.0",
port=12000,
initial_peers=[
"/ip4/142.93.37.4/udp/40184/quic-v1/p2p/12D3KooWPC8q7QGZsmuTtCYxZ2s3FPXPZcS8LVKkayXkVFkqDEQB",
],
local=False,
root_dir=None, # Uses default directory
home_network=False
)
Node Information:
peer_id()
: Get the node's peer IDget_rewards_address()
: Get current rewards/wallet addressset_rewards_address(address: str)
: Set new rewards address (requires restart)get_kbuckets()
: Get routing table informationget_all_record_addresses()
: Get all stored record addresses
Storage Operations:
store_record(key: str, value: bytes, record_type: str)
: Store datakey
: Hex stringvalue
: Bytes to storerecord_type
: "chunk" or "scratchpad"
get_record(key: str) -> Optional[bytes]
: Retrieve stored datadelete_record(key: str) -> bool
: Delete stored dataget_stored_records_size() -> int
: Get total size of stored data
Directory Management:
get_root_dir() -> str
: Get current root directory pathget_default_root_dir(peer_id: Optional[str]) -> str
: Get default root directoryget_logs_dir() -> str
: Get logs directory pathget_data_dir() -> str
: Get data storage directory path
# Get various directory paths
root_dir = node.get_root_dir()
logs_dir = node.get_logs_dir()
data_dir = node.get_data_dir()
# Get default directory for a specific peer
default_dir = SafeNode.get_default_root_dir(peer_id)
- Initial peers list should contain currently active network peers
- Rewards address must be a valid EVM address
- Changing rewards address requires node restart
- Storage keys must be valid hex strings
- Record types are limited to 'chunk' and 'scratchpad'
- Directory paths are platform-specific
- Custom root directories can be set at node startup
src/
: Source code filesapi.rs
: API definitionserror.rs
: Error types and handlingevent.rs
: Event-related logicget_validation.rs
: Validation for GET requestsput_validation.rs
: Validation for PUT requestsreplication.rs
: Data replication logicspends.rs
: Logic related to spending tokens or resources
tests/
: Test filescommon/mod.rs
: Common utilities for testsdata_with_churn.rs
: Tests related to data with churnsequential_transfers.rs
: Tests for sequential data transfersstorage_payments.rs
: Tests related to storage paymentsverify_data_location.rs
: Tests for verifying data locations
To run tests, navigate to the sn_node
directory and execute:
cargo test
Please feel free to clone and modify this project. Pull requests are welcome.
We follow the Conventional Commits specification for all commits. Make sure your commit messages adhere to this standard.
This Safe Network repository is licensed under the General Public License (GPL), version 3 (LICENSE http://www.gnu.org/licenses/gpl-3.0.en.html).