Ejemplo n.º 1
0
    def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY):
        outputs = []
        has_change = False

        for _type, address, amount in tx.outputs():
            info = tx.output_info.get(address)
            if info is not None and not has_change:
                has_change = True  # no more than one change address
                index, xpubs, m = info
                if len(xpubs) == 1:
                    if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
                        script_type = self.types.OutputScriptType.PAYTOWITNESS
                    elif script_gen == SCRIPT_GEN_P2SH_SEGWIT:
                        script_type = self.types.OutputScriptType.PAYTOP2SHWITNESS
                    else:
                        script_type = self.types.OutputScriptType.PAYTOADDRESS
                    address_n = self.client_class.expand_path(derivation +
                                                              "/%d/%d" % index)
                    txoutputtype = self.types.TxOutputType(
                        amount=amount,
                        script_type=script_type,
                        address_n=address_n,
                    )
                else:
                    if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
                        script_type = self.types.OutputScriptType.PAYTOWITNESS
                    elif script_gen == SCRIPT_GEN_P2SH_SEGWIT:
                        script_type = self.types.OutputScriptType.PAYTOP2SHWITNESS
                    else:
                        script_type = self.types.OutputScriptType.PAYTOMULTISIG
                    address_n = self.client_class.expand_path("/%d/%d" % index)
                    nodes = map(self.ckd_public.deserialize, xpubs)
                    pubkeys = [
                        self.types.HDNodePathType(node=node,
                                                  address_n=address_n)
                        for node in nodes
                    ]
                    multisig = self.types.MultisigRedeemScriptType(
                        pubkeys=pubkeys, signatures=[b''] * len(pubkeys), m=m)
                    txoutputtype = self.types.TxOutputType(
                        multisig=multisig,
                        amount=amount,
                        address_n=self.client_class.expand_path(derivation +
                                                                "/%d/%d" %
                                                                index),
                        script_type=script_type)
            else:
                txoutputtype = self.types.TxOutputType()
                txoutputtype.amount = amount
                if _type == TYPE_SCRIPT:
                    txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
                    txoutputtype.op_return_data = address[2:]
                elif _type == TYPE_ADDRESS:
                    txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
                    txoutputtype.address = qtum_addr_to_bitcoin_addr(address)

            outputs.append(txoutputtype)
        return outputs
Ejemplo n.º 2
0
 def create_output_by_address():
     txoutputtype = self.types.TxOutputType()
     txoutputtype.amount = amount
     if _type == TYPE_SCRIPT:
         txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
         txoutputtype.op_return_data = address[2:]
     elif _type == TYPE_ADDRESS:
         txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
         txoutputtype.address = qtum_addr_to_bitcoin_addr(address)
     return txoutputtype
Ejemplo n.º 3
0
 def create_output_by_address():
     txoutputtype = TxOutputType()
     txoutputtype.amount = amount
     if _type == TYPE_SCRIPT:
         txoutputtype.script_type = OutputScriptType.PAYTOOPRETURN
         txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(o)
     elif _type == TYPE_ADDRESS:
         txoutputtype.script_type = OutputScriptType.PAYTOADDRESS
         # qtum diff
         txoutputtype.address = qtum_addr_to_bitcoin_addr(address)
     return txoutputtype