fromAppBoxReference static method
Implementation
static BoxReference fromAppBoxReference(
AppBoxReference box,
List<int>? foreignApps,
int? currentApp,
) {
if (box.applicationId == NEW_APP_ID) {
return BoxReference(appIndex: 0, name: box.name);
}
if (foreignApps == null || !foreignApps.contains(box.applicationId)) {
// If the app references itself in foreign apps, then prefer foreign app index.
// Otherwise, fallback to comparing against the invoked app (currentApp).
if (box.applicationId == currentApp) {
return BoxReference(appIndex: 0, name: box.name);
} else {
throw AlgorandException(
message:
'Box app ID (${box.applicationId}) is not present in the foreign apps array: $currentApp $foreignApps',
);
}
} else {
return BoxReference(
appIndex:
foreignApps.indexOf(box.applicationId) + FOREIGN_APPS_INDEX_OFFSET,
name: box.name,
);
}
}