Merge pull request #3536 from stacks-network/feat/abi-add-epoch

feat: add epoch to abi RPC endpoint
This commit is contained in:
Brice Dobry
2023-02-01 21:04:16 -05:00
committed by GitHub
6 changed files with 18 additions and 2 deletions

View File

@@ -59,6 +59,7 @@ fn arithmetic_check(
contract_identifier,
expressions,
LimitedCostTracker::new_free(),
epoch,
version,
);

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use stacks_common::types::StacksEpochId;
use crate::vm::analysis::types::ContractAnalysis;
use crate::vm::types::signatures::CallableSubtype;
use crate::vm::types::{
@@ -25,7 +27,10 @@ use std::collections::{BTreeMap, BTreeSet};
use crate::vm::ClarityVersion;
pub fn build_contract_interface(contract_analysis: &ContractAnalysis) -> ContractInterface {
let mut contract_interface = ContractInterface::new(contract_analysis.clarity_version.clone());
let mut contract_interface = ContractInterface::new(
contract_analysis.epoch.clone(),
contract_analysis.clarity_version.clone(),
);
let ContractAnalysis {
private_function_types,
@@ -36,6 +41,7 @@ pub fn build_contract_interface(contract_analysis: &ContractAnalysis) -> Contrac
map_types,
fungible_tokens,
non_fungible_tokens,
epoch: _,
clarity_version: _,
defined_traits: _,
implemented_traits: _,
@@ -365,17 +371,19 @@ pub struct ContractInterface {
pub maps: Vec<ContractInterfaceMap>,
pub fungible_tokens: Vec<ContractInterfaceFungibleTokens>,
pub non_fungible_tokens: Vec<ContractInterfaceNonFungibleTokens>,
pub epoch: StacksEpochId,
pub clarity_version: ClarityVersion,
}
impl ContractInterface {
pub fn new(clarity_version: ClarityVersion) -> Self {
pub fn new(epoch: StacksEpochId, clarity_version: ClarityVersion) -> Self {
Self {
functions: Vec::new(),
variables: Vec::new(),
maps: Vec::new(),
fungible_tokens: Vec::new(),
non_fungible_tokens: Vec::new(),
epoch,
clarity_version,
}
}

View File

@@ -128,6 +128,7 @@ pub fn run_analysis(
contract_identifier.clone(),
expressions.to_vec(),
cost_tracker,
epoch,
version,
);
let result = analysis_db.execute(|db| {

View File

@@ -171,6 +171,7 @@ fn test_names_tokens_contracts_interface() {
serde_json::from_str(&test_contract_json_str).unwrap();
let test_contract_json_expected: serde_json::Value = serde_json::from_str(r#"{
"epoch": "Epoch2_05",
"clarity_version": "Clarity1",
"functions": [
{ "name": "f00",

View File

@@ -436,6 +436,7 @@ fn test_names_tokens_contracts_interface() {
],
"fungible_tokens": [],
"non_fungible_tokens": [],
"epoch": "Epoch21",
"clarity_version": "Clarity2"
}"#).unwrap();

View File

@@ -54,6 +54,7 @@ pub struct ContractAnalysis {
pub implemented_traits: BTreeSet<TraitIdentifier>,
pub contract_interface: Option<ContractInterface>,
pub is_cost_contract_eligible: bool,
pub epoch: StacksEpochId,
pub clarity_version: ClarityVersion,
#[serde(skip)]
pub expressions: Vec<SymbolicExpression>,
@@ -68,6 +69,7 @@ impl ContractAnalysis {
contract_identifier: QualifiedContractIdentifier,
expressions: Vec<SymbolicExpression>,
cost_track: LimitedCostTracker,
epoch: StacksEpochId,
clarity_version: ClarityVersion,
) -> ContractAnalysis {
ContractAnalysis {
@@ -87,6 +89,7 @@ impl ContractAnalysis {
non_fungible_tokens: BTreeMap::new(),
cost_track: Some(cost_track),
is_cost_contract_eligible: false,
epoch,
clarity_version,
}
}
@@ -281,6 +284,7 @@ mod test {
QualifiedContractIdentifier::local("foo").unwrap(),
vec![],
LimitedCostTracker::new_free(),
StacksEpochId::Epoch20,
ClarityVersion::Clarity1,
);
let trait_id = TraitIdentifier::new(