Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for contract instance storage. #115

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
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
49 changes: 27 additions & 22 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@ enum SCValType
SCV_VEC = 16,
SCV_MAP = 17,

// SCContractExecutable and SCAddressType are types that gets used separately from
// SCVal so we do not flatten their structures into separate SCVal cases.
SCV_CONTRACT_EXECUTABLE = 18,
SCV_ADDRESS = 19,

// SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique
// symbolic SCVals used as the key for ledger entries for a contract's code
// and an address' nonce, respectively.
SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20,
SCV_LEDGER_KEY_NONCE = 21,

SCV_STORAGE_TYPE = 22
// The following are the internal SCVal variants that are not
// exposed to the contracts.
SCV_ADDRESS = 18,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Address exposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, just messed this up during reordering...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCV_CONTRACT_INSTANCE = 19,
SCV_STORAGE_TYPE = 20,

// SCV_LEDGER_KEY_CONTRACT_INSTANCE and SCV_LEDGER_KEY_NONCE are unique
// symbolic SCVals used as the key for ledger entries for a contract's
// instance and an address' nonce, respectively.
SCV_LEDGER_KEY_CONTRACT_INSTANCE = 21,
SCV_LEDGER_KEY_NONCE = 22
};

enum SCErrorType
Expand Down Expand Up @@ -139,17 +138,17 @@ struct Int256Parts {
uint64 lo_lo;
};

enum SCContractExecutableType
enum ContractExecutableType
{
SCCONTRACT_EXECUTABLE_WASM_REF = 0,
SCCONTRACT_EXECUTABLE_TOKEN = 1
CONTRACT_EXECUTABLE_WASM = 0,
CONTRACT_EXECUTABLE_TOKEN = 1
};

union SCContractExecutable switch (SCContractExecutableType type)
union ContractExecutable switch (ContractExecutableType type)
{
case SCCONTRACT_EXECUTABLE_WASM_REF:
Hash wasm_id;
case SCCONTRACT_EXECUTABLE_TOKEN:
case CONTRACT_EXECUTABLE_WASM:
Hash wasm_hash;
case CONTRACT_EXECUTABLE_TOKEN:
void;
};

Expand Down Expand Up @@ -189,6 +188,11 @@ struct SCNonceKey {
int64 nonce;
};

struct SCContractInstance {
ContractExecutable executable;
SCMap* storage;
};

union SCVal switch (SCValType type)
{

Expand Down Expand Up @@ -237,20 +241,21 @@ case SCV_VEC:
case SCV_MAP:
SCMap *map;

case SCV_CONTRACT_EXECUTABLE:
SCContractExecutable exec;
case SCV_ADDRESS:
SCAddress address;

// Special SCVals reserved for system-constructed contract-data
// ledger keys, not generally usable elsewhere.
case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE:
case SCV_LEDGER_KEY_CONTRACT_INSTANCE:
void;
case SCV_LEDGER_KEY_NONCE:
SCNonceKey nonce_key;

case SCV_STORAGE_TYPE:
ContractDataType storageType;

case SCV_CONTRACT_INSTANCE:
SCContractInstance instance;
};

struct SCMapEntry
Expand Down
2 changes: 1 addition & 1 deletion Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ case CONTRACT_ID_PREIMAGE_FROM_ASSET:
struct CreateContractArgs
{
ContractIDPreimage contractIDPreimage;
SCContractExecutable executable;
ContractExecutable executable;
};

union HostFunction switch (HostFunctionType type)
Expand Down