fix: correct transaction field mapping and standardize genesis path resolution in PoA consensus
All checks were successful
All checks were successful
🔧 Transaction Field Mapping: • Change sender field from "sender" to "from" in transaction parsing • Change recipient field from nested "payload.to" to direct "to" • Change value field from nested "payload.amount" to direct "amount" • Align transaction structure with RPC endpoint format 📁 Genesis File Path Resolution: • Use standardized /var/lib/aitbc/data/{chain_id}/genesis.json path • Remove
This commit is contained in:
@@ -6,7 +6,7 @@ echo "=== AITBC Transaction Manager ==="
|
||||
|
||||
# Configuration
|
||||
GENESIS_WALLET="aitbc1genesis"
|
||||
TARGET_WALLET="aitbc-wallet"
|
||||
TARGET_WALLET="aitbc-user"
|
||||
AMOUNT=1000
|
||||
FEE=10
|
||||
PASSWORD_FILE="/var/lib/aitbc/keystore/.password"
|
||||
@@ -20,16 +20,16 @@ fi
|
||||
|
||||
# Get wallet addresses
|
||||
echo "2. Getting wallet addresses..."
|
||||
GENESIS_ADDR=$(cat /opt/aitbc/apps/blockchain-node/keystore/aitbc1genesis.json | jq -r '.address')
|
||||
TARGET_ADDR=$(ssh aitbc 'cat /var/lib/aitbc/keystore/aitbc-wallet.json | jq -r ".address"')
|
||||
GENESIS_ADDR=$(cat /var/lib/aitbc/keystore/aitbc1genesis.json | jq -r '.address')
|
||||
TARGET_ADDR=$(/opt/aitbc/aitbc-cli balance --name aitbc-user 2>/dev/null | grep "Address:" | awk '{print $2}' || echo "")
|
||||
|
||||
echo "Genesis address: $GENESIS_ADDR"
|
||||
echo "Target address: $TARGET_ADDR"
|
||||
|
||||
# Check balances
|
||||
echo "3. Checking current balances..."
|
||||
GENESIS_BALANCE=$(curl -s "http://localhost:8006/rpc/getBalance/$GENESIS_ADDR" | jq .balance)
|
||||
TARGET_BALANCE=$(curl -s "http://localhost:8006/rpc/getBalance/$TARGET_ADDR" | jq .balance)
|
||||
GENESIS_BALANCE=$(curl -s "http://localhost:8006/rpc/accounts/$GENESIS_ADDR" | jq .balance)
|
||||
TARGET_BALANCE=$(curl -s "http://localhost:8006/rpc/accounts/$TARGET_ADDR" | jq .balance 2>/dev/null || echo "0")
|
||||
|
||||
echo "Genesis balance: $GENESIS_BALANCE AIT"
|
||||
echo "Target balance: $TARGET_BALANCE AIT"
|
||||
@@ -38,14 +38,14 @@ echo "Target balance: $TARGET_BALANCE AIT"
|
||||
echo "4. Creating and sending transaction..."
|
||||
TX_DATA=$(cat << EOF
|
||||
{
|
||||
"type": "transfer",
|
||||
"from": "$GENESIS_ADDR",
|
||||
"sender": "$GENESIS_ADDR",
|
||||
"to": "$TARGET_ADDR",
|
||||
"amount": $AMOUNT,
|
||||
"fee": $FEE,
|
||||
"nonce": $GENESIS_BALANCE,
|
||||
"payload": "0x"
|
||||
"nonce": 0,
|
||||
"payload": "0x",
|
||||
"chain_id": "ait-mainnet",
|
||||
"signature": "0x1234567890"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
@@ -54,7 +54,7 @@ echo "Transaction data: $TX_DATA"
|
||||
|
||||
# Send transaction
|
||||
echo "5. Sending transaction..."
|
||||
TX_RESULT=$(curl -X POST http://localhost:8006/rpc/sendTx \
|
||||
TX_RESULT=$(curl -s -X POST http://localhost:8006/rpc/transaction \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$TX_DATA")
|
||||
|
||||
@@ -71,9 +71,14 @@ if [ -n "$TX_HASH" ] && [ "$TX_HASH" != "null" ]; then
|
||||
echo "6. Waiting for transaction to be mined..."
|
||||
for i in {1..20}; do
|
||||
sleep 2
|
||||
NEW_BALANCE=$(curl -s "http://localhost:8006/rpc/getBalance/$TARGET_ADDR" | jq .balance)
|
||||
NEW_BALANCE=$(curl -s "http://localhost:8006/rpc/accounts/$TARGET_ADDR" | jq .balance 2>/dev/null || echo "0")
|
||||
echo "Check $i/20: Target balance = $NEW_BALANCE AIT"
|
||||
|
||||
# Handle null balance
|
||||
if [ "$NEW_BALANCE" = "null" ] || [ "$NEW_BALANCE" = "" ]; then
|
||||
NEW_BALANCE=0
|
||||
fi
|
||||
|
||||
if [ "$NEW_BALANCE" -gt "$TARGET_BALANCE" ]; then
|
||||
echo "✅ Transaction mined successfully!"
|
||||
echo "New balance: $NEW_BALANCE AIT"
|
||||
@@ -86,26 +91,32 @@ else
|
||||
|
||||
# Try alternative method using CLI
|
||||
echo "7. Trying alternative CLI method..."
|
||||
/opt/aitbc/venv/bin/python /opt/aitbc/cli/simple_wallet.py send \
|
||||
/opt/aitbc/aitbc-cli send \
|
||||
--from $GENESIS_WALLET \
|
||||
--to $TARGET_ADDR \
|
||||
--amount $AMOUNT \
|
||||
--fee $FEE \
|
||||
--password-file $PASSWORD_FILE \
|
||||
--rpc-url http://localhost:8006
|
||||
--password-file $PASSWORD_FILE
|
||||
fi
|
||||
|
||||
# Final verification
|
||||
echo "8. Final balance verification..."
|
||||
FINAL_GENESIS_BALANCE=$(curl -s "http://localhost:8006/rpc/getBalance/$GENESIS_ADDR" | jq .balance)
|
||||
FINAL_TARGET_BALANCE=$(curl -s "http://localhost:8006/rpc/getBalance/$TARGET_ADDR" | jq .balance)
|
||||
FINAL_GENESIS_BALANCE=$(curl -s "http://localhost:8006/rpc/accounts/$GENESIS_ADDR" | jq .balance 2>/dev/null || echo "0")
|
||||
FINAL_TARGET_BALANCE=$(curl -s "http://localhost:8006/rpc/accounts/$TARGET_ADDR" | jq .balance 2>/dev/null || echo "0")
|
||||
|
||||
# Handle null values
|
||||
if [ "$FINAL_GENESIS_BALANCE" = "null" ] || [ "$FINAL_GENESIS_BALANCE" = "" ]; then
|
||||
FINAL_GENESIS_BALANCE=0
|
||||
fi
|
||||
if [ "$FINAL_TARGET_BALANCE" = "null" ] || [ "$FINAL_TARGET_BALANCE" = "" ]; then
|
||||
FINAL_TARGET_BALANCE=0
|
||||
fi
|
||||
|
||||
echo "Final genesis balance: $FINAL_GENESIS_BALANCE AIT"
|
||||
echo "Final target balance: $FINAL_TARGET_BALANCE AIT"
|
||||
|
||||
if [ "$FINAL_TARGET_BALANCE" -gt "$TARGET_BALANCE" ]; then
|
||||
TRANSFERRED=$((FINAL_TARGET_BALANCE - TARGET_BALANCE))
|
||||
echo "✅ Transaction successful! Transferred: $TRANSFERRED AIT"
|
||||
echo "✅ Transaction completed successfully!"
|
||||
else
|
||||
echo "❌ Transaction may have failed or is still pending"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user