Fix minor issues and add wallet funding documentation
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Documentation Validation / validate-docs (push) Has been cancelled
Documentation Validation / validate-policies-strict (push) Has been cancelled

Changes:
- Fix certificate viewing display issue in master_training_launcher.sh
  - Use array to store certificate files for reliable iteration
  - Add error handling for read command
  - Ensure CERT_DIR exists before checking for certificates
  - Fix certificate selection using array index instead of head/tail

- Add wallet funding script (scripts/training/fund_wallet.sh)
  - Fund wallets from genesis using genesis password
  - Reads password from /var/lib/aitbc/keystore/.genesis_password
  - Verifies genesis balance before funding
  - Shows transaction hash and wallet balance after funding

- Add wallet funding documentation (docs/agent-training/WALLET_FUNDING.md)
  - Genesis wallet details and password location
  - Quick funding script usage
  - Manual funding with AITBC CLI
  - Faucet service information
  - Common training wallets
  - Troubleshooting guide
  - Security notes
This commit is contained in:
aitbc
2026-05-07 14:13:57 +02:00
parent 4afa754499
commit 60a5abd2fd
3 changed files with 273 additions and 5 deletions

104
scripts/training/fund_wallet.sh Executable file
View File

@@ -0,0 +1,104 @@
#!/bin/bash
# AITBC Wallet Funding Script
# Funds a wallet from the genesis wallet using the genesis password
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AITBC_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
CLI_PATH="$AITBC_DIR/aitbc-cli"
GENESIS_PASSWORD_FILE="/var/lib/aitbc/keystore/.genesis_password"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
usage() {
echo "Usage: $0 <wallet_name> [amount]"
echo ""
echo "Arguments:"
echo " wallet_name Name of the wallet to fund"
echo " amount Amount of AIT to send (default: 1000)"
echo ""
echo "Example:"
echo " $0 hermes-trainee 1000"
echo ""
echo "Note: The genesis password is read from $GENESIS_PASSWORD_FILE"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
WALLET_NAME="$1"
AMOUNT="${2:-1000}"
print_status "Funding wallet: $WALLET_NAME"
print_status "Amount: $AMOUNT AIT"
# Check if genesis password file exists
if [ ! -f "$GENESIS_PASSWORD_FILE" ]; then
print_error "Genesis password file not found: $GENESIS_PASSWORD_FILE"
print_error "Please ensure the genesis wallet is properly configured"
exit 1
fi
# Read genesis password
GENESIS_PASSWORD=$(cat "$GENESIS_PASSWORD_FILE")
if [ -z "$GENESIS_PASSWORD" ]; then
print_error "Genesis password file is empty"
exit 1
fi
print_status "Genesis password loaded"
# Check if CLI exists
if [ ! -f "$CLI_PATH" ]; then
print_error "AITBC CLI not found: $CLI_PATH"
exit 1
fi
# Check genesis wallet balance
print_status "Checking genesis wallet balance..."
GENESIS_BALANCE=$("$CLI_PATH" wallet balance genesis 2>&1 || echo "0")
print_status "Genesis wallet balance: $GENESIS_BALANCE"
# Fund the wallet
print_status "Sending $AMOUNT AIT from genesis to $WALLET_NAME..."
cd "$AITBC_DIR"
RESULT=$("$CLI_PATH" wallet send genesis "$WALLET_NAME" "$AMOUNT" "$GENESIS_PASSWORD" 2>&1)
if [ $? -eq 0 ]; then
print_success "Transaction sent successfully"
echo "Transaction hash: $RESULT"
# Verify balance
print_status "Verifying wallet balance..."
WALLET_BALANCE=$("$CLI_PATH" wallet balance "$WALLET_NAME" 2>&1 || echo "0")
print_success "Wallet $WALLET_NAME balance: $WALLET_BALANCE"
else
print_error "Funding failed: $RESULT"
exit 1
fi
print_success "Wallet funding completed"

View File

@@ -357,7 +357,18 @@ display_badge() {
view_certificates() {
print_header "Stage Completion Certificates"
if [ ! -d "$CERT_DIR" ] || [ -z "$(ls -A $CERT_DIR)" ]; then
# Ensure directory exists
mkdir -p "$CERT_DIR"
# Check for certificates
local cert_files=()
for cert_file in "$CERT_DIR"/stage*_certificate.json; do
if [ -f "$cert_file" ]; then
cert_files+=("$cert_file")
fi
done
if [ ${#cert_files[@]} -eq 0 ]; then
print_warning "No certificates found yet"
echo "Complete stages to earn certificates"
return 0
@@ -367,7 +378,7 @@ view_certificates() {
echo
local cert_count=0
for cert_file in "$CERT_DIR"/stage*_certificate.json; do
for cert_file in "${cert_files[@]}"; do
if [ -f "$cert_file" ]; then
((cert_count++))
local stage_num=$(echo "$cert_file" | grep -o 'stage[0-9]' | grep -o '[0-9]')
@@ -385,10 +396,10 @@ view_certificates() {
echo
echo -n "View certificate details? [1-$cert_count/N]: "
read -r view_choice
read -r view_choice || view_choice="N"
if [[ "$view_choice" =~ ^[0-9]+$ ]] && [ "$view_choice" -le "$cert_count" ]; then
local cert_file=$(ls "$CERT_DIR"/stage*_certificate.json | head -"$view_choice" | tail -1)
if [[ "$view_choice" =~ ^[0-9]+$ ]] && [ "$view_choice" -ge 1 ] && [ "$view_choice" -le "$cert_count" ]; then
local cert_file="${cert_files[$((view_choice-1))]}"
if [ -f "$cert_file" ]; then
echo
echo -e "${BOLD}Certificate Details:${NC}"