mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-24 16:19:50 +08:00
feat: ensure epoch matches type
When in epoch < 2.1, we should not see `CallableType` and in epoch >= 2.1, we should not see `TraitReferenceType`.
This commit is contained in:
@@ -183,12 +183,23 @@ impl DefinedFunction {
|
||||
(
|
||||
TypeSignature::TraitReferenceType(trait_identifier),
|
||||
Value::Principal(PrincipalData::Contract(callee_contract_id)),
|
||||
)
|
||||
) if *env.epoch() < StacksEpochId::Epoch21 => {
|
||||
// Argument is a trait reference, probably leading to a dynamic contract call
|
||||
// We keep a reference of the mapping (var-name: (callee_contract_id, trait_id)) in the context.
|
||||
// The code fetching and checking the trait is implemented in the contract_call eval function.
|
||||
context.callable_contracts.insert(
|
||||
name.clone(),
|
||||
CallableData {
|
||||
contract_identifier: callee_contract_id.clone(),
|
||||
trait_identifier: Some(trait_identifier.clone()),
|
||||
},
|
||||
);
|
||||
}
|
||||
// Epoch >= 2.1 uses CallableType
|
||||
| (
|
||||
(
|
||||
TypeSignature::CallableType(CallableSubtype::Trait(trait_identifier)),
|
||||
Value::Principal(PrincipalData::Contract(callee_contract_id)),
|
||||
) => {
|
||||
) if *env.epoch() >= StacksEpochId::Epoch21 => {
|
||||
// Argument is a trait reference, probably leading to a dynamic contract call
|
||||
// We keep a reference of the mapping (var-name: (callee_contract_id, trait_id)) in the context.
|
||||
// The code fetching and checking the trait is implemented in the contract_call eval function.
|
||||
|
||||
@@ -641,6 +641,9 @@ impl TypeSignature {
|
||||
}
|
||||
}
|
||||
NoType => Err(CheckErrors::CouldNotDetermineType),
|
||||
TraitReferenceType(_) => {
|
||||
unreachable!("TraitReferenceType should not be used in epoch v2.1")
|
||||
}
|
||||
_ => Ok(&other == self),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user