Vouch

bizlogic.vouch.VouchWriter

Class for writing Vouches.

"voucher": person giving the vouch "vouchee": person receiving the vouch

ipfs filename

vouch/vouchee_.voucher_/created_

Source code in bizlogic/vouch.py
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
class VouchWriter:
    """Class for writing Vouches.

    "voucher": person giving the vouch
    "vouchee": person receiving the vouch

    ipfs filename:
        vouch/vouchee_<id>.voucher_<id>/created_<timestamp>
    """

    vouch_id: str
    vouchee: str
    voucher: str
    ipfsclient: Ipfs
    data: Vouch

    def __init__(
            self: Self,
            ipfsclient: Ipfs,
            voucher: str,
            vouchee: str) -> None:
        """Initialize VouchWriter.

        Args:
            ipfsclient (Ipfs): IPFS client.
            voucher (str): voucher string.
            vouchee (str): vouchee string.
        """
        self.vouch_id = str(uuid.uuid4())
        self.vouchee = vouchee
        self.voucher = voucher
        self.ipfsclient = ipfsclient
        self.data = Vouch(active=True)

    def write(self: Self) -> None:
        """Write the Vouch."""
        self._generate_index()

        store = Store(
            index=self.index,
            ipfs=self.ipfsclient,
            writer=self.data
        )

        store.add()

    @TestingOnly.decorator
    def delete(self: Self) -> None:
        """Delete the vouch from IPFS."""
        store = Store(
            index=self.index,
            ipfs=self.ipfsclient,
            writer=self.data
        )

        store.delete()

    def _generate_index(self: Self) -> None:
        """Generate the index for the vouch."""
        self.index = Index(
            prefix=PREFIX,
            index={
                "vouchee": self.vouchee,
                "voucher": self.voucher,
                "vouch": self.vouch_id
            },
            subindex=Index(
                index={
                    "created": str(time.time_ns())
                }
            )
        )

__init__(ipfsclient, voucher, vouchee)

Initialize VouchWriter.

Parameters:
  • ipfsclient (Ipfs) –

    IPFS client.

  • voucher (str) –

    voucher string.

  • vouchee (str) –

    vouchee string.

bizlogic/vouch.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(
        self: Self,
        ipfsclient: Ipfs,
        voucher: str,
        vouchee: str) -> None:
    """Initialize VouchWriter.

    Args:
        ipfsclient (Ipfs): IPFS client.
        voucher (str): voucher string.
        vouchee (str): vouchee string.
    """
    self.vouch_id = str(uuid.uuid4())
    self.vouchee = vouchee
    self.voucher = voucher
    self.ipfsclient = ipfsclient
    self.data = Vouch(active=True)

bizlogic.vouch.VouchReader

Read and query vouches from IPFS.

Source code in bizlogic/vouch.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class VouchReader():
    """Read and query vouches from IPFS."""

    ipfsclient: Ipfs

    def __init__(self: Self, ipfsclient: Ipfs) -> None:
        """Create a new vouch reader.

        Args:
            ipfsclient (Ipfs): The ipfs client
        """
        self.ipfsclient = ipfsclient

    def get_all_vouches(self: Self) -> pd.DataFrame:
        """Get all vouches.

        Returns:
            pd.DataFrame: A dataframe of all vouches
        """
        query_results = Store.query(
            query_index=Index(
                prefix=PREFIX,
                index={}
            ),
            ipfs=self.ipfsclient,
            reader=Vouch()
        )

        # parse applications into a dataframe
        df = Store.to_dataframe(query_results, PARSERS[ParserType.VOUCH])
        if df.empty:
            return df

        # filter for most recent applications per loan_id
        return Utils.get_most_recent(df, GROUP_BY[ParserType.VOUCH])

    def query_vouches(
        self: Self,
        voucher: str = None,
        vouchee: str = None
    ) -> pd.DataFrame:
        """Search vouches for a vouchee or voucher.

        Args:
            voucher (str, optional): The voucher to search for.
                Defaults to None.
            vouchee (str, optional): The vouchee to search for.
                Defaults to None.

        Returns:
            pd.DataFrame: A dataframe of all vouches matching the query
        """
        assert voucher or vouchee, "Must provide voucher or vouchee"

        index = {
            "voucher": voucher
        } if voucher else {
            "vouchee": vouchee
        }

        query_results = Store.query(
            query_index=Index(
                prefix=PREFIX,
                index=index,
                size=2
            ),
            ipfs=self.ipfsclient,
            reader=Vouch()
        )

        # parse applications into a dataframe
        df = Store.to_dataframe(query_results, PARSERS[ParserType.VOUCH])
        if df.empty:
            return df

        # filter for most recent applications per loan_id
        return Utils.get_most_recent(df, GROUP_BY[ParserType.VOUCH])

__init__(ipfsclient)

Create a new vouch reader.

Parameters:
  • ipfsclient (Ipfs) –

    The ipfs client

bizlogic/vouch.py
 98
 99
100
101
102
103
104
def __init__(self: Self, ipfsclient: Ipfs) -> None:
    """Create a new vouch reader.

    Args:
        ipfsclient (Ipfs): The ipfs client
    """
    self.ipfsclient = ipfsclient