getAddressNetwork function
Returns the networkPrefix for a valid address Returns {success: boolean, networkPrefix:
Implementation
Map<String, dynamic> getAddressNetwork(String address) {
final decodedAddress = Base58Encoder.instance.decode(address);
final result = <String, dynamic>{};
result['success'] = false;
if (decodedAddress.isNotEmpty) {
validNetworks.forEach((prefix) {
if ((networksDefault[prefix] ?? const {})['decimal'] ==
decodedAddress.first) {
result['networkPrefixString'] = prefix;
result['networkPrefix'] = (networksDefault[prefix] ?? const {})['hex'];
}
});
if (result['networkPrefix'] == null ||
!isValidNetwork(result['networkPrefixString'] as String)) {
result['error'] = 'invalid network prefix found';
} else {
result['success'] = true;
}
}
return result;
}