1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;

impl MarketStateExt for market::State {
    fn get_allocations_for_pending_deals(
        &self,
        store: &impl Blockstore,
    ) -> anyhow::Result<HashMap<DealID, AllocationID>> {
        let mut result = HashMap::default();
        match self {
            Self::V8(_) => {
                anyhow::bail!("unsupported before actors v9");
            }
            Self::V9(s) => {
                let map = fil_actors_shared::v9::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v9::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v9::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
            Self::V10(s) => {
                let map = fil_actors_shared::v10::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v10::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v10::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
            Self::V11(s) => {
                let map = fil_actors_shared::v11::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v11::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v11::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
            Self::V12(s) => {
                let map = fil_actors_shared::v12::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v12::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v12::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
            Self::V13(s) => {
                let map = fil_actors_shared::v13::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v13::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v13::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
            Self::V14(s) => {
                let map = fil_actors_shared::v14::Map::<_, AllocationID>::load_with_bit_width(
                    &s.pending_deal_allocation_ids,
                    store,
                    fil_actors_shared::v14::HAMT_BIT_WIDTH,
                )?;
                map.for_each(|k, &v| {
                    let deal_id = fil_actors_shared::v14::parse_uint_key(k)?;
                    result.insert(deal_id, v);
                    Ok(())
                })?;
            }
        }
        Ok(result)
    }

    fn get_allocation_id_for_pending_deal(
        &self,
        store: &impl Blockstore,
        deal_id: &DealID,
    ) -> anyhow::Result<AllocationID> {
        let allocations = self.get_allocations_for_pending_deals(store)?;
        Ok(allocations
            .get(deal_id)
            .copied()
            .unwrap_or(fil_actor_market_state::v14::NO_ALLOCATION_ID))
    }
}