Class ContractMeta

java.lang.Object
org.stellar.sdk.contract.ContractMeta

public final class ContractMeta extends Object
Represents SEP-0046 contract metadata and SEP-0047 contract interface discovery data.

Entries are stored in module order and exposed as an unmodifiable list. Construct with raw SCMetaEntry values, decode from contract Wasm bytes via fromWasm(byte[]), or decode from a SEP-0046 XDR stream via fromXdrBytes(byte[]).

This wrapper is shallow immutable: the entry list cannot be modified, but the contained SCMetaEntry objects are the underlying mutable XDR types. Do not mutate them after construction; doing so also affects equals(Object), hashCode(), and the decoded views.

See Also:
  • Constructor Details

    • ContractMeta

      public ContractMeta()
    • ContractMeta

      public ContractMeta(List<SCMetaEntry> entries)
  • Method Details

    • fromWasm

      public static ContractMeta fromWasm(byte[] wasm)
      Creates a ContractMeta from contract Wasm bytes by decoding each contractmetav0 custom section as a self-contained XDR stream and appending the resulting entries in module order. Per SEP-0046, an entry never spans two sections.
      Parameters:
      wasm - contract Wasm bytes
      Throws:
      InvalidWasmException - if the Wasm module or metadata section cannot be decoded
    • fromWasmFile

      public static ContractMeta fromWasmFile(Path path) throws IOException
      Creates a ContractMeta from a contract Wasm file.
      Parameters:
      path - path to the contract Wasm file
      Throws:
      IOException - if the file cannot be read
      InvalidWasmException - if the Wasm module or metadata section cannot be decoded
    • fromXdrBytes

      public static ContractMeta fromXdrBytes(byte[] data)
      Creates a ContractMeta from a SEP-0046 XDR stream of SCMetaEntry values.
      Parameters:
      data - XDR stream bytes
      Throws:
      InvalidWasmException - if the XDR stream cannot be decoded
    • toXdrBytes

      public byte[] toXdrBytes()
      Serializes the entries as a SEP-0046 XDR stream.
    • items

      public List<Map.Entry<String,String>> items()
      Returns SC_META_V0 key/value pairs decoded as UTF-8, in entry order.
      Throws:
      InvalidWasmException - if a key or value is not valid UTF-8
    • get

      public Optional<String> get(String key)
      Returns the first SC_META_V0 value for key.
      Throws:
      InvalidWasmException - if a key or value is not valid UTF-8
    • getAll

      public List<String> getAll(String key)
      Returns all SC_META_V0 values for key in entry order.
      Throws:
      InvalidWasmException - if a key or value is not valid UTF-8
    • supportedSeps

      public Set<Integer> supportedSeps()
      Returns SEP-0047 SEP identifiers declared via sep metadata entries. Invalid identifiers are skipped.

      SEP-0047 treats the declared identifiers as an unordered set: the value "may be in any order" and the same identifier may be repeated across entries. The returned set is de-duplicated; its iteration order is the first-seen order purely for deterministic output and carries no meaning.

    • supportedSeps

      public Set<Integer> supportedSeps(boolean strict)
      Returns SEP-0047 SEP identifiers declared via sep metadata entries.
      Parameters:
      strict - when true, invalid identifiers cause an IllegalArgumentException rather than being skipped
      Throws:
      IllegalArgumentException - if strict is true and an identifier is invalid
      InvalidWasmException - if a key or value is not valid UTF-8
    • implementsSep

      public boolean implementsSep(int sep)
      Returns whether the contract declares support for sep via SEP-0047.
    • getEntries

      public List<SCMetaEntry> getEntries()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object