예제 #1
0
    def transfer(self,
                 deckid: str,
                 receiver: list = None,
                 amount: list = None,
                 asset_specific_data: str = None,
                 locktime: int = 0,
                 verify: bool = False,
                 sign: bool = False,
                 send: bool = False) -> str:
        '''prepare CardTransfer transaction'''

        card = self.__new(deckid, receiver, amount, asset_specific_data)

        issue = pa.card_transfer(provider=provider,
                                 inputs=provider.select_inputs(
                                     Settings.key.address, 0.02),
                                 card=card,
                                 change_address=Settings.change,
                                 locktime=locktime)

        if verify:
            return cointoolkit_verify(
                issue.hexlify())  # link to cointoolkit - verify

        if sign:

            tx = signtx(issue)

            if send:
                return sendtx(tx)

            return tx.hexlify()

        return issue.hexlify()
예제 #2
0
def c_transfer():
    '''simulate p2p card_transfer'''
    print("Card burn.")

    addr = select_random_address()
    print("Selected addr: {addr}".format(addr=addr))
    if not provider.validateaddress(addr)["ismine"]:
        provider.importprivkey(keypairs[addr])
        print("Imported {address} to wallet.".format(address=addr))
    if provider.getreceivedbyaddress(addr) == 0:
        send_to_address(addr)
        return  ## return until the next time
    else:
        try:
            utxo = provider.select_inputs(0.02, addr)
        except Exception as e:
            print("Something went wrong with UTXO selection:", e)
            return

    receiver = select_random_keypairs()
    amount = [
        round(random.uniform(0.1, 160000), deck.number_of_decimals)
        for i in range(len(receiver))
    ]
    ct = pa.CardTransfer(deck, receiver, amount)  # CardTransfer instance
    raw = hexlify(pa.card_transfer(deck, ct, utxo, change_addr)).decode()
    signed = provider.signrawtransaction(raw)
    print("Sending cards to: {0}".format(receiver))
    logging.info("Transfer: {0}".format(datetime.datetime.now().isoformat()))
    logging.info("Sending cards to: {0}".format(receiver))
    txid = provider.sendrawtransaction(signed["hex"])  # send the tx
    print(txid)
    Session.total_issuance = +1
예제 #3
0
파일: __main__.py 프로젝트: saeveritt/pacli
def card_transfer(provider, args):
    '''
    Transfer cards to <receivers>

    pacli card -transfer '{"deck": "deck_id",
                        "receivers": [list of receiver addresses], "amounts": [list of amounts]
                        }
    '''

    args = json.loads(args)
    try:
        deck = pa.find_deck(provider, args["deck"])[0]
    except IndexError:
        print({"error": "Deck not found!"})
        return
    if not provider.getaddressesbyaccount(deck.name):
        print(
            "\n", {
                "error":
                "You are not even subscribed to this deck, how can you transfer cards?"
            })

    utxo = provider.select_inputs(0.02)
    change_address = change(utxo)
    args["amounts"] = [float(i) for i in args["amounts"]]
    ct = pa.CardTransfer(deck, args["receivers"], args["amounts"])
    raw_ct = hexlify(
        pa.card_transfer(deck, ct, utxo, change_address,
                         Settings.prod)).decode()

    signed = provider.signrawtransaction(raw_ct)
    print("\n", provider.sendrawtransaction(signed["hex"]),
          "\n")  # send the tx
예제 #4
0
파일: card.py 프로젝트: micimize/pacli
def transfer_cards(deck, receivers, amounts, broadcast):
    validate_transfer(deck, amounts)
    utxo = provider.select_inputs(0.02)

    change_address = change(utxo)
    ct = pa.CardTransfer(deck=deck, receiver=receivers, amount=amounts)
    handle_transaction(pa.card_transfer(deck, ct, utxo, change_address),
                       broadcast)
예제 #5
0
def test_card_transfer():

    provider = Explorer(network='tppc')
    address = "mthKQHpr7zUbMvLcj8GHs33mVcf91DtN6L"
    inputs = provider.select_inputs(address, 0.02)
    change_address = address
    deck = pa.find_deck(provider,
                         '078f41c257642a89ade91e52fd484c141b11eda068435c0e34569a5dfcce7915',
                         1, True)
    card = pa.CardTransfer(deck=deck,
                           receiver=['n12h8P5LrVXozfhEQEqg8SFUmVKtphBetj',
                                     'n422r6tcJ5eofjsmRvF6TcBMigmGbY5P7E'],
                           amount=[1, 2]
                           )

    card_transfer = pa.card_transfer(provider, card, inputs, change_address,
                                     locktime=300000)

    assert isinstance(card_transfer, Transaction)
예제 #6
0
    def transfer(self,
                 deckid: str,
                 receiver: list = None,
                 amount: list = None,
                 asset_specific_data: str = None,
                 verify=False) -> str:
        '''prepare CardTransfer transaction'''

        card = self.__new(deckid, receiver, amount, asset_specific_data)

        issue = pa.card_transfer(provider=provider,
                                 inputs=provider.select_inputs(
                                     Settings.key.address, 0.02),
                                 card=card,
                                 change_address=Settings.change)

        if verify:
            return cointoolkit_verify(
                issue.hexlify())  # link to cointoolkit - verify

        return issue.hexlify()
예제 #7
0
    print("Found the Friendly Co. Deck!")

    # Card Issue

    print("Build, sign and send the Card Issue transaction to Alice...")

    card_transfer = pa.CardTransfer(
        deck=deck,
        receiver=[ALICE],
        amount=[1000000],
        sender=FRIENDLY_CO,
    )

    card_transfer_tx = pa.card_transfer(
        provider=rpc_node,
        card=card_transfer,
        inputs=rpc_node.select_inputs(FRIENDLY_CO, 0.02),
        change_address=FRIENDLY_CO,
    )
    card_transfer_tx = sign_transaction(rpc_node, card_transfer_tx, friendly_co_key)
    rpc_node.sendrawtransaction(card_transfer_tx.hexlify())

    print("Transaction to issue Friendly Co. Cards sent to the network!")
    print("Transaction ID: " + card_transfer_tx.txid)
    print("Waiting for confirmation...")
    wait_for_confirmation(rpc_node, card_transfer_tx.txid)
    print("Friendly Co. Cards created!")

    print("Double checking the Friendly Co. Deck State...")
    cards = pa.find_all_valid_cards(rpc_node, deck)
    deck_state = pa.DeckState(cards)
    assert len(deck_state.balances) == 1, "Only Alice should have Friendly Co. Cards."