예제 #1
0
def find_vote_casts(provider: Provider, vote: Vote,
                    choice_index: int) -> Iterable[VoteCast]:
    '''find and verify vote_casts on this vote_choice_address'''

    vote_casts = provider.listtransactions(
        vote.vote_choice_address[choice_index])
    for tx in vote_casts:
        raw_tx = provider.getrawtransaction(tx, 1)

        sender = find_tx_sender(provider, raw_tx)
        confirmations = raw_tx["confirmations"]
        blocknum = provider.getblock(raw_tx["blockhash"])["height"]
        yield VoteCast(vote, sender, blocknum, confirmations,
                       raw_tx["blocktime"])
예제 #2
0
def card_bundler(provider: Provider, deck: Deck, tx: dict) -> CardBundle:
    '''each blockchain transaction can contain multiple cards,
       wrapped in bundles. This method finds and returns those bundles.'''

    return CardBundle(deck=deck,
                      blockhash=tx['blockhash'],
                      txid=tx['txid'],
                      timestamp=tx['time'],
                      blockseq=tx_serialization_order(provider,
                                                      tx["blockhash"],
                                                      tx["txid"]),
                      blocknum=provider.getblock(tx["blockhash"])["height"],
                      sender=find_tx_sender(provider, tx),
                      vouts=tx['vout'],
                      tx_confirmations=tx['confirmations'])
예제 #3
0
def find_card_bundles(provider: Provider, deck: Deck) -> Optional[Iterator]:
    '''each blockchain transaction can contain multiple cards,
       wrapped in bundles. This method finds and returns those bundles.'''

    if isinstance(provider, RpcNode):
        if deck.id is None:
            raise Exception("deck.id required to listtransactions")

        batch_data = [('getrawtransaction', [i["txid"], 1]) for
                      i in provider.listtransactions(deck.id)]
        result = provider.batch(batch_data)

        if result is not None:
            raw_txns = [i['result'] for i in result if result]

        else:
            raise EmptyP2THDirectory({'error': 'No cards found on this deck.'})

    else:
        if deck.p2th_address is None:
            raise Exception("deck.p2th_address required to listtransactions")

        try:
            raw_txns = (provider.getrawtransaction(i, 1) for i in
                        provider.listtransactions(deck.p2th_address))
        except TypeError:
            raise EmptyP2THDirectory({'error': 'No cards found on this deck.'})

    return (CardBundle(deck=deck,
                       blockhash=i['blockhash'],
                       txid=i['txid'],
                       timestamp=i['time'],
                       blockseq=tx_serialization_order(provider, i["blockhash"],
                                                       i["txid"]),
                       blocknum=provider.getblock(i["blockhash"])["height"],
                       sender=find_tx_sender(provider, i),
                       vouts=i['vout'],
                       tx_confirmations=i['confirmations']
                       ) for i in raw_txns)
예제 #4
0
def tx_serialization_order(provider: Provider, blockhash: str,
                           txid: str) -> int:
    '''find index of this tx in the blockid'''

    return provider.getblock(blockhash)["tx"].index(txid)