Esempio n. 1
0
 def find_by_public_key(self, public_key):
     address = address_from_public_key(public_key)
     wallet = self.find_by_address(address)
     if wallet.public_key is None:
         wallet.public_key = public_key
         self.save_wallet(wallet)
     return wallet
Esempio n. 2
0
    def delete_by_public_key(self, public_key):
        """Deletes a wallet by public key

        :param string public_key: wallets' public key
        """
        address = address_from_public_key(public_key)
        key = self.key_for_address(address)
        self.redis.delete(key)
Esempio n. 3
0
    def revert_block(self, block):
        address = address_from_public_key(block.generator_public_key)
        if block.generator_public_key == self.public_key and address == self.address:
            self.balance -= block.reward + block.total_fee

            self.forged_fees -= block.total_fee
            self.forged_rewards -= block.reward
        else:
            raise Exception("Couldn't revert block {} for wallet {}".format(
                block.id, self.public_key))
Esempio n. 4
0
    def find_by_public_key(self, public_key):
        """Finds a wallet by public key.

        It calculates the address from public key and uses the `find_by_address`
        function, which if wallet is not found for this address, it copies it from
        blockchain wallet manager.

        :param string public_key: wallet's public key
        :returns Wallet: wallet object
        """
        address = address_from_public_key(public_key)
        return self.find_by_address(address)
Esempio n. 5
0
    def apply_block(self, block):
        address = address_from_public_key(block.generator_public_key)
        is_correct_wallet = (block.generator_public_key == self.public_key
                             or address == self.address)
        if is_correct_wallet:
            self.balance += block.reward
            self.balance += block.total_fee

            self.produced_blocks += 1
            self.forged_fees += block.total_fee
            self.forged_rewards += block.reward
        else:
            raise Exception("Couldn't apply block {} to wallet {}".format(
                block.id, self.public_key))
Esempio n. 6
0
    def __init__(self, redis, **kwargs):

        if "address" not in kwargs and "public_key" not in kwargs:
            raise ValueError("address or public_key are required")

        address = kwargs.get("address")
        if not address:
            address = address_from_public_key(kwargs["public_key"])
            kwargs["address"] = address

        self.key = "wallets:address:{}".format(address)
        self.redis = redis

        wallet = Wallet(kwargs)
        redis.set(self.key, wallet.to_json())
        self._set_attributes(wallet)
Esempio n. 7
0
    def revert_for_sender_wallet(self, wallet):
        """Reverts transaction on senders wallet

        :param (Wallet) wallet: senders wallet
        """
        address = address_from_public_key(self.sender_public_key)
        incorrect_wallet = (self.sender_public_key != wallet.public_key
                            and address != wallet.address)
        if incorrect_wallet:
            raise Exception(
                "Incorrect wallet. Wallet with address {} ({}) does not match with "
                "transaction address {} ({})".format(wallet.address,
                                                     wallet.public_key,
                                                     address,
                                                     self.sender_public_key))
        total = self.amount + self.fee
        wallet.balance += total
Esempio n. 8
0
    def _apply_v1_compatibility(self):
        if self.version != 1:
            return

        if self.second_signature:
            self.sign_signature = self.second_signature

        if self.type == TRANSACTION_TYPE_VOTE:
            self.recipient_id = address_from_public_key(
                self.sender_public_key, self.network)
        elif self.type == TRANSACTION_TYPE_MULTI_SIGNATURE:
            keysgroup = []
            for key in self.asset["multisignature"]["keysgroup"]:
                if not key.startswith("+"):
                    key = "+{}".format(key)
                keysgroup.append(key)
            self.asset["multisignature"]["keysgroup"] = keysgroup
Esempio n. 9
0
 def exists_by_public_key(self, public_key):
     address = address_from_public_key(public_key)
     return self.exists_by_address(address)
Esempio n. 10
0
 def exists(self, public_key):
     address = address_from_public_key(public_key)
     if self.redis.exists(self.key_for_address(address)) == 1:
         return True
     return False