1use crate::error::{Error, Result};
2use dap::types::Breakpoint;
3use fuel_types::ContractId;
4use std::{
5 collections::HashMap,
6 ops::{Deref, DerefMut},
7 path::PathBuf,
8};
9use sway_core::asm_generation::ProgramABI;
10
11pub type ExitCode = i64;
12pub type Instruction = u64;
13pub type Breakpoints = HashMap<PathBuf, Vec<Breakpoint>>;
14
15#[derive(Debug, Default)]
17pub struct AbiMap(HashMap<ContractId, ProgramABI>);
18
19impl AbiMap {
20 pub fn register_abi(&mut self, contract_id: ContractId, abi: ProgramABI) {
22 self.insert(contract_id, abi);
23 }
24
25 pub fn get_or_fetch_abi(&mut self, contract_id: &ContractId) -> Option<&ProgramABI> {
27 if self.contains_key(contract_id) {
29 return self.get(contract_id);
30 }
31
32 match fetch_abi_from_registry(contract_id) {
34 Ok(abi) => {
35 self.register_abi(*contract_id, abi);
36 self.get(contract_id)
37 }
38 Err(_) => None,
39 }
40 }
41}
42
43impl Deref for AbiMap {
44 type Target = HashMap<ContractId, ProgramABI>;
45 fn deref(&self) -> &Self::Target {
46 &self.0
47 }
48}
49
50impl DerefMut for AbiMap {
51 fn deref_mut(&mut self) -> &mut Self::Target {
52 &mut self.0
53 }
54}
55
56fn fetch_abi_from_registry(_contract_id: &ContractId) -> Result<ProgramABI> {
58 Err(Error::AbiError("Not implemented yet".to_string()))
61}