<commit_before>inset('btcSpecialTx.py')

data owner
data trustedBtcRelay
data btcAcceptAddr

# records txs that have successfully claimed Ether (thus not allowed to re-claim)
data txClaim[2^256]


# TODO remove when not testing, since owners should create another copy of this
# contract if they want to get paid to a different btcAddr
def testingonlySetBtcAddr(btcAddr):
    if tx.origin == self.owner:
        self.btcAcceptAddr = btcAddr
        return(1)
    return(0)

def shared():
    BTC_NEED = 5 * 10**8 # satoshis
    MY_BTC_ADDR = 0xc398efa9c392ba6013c5e04ee729755ef7f58b32  # testable with tx[1] from block100K
    ETH_TO_SEND = 13  # wei

def init():
    self.owner = msg.sender
    self.btcAcceptAddr = MY_BTC_ADDR

# trustedRelayContract is the address of the trusted btcrelay contract
def setTrustedBtcRelay(trustedRelayContract):
    if tx.origin == self.owner:
        self.trustedBtcRelay = trustedRelayContract
        return(1)
    return(0)


# returns 0 if contract conditions are not met.
# returns the value of send() if they are met (typically send() returns 1 on success)
# callers should probably explicitly check for a return value of 1 for success,
# to protect against the possibility of send() returning non-zero error codes
def processTransaction(txStr:str, txHash):
    # apart from trustedBtcRelay, only the owner may claim ether
    if msg.sender != self.trustedBtcRelay:
        if tx.origin != self.owner:  # tx.origin is superset of msg.sender, so no need for checking msg.sender==self.owner
            return(0)

    # only the owner may reclaim; trustedBtcRelay and others can NOT reclaim
    if self.txClaim[txHash] != 0:
        if tx.origin != self.owner:  # allow owner to keep reclaiming (helpful in testing)
            return(0)

    outputData = self.getFirst2Outputs(txStr, outitems=3)

    if outputData == 0:
        return(0)

    numSatoshi = outputData[0]
    indexScriptOne = outputData[1]

    #TODO strictly compare the script because an attacker may have a script that mentions
    #our BTC address, but the BTC is not spendable by our private key (only spendable by attacker's key)
    # btcWasSentToMe = compareScriptWithAddr(indexScriptOne, txStr, self.btcAcceptAddr)
    addrBtcWasSentTo = getEthAddr(indexScriptOne, txStr, 20, 6)

    btcWasSentToMe = addrBtcWasSentTo == self.btcAcceptAddr


    indexScriptTwo = outputData[2]
    ethAddr = getEthAddr(indexScriptTwo, txStr, 20, 6)
    # log(ethAddr)  # exp 848063048424552597789830156546485564325215747452L

    # expEthAddr = text("948c765a6914d43f2a7ac177da2c2f6b52de3d7c")

    if (btcWasSentToMe && numSatoshi >= BTC_NEED):
        res = send(ethAddr, ETH_TO_SEND)
        self.txClaim[txHash] = res
        log(msg.sender, data=[res])
        return(res)

    return(0)<commit_msg>need log() for all paths for frontend; mBTC for testnet<commit_after>inset('btcSpecialTx.py')

data owner
data trustedBtcRelay
data btcAcceptAddr

# records txs that have successfully claimed Ether (thus not allowed to re-claim)
data txClaim[2^256]


# TODO remove when not testing, since owners should create another copy of this
# contract if they want to get paid to a different btcAddr
def testingonlySetBtcAddr(btcAddr):
    if tx.origin == self.owner:
        self.btcAcceptAddr = btcAddr
        return(1)
    return(0)

def shared():
    BTC_NEED = 1700000 # 1.7mBTC for btcTestnet
    # BTC_NEED = 5 * 10**8 # satoshis
    MY_BTC_ADDR = 0xc398efa9c392ba6013c5e04ee729755ef7f58b32  # testable with tx[1] from block100K
    ETH_TO_SEND = 13  # wei

def init():
    self.owner = msg.sender
    self.btcAcceptAddr = MY_BTC_ADDR

# trustedRelayContract is the address of the trusted btcrelay contract
def setTrustedBtcRelay(trustedRelayContract):
    if tx.origin == self.owner:
        self.trustedBtcRelay = trustedRelayContract
        return(1)
    return(0)


# returns 0 if contract conditions are not met.
# returns the value of send() if they are met (typically send() returns 1 on success)
# callers should probably explicitly check for a return value of 1 for success,
# to protect against the possibility of send() returning non-zero error codes
def processTransaction(txStr:str, txHash):
    # apart from trustedBtcRelay, only the owner may claim ether
    if msg.sender != self.trustedBtcRelay:
        if tx.origin != self.owner:  # tx.origin is superset of msg.sender, so no need for checking msg.sender==self.owner
            log(msg.sender, data=[-10])
            return(0)

    # only the owner may reclaim; trustedBtcRelay and others can NOT reclaim
    if self.txClaim[txHash] != 0:
        if tx.origin != self.owner:  # allow owner to keep reclaiming (helpful in testing)
            log(msg.sender, data=[-20])
            return(0)

    outputData = self.getFirst2Outputs(txStr, outitems=3)

    if outputData == 0:
        log(msg.sender, data=[-30])
        return(0)

    numSatoshi = outputData[0]
    indexScriptOne = outputData[1]

    #TODO strictly compare the script because an attacker may have a script that mentions
    #our BTC address, but the BTC is not spendable by our private key (only spendable by attacker's key)
    # btcWasSentToMe = compareScriptWithAddr(indexScriptOne, txStr, self.btcAcceptAddr)
    addrBtcWasSentTo = getEthAddr(indexScriptOne, txStr, 20, 6)

    btcWasSentToMe = addrBtcWasSentTo == self.btcAcceptAddr


    indexScriptTwo = outputData[2]
    ethAddr = getEthAddr(indexScriptTwo, txStr, 20, 6)
    # log(ethAddr)  # exp 848063048424552597789830156546485564325215747452L

    # expEthAddr = text("948c765a6914d43f2a7ac177da2c2f6b52de3d7c")

    if (btcWasSentToMe && numSatoshi >= BTC_NEED):
        res = send(ethAddr, ETH_TO_SEND)
        self.txClaim[txHash] = res
        log(msg.sender, data=[res])
        return(res)

    log(msg.sender, data=[-100])
    return(0)
{'fraction_non_alphanumeric': 0.07987001881306653, 'fraction_numerical': 0.049598084487771504, 'mean_word_length': 3.5723221266614544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '466861', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1876, 'n_words': 575}