getConstant method
Get a specific constant value from a pallet
Returns the decoded constant value or null if not found. The value is cached after first decode for performance.
Implementation
dynamic getConstant(final String palletName, final String constantName) {
if (_decodedCache.containsKey(palletName) &&
_decodedCache[palletName]!.containsKey(constantName)) {
return _decodedCache[palletName]![constantName];
}
// Find the pallet
final pallet = registry.palletByName(palletName);
if (pallet == null) {
throw MetadataException('Pallet $palletName not found');
}
// Find the constant
final constant = pallet.constants.firstWhere(
(c) => c.name == constantName,
orElse: () =>
throw MetadataException('Constant $constantName not found in pallet $palletName'),
);
final decodedValue = _decodeConstant(constant);
_cacheConstant(palletName, constantName, decodedValue);
return decodedValue;
}