Exemplo n.º 1
0
def get_balance(address):
    bc = Blockchain()
    utxo_set = UTXOSet(bc)
    pubkey_hash = utils.address_to_pubkey_hash(address)
    utxos = utxo_set.find_utxo(pubkey_hash)
    balance = 0

    for out in utxos:
        balance += out.value

    print('Balance: {0}'.format(balance))
Exemplo n.º 2
0
def get_address_balance(address):
    # get address balance for a specifiedc address
    bc = Blockchain()
    utxo_set = UTXOSet(bc)

    pubkey_hash = utils.address_to_pubkey_hash(address)
    utxos = utxo_set.find_utxo(pubkey_hash)
    balance = 0

    for out in utxos:
        balance += out.value

    return balance / COIN
Exemplo n.º 3
0
    def __init__(self):
        self._private_key = os.urandom(32)

        # wallet import format
        # self._private_key_wif = utils.privatekey_to_wif(self._private_key)
        self._public_key = utils.privatekey_to_publickey(self._private_key)
        self._hash_public_key = utils.hash_public_key(self._public_key)
        self._address = utils.get_address(self._hash_public_key)

    @property
    def private_key(self):
        return self._private_key

    @property
    def public_key(self):
        return self._public_key

    @property
    def hash_public_key(self):
        return self._hash_public_key

    @property
    def address(self):
        return self._address


if __name__ == '__main__':
    w = Wallet()
    assert w.hash_public_key == utils.address_to_pubkey_hash(
        w.address), "Hash of public key is Not Equal!"
 def _lock(address):
     return utils.address_to_pubkey_hash(address)
Exemplo n.º 5
0
 def __init__(self, value, address):
     self._value = value
     self._address = address
     self._public_key_hash = utils.address_to_pubkey_hash(address)
 def lock(self, address):
     hex_pub_key_hash = binascii.hexlify(address_to_pubkey_hash(address))
     self.pub_key_hash = hex_pub_key_hash
Exemplo n.º 7
0
                self.wallets = pickle.load(f)
        except IOError:
            self.wallets = {}

    def __getitem__(self, key):
        return self.wallets[key]

    def __setitem__(self, key, value):
        self.wallets[key] = value

    def get(self, key, default=None):
        return self.wallets.get(key, default)

    def save(self):
        with open(self.wallet_file, 'wb') as f:
            pickle.dump(self.wallets, f)

    def items(self):
        return self.wallets.items()


if __name__ == "__main__":
    from wallet import Wallet
    w = Wallet.generate_wallet()
    ws = Wallets()
    ws[w.address] = w
    print(w.address)
    from utils import address_to_pubkey_hash
    h = address_to_pubkey_hash(w.address)
    # ws.save()
Exemplo n.º 8
0
 def address(self, r_value):
     self._address = r_value
     self._public_key_hash =  utils.address_to_pubkey_hash(r_value)