هذا هو الكود البرمجي (JavaScript ) الذي يشغل "محرك التنفيذ" في النموذج الأولي. إنه يجسد المنطق الذي يحول العقد المبني من "الذرات" إلى عملية آلية تتفاعل مع بيانات الواقع (Oracles) لتنفيذ البنود تلقائياً.
// Function to run the simulation of the smart contract execution
function runSimulation() {
log.innerHTML = '';
logCounter = 0;
if (contractAtoms.length === 0) {
logMessage("خطأ: لوحة بناء العقد فارغة.", 'var(--color-red)');
return;
}
logMessage("... بدء محاكاة التنفيذ التلقائي ...", 'var(--color-gold)');
let delay = 500;
// Check if the 'quality-check' atom is part of the contract
if (contractAtoms.includes('quality-check')) {
setTimeout(() => {
// The engine actively listens to external data sources (Oracles)
logMessage("[محرك التنفيذ] يراقب أجهزة الاستشعار (Oracle)...", 'var(--color-blue)');
}, delay);
delay += 1500;
setTimeout(() => {
// A real-world event is triggered and captured by an IoT sensor
logMessage("[Oracle: IoT Sensor] إشارة واردة: 'تم استيفاء معايير الجودة'.", 'var(--color-green)');
}, delay);
delay += 1000;
}
// Check if the 'payment' atom is part of the contract
if (contractAtoms.includes('payment')) {
setTimeout(() => {
// The engine evaluates the contract's conditions
if (contractAtoms.includes('quality-check')) {
logMessage("[محرك التنفيذ] شرط الجودة استوفي. تفعيل 'ذرة الدفع'.", 'var(--color-blue)');
} else {
logMessage("[محرك التنفيذ] تفعيل 'ذرة الدفع'...", 'var(--color-blue)');
}
}, delay);
delay += 1500;
setTimeout(() => {
// The engine automatically executes the next step: triggering a payment
logMessage("[النظام] إرسال أمر دفع آلي إلى منصة 'اعتماد'.", 'var(--color-gold)');
}, delay);
delay += 1000;
setTimeout(() => {
logMessage("[النظام] تم تأكيد الدفع بنجاح.", 'var(--color-green)');
}, delay);
}
setTimeout(() => {
logMessage("... انتهت المحاكاة بنجاح ...", 'var(--color-gold)');
}, delay + 500);
}