Esempio n. 1
0
    def serializeForSignature(self, inputIndex, hashType):
        data_list = []
        data_list.append(struct.pack("<L", self.version))

        if (hashType & SIGHASH_ANYONECANPAY) != 0:
            data_list.append(Bitcoin.serialize_variable_int(1))
            data_list.append(self.inputs[inputIndex].serializeForSignature(hashType, True))
        else:
            data_list.append(Bitcoin.serialize_variable_int(len(self.inputs)))
            for i, input in enumerate(self.inputs):
                data_list.append(input.serializeForSignature(hashType, i == inputIndex))

        # outputs
        if (hashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_NONE:
            data_list.append(Bitcoin.serialize_variable_int(0))
        elif (hashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_ALL:
            data_list.append(Bitcoin.serialize_variable_int(len(self.outputs)))
            for i, output in enumerate(self.outputs):
                data_list.append(output.serializeForSignature(hashType))
        elif (hashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE:
            data_list.append(Bitcoin.serialize_variable_int(1))
            assert inputIndex < len(self.outputs)
            data_list.append(self.outputs[inputIndex].serializeForSignature(hashType))

        data_list.append(struct.pack("<L", self.lock_time))

        data_list.append(struct.pack("<L", hashType))

        return b''.join(data_list)
Esempio n. 2
0
    def serialize(self):
        data_list = []
        data_list.append(struct.pack("<L", self.version))

        data_list.append(Bitcoin.serialize_variable_int(len(self.inputs)))
        for i, input in enumerate(self.inputs):
            data_list.append(input.serialize())

        data_list.append(Bitcoin.serialize_variable_int(len(self.outputs)))
        for i, output in enumerate(self.outputs):
            data_list.append(output.serialize())

        data_list.append(struct.pack("<L", self.lock_time))

        return b''.join(data_list)
Esempio n. 3
0
    def sendGetData(self, items):
        data = []
        for item in items:
            data.append(Bitcoin.serialize_inv(item[0], item[1]))

        payload = Bitcoin.serialize_variable_int(len(data)) + b''.join(data)
        message = Bitcoin.wrap_message("getdata", payload, Bitcoin.NETWORK_DELIVERY)
        self.send(message)
Esempio n. 4
0
    def sendGetData(self, items):
        data = []
        for item in items:
            data.append(Bitcoin.serialize_inv(item[0], item[1]))

        payload = Bitcoin.serialize_variable_int(len(data)) + b''.join(data)
        message = Bitcoin.wrap_message("getdata", payload,
                                       Bitcoin.NETWORK_DELIVERY)
        self.send(message)
Esempio n. 5
0
    def serialize(self):
        self.createOutputScript()

        data_list = []

        data_list.append(struct.pack("<Q", self.amount))
        script_bytes = self.scriptPubKey.serialize()
        data_list.append(Bitcoin.serialize_variable_int(len(script_bytes)))
        data_list.append(script_bytes)

        return b''.join(data_list)
Esempio n. 6
0
    def serialize(self):
        data_list = []
        data_list.append(self.tx_hash)
        data_list.append(struct.pack("<L", self.n))

        script_bytes = self.scriptSig.serialize()
        data_list.append(Bitcoin.serialize_variable_int(len(script_bytes)))
        data_list.append(script_bytes)

        data_list.append(struct.pack("<L", self.sequence))

        return b''.join(data_list)
Esempio n. 7
0
    def serializeForSignature(self, hashType, selfSig):
        data_list = []
        data_list.append(self.tx_hash)
        data_list.append(struct.pack("<L", self.n))

        if selfSig:
            script_bytes = self.scriptPubKey
        else:
            script_bytes = b''

        data_list.append(Bitcoin.serialize_variable_int(len(script_bytes)))
        data_list.append(script_bytes)

        if selfSig or (hashType & ~SIGHASH_ANYONECANPAY) != SIGHASH_NONE:
            data_list.append(struct.pack("<L", self.sequence))
        else:
            data_list.append(struct.pack("<L", 0))

        return b''.join(data_list)