Subcall
Interact with Oasis Runtime SDK modules from Sapphire.
State Variables
CONSENSUS_DELEGATE
string private constant CONSENSUS_DELEGATE = "consensus.Delegate";
CONSENSUS_UNDELEGATE
string private constant CONSENSUS_UNDELEGATE = "consensus.Undelegate";
CONSENSUS_WITHDRAW
string private constant CONSENSUS_WITHDRAW = "consensus.Withdraw";
CONSENSUS_TAKE_RECEIPT
string private constant CONSENSUS_TAKE_RECEIPT = "consensus.TakeReceipt";
ACCOUNTS_TRANSFER
string private constant ACCOUNTS_TRANSFER = "accounts.Transfer";
CORE_CALLDATAPUBLICKEY
string private constant CORE_CALLDATAPUBLICKEY = "core.CallDataPublicKey";
CORE_CURRENT_EPOCH
string private constant CORE_CURRENT_EPOCH = "core.CurrentEpoch";
ROFL_IS_AUTHORIZED_ORIGIN
string private constant ROFL_IS_AUTHORIZED_ORIGIN = "rofl.IsAuthorizedOrigin";
SUBCALL
Address of the SUBCALL precompile
address internal constant SUBCALL = 0x0100000000000000000000000000000000000103;
Functions
subcall
Submit a native message to the Oasis runtime layer. Messages
which re-enter the EVM module are forbidden: evm.*
.
function subcall(string memory method, bytes memory body) internal returns (uint64 status, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
method | string | Native message type. |
body | bytes | CBOR encoded body. |
Returns
Name | Type | Description |
---|---|---|
status | uint64 | Result of call. |
data | bytes | CBOR encoded result. |
subcall_static
Submit a read-only native message to the Oasis runtime layer using STATICCALL.
Messages which re-enter the EVM module are forbidden: evm.*
.
function subcall_static(string memory method, bytes memory body)
internal
view
returns (uint64 status, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
method | string | Native message type. |
body | bytes | CBOR encoded body. |
Returns
Name | Type | Description |
---|---|---|
status | uint64 | Result of call. |
data | bytes | CBOR encoded result. |
_subcallWithToAndAmount
Generic method to call {to:address, amount:uint128}
.
function _subcallWithToAndAmount(string memory method, StakingAddress to, uint128 value, bytes memory token)
internal
returns (uint64 status, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
method | string | Runtime SDK method name ('module.Action'). |
to | StakingAddress | Destination address. |
value | uint128 | Amount specified. |
token | bytes |
Returns
Name | Type | Description |
---|---|---|
status | uint64 | Non-zero on error. |
data | bytes | Module name on error. |
consensusTakeReceipt
Returns a CBOR encoded structure, containing the following possible keys. All keys are optional:
- shares:
u128
- epoch:
EpochTime
- receipt:
u64
- amount:
u128
- error:
{module: string, code: u32}
Keys returned by specific subcalls
Delegate
will have theerror
orshares
keys.UndelegateStart
will have theepoch
andreceipt
keys.UndelegateDone
will have theamount
key.
function consensusTakeReceipt(SubcallReceiptKind kind, uint64 receiptId) internal returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
kind | SubcallReceiptKind | 1 (Delegate ), 2 (UndelegateStart ) or 3 (UndelegateDone ) |
receiptId | uint64 | ID of receipt |
_decodeReceiptUndelegateStart
function _decodeReceiptUndelegateStart(bytes memory result) internal pure returns (uint64 epoch, uint64 endReceipt);
_decodeReceiptUndelegateDone
function _decodeReceiptUndelegateDone(bytes memory result) internal pure returns (uint128 amount);
_decodeReceiptDelegate
Decodes a 'Delegate' receipt.
function _decodeReceiptDelegate(uint64 receiptId, bytes memory result) internal pure returns (uint128 shares);
Parameters
Name | Type | Description |
---|---|---|
receiptId | uint64 | Previously unretrieved receipt. |
result | bytes | CBOR encoded {shares: u128}. |
consensusTakeReceiptDelegate
function consensusTakeReceiptDelegate(uint64 receiptId) internal returns (uint128 shares);
consensusTakeReceiptUndelegateStart
function consensusTakeReceiptUndelegateStart(uint64 receiptId) internal returns (uint64 epoch, uint64 endReceipt);
consensusTakeReceiptUndelegateDone
function consensusTakeReceiptUndelegateDone(uint64 receiptId) internal returns (uint128 amount);
consensusUndelegate
Start the undelegation process of the given number of shares from consensus staking account to runtime account.
function consensusUndelegate(StakingAddress from, uint128 shares) internal;
Parameters
Name | Type | Description |
---|---|---|
from | StakingAddress | Consensus address which shares were delegated to. |
shares | uint128 | Number of shares to withdraw back to us. |
consensusUndelegate
function consensusUndelegate(StakingAddress from, uint128 shares, uint64 receiptId) internal;
consensusDelegate
Delegate native token to consensus level.
function consensusDelegate(StakingAddress to, uint128 amount) internal returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
to | StakingAddress | Consensus address shares are delegated to. |
amount | uint128 | Native token amount (in wei). |
consensusDelegate
Delegate native token to consensus level. Requests that the
number of shares allocated can be retrieved with a receipt. The receipt
will be of ReceiptKind.DelegateDone
and can be decoded using
decodeReceiptDelegateDone
.
function consensusDelegate(StakingAddress to, uint128 amount, uint64 receiptId) internal returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
to | StakingAddress | Consensus address shares are delegated to. |
amount | uint128 | Native token amount (in wei). |
receiptId | uint64 | contract-specific receipt to retrieve result. |
consensusWithdraw
Transfer from an account in this runtime to a consensus staking account.
function consensusWithdraw(StakingAddress to, uint128 value) internal;
Parameters
Name | Type | Description |
---|---|---|
to | StakingAddress | Consensus address which gets the tokens. |
value | uint128 | Token amount (in wei). |
accountsTransfer
Perform a transfer to another account. This is equivalent of
payable(to).transfer(value);
.
function accountsTransfer(address to, uint128 value) internal;
Parameters
Name | Type | Description |
---|---|---|
to | address | Destination account. |
value | uint128 | native token amount (in wei). |
roflEnsureAuthorizedOrigin
Verify whether the origin transaction is signed by an authorized ROFL instance for the given application.
function roflEnsureAuthorizedOrigin(bytes21 appId) internal view;
Parameters
Name | Type | Description |
---|---|---|
appId | bytes21 | ROFL app identifier |
_parseCBORPublicKeyInner
function _parseCBORPublicKeyInner(bytes memory in_data, uint256 in_offset)
internal
pure
returns (uint256 offset, CallDataPublicKey memory public_key);
_parseCBORCallDataPublicKey
function _parseCBORCallDataPublicKey(bytes memory in_data)
internal
pure
returns (uint256 epoch, CallDataPublicKey memory public_key);
coreCallDataPublicKey
function coreCallDataPublicKey() internal view returns (uint256 epoch, CallDataPublicKey memory public_key);
coreCurrentEpoch
function coreCurrentEpoch() internal view returns (uint256);
Errors
SubcallError
Raised if the underlying subcall precompile does not succeed
error SubcallError();
ParseReceiptError
There was an error parsing the receipt
error ParseReceiptError(uint64 receiptId);
ConsensusUndelegateError
error ConsensusUndelegateError(uint64 status, string data);
ConsensusDelegateError
error ConsensusDelegateError(uint64 status, string data);
ConsensusTakeReceiptError
error ConsensusTakeReceiptError(uint64 status, string data);
ConsensusWithdrawError
error ConsensusWithdrawError(uint64 status, string data);
AccountsTransferError
error AccountsTransferError(uint64 status, string data);
WrongMapSizeError
Expected map of different size!
error WrongMapSizeError();
TakeReceiptKindOutOfRange
Unknown type of receipt!
error TakeReceiptKindOutOfRange(uint256 receiptKind);
RoflOriginNotAuthorizedForApp
The origin is not authorized for the given ROFL app
error RoflOriginNotAuthorizedForApp();
TokenNameTooLong
Name of token cannot be CBOR encoded with current functions
error TokenNameTooLong();
InvalidReceiptId
Invalid receipt ID
error InvalidReceiptId();
MissingKey
CBOR parser expected a key, but it was not found in the map!
error MissingKey();
IncompleteParse
We expected to have parsed everything, but there are excess bytes!
error IncompleteParse();
CoreCurrentEpochError
Error while trying to retrieve current epoch
error CoreCurrentEpochError(uint64);
CoreCallDataPublicKeyError
Error while trying to retrieve the calldata public key
error CoreCallDataPublicKeyError(uint64);
Structs
CallDataPublicKey
struct CallDataPublicKey {
bytes32 key;
bytes32 checksum;
bytes32[2] signature;
uint256 expiration;
}