Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
- Creates epoch 3.3 and costs-4 in preparation for a hardfork to activate Clarity 4
- Adds support for new Clarity 4 builtins (not activated until epoch 3.3):
- `contract-hash?`
- `current-contract`

### Changed

Expand Down
5 changes: 2 additions & 3 deletions clarity/src/vm/analysis/arithmetic_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ impl ArithmeticOnlyChecker<'_> {
{
match native_var {
ContractCaller | TxSender | TotalLiquidMicroSTX | BlockHeight | BurnBlockHeight
| Regtest | TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight => {
Err(Error::VariableForbidden(native_var))
}
| Regtest | TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight
| CurrentContract => Err(Error::VariableForbidden(native_var)),
NativeNone | NativeTrue | NativeFalse => Ok(()),
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/analysis/type_checker/v2_05/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ fn type_reserved_variable(variable_name: &str) -> CheckResult<Option<TypeSignatu
NativeFalse => TypeSignature::BoolType,
TotalLiquidMicroSTX => TypeSignature::UIntType,
Regtest => TypeSignature::BoolType,
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight => {
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight | CurrentContract => {
return Err(CheckErrors::Expects(
"tx-sponsor, mainnet, chain-id, stacks-block-height, and tenure-height should not reach here in 2.05".into(),
"tx-sponsor, mainnet, chain-id, stacks-block-height, tenure-height, and current-contract should not reach here in 2.05".into(),
)
.into())
}
Expand Down
1 change: 1 addition & 0 deletions clarity/src/vm/analysis/type_checker/v2_1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ fn type_reserved_variable(
Regtest => TypeSignature::BoolType,
Mainnet => TypeSignature::BoolType,
ChainId => TypeSignature::UIntType,
CurrentContract => TypeSignature::PrincipalType,
};
Ok(Some(var_type))
} else {
Expand Down
10 changes: 10 additions & 0 deletions clarity/src/vm/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ to the same contract principal.",
example: "(print contract-caller) ;; Will print out a Stacks address of the transaction sender",
};

const CURRENT_CONTRACT_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
name: "current-contract",
snippet: "current-contract",
output_type: "principal",
description: "Returns the principal of the current contract.",
example:
"(print current-contract) ;; Will print out the Stacks address of the current contract",
};

const STACKS_BLOCK_HEIGHT_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
name: "stacks-block-height",
snippet: "stacks-block-height",
Expand Down Expand Up @@ -2660,6 +2669,7 @@ pub fn make_keyword_reference(variable: &NativeVariables) -> Option<KeywordAPI>
NativeVariables::Mainnet => MAINNET_KEYWORD.clone(),
NativeVariables::ChainId => CHAINID_KEYWORD.clone(),
NativeVariables::TxSponsor => TX_SPONSOR_KEYWORD.clone(),
NativeVariables::CurrentContract => CURRENT_CONTRACT_KEYWORD.clone(),
};
Some(KeywordAPI {
name: keyword.name,
Expand Down
Loading