示例#1
0
def decodeGameKey(gk):
    decoded = ByteArray(b58decode(gk))

    addrID = decoded.pop(2)
    if addrID not in AddrIDs.values():
        exit("invalid address ID %s" + repr(addrID))

    netByte = decoded.pop(1)[0]
    if netByte not in NetBytes.values():
        exit("invalid net byte" + repr(netByte))

    net = nets.mainnet if netByte == 1 else nets.testnet if netByte == 2 else nets.simnet

    doubleHash = decoded.pop(32)
    signingKey = crypto.privKeyFromBytes(decoded)  # The remaining 32 bytes

    # Rebuilt the script. See fund.py
    redeemScript = ByteArray(opcode.OP_SHA256)
    redeemScript += txscript.addData(doubleHash)
    redeemScript += opcode.OP_EQUALVERIFY
    redeemScript += txscript.addData(signingKey.pub.serializeCompressed())
    redeemScript += opcode.OP_CHECKSIG

    challengeAddr = AddressScriptHash.fromScript(redeemScript, net)

    return net, signingKey, doubleHash, redeemScript, challengeAddr
示例#2
0
    def btcDecode(b, pver):
        """
        btcDecode decodes r using the Decred protocol encoding into the
        receiver. This is part of the Message interface implementation.
        See deserialize for decoding transactions stored to disk, such as in a
        database, as opposed to decoding transactions from the wire.
        """
        # The serialized encoding of the version includes the real transaction
        # version in the lower 16 bits and the transaction serialization type
        # in the upper 16 bits.
        b = ByteArray(b)
        ver = b.pop(4).unLittle().int()

        tx = MsgTx.new()

        tx.version = ver & 0xFFFF
        tx.serType = ver >> 16

        # Serialize the transactions depending on their serialization
        # types.
        if tx.serType == wire.TxSerializeNoWitness:
            b, _ = tx.decodePrefix(b, pver)

        elif tx.serType == wire.TxSerializeOnlyWitness:
            b, _ = tx.decodeWitness(b, pver, False)

        elif tx.serType == wire.TxSerializeFull:
            b, _ = tx.decodePrefix(b, pver)
            b, _ = tx.decodeWitness(b, pver, True)

        else:
            raise NotImplementedError(
                "MsgTx.BtcDecode: unsupported transaction type")

        return tx