AssetCode.initialize constructor

AssetCode.initialize(
  1. int version,
  2. ToplAddress issuer,
  3. String name,
  4. String networkPrefix,
)

This method creates a new assetCode with correct version networkPrefix (which is the network on which the asset will be stored). The short name of the asset name is only allowed to be up to 8 bytes long with a latin-1 encoding. Returns a new assetCode

Implementation

factory AssetCode.initialize(
    int version, ToplAddress issuer, String name, String networkPrefix) {
  if (!isValidNetwork(networkPrefix)) {
    throw ArgumentError('Invalid network provided');
  }
  assert(version == supportedAssetCodeVersion,
      'AssetCode version required to be 1');
  assert(name.length <= shortNameLimit,
      'Asset short names must be less than 8 Latin-1 encoded characters');
  final latin1Name =
      Latin1Data.validated(name.padRight(shortNameLimit, latin1.decode([0])));
  final validationResult =
      validateAddressByNetwork(networkPrefix, issuer.toBase58());
  if (!(validationResult['success'] as bool)) {
    throw ArgumentError(
        'Invalid Issuer Address:: Network Type: <$networkPrefix> Invalid Address: <${issuer.toBase58()}>');
  }
  return AssetCode(version, issuer, latin1Name, networkPrefix);
}