<commit_before># This file is an optimized version of btcTx.py for retrieving
# the first 2 outputs of a Bitcoin transaction.
# It is tested via test_btc-eth.py

# read the VarInt and advance the cursor
macro parseVarInt($txStr, $cursor):
    $arr = getVarintNum($txStr, $cursor)
    $cursor += $arr[0]
    $arr[1]


# return 0 if tx has less than 2 outputs
# or other error, otherwise return array
# of [out1stSatoshis, out1stScriptIndex, out2ndScriptSize]
def getFirst2Outputs(txStr:str):
    cursor = 4  # skip version

    numIns = parseVarInt(txStr, cursor)
    # log(numIns)
    # log(cursor)

    i = 0
    while i < numIns:
        cursor += 36  # skip prevTxId (32) and outputIndex (4)

        scriptSize = parseVarInt(txStr, cursor)
        cursor += scriptSize + 4  # skip input script and seqNum (4)

        i += 1

    numOuts = parseVarInt(txStr, cursor)
    if numOuts < 2:
        return(0)


    ###########################################################
    # 1st output
    tmpArr = getUInt64LE(txStr, cursor)
    cursor += 8
    out1stSatoshis = tmpArr[1]

    # log(satoshis)

    scriptSize = parseVarInt(txStr, cursor)
    # log(scriptSize)

    if scriptSize == 0:
        return(0)

    out1stScriptIndex = cursor
    cursor += scriptSize + 8  # skip script and 2nd output's satoshis (8)
    ###########################################################



    ###########################################################
    # 2nd output (satoshis were already skipped in previous line)

    scriptSize = parseVarInt(txStr, cursor)
    # log(scriptSize)

    if scriptSize == 0:
        return(0)

    out2ndScriptIndex = cursor
    ###########################################################

    return([out1stSatoshis, out1stScriptIndex, out2ndScriptIndex], items=3)



macro getVarintNum($txStr, $pos):
    $ret = getUInt8($txStr, $pos)
    if $ret == 0xfd:
        $ret = getUInt16LE($txStr, $pos)
    elif $ret == 0xfe:
        $ret = getUInt32LE($txStr, $pos)
    elif $ret == 0xff:
        $ret = getUInt64LE($txStr, $pos)

    $ret

macro getUInt8($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 8, outitems=2)


macro getUInt16LE($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 16, outitems=2)


macro getUInt32LE($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 32, outitems=2)

<commit_msg>fix Warning: function return type inconsistent<commit_after># This file is an optimized version of btcTx.py for retrieving
# the first 2 outputs of a Bitcoin transaction.
# It is tested via test_btc-eth.py

# read the VarInt and advance the cursor
macro parseVarInt($txStr, $cursor):
    $arr = getVarintNum($txStr, $cursor)
    $cursor += $arr[0]
    $arr[1]


# return 0 if tx has less than 2 outputs
# or other error, otherwise return array
# of [out1stSatoshis, out1stScriptIndex, out2ndScriptSize]
def getFirst2Outputs(txStr:str):
    cursor = 4  # skip version

    numIns = parseVarInt(txStr, cursor)
    # log(numIns)
    # log(cursor)

    i = 0
    while i < numIns:
        cursor += 36  # skip prevTxId (32) and outputIndex (4)

        scriptSize = parseVarInt(txStr, cursor)
        cursor += scriptSize + 4  # skip input script and seqNum (4)

        i += 1

    numOuts = parseVarInt(txStr, cursor)
    if numOuts < 2:
        return


    ###########################################################
    # 1st output
    tmpArr = getUInt64LE(txStr, cursor)
    cursor += 8
    out1stSatoshis = tmpArr[1]

    # log(satoshis)

    scriptSize = parseVarInt(txStr, cursor)
    # log(scriptSize)

    if scriptSize == 0:
        return

    out1stScriptIndex = cursor
    cursor += scriptSize + 8  # skip script and 2nd output's satoshis (8)
    ###########################################################



    ###########################################################
    # 2nd output (satoshis were already skipped in previous line)

    scriptSize = parseVarInt(txStr, cursor)
    # log(scriptSize)

    if scriptSize == 0:
        return

    out2ndScriptIndex = cursor
    ###########################################################

    return([out1stSatoshis, out1stScriptIndex, out2ndScriptIndex], items=3)



macro getVarintNum($txStr, $pos):
    $ret = getUInt8($txStr, $pos)
    if $ret == 0xfd:
        $ret = getUInt16LE($txStr, $pos)
    elif $ret == 0xfe:
        $ret = getUInt32LE($txStr, $pos)
    elif $ret == 0xff:
        $ret = getUInt64LE($txStr, $pos)

    $ret

macro getUInt8($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 8, outitems=2)


macro getUInt16LE($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 16, outitems=2)


macro getUInt32LE($txStr, $pos):
    self.getUnsignedBitsLE($txStr, $pos, 32, outitems=2)


{'fraction_non_alphanumeric': 0.19868810833685993, 'fraction_numerical': 0.026449428692340245, 'mean_word_length': 3.4095149253731343, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2065186', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1500, 'n_words': 411}