getXChainClaimId static method
Retrieves the XChainClaimID from the metadata of an XChainCreateClaimID transaction.
This function expects the metadata from an XChainCreateClaimID transaction and searches for the newly created XChainOwnedClaimID. If found, it extracts and returns the associated XChainClaimID.
Parameters:
- meta: The metadata from an XChainCreateClaimID transaction.
Returns: The XChainClaimID from the newly created XChainOwnedClaimID entry.
Throws:
- StateError: If the provided metadata is null or lacks the necessary information.
- StateError: If no XChainOwnedClaimID is found in the affected nodes.
- StateError: If multiple XChainOwnedClaimIDs are somehow created.
Implementation
static String getXChainClaimId(Map<String, dynamic>? meta) {
if (meta == null || meta['AffectedNodes'] == null) {
throw StateError(
"Unable to parse the parameter given to get_xchain_claim_id. 'meta' must be the metadata from an XChainCreateClaimID transaction. Received $meta instead.");
}
List affectedNodes = meta['AffectedNodes'];
List createdNodes = affectedNodes.where((node) {
return isCreatedNode(node) &&
node['CreatedNode']['LedgerEntryType'] == 'XChainOwnedClaimID';
}).toList();
if (createdNodes.isEmpty) {
throw StateError('No XChainOwnedClaimID created.');
}
if (createdNodes.length > 1) {
throw StateError(
'Multiple XChainOwnedClaimIDs were somehow created. Please report this error.');
}
return createdNodes[0]['CreatedNode']['NewFields']['XChainClaimID'];
}