Skip to content

Commit

Permalink
XDR side of the contract deployment changes specified in CAP-46-02. (#51
Browse files Browse the repository at this point in the history
)

* XDR side of the contract deployment changes specified in CAP-46-02.

This introduces the ledger entries to store the wasm code and also changes the host functions to support creating/installing the contracts.

* Remove option to create and install contract in the same operation.

This relies on the ability to include multiple Soroban operations in the transaction. We can bring this back if we decide against that.
  • Loading branch information
dmkozh authored Nov 10, 2022
1 parent 48d5e17 commit 1a76201
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ case NEGATIVE:

enum SCContractCodeType
{
SCCONTRACT_CODE_WASM = 0,
SCCONTRACT_CODE_WASM_REF = 0,
SCCONTRACT_CODE_TOKEN = 1
};

union SCContractCode switch (SCContractCodeType type)
{
case SCCONTRACT_CODE_WASM:
opaque wasm<SCVAL_LIMIT>;
case SCCONTRACT_CODE_WASM_REF:
Hash wasm_id;
case SCCONTRACT_CODE_TOKEN:
void;
};
Expand Down
20 changes: 18 additions & 2 deletions Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ enum LedgerEntryType
CLAIMABLE_BALANCE = 4,
LIQUIDITY_POOL = 5,
CONTRACT_DATA = 6,
CONFIG_SETTING = 7
CONTRACT_CODE = 7,
CONFIG_SETTING = 8
};

struct Signer
Expand Down Expand Up @@ -499,6 +500,13 @@ struct ContractDataEntry {
SCVal val;
};

struct ContractCodeEntry {
ExtensionPoint ext;

Hash hash;
opaque code<SCVAL_LIMIT>;
};

enum ConfigSettingType
{
CONFIG_SETTING_TYPE_UINT32 = 0
Expand Down Expand Up @@ -560,6 +568,8 @@ struct LedgerEntry
LiquidityPoolEntry liquidityPool;
case CONTRACT_DATA:
ContractDataEntry contractData;
case CONTRACT_CODE:
ContractCodeEntry contractCode;
case CONFIG_SETTING:
ConfigSettingEntry configSetting;
}
Expand Down Expand Up @@ -622,6 +632,11 @@ case CONTRACT_DATA:
Hash contractID;
SCVal key;
} contractData;
case CONTRACT_CODE:
struct
{
Hash hash;
} contractCode;
case CONFIG_SETTING:
struct
{
Expand All @@ -645,6 +660,7 @@ enum EnvelopeType
ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8,
ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9,
ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10,
ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11
ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11,
ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12
};
}
79 changes: 68 additions & 11 deletions Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -474,23 +474,66 @@ struct LiquidityPoolWithdrawOp
int64 minAmountB; // minimum amount of second asset to withdraw
};

enum HostFunction
enum HostFunctionType
{
HOST_FN_INVOKE_CONTRACT = 0,
HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1,
HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2,
HOST_FN_CREATE_TOKEN_CONTRACT_WITH_SOURCE_ACCOUNT = 3,
HOST_FN_CREATE_TOKEN_CONTRACT_WITH_ASSET = 4
HOST_FUNCTION_TYPE_INVOKE_CONTRACT = 0,
HOST_FUNCTION_TYPE_CREATE_CONTRACT = 1,
HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE = 2
};

enum ContractIDType
{
CONTRACT_ID_FROM_SOURCE_ACCOUNT = 0,
CONTRACT_ID_FROM_ED25519_PUBLIC_KEY = 1,
CONTRACT_ID_FROM_ASSET = 2
};

enum ContractIDPublicKeyType
{
CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT = 0,
CONTRACT_ID_PUBLIC_KEY_ED25519 = 1
};

struct InstallContractCodeArgs
{
opaque code<SCVAL_LIMIT>;
};

union ContractID switch (ContractIDType type)
{
case CONTRACT_ID_FROM_SOURCE_ACCOUNT:
uint256 salt;
case CONTRACT_ID_FROM_ED25519_PUBLIC_KEY:
struct
{
uint256 key;
Signature signature;
uint256 salt;
} fromEd25519PublicKey;
case CONTRACT_ID_FROM_ASSET:
Asset asset;
};

struct CreateContractArgs
{
ContractID contractID;
SCContractCode source;
};

union HostFunction switch (HostFunctionType type)
{
case HOST_FUNCTION_TYPE_INVOKE_CONTRACT:
SCVec invokeArgs;
case HOST_FUNCTION_TYPE_CREATE_CONTRACT:
CreateContractArgs createContractArgs;
case HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE:
InstallContractCodeArgs installContractCodeArgs;
};

struct InvokeHostFunctionOp
{
// The host function to invoke
HostFunction function;

// Parameters to the host function
SCVec parameters;

// The footprint for this invocation
LedgerFootprint footprint;
};
Expand Down Expand Up @@ -580,23 +623,37 @@ case ENVELOPE_TYPE_POOL_REVOKE_OP_ID:
case ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519:
struct
{
Hash networkID;
uint256 ed25519;
uint256 salt;
} ed25519ContractID;
case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT:
struct
{
Hash networkID;
Hash contractID;
uint256 salt;
} contractID;
case ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET:
Asset fromAsset;
struct
{
Hash networkID;
Asset asset;
} fromAsset;
case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT:
struct
{
Hash networkID;
AccountID sourceAccount;
uint256 salt;
} sourceAccountContractID;
case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS:
struct
{
Hash networkID;
SCContractCode source;
uint256 salt;
} createContractArgs;
};

enum MemoType
Expand Down

0 comments on commit 1a76201

Please sign in to comment.