SPLTokenMetaDataUpdateAuthorityLayout.fromBuffer constructor

SPLTokenMetaDataUpdateAuthorityLayout.fromBuffer(
  1. List<int> bytes
)

Decodes the provided byte array to extract the new authority information.

Implementation

factory SPLTokenMetaDataUpdateAuthorityLayout.fromBuffer(List<int> bytes) {
  // Decode the provided byte array and validate the structure.
  final decode = SPLTokenMetaDataProgramLayout.decodeAndValidateStruct(
      layout: _layout,
      bytes: bytes,
      instructionBytes:
          SPLTokenMetaDataProgramSplDiscriminate.updateAuthority.insturction);
  // Extract the new authority from the decoded data.
  final SolAddress newAuthority = decode["new_authority"];
  // Return a new instance of [SPLTokenMetaDataUpdateAuthorityLayout].
  return SPLTokenMetaDataUpdateAuthorityLayout(
    // If the new authority is zero, set it to null, else set it to the extracted value.
    newAuthority:
        newAuthority == SolAddress.defaultPubKey ? null : newAuthority,
  );
}