Ejemplo n.º 1
0
 def processSegwitOutput(self, outputDict, addresses):
     assert len(addresses) <= 1
     if len(addresses) == 0:
         outputType = OUTPUT_TYPES[outputDict["scriptPubKey"]["type"]]
         prefix = "wkh_" if outputType == OUTPUT_TYPES[
             "witness_v0_keyhash"] else "wsh_"
         addresses.append(
             bech32.encode(
                 prefix, 0,
                 binascii.unhexlify(outputDict["scriptPubKey"]["hex"][4:])))
Ejemplo n.º 2
0
    def processOutput(self, transaction, outputDict, outputIndex):
        if not outputDict["scriptPubKey"]["type"] in OUTPUT_TYPES:
            print outputDict["scriptPubKey"]["type"]
        assert (outputDict["scriptPubKey"]["type"] in OUTPUT_TYPES)
        outputType = OUTPUT_TYPES[outputDict["scriptPubKey"]["type"]]

        if "addresses" in outputDict["scriptPubKey"]:
            addresses = outputDict["scriptPubKey"]["addresses"]
            for address in addresses:
                assert (len(address) <= MAX_ADDRESS_LENGTH)
                assert (len(address) > 0)
        else:
            addresses = []

        if outputType in [
                OUTPUT_TYPES["nonstandard"], OUTPUT_TYPES["nulldata"],
                OUTPUT_TYPES["multisig"]
        ]:
            pass
        elif outputType == OUTPUT_TYPES["pubkey"]:
            if "addresses" in outputDict["scriptPubKey"]:
                assert (len(addresses) == 1)
        elif outputType in [
                OUTPUT_TYPES["witness_v0_keyhash"],
                OUTPUT_TYPES["witness_v0_scripthash"]
        ]:
            assert (len(addresses) <= 1)
            if len(addresses) == 0:
                prefix = "wkh_" if outputType == OUTPUT_TYPES[
                    "witness_v0_keyhash"] else "wsh_"
                addresses = [
                    bech32.encode(prefix, 0, [
                        ord(s) for s in binascii.unhexlify(
                            outputDict["scriptPubKey"]["hex"][4:])
                    ])
                ]
        else:
            assert (len(addresses) == 1)

        scriptHex = outputDict["scriptPubKey"]["hex"]
        value = outputValueToSatoshis(outputDict["value"])
        transaction.addOutput(
            (outputIndex, outputType, addresses, scriptHex, value))