def __init__(self, from_addr, to_addr, amount, utxo_set): inputs = [] outputs = [] wallets = ws.Wallets() wallet = wallets.get_wallet(from_addr) pubkey_hash = utils.hash_public_key(wallet.public_key) acc, valid_outputs = utxo_set.find_spendable_outputs( pubkey_hash, amount) if acc < amount: print('Not enough funds') sys.exit() # inputs for tx_id, outs in valid_outputs.items(): for out in outs: input = TXInput(tx_id, out, None, wallet.public_key) inputs.append(input) # outputs outputs.append(TXOutput(amount, to_addr)) if acc > amount: outputs.append(TXOutput(acc - amount, from_addr)) self._tx = Transaction(None, inputs, outputs).set_id() self._utxo_set = utxo_set self._sign_utxo(wallet.private_key) print('Signing complete\n')
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)
def __init__(self, from_addr, to_addr, amount, utxo_set): inputs = [] outputs = [] # log('UTXOTx') wallets = ws.Wallets() wallet = wallets.get_wallet(from_addr) pubkey_hash = utils.hash_public_key(wallet.public_key) acc, valid_outputs = utxo_set.find_spendable_outputs( pubkey_hash, amount) if acc < amount: # log.error('Not enough funds') utils.logg('Not enough funds') sys.exit() # Build a list of inputs for tx_id, outs in valid_outputs.items(): for out in outs: ctxin = TXInput() ctxin._tx_id = tx_id ctxin._vout = out ctxin._signature = None ctxin._public_key = wallet.public_key inputs.append(ctxin) # Build a list of outputs outputs.append(TXOutput(amount, to_addr)) if acc > amount: # A change outputs.append(TXOutput(acc-amount, from_addr)) self._tx = Transaction() self._tx.vin = inputs self._tx.vout = outputs self._tx.set_id() self._utxo_set = utxo_set self._sign_utxo(wallet.private_key)
def __init__(self): self._private_key = os.urandom(32) 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)
def uses_key(self, pubkey_hash): # checks whether the address initiated the transaction pubkey_hash = utils.hash_public_key(self._public_key) return pubkey_hash == pubkey_hash
def use_key(self, pub_key_hash): bin_pub_key = binascii.unhexlify(self.pub_key) hash = hash_public_key(bin_pub_key) return pub_key_hash == hash
def uses_key(self, pubkey_hash): return pubkey_hash == utils.hash_public_key(self.pubkey)
def _hash_public_key(self): return hash_public_key(self._public_key.to_string())