Skip to content

Commit 6c9a2f7

Browse files
committed
feat: add Clarity4 keyword current-contract
1 parent f183be7 commit 6c9a2f7

File tree

7 files changed

+220
-73
lines changed

7 files changed

+220
-73
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1515
- Creates epoch 3.3 and costs-4 in preparation for a hardfork to activate Clarity 4
1616
- Adds support for new Clarity 4 builtins (not activated until epoch 3.3):
1717
- `contract-hash?`
18+
- `current-contract`
1819

1920
### Changed
2021

clarity/src/vm/analysis/arithmetic_checker/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ impl ArithmeticOnlyChecker<'_> {
144144
{
145145
match native_var {
146146
ContractCaller | TxSender | TotalLiquidMicroSTX | BlockHeight | BurnBlockHeight
147-
| Regtest | TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight => {
148-
Err(Error::VariableForbidden(native_var))
149-
}
147+
| Regtest | TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight
148+
| CurrentContract => Err(Error::VariableForbidden(native_var)),
150149
NativeNone | NativeTrue | NativeFalse => Ok(()),
151150
}
152151
} else {

clarity/src/vm/analysis/type_checker/v2_05/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ fn type_reserved_variable(variable_name: &str) -> CheckResult<Option<TypeSignatu
318318
NativeFalse => TypeSignature::BoolType,
319319
TotalLiquidMicroSTX => TypeSignature::UIntType,
320320
Regtest => TypeSignature::BoolType,
321-
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight => {
321+
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight | CurrentContract => {
322322
return Err(CheckErrors::Expects(
323-
"tx-sponsor, mainnet, chain-id, stacks-block-height, and tenure-height should not reach here in 2.05".into(),
323+
"tx-sponsor, mainnet, chain-id, stacks-block-height, tenure-height, and current-contract should not reach here in 2.05".into(),
324324
)
325325
.into())
326326
}

clarity/src/vm/analysis/type_checker/v2_1/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ fn type_reserved_variable(
991991
Regtest => TypeSignature::BoolType,
992992
Mainnet => TypeSignature::BoolType,
993993
ChainId => TypeSignature::UIntType,
994+
CurrentContract => TypeSignature::PrincipalType,
994995
};
995996
Ok(Some(var_type))
996997
} else {

clarity/src/vm/docs/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ to the same contract principal.",
125125
example: "(print contract-caller) ;; Will print out a Stacks address of the transaction sender",
126126
};
127127

128+
const CURRENT_CONTRACT_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
129+
name: "current-contract",
130+
snippet: "current-contract",
131+
output_type: "principal",
132+
description: "Returns the principal of the current contract.",
133+
example:
134+
"(print current-contract) ;; Will print out the Stacks address of the current contract",
135+
};
136+
128137
const STACKS_BLOCK_HEIGHT_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
129138
name: "stacks-block-height",
130139
snippet: "stacks-block-height",
@@ -2660,6 +2669,7 @@ pub fn make_keyword_reference(variable: &NativeVariables) -> Option<KeywordAPI>
26602669
NativeVariables::Mainnet => MAINNET_KEYWORD.clone(),
26612670
NativeVariables::ChainId => CHAINID_KEYWORD.clone(),
26622671
NativeVariables::TxSponsor => TX_SPONSOR_KEYWORD.clone(),
2672+
NativeVariables::CurrentContract => CURRENT_CONTRACT_KEYWORD.clone(),
26632673
};
26642674
Some(KeywordAPI {
26652675
name: keyword.name,

0 commit comments

Comments
 (0)