Exemplo n.º 1
0
def find_txn_on_zcash_explorer(contribution):

    subscription = contribution.subscription
    grant = subscription.grant
    token_symbol = subscription.token_symbol

    if subscription.tenant != 'ZCASH':
        return None

    if token_symbol != 'ZEC':
        return None

    to_address = grant.zcash_payout_address
    from_address = subscription.contributor_address
    amount = subscription.amount_per_period

    url = f'https://sochain.com/api/v2/address/ZEC/{from_address}'
    response = requests.get(url).json()

    # Check contributors txn history
    if response['status'] == 'success' and response['data'] and response[
            'data']['txs']:
        txns = response['data']['txs']

        for txn in txns:
            if txn.get('outgoing') and txn['outgoing']['outputs']:
                for output in txn['outgoing']['outputs']:
                    if contribution.tx_id and contribution.tx_id != '0x0':
                        if txn['txid'] == contribution.tx_id:
                            if (output['address'] == to_address
                                    and float(output['value']) == float(amount)
                                    and is_txn_done_recently(txn['time'])):
                                return txn['txid']
                    else:
                        if (output['address'] == to_address
                                and response['data']['address'] == from_address
                                and float(output['value']) == float(amount)
                                and is_txn_done_recently(txn['time'])
                                and not txn_already_used(
                                    txn['txid'], token_symbol)):
                            return txn['txid']

    url = f'https://sochain.com/api/v2/address/ZEC/{to_address}'
    response = requests.get(url).json()

    # Check funders txn history
    # if response['status'] == 'success' and response['data'] and response['data']['txs']:
    #     txns = response['data']['txs']
    #     for txn in txns:
    #         if txn.get('incoming') and txn['incoming']['inputs']:
    #             for input_tx in txn['incoming']['inputs']:
    #                 if (
    #                     input_tx['address'] == from_address and
    #                     response['data']['address'] == to_address and
    #                     is_txn_done_recently(txn['time']) and
    #                     not txn_already_used(txn['txid'], token_symbol)
    #                 ):
    #                     return txn['txid']
    return None
Exemplo n.º 2
0
def find_txn_on_zil_explorer(contribution):

    subscription = contribution.subscription
    grant = subscription.grant
    token_symbol = subscription.token_symbol

    if subscription.tenant != 'ZIL':
        return None

    if token_symbol != 'ZIL':
        return None

    to_address = grant.zil_payout_address
    from_address = subscription.contributor_address
    amount = subscription.amount_per_period

    url = f'https://api.viewblock.io/v1/zilliqa/addresses/{to_address}/txs?network=mainnet'
    response = requests.get(url, headers=headers).json()

    if len(response):
        for txn in response:
            if (
                txn['from'] == from_address.lower() and
                txn['to'] == to_address.lower() and
                txn['direction'] == 'in' and
                float(txn['value']) / 10 ** DECIMALS == float(amount) and
                is_txn_done_recently(txn['timestamp']/1000) and
                not txn_already_used(txn['hash'], token_symbol)
            ):
                return txn['hash']
    return None
Exemplo n.º 3
0
def is_valid_zcash_txn(contribution):

    subscription = contribution.subscription
    grant = subscription.grant

    txn_id = contribution.tx_id
    to_address = grant.zcash_payout_address
    amount = subscription.amount_per_period
    token_symbol = subscription.token_symbol

    if not txn_id or txn_id == '0x0':
        return None

    url = f'https://sochain.com/api/v2/tx/ZEC/{txn_id}'

    response = requests.get(url).json()

    if (response['status'] == 'success' and response['data']
            and response['data']['outputs']):
        for txn in response['data']['outputs']:
            if (txn['address'] == to_address
                    and float(txn['value']) == float(amount)
                    and is_txn_done_recently(response['data']['time'])
                    and not txn_already_used(txn_id, token_symbol)):
                return True

    return None
Exemplo n.º 4
0
def find_txn_on_celo_explorer(contribution):

    subscription = contribution.subscription
    grant = subscription.grant
    token_symbol = subscription.token_symbol

    if subscription.tenant != 'CELO':
        return None

    if token_symbol != 'cUSD' and token_symbol != 'CELO':
        return None

    to_address = grant.celo_payout_address
    from_address = subscription.contributor_address
    amount = subscription.amount_per_period

    blockscout_url = f'https://explorer.celo.org/api?module=account&action=tokentx&address={to_address}'
    blockscout_response = requests.get(blockscout_url).json()

    if blockscout_response['message'] and blockscout_response['result']:
        for txn in blockscout_response['result']:
            if (txn['from'] == from_address.lower()
                    and txn['to'] == to_address.lower() and
                    int(txn['value']) / 10**int(txn['tokenDecimal']) == amount
                    and is_txn_done_recently(txn['timeStamp'])
                    and not txn_already_used(txn['hash'], token_symbol)):
                return txn['hash']
    return None