Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions Stellar-contract-spec.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace stellar

const SC_SPEC_DOC_LIMIT = 1024;

// The number of bytes in a spec id. An id is the SHA-256 hash of the fully
// qualified name of the item a spec entry describes, or a reference refers
// to, truncated to this length. Ids are unique within the build that
// produced the contract, across the crates that make it up, even when items
// share a name.
const SC_SPEC_ID_LEN = 8;

enum SCSpecType
{
SC_SPEC_TYPE_VAL = 0,
Expand Down Expand Up @@ -45,7 +52,8 @@ enum SCSpecType
SC_SPEC_TYPE_BYTES_N = 1006,

// User defined types.
SC_SPEC_TYPE_UDT = 2000
SC_SPEC_TYPE_UDT = 2000,
SC_SPEC_TYPE_UDT_V2 = 2001
};

struct SCSpecTypeOption
Expand Down Expand Up @@ -85,6 +93,15 @@ struct SCSpecTypeUDT
string name<60>;
};

// A reference to a user-defined type by name and id. The id identifies the
// referenced type exactly, so two references are known to refer to the same
// type, or to different types, even when the types share a name.
struct SCSpecTypeUDTV2
{
string name<60>;
opaque id[SC_SPEC_ID_LEN];
};

union SCSpecTypeDef switch (SCSpecType type)
{
case SC_SPEC_TYPE_VAL:
Expand Down Expand Up @@ -121,6 +138,8 @@ case SC_SPEC_TYPE_BYTES_N:
SCSpecTypeBytesN bytesN;
case SC_SPEC_TYPE_UDT:
SCSpecTypeUDT udt;
case SC_SPEC_TYPE_UDT_V2:
SCSpecTypeUDTV2 udtV2;
};

struct SCSpecUDTStructFieldV0
Expand Down Expand Up @@ -256,7 +275,32 @@ enum SCSpecEntryKind
SC_SPEC_ENTRY_UDT_UNION_V0 = 2,
SC_SPEC_ENTRY_UDT_ENUM_V0 = 3,
SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0 = 4,
SC_SPEC_ENTRY_EVENT_V0 = 5
SC_SPEC_ENTRY_EVENT_V0 = 5,
SC_SPEC_ENTRY_V2 = 6
};

// An entry paired with the id that uniquely identifies it. The id is the
// SHA-256 hash of the fully qualified name of the item the entry describes,
// truncated to SC_SPEC_ID_LEN. A reference carrying an id, such as
// SCSpecTypeUDTV2, refers to the entry whose id matches.
struct SCSpecEntryV2
{
opaque id[SC_SPEC_ID_LEN];
union switch (SCSpecEntryKind kind)
{
case SC_SPEC_ENTRY_FUNCTION_V0:
SCSpecFunctionV0 functionV0;
case SC_SPEC_ENTRY_UDT_STRUCT_V0:
SCSpecUDTStructV0 udtStructV0;
case SC_SPEC_ENTRY_UDT_UNION_V0:
SCSpecUDTUnionV0 udtUnionV0;
case SC_SPEC_ENTRY_UDT_ENUM_V0:
SCSpecUDTEnumV0 udtEnumV0;
case SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0:
SCSpecUDTErrorEnumV0 udtErrorEnumV0;
case SC_SPEC_ENTRY_EVENT_V0:
SCSpecEventV0 eventV0;
} body;
};

union SCSpecEntry switch (SCSpecEntryKind kind)
Expand All @@ -273,6 +317,8 @@ case SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0:
SCSpecUDTErrorEnumV0 udtErrorEnumV0;
case SC_SPEC_ENTRY_EVENT_V0:
SCSpecEventV0 eventV0;
case SC_SPEC_ENTRY_V2:
SCSpecEntryV2 v2;
};

}
Loading