예제 #1
0
    def prepare_miner_block(self, args):
        if args:
            args_splitted = args.split(' ')
            privkey_addr = args_splitted[0]
            f = open(privkey_addr, 'r')
            miner_privkey_wif = f.read()
            f.close()
        else:
            f = open(MINER_PRIVKEY_FILE, 'r')
            miner_privkey_wif = f.read()
            f.close()
        transactions = Blockchain.get_transactions_to_block()

        miner_privkey = Wallet.WIF_to_priv(miner_privkey_wif)

        coinbase = CoinbaseTransaction()
        coinbase.recipient_address = Wallet.private_key_to_addr(miner_privkey)

        coinbase_hash = coinbase.transaction_hash()

        sign, publkey = Wallet.sign_message(coinbase_hash, miner_privkey)
        serialized_coinbase = Serializer.serialize(coinbase.amount,
                                                   coinbase.sender_address,
                                                   coinbase.recipient_address,
                                                   publkey, sign)
        if transactions[0] == '':
            transactions = [serialized_coinbase]
        else:
            transactions.append(serialized_coinbase)
        last_block = Blockchain.get_chain()[-1]
        last_block_h = last_block.hash_block()

        timestamp = int(time.time())

        new_block = Block(timestamp, last_block_h, transactions)

        return new_block
예제 #2
0
 def test_wif(self):
     self.assertEqual(pk, Wallet.WIF_to_priv(Wallet.priv_to_WIF(pk)))
예제 #3
0
        super(RawCoinbaseTransaction, self).__init__(
            sender_addr='0000000000000000000000000000000000',
            recepient_addr='0000000000000000000000000000000000',
            inputs=
            '0000000000000000000000000000000000000000000000000000000000000000',
            value=50,
            locktime=0)


out_txid = '746f07af15f9fca472c993cd343ab3207072020b0fd3797def150473e88cbdf6'
my_address = '2NEBZ1E7FqWCQsC3aETLepmADibZ7Mgnz3D'
taras_address = '2NEHZANaV4s48mzmnuRanzW4nF9vLnB2you'

tx = RawTransaction(my_address, taras_address, out_txid, 20, 10)
# print(tx.raw_transaction(Alice_private_key))
privkey = Wallet.WIF_to_priv(my_privkey)
prRed(privkey)
prk = swap_bits_in_str(privkey)
# print(prk)
abcde = Wallet.WIF_to_priv(
    'Qqj2j371SdysJ9ru9WaTnfimX2tsQKr1snvJRrNg4X6jwYnZnUoKgUhDgppodgFbQY6dB4V')
prRed(abcde)
raw = tx.raw_transaction(prk[2:])

raw_dict = deserialize(raw.hex())
sig_script_len = make_varint(len(tx.sig_script.hex()))
pk_script_len = make_varint(len(tx.tx_out1['pk_script'].hex()))
# print(sig_script_len + tx.sig_script.hex())
# print('------')
# print(pk_script_len + tx.tx_out1['pk_script'].hex())
script = (sig_script_len + tx.sig_script.hex() + pk_script_len +