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";

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.

_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

_parseCBORUint

function _parseCBORUint(bytes memory result, uint256 offset) public pure returns (uint256 newOffset, uint256 value);

_parseCBORUint64

function _parseCBORUint64(bytes memory result, uint256 offset) public pure returns (uint256 newOffset, uint64 value);

_parseCBORUint128

function _parseCBORUint128(bytes memory result, uint256 offset)
    public
    pure
    returns (uint256 newOffset, uint128 value);

_parseCBORKey

function _parseCBORKey(bytes memory result, uint256 offset)
    internal
    pure
    returns (uint256 newOffset, bytes32 keyDigest);

_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).

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);

TokenNameTooLong

Name of token cannot be CBOR encoded with current functions

error TokenNameTooLong();

InvalidKey

While parsing CBOR map, unexpected key

error InvalidKey();

InvalidMap

While parsing CBOR map, length is invalid, or other parse error

error InvalidMap();

InvalidLength

While parsing CBOR structure, data length was unexpected

error InvalidLength();

InvalidReceiptId

Invalid receipt ID

error InvalidReceiptId();

ValueOutOfRange

CBOR parsed valid is out of expected range

error ValueOutOfRange();

MissingKey

CBOR parser expected a key, but it was not found in the map!

error MissingKey();