Exemplo n.º 1
0
def get_state(deck):
    '''return balances of this deck'''

    cards = pa.find_card_transfers(provider, deck)
    if cards:
        return pa.DeckState(cards)
    else:
        raise ValueError("No cards on this deck.")
Exemplo n.º 2
0
def test_find_cards():

    provider = pa.Cryptoid(network="tppc")

    deck = pa.find_deck(provider, 'b6a95f94fef093ee9009b04a09ecb9cb5cba20ab6f13fe0926aeb27b8671df43', 1)

    cards = pa.find_card_transfers(provider, deck)

    assert cards
    assert isinstance(cards[0], pa.CardTransfer)
Exemplo n.º 3
0
def export(deck_id, filename):
    ''' export cards to csv <filename> '''

    deck = find_deck(deck_id)

    if not provider.getaddressesbyaccount(deck.asset_id):
        throw("You must subscribe to deck to be able to list transactions.")

    all_cards = pa.find_card_transfers(provider, deck)
    cards = pa.validate_card_issue_modes(deck, all_cards)

    export_to_csv(cards, filename)
Exemplo n.º 4
0
def list(deck_id):
    '''List cards of this <deck>'''
    deck = find_deck(deck_id)

    if isinstance(provider, pa.RpcNode):
        if not provider.getaddressesbyaccount(deck.asset_id):
            print(
                "\n", {
                    "error":
                    "You must subscribe to deck to be able to list transactions."
                })
            return
    all_cards = pa.find_card_transfers(provider, deck)

    if not all_cards:
        print("\n", "No cards have been issued for deck %s" % deck.asset_id)
        return

    cards = pa.validate_card_issue_modes(deck, all_cards)
    print_card_list(cards)
Exemplo n.º 5
0
def init_decks():
    n = 0

    def message(n):
        sys.stdout.flush()
        sys.stdout.write('{} Decks Loaded\r'.format(n))

    def add_deck(deck):
        if deck is not None:
            entry = db.session.query(Deck).filter(Deck.id == deck.id).first()
            subscribe = deck.id in subscribed
            if not entry:
                try:
                    D = Deck(deck.id, deck.name, deck.issuer, deck.issue_mode,
                             deck.number_of_decimals, subscribe)
                    db.session.add(D)
                    db.session.commit()
                except Exception as e:
                    print(e)
                    pass
            else:
                db.session.query(Deck).filter(Deck.id == deck.id).update(
                    {"subscribed": subscribe})
                db.session.commit()

    def add_cards(cards):
        if cards is not None:
            for cardset in cards:
                for card in cardset:
                    sys.stdout.write(card.txid + '\r')
                    sys.stdout.flush()
                    card_id = card.txid + str(card.blockseq) + str(
                        card.cardseq)
                    entry = db.session.query(Card).filter(
                        Card.id == card_id).first()
                    if not entry:
                        C = Card(card_id, card.txid, card.cardseq,
                                 card.receiver[0], card.sender, card.amount[0],
                                 card.type, card.blocknum, card.blockseq,
                                 card.deck_id)
                        db.session.add(C)
                    db.session.commit()
            sys.stdout.flush()

    if not autoload:
        decks = [pa.find_deck(node, txid, version)[0] for txid in subscribed]

        for deck in decks:
            if deck is not None:
                add_deck(deck)
                add_cards(pa.find_card_transfers(node, deck))
                n += 1
                message(n)

    else:
        decks = pa.find_all_valid_decks(node, 1, True)
        while True:
            try:
                deck = next(decks)
                add_deck(deck)
                if deck.id in subscribed:
                    add_cards(pa.find_card_transfers(node, deck))
                n += 1
                message(n)
            except StopIteration:
                break
Exemplo n.º 6
0
def total_burns():
    return len([
        ct for ct in pa.find_card_transfers(provider, deck)
        if ct.type is "CardBurn"
    ])
Exemplo n.º 7
0
def total_issuance():
    return len([
        ct for ct in pa.find_card_transfers(provider, deck)
        if ct.type is "CardIssue"
    ])
Exemplo n.º 8
0
def get_state(deck):
    deck = pa.find_deck(provider,deck)[0]
    cards = pa.find_card_transfers(provider,deck)
    return DeckState(cards)
Exemplo n.º 9
0
'''
Find card transfers for <deck>.
'''

import sys
import pypeerassets as pa
provider = pa.RpcNode(testnet=True)

print("Searching for deck {deck}.".format(deck=sys.argv[1]))
deck = pa.find_deck(provider, sys.argv[1])[0]
cards = pa.find_card_transfers(provider, deck)

print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print(
    "This deck issuer has issued: {cards} cards in {transfers} card issue transactions."
    .format(cards=round(
        sum((i.amount[0] for i in cards if i.type == "CardIssue")),
        deck.number_of_decimals),
            transfers=len([i for i in cards if i.type == "CardIssue"])))

print(
    "Peers on this deck have transacted {cards} cards in {transfers} card transactions."
    .format(cards=round(
        sum((i.amount[0] for i in cards if i.type == "CardTransfer")),
        deck.number_of_decimals),
            transfers=len([i for i in cards if i.type == "CardTransfer"])))

print(
    "Peers on this deck have burned {cards} cards in {transfers} card transactions."
    .format(cards=round(
        sum((i.amount[0] for i in cards if i.type == "CardBurn")),