Skip to content

Commit

Permalink
Add support for contract instance storage. (#115)
Browse files Browse the repository at this point in the history
- Store contract instance that includes executable and storage map under a special key
- Make contract executable separate from ScVal
  • Loading branch information
dmkozh authored Jun 21, 2023
1 parent 0769d7a commit 7b40310
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
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,
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

0 comments on commit 7b40310

Please sign in to comment.