Fix CLI transaction nonce to use blockchain account state instead of timestamp
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Waiting to run
Documentation Validation / validate-docs (push) Waiting to run
Staking Tests / test-staking-service (push) Waiting to run
Staking Tests / test-staking-integration (push) Blocked by required conditions
Staking Tests / test-staking-contract (push) Blocked by required conditions
Staking Tests / run-staking-test-runner (push) Blocked by required conditions
CLI Tests / test-cli (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

- Replace hardcoded nonce=0 in send_transaction with actual account nonce from blockchain
- Replace timestamp-based nonce in agent_operations with actual account nonce from blockchain
- Add RPC account endpoint query to fetch current nonce before transaction creation
- Add error handling with fallback to nonce=0 if RPC query fails
- Ensures transactions use correct sequential nonce values for proper ordering
This commit is contained in:
aitbc
2026-04-13 22:12:39 +02:00
parent 7c51f3490b
commit 9bfa27f518

View File

@@ -192,6 +192,17 @@ def send_transaction(from_wallet: str, to_address: str, amount: float, fee: floa
except Exception:
pass
# Get actual nonce from blockchain
try:
nonce_response = requests.get(f"{rpc_url}/rpc/account/{sender_address}", timeout=5)
if nonce_response.status_code == 200:
account_data = nonce_response.json()
actual_nonce = account_data.get("nonce", 0)
else:
actual_nonce = 0
except Exception:
actual_nonce = 0
# Create transaction
transaction = {
"chain_id": chain_id,
@@ -199,7 +210,7 @@ def send_transaction(from_wallet: str, to_address: str, amount: float, fee: floa
"to": to_address,
"amount": int(amount),
"fee": int(fee),
"nonce": 0,
"nonce": actual_nonce,
"payload": {}
}
@@ -1040,13 +1051,24 @@ def agent_operations(action: str, **kwargs) -> Optional[Dict]:
except Exception:
pass
# Get actual nonce from blockchain
try:
nonce_response = requests.get(f"{rpc_url}/rpc/account/{sender_address}", timeout=5)
if nonce_response.status_code == 200:
account_data = nonce_response.json()
actual_nonce = account_data.get("nonce", 0)
else:
actual_nonce = 0
except Exception:
actual_nonce = 0
tx = {
"type": "transfer",
"from": sender_address,
"to": agent,
"amount": 0,
"fee": 10,
"nonce": int(time.time() * 1000),
"nonce": actual_nonce,
"payload": message,
"chain_id": chain_id
}