Пример #1
0
    def address(self):
        """
        Returns the (unique) address this GGO has on the ledger.

        :rtype: str
        """
        return ols.generate_address(ols.AddressPrefix.GGO, self.key.PublicKey())
Пример #2
0
    def create_child(self, amount, user):
        """
        Creates a new child Ggo.

        :param int amount:
        :param User user:
        :rtype: Ggo
        """
        assert 0 < amount <= self.amount

        key_index = GgoIndexSequence.get_next(user.id,
                                              Session.object_session(self))
        key = KeyGenerator.get_key_for_traded_ggo_at_index(user, key_index)
        address = ols.generate_address(ols.AddressPrefix.GGO, key.PublicKey())

        return Ggo(
            user_id=user.id,
            parent_id=self.id,
            address=address,
            key_index=key_index,
            issue_time=self.issue_time,
            expire_time=self.expire_time,
            sector=self.sector,
            begin=self.begin,
            end=self.end,
            technology_code=self.technology_code,
            fuel_code=self.fuel_code,
            emissions=self.emissions,
            amount=amount,
            issued=False,
            stored=False,
            retired=False,
            synchronized=False,
            locked=False,
        )
Пример #3
0
    def address(self):
        """
        Returns the (unique) address this measurement has on the ledger.

        :rtype: str
        """
        return ols.generate_address(ols.AddressPrefix.MEASUREMENT,
                                    self.key.PublicKey())
Пример #4
0
    def settlement_address(self):
        """
        Returns the (unique) address on the ledger to put settlements when
        retiring GGOs to this measurement.

        :rtype: str
        """
        return ols.generate_address(ols.AddressPrefix.SETTLEMENT,
                                    self.key.PublicKey())
Пример #5
0
    def build_ledger_request(self):
        """
        :rtype: ols.RetireGGORequest
        """
        measurement_key = KeyGenerator.get_key_for_measurement(
            self.meteringpoint, self.begin)

        settlement_address = ols.generate_address(
            ols.AddressPrefix.SETTLEMENT, measurement_key.PublicKey())

        return ols.RetireGGORequest(
            settlement_address=settlement_address,
            measurement_address=self.measurement_address,
            measurement_private_key=measurement_key.PrivateKey(),
            parts=[
                ols.RetireGGOPart(
                    address=ols.generate_address(ols.AddressPrefix.GGO, self.parent_ggo.key.PublicKey()),
                    private_key=self.parent_ggo.key.PrivateKey(),
                )
            ],
        )