Subcall

Git Source

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

NameTypeDescription
methodstringNative message type.
bodybytesCBOR encoded body.

Returns

NameTypeDescription
statusuint64Result of call.
databytesCBOR 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

NameTypeDescription
methodstringNative message type.
bodybytesCBOR encoded body.

Returns

NameTypeDescription
statusuint64Result of call.
databytesCBOR 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

NameTypeDescription
methodstringRuntime SDK method name ('module.Action').
toStakingAddressDestination address.
valueuint128Amount specified.
tokenbytes

Returns

NameTypeDescription
statusuint64Non-zero on error.
databytesModule 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 the error or shares keys.
  • UndelegateStart will have the epoch and receipt keys.
  • UndelegateDone will have the amount key.
function consensusTakeReceipt(SubcallReceiptKind kind, uint64 receiptId) internal returns (bytes memory);

Parameters

NameTypeDescription
kindSubcallReceiptKind1 (Delegate), 2 (UndelegateStart) or 3 (UndelegateDone)
receiptIduint64ID 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

NameTypeDescription
receiptIduint64Previously unretrieved receipt.
resultbytesCBOR 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

NameTypeDescription
fromStakingAddressConsensus address which shares were delegated to.
sharesuint128Number 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

NameTypeDescription
toStakingAddressConsensus address shares are delegated to.
amountuint128Native 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

NameTypeDescription
toStakingAddressConsensus address shares are delegated to.
amountuint128Native token amount (in wei).
receiptIduint64contract-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

NameTypeDescription
toStakingAddressConsensus address which gets the tokens.
valueuint128Token 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

NameTypeDescription
toaddressDestination account.
valueuint128native 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

NameTypeDescription
appIdbytes21ROFL 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;
}