Ejemplo n.º 1
0
def check_enc(context):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = os.path.dirname(os.path.dirname(dir_path))
    new = transaction.retrieve_from_file(dir_path + "/temp/raw" + context.num +
                                         ".tx")
    old = transaction.retrieve_from_file(dir_path + "/temp/old" + context.num +
                                         ".tx")
    assert encoding.msgpack_encode(new[0]) == encoding.msgpack_encode(old[0])
Ejemplo n.º 2
0
    def test_file_read_write(self):
        # get suggested parameters and fee
        params = self.acl.suggested_params()
        gh = params["genesishashb64"]
        last_round = params["lastRound"]
        fee = params["fee"]

        # create transaction
        txn = transaction.PaymentTxn(self.account_0, fee, last_round,
                                     last_round + 100, gh, self.account_0,
                                     1000)

        # get private key
        w = wallet.Wallet(wallet_name, wallet_pswd, self.kcl)
        private_key = w.export_key(self.account_0)

        # sign transaction
        stx = txn.sign(private_key)

        # write to file
        dir_path = os.path.dirname(os.path.realpath(__file__))
        transaction.write_to_file([txn, stx], dir_path + "/raw.tx")

        # read from file
        txns = transaction.retrieve_from_file(dir_path + "/raw.tx")

        # check that the transactions are still the same
        self.assertEqual(encoding.msgpack_encode(txn),
                         encoding.msgpack_encode(txns[0]))
        self.assertEqual(encoding.msgpack_encode(stx),
                         encoding.msgpack_encode(txns[1]))

        # delete the file
        os.remove("raw.tx")
Ejemplo n.º 3
0
def check_save_txn(context):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = os.path.dirname(os.path.dirname(dir_path))
    stx = transaction.retrieve_from_file(dir_path + "/temp/txn.tx")[0]
    txid = stx.transaction.get_txid()
    last_round = context.acl.status()["lastRound"]
    context.acl.status_after_block(last_round + 2)
    assert context.acl.transaction_info(stx.transaction.sender, txid)
Ejemplo n.º 4
0
def complete_trade(update, context):
    """
    To complete the atomic transaction, Buyer signs and submit half-signed transaction.
    :param update: Telegram obj.
    :param context: Telegram obj.
    :param context: Authorization key from the buyer.
    :return:
    """
    sk = context.user_data['Authorization_key']
    _address = account.address_from_private_key(sk)
    sk_bytes = rf(update, context, _address)
    bt = base64.decodebytes(sk_bytes)
    s = bt.decode()
    key = _address[:10]
    seller = TRANSACTIONS["{}".format(key)]['Seller']
    update.message.reply_text("Completing trade...\nbetween:\nSeller - {} and Buyer - {}".format(seller, _address))
    file = _address[:11]

    if _address in ex_file and _address == TRANSACTIONS["{}".format(key)]['Buyer']:
        rtv = transaction.retrieve_from_file("./asa{}.txn".format(file))
        grid = transaction.calculate_group_id([rtv[0], rtv[1], rtv[2], rtv[3]])
        rtv[0].group = grid
        rtv[1].group = grid
        rtv[2].group = grid
        rtv[3].group = grid

        txn1 = rtv[0].sign(sk)
        txn2 = rtv[1].sign(sk)
        txn3 = rtv[2].sign(s)
        txn4 = rtv[3].sign(s)

        tx_id = client.send_transactions([txn1, txn2, txn3, txn4])
        wait_for_confirmation(update, context, client, tx_id)
    else:
        update.message.reply_text("Trade could not be completed!")
    context.user_data.clear()
    remove_data(update, context, _address)
    return ConversationHandler.conversation_timeout
Ejemplo n.º 5
0
def read_txn(context, txn, num):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = os.path.dirname(os.path.dirname(dir_path))
    context.num = num
    context.txn = transaction.retrieve_from_file(dir_path + "/temp/raw" + num +
                                                 ".tx")[0]