Package org.stellar.sdk.contract
Class ContractSpec
java.lang.Object
org.stellar.sdk.contract.ContractSpec
Represents a SEP-0048 contract interface specification.
Entries are stored in module order and exposed as an unmodifiable list. The classified views
(getFunctions(), getEvents(), etc.) are derived from getEntries() on
each call. Construct with raw SCSpecEntry values, decode from contract Wasm bytes via
fromWasm(byte[]), or decode from a SEP-0048 XDR stream via fromXdrBytes(byte[]).
SEP-0048 does not require entry names to be unique, so the getFunction/
getEvent/getUdt lookups return the first matching entry in module order.
This wrapper is shallow immutable: the entry list cannot be modified, but the contained SCSpecEntry objects are the underlying mutable XDR types. Do not mutate them after construction;
doing so also affects equals(Object), hashCode(), and the classified views.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic ContractSpecfromWasm(byte[] wasm) Creates aContractSpecfrom contract Wasm bytes.static ContractSpecfromWasmFile(Path path) Creates aContractSpecfrom a contract Wasm file.static ContractSpecfromXdrBytes(byte[] data) Creates aContractSpecfrom a SEP-0048 XDR stream ofSCSpecEntryvalues.getEnums()Returns the first event with the given name, if present.getFunction(String name) Returns the first function with the given name, if present.Returns the first user-defined type entry (struct, union, enum, or error enum) with the given name, if present.inthashCode()toString()byte[]Serializes the entries as a SEP-0048 XDR stream.
-
Constructor Details
-
ContractSpec
public ContractSpec() -
ContractSpec
-
-
Method Details
-
getFunctions
-
getEvents
-
getStructs
-
getUnions
-
getEnums
-
getErrorEnums
-
fromWasm
Creates aContractSpecfrom contract Wasm bytes. Returns an empty spec if thecontractspecv0section is absent.- Parameters:
wasm- contract Wasm bytes- Throws:
InvalidWasmException- if the Wasm module or specification section cannot be decoded, or if multiplecontractspecv0sections are present
-
fromWasmFile
Creates aContractSpecfrom a contract Wasm file.- Parameters:
path- path to the contract Wasm file- Throws:
IOException- if the file cannot be readInvalidWasmException- if the Wasm module or specification section cannot be decoded
-
fromXdrBytes
Creates aContractSpecfrom a SEP-0048 XDR stream ofSCSpecEntryvalues.- Parameters:
data- XDR stream bytes- Throws:
InvalidWasmException- if the XDR stream cannot be decoded
-
toXdrBytes
public byte[] toXdrBytes()Serializes the entries as a SEP-0048 XDR stream. -
getFunction
Returns the first function with the given name, if present. SEP-0048 does not require names to be unique.- Throws:
InvalidWasmException- if a function name is not valid UTF-8
-
getEvent
Returns the first event with the given name, if present. SEP-0048 does not require names to be unique.- Throws:
InvalidWasmException- if an event name is not valid UTF-8
-
getUdt
Returns the first user-defined type entry (struct, union, enum, or error enum) with the given name, if present. SEP-0048 does not require names to be unique.- Throws:
InvalidWasmException- if a type name is not valid UTF-8
-
getEntries
-
equals
-
hashCode
public int hashCode() -
toString
-