Beispiel #1
0
def create_coinbase(heightAdjust=0, comm_quota=85):
    global counter
    coinbase = CTransaction()
    coinbase.vin.append(
        CTxIn(COutPoint(0, 0xffffffff), CScript([counter + heightAdjust,
                                                 OP_0]), 0xffffffff))
    counter += 1
    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = int(12.5 * 100000000)
    halvings = int((counter + heightAdjust) / 2000)  # regtest
    coinbaseoutput.nValue >>= halvings
    coinbaseoutput.scriptPubKey = ""
    coinbase.vout = [coinbaseoutput]
    if halvings == 0:  # regtest
        comm_output = CTxOut()
        comm_output.nValue = (coinbaseoutput.nValue * comm_quota // 1000)
        # regtest
        com_addr = bytearray([
            0xb6, 0x86, 0x3b, 0x18, 0x2a, 0x52, 0x74, 0x5b, 0xf6, 0xd5, 0xfb,
            0x19, 0x01, 0x39, 0xa2, 0xaa, 0x87, 0x6c, 0x08, 0xf5
        ])
        comm_output.scriptPubKey = CScript([OP_HASH160, com_addr, OP_EQUAL])
        coinbaseoutput.nValue -= comm_output.nValue
        coinbase.vout.append(comm_output)
    coinbase.calc_sha256()
    return coinbase
Beispiel #2
0
def create_coinbase(heightAdjust=0):
    global counter
    coinbase = CTransaction()
    coinbase.vin.append(
        CTxIn(COutPoint(0, 0xffffffff), CScript([counter + heightAdjust,
                                                 OP_0]), 0xffffffff))
    counter += 1
    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = int(5 * 100000000)
    halvings = int((counter + heightAdjust) / 150)  # regtest
    coinbaseoutput.nValue >>= halvings
    coinbaseoutput.scriptPubKey = ""
    coinbase.vout = [coinbaseoutput]
    if halvings == 0:  # regtest
        froutput = CTxOut()
        froutput.nValue = coinbaseoutput.nValue / 5
        # regtest
        fraddr = bytearray([
            0x67, 0x08, 0xe6, 0x67, 0x0d, 0xb0, 0xb9, 0x50, 0xda, 0xc6, 0x80,
            0x31, 0x02, 0x5c, 0xc5, 0xb6, 0x32, 0x13, 0xa4, 0x91
        ])
        froutput.scriptPubKey = CScript([OP_HASH160, fraddr, OP_EQUAL])
        coinbaseoutput.nValue -= froutput.nValue
        coinbase.vout = [coinbaseoutput, froutput]
    coinbase.calc_sha256()
    return coinbase
Beispiel #3
0
def create_coinbase(heightAdjust = 0):
    global counter
    coinbase = CTransaction()
    coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), 
                ser_string(serialize_script_num(counter+heightAdjust)), 0xffffffff))
    counter += 1
    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = 50*100000000
    halvings = int((counter+heightAdjust)/150) # regtest
    coinbaseoutput.nValue >>= halvings
    coinbaseoutput.scriptPubKey = ""
    coinbase.vout = [ coinbaseoutput ]
    coinbase.calc_sha256()
    return coinbase
Beispiel #4
0
def create_transaction(prevtx, n, sig, value):
    tx = CTransaction()
    assert (n < len(prevtx.vout))
    tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
    tx.vout.append(CTxOut(value, ""))
    tx.calc_sha256()
    return tx
Beispiel #5
0
def create_coinbase(heightAdjust=0):
    global counter
    coinbase = CTransaction()
    coinbase.vin.append(
        CTxIn(COutPoint(0, 0xffffffff),
              ser_string(serialize_script_num(counter + heightAdjust)),
              0xffffffff))
    counter += 1
    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = 50 * 100000000
    halvings = int((counter + heightAdjust) / 150)  # regtest
    coinbaseoutput.nValue >>= halvings
    coinbaseoutput.scriptPubKey = ""
    coinbase.vout = [coinbaseoutput]
    coinbase.calc_sha256()
    return coinbase
Beispiel #6
0
def SignatureHash(script, txTo, inIdx, hashtype):
    """Consensus-correct SignatureHash

    Returns (hash, err) to precisely match the consensus-critical behavior of
    the SIGHASH_SINGLE bug. (inIdx is *not* checked for validity)
    """
    HASH_ONE = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

    if inIdx >= len(txTo.vin):
        return (HASH_ONE,
                "inIdx %d out of range (%d)" % (inIdx, len(txTo.vin)))
    txtmp = CTransaction(txTo)

    for txin in txtmp.vin:
        txin.scriptSig = b''
    txtmp.vin[inIdx].scriptSig = FindAndDelete(script,
                                               CScript([OP_CODESEPARATOR]))

    if (hashtype & 0x1f) == SIGHASH_NONE:
        txtmp.vout = []

        for i in range(len(txtmp.vin)):
            if i != inIdx:
                txtmp.vin[i].nSequence = 0

    elif (hashtype & 0x1f) == SIGHASH_SINGLE:
        outIdx = inIdx
        if outIdx >= len(txtmp.vout):
            return (HASH_ONE,
                    "outIdx %d out of range (%d)" % (outIdx, len(txtmp.vout)))

        tmp = txtmp.vout[outIdx]
        txtmp.vout = []
        for i in range(outIdx):
            txtmp.vout.append(CTxOut(-1))
        txtmp.vout.append(tmp)

        for i in range(len(txtmp.vin)):
            if i != inIdx:
                txtmp.vin[i].nSequence = 0

    if hashtype & SIGHASH_ANYONECANPAY:
        tmp = txtmp.vin[inIdx]
        txtmp.vin = []
        txtmp.vin.append(tmp)

    s = txtmp.serialize()
    s += struct.pack(b"<I", hashtype)

    hash = hash256(s)

    return (hash, None)
Beispiel #7
0
def create_coinbase(heightAdjust = 0):
    global counter
    coinbase = CTransaction()
    coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), 
                CScript([counter+heightAdjust, OP_0]), 0xffffffff))
    counter += 1
    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = int(12.5*100000000)
    halvings = int((counter+heightAdjust)/150) # regtest
    coinbaseoutput.nValue >>= halvings
    coinbaseoutput.scriptPubKey = ""
    coinbase.vout = [ coinbaseoutput ]
    if halvings == 0: # regtest
        froutput = CTxOut()
        froutput.nValue = coinbaseoutput.nValue / 5
        # regtest
        fraddr = bytearray([0x67, 0x08, 0xe6, 0x67, 0x0d, 0xb0, 0xb9, 0x50,
                            0xda, 0xc6, 0x80, 0x31, 0x02, 0x5c, 0xc5, 0xb6,
                            0x32, 0x13, 0xa4, 0x91])
        froutput.scriptPubKey = CScript([OP_HASH160, fraddr, OP_EQUAL])
        coinbaseoutput.nValue -= froutput.nValue
        coinbase.vout = [ coinbaseoutput, froutput ]
    coinbase.calc_sha256()
    return coinbase
Beispiel #8
0
def create_coinbase_h(block_height, halving_interval=2000, heightAdjust=0):

    subsidy = int(12.5 * 100000000)

    halvings = int((block_height + heightAdjust) //
                   halving_interval)  # 2000 is default for regtest
    subsidy >>= halvings

    coinbase = CTransaction()
    coinbase.vin.append(
        CTxIn(COutPoint(0, 0xffffffff),
              CScript([block_height + heightAdjust, OP_0]), 0xffffffff))

    coinbaseoutput = CTxOut()
    coinbaseoutput.nValue = subsidy

    coinbaseoutput.scriptPubKey = b""
    coinbase.vout.append(coinbaseoutput)

    found, supn, secn = get_coinbase_quotas(block_height)

    found_out = CTxOut()
    found_out.nValue = subsidy * found // 1000
    found_out.scriptPubKey = CScript([OP_HASH160, found_addr, OP_EQUAL])
    coinbaseoutput.nValue -= found_out.nValue
    coinbase.vout.append(found_out)

    if supn > 0:
        supn_out = CTxOut()
        supn_out.nValue = subsidy * supn // 1000
        supn_out.scriptPubKey = CScript([OP_HASH160, supn_addr, OP_EQUAL])
        coinbaseoutput.nValue -= supn_out.nValue
        coinbase.vout.append(supn_out)

    if secn > 0:
        secn_out = CTxOut()
        secn_out.nValue = subsidy * secn // 1000
        secn_out.scriptPubKey = CScript([OP_HASH160, secn_addr, OP_EQUAL])
        coinbaseoutput.nValue -= secn_out.nValue
        coinbase.vout.append(secn_out)

    coinbase.calc_sha256()
    return coinbase