예제 #1
0
    def _get_live_data(self):
        txs_pending = BrsApi(settings.BRS_NODE).get_unconfirmed_transactions()

        for t in txs_pending:
            t["timestamp"] = datetime.fromtimestamp(t["timestamp"] +
                                                    BLOCK_CHAIN_START_AT)
            t["amountNQT"] = int(t["amountNQT"])
            t["feeNQT"] = int(t["feeNQT"])
            t["sender_name"] = get_account_name(int(t["sender"]))

            if "recipient" in t:
                t["recipient_exists"] = (
                    Account.objects.using("java_wallet").filter(
                        id=t["recipient"]).exists())
                if t["recipient_exists"]:
                    t["recipient_name"] = get_account_name(int(t["recipient"]))

            if "attachment" in t and "recipients" in t["attachment"]:
                t["multiout"] = len(t["attachment"]["recipients"])

                for i, x in enumerate(t["attachment"]["recipients"]):
                    if t["subtype"] == TxSubtypePayment.MULTI_OUT:
                        t["attachment"]["recipients"][i] = [
                            int(x[0]), int(x[1])
                        ]
                    elif t["subtype"] == TxSubtypePayment.MULTI_OUT_SAME:
                        t["attachment"]["recipients"][i] = int(x)

            t["tx_name"] = get_desc_tx_type(t["type"], t["subtype"])

        txs_pending.sort(key=lambda _x: _x["feeNQT"], reverse=True)

        return txs_pending
예제 #2
0
def fill_data_block(obj):
    obj.txs_cnt = get_txs_count_in_block(obj.id)
    obj.generator_name = get_account_name(obj.generator_id)
    pool_id = get_pool_id_for_block(obj)
    if pool_id:
        obj.pool_id = pool_id
        obj.pool_name = get_account_name(pool_id)
예제 #3
0
def fill_data_transaction(obj, list_page=True):
    obj.sender_name = get_account_name(obj.sender_id)
    if obj.recipient_id:
        obj.recipient_name = get_account_name(obj.recipient_id)

    if obj.type == 0 and obj.subtype in {1, 2}:
        v, obj.multiout = MultiOutPack().unpack_header(obj.attachment_bytes)
        if not list_page:
            obj.recipients = MultiOut.objects.filter(tx_id=obj.id).all()
예제 #4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        # total count
        context["purchases_cnt"] = self.filter_set.qs.count()
        obj = context[self.context_object_name]
        for purchase in obj:
            purchase.seller_name = get_account_name(purchase.seller_id)
            purchase.buyer_name = get_account_name(purchase.buyer_id)

        return context
예제 #5
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        obj = context[self.context_object_name]
        for t in obj:
            t.account_name = get_account_name(t.account_id)

        return context
예제 #6
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        obj = context[self.context_object_name]
        obj.account_name = get_account_name(obj.account_id)

        # assets transfer

        assets_transfers = (AssetTransfer.objects.using("java_wallet").using(
            "java_wallet").filter(asset_id=obj.id).order_by("-height")[:15])

        for transfer in assets_transfers:
            fill_data_asset_transfer(transfer)

        context["assets_transfers"] = assets_transfers
        context["assets_transfers_cnt"] = (
            AssetTransfer.objects.using("java_wallet").filter(
                asset_id=obj.id).count())

        # assets trades

        assets_trades = (
            Trade.objects.using("java_wallet").using("java_wallet").filter(
                asset_id=obj.id).order_by("-height")[:15])

        for trade in assets_trades:
            fill_data_asset_trade(trade)

        context["assets_trades"] = assets_trades
        context["assets_trades_cnt"] = (
            Trade.objects.using("java_wallet").filter(asset_id=obj.id).count())
        return context
예제 #7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        obj = context[self.context_object_name]
        obj.seller_name = get_account_name(obj.seller_id)
        purchases = (
            Purchase.objects.using("java_wallet").using("java_wallet").filter(
                goods_id=obj.id).order_by("-height")[:15])

        for purchase in purchases:
            purchase.buyer_name = get_account_name(purchase.buyer_id)

        context["purchases"] = purchases
        context["purchases_cnt"] = (
            Purchase.objects.using("java_wallet").filter(
                goods_id=obj.id).count())

        return context
예제 #8
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        obj = context[self.context_object_name]

        # transactions

        txs = (Transaction.objects.using("java_wallet").filter(
            Q(sender_id=obj.id)
            | Q(recipient_id=obj.id)).order_by("-height")[:15])

        for t in txs:
            fill_data_transaction(t, list_page=True)

        context["txs"] = txs
        context["txs_cnt"] = (Transaction.objects.using("java_wallet").filter(
            Q(sender_id=obj.id) | Q(recipient_id=obj.id)).count())

        # multiouts

        mos = MultiOut.objects.filter(
            Q(sender_id=obj.id)
            | Q(recipient_id=obj.id)).order_by("-height")[:15]

        for t in mos:
            fill_data_multiouts(t)

        context["mos"] = mos
        context["mos_cnt"] = MultiOut.objects.filter(
            Q(sender_id=obj.id) | Q(recipient_id=obj.id)).count()

        # assets

        assets = (AccountAsset.objects.using("java_wallet").filter(
            account_id=obj.id, latest=True).order_by("-db_id"))

        for asset in assets:
            asset.name, asset.decimals, asset.total_quantity = get_asset_details(
                asset.asset_id)

        context["assets"] = assets
        context["assets_cnt"] = (
            AccountAsset.objects.using("java_wallet").filter(
                account_id=obj.id, latest=True).count())

        # assets transfer

        assets_transfers = (
            AssetTransfer.objects.using("java_wallet").using("java_wallet").
            filter(Q(sender_id=obj.id)
                   | Q(recipient_id=obj.id)).order_by("-height")[:15])

        for transfer in assets_transfers:
            fill_data_asset_transfer(transfer)

        context["assets_transfers"] = assets_transfers
        context["assets_transfers_cnt"] = (
            AssetTransfer.objects.using("java_wallet").filter(
                Q(sender_id=obj.id) | Q(recipient_id=obj.id)).count())

        # assets trades

        assets_trades = (
            Trade.objects.using("java_wallet").using("java_wallet").filter(
                Q(buyer_id=obj.id)
                | Q(seller_id=obj.id)).order_by("-height")[:15])

        for trade in assets_trades:
            fill_data_asset_trade(trade)

        context["assets_trades"] = assets_trades
        context["assets_trades_cnt"] = (Trade.objects.using(
            "java_wallet").filter(Q(buyer_id=obj.id)
                                  | Q(seller_id=obj.id)).count())

        # pool info

        pool_id = get_pool_id_for_account(obj.id)
        if pool_id:
            obj.pool_id = pool_id
            obj.pool_name = get_account_name(pool_id)

        # blocks

        mined_blocks = (Block.objects.using("java_wallet").filter(
            generator_id=obj.id).order_by("-height")[:15])

        for block in mined_blocks:
            pool_id = get_pool_id_for_block(block)
            if pool_id:
                block.pool_id = pool_id
                block.pool_name = get_account_name(pool_id)

        context["mined_blocks"] = mined_blocks
        context["mined_blocks_cnt"] = (
            Block.objects.using("java_wallet").filter(
                generator_id=obj.id).count())

        return context
예제 #9
0
def fill_data_asset_trade(trade):
    trade.name, trade.decimals, trade.total_quantity = get_asset_details(
        trade.asset_id)
    trade.buyer_name = get_account_name(trade.buyer_id)
    trade.seller_name = get_account_name(trade.seller_id)
예제 #10
0
def fill_data_asset_transfer(transfer):
    transfer.name, transfer.decimals, transfer.total_quantity = get_asset_details(
        transfer.asset_id)
    transfer.sender_name = get_account_name(transfer.sender_id)
    transfer.recipient_name = get_account_name(transfer.recipient_id)
예제 #11
0
def fill_data(obj):
    obj.creator_name = get_account_name(obj.creator_id)
예제 #12
0
def fill_data_multiouts(obj):
    obj.sender_name = get_account_name(obj.sender_id)
    if obj.recipient_id:
        obj.recipient_name = get_account_name(obj.recipient_id)