Beispiel #1
0
 def serialize_header(self, res):
     s = write_uint64(res.get('version')) \
         + reverse_hex_str(res.get('prev_block_hash')) \
         + reverse_hex_str(res.get('merkle_root')) \
         + write_uint64(int(res.get('timestamp'))) \
         + write_uint64(int(res.get('bits'))) \
         + write_uint64(int(res.get('nonce')))
     return s
Beispiel #2
0
 def serialize_preimage(self, i):
     """
     get to be sign content
     :param i:
     :return:
     """
     version = write_uint32(self.tx_ver).encode('hex')
     hash_type = write_uint32(1).encode('hex')
     locktime = write_uint32(self.tx_locktime).encode('hex')
     input_list = self._input_list
     output_list = self._output_list
     txin = input_list[i]
     if txin.is_segwit_input():
         hash_prevouts = double_sha256(
             ''.join(txin.serialize_outpoint() for txin in input_list).decode('hex')).encode(
             'hex')
         hash_sequence = double_sha256(
             ''.join(write_uint32(txin.in_sequence) for txin in input_list).decode(
                 'hex')).encode('hex')
         hash_outputs = double_sha256(
             ''.join(o.serialize_output() for o in output_list).decode('hex')).encode('hex')
         outpoint = txin.serialize_outpoint()
         pubkey = txin.in_dict['pubkeys'][0]
         pkh = hash_160(pubkey.decode('hex')).encode('hex')
         # redeem_script = '00' + push_script(pkh)
         script_code = push_script('76a9' + push_script(pkh) + '88ac')
         # script_hash = hash_160(redeem_script.decode('hex')).encode('hex')
         # script_pub_key = 'a9' + push_script(script_hash) + '87'
         amount = write_uint64(txin.in_value)
         sequence = write_uint32(txin.in_sequence)
         preimage = version + hash_prevouts + hash_sequence + outpoint + script_code + amount + sequence + hash_outputs + locktime + hash_type
     else:
         txins = int_to_hex(len(input_list)) + ''.join(
             txin.serialize_input_preimage(k) for
             k, txin in enumerate(input_list))
         txouts = int_to_hex(len(output_list)) + ''.join(
             o.serialize_output() for o in output_list)
         preimage = version + txins + txouts + locktime + hash_type
     return preimage
Beispiel #3
0
 def serialize_output(self):
     s = write_uint64(self.out_value).encode('hex')
     script = self.pay_script_from_address()
     s += int_to_hex(len(script) / 2)
     s += script
     return s