コード例 #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])
コード例 #2
0
ファイル: offline.py プロジェクト: jsmrcaga/docs
def read_unsigned_transaction_from_file():
    algod_client = connect_to_network()

    passphrase = "price clap dilemma swim genius fame lucky crack torch hunt maid palace ladder unlock symptom rubber scale load acoustic drop oval cabbage review abstract embark"

    my_address = mnemonic.to_public_key(passphrase)
    print("My address: {}".format(my_address))
    account_info = algod_client.account_info(my_address)
    print("Account balance: {} microAlgos".format(account_info.get('amount')))

    dir_path = os.path.dirname(os.path.realpath(__file__))
    txns = transaction.retrieve_from_file(dir_path + "/unsigned.txn")
    # sign and submit transaction
    txn = txns[0]
    signed_txn = txn.sign(mnemonic.to_private_key(passphrase))
    txid = signed_txn.transaction.get_txid()
    print("Signed transaction with txID: {}".format(txid))	

    try:
        txid = algod_client.send_transaction(signed_txn)
        # wait for confirmation              
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    except Exception as err:
        print(err)
        return

    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=4)))
    print("Decoded note: {}".format(base64.b64decode(
        confirmed_txn["txn"]["txn"]["note"]).decode()))
コード例 #3
0
    def test_file_read_write(self):
        # get suggested parameters and fee
        gh = self.acl.versions()['genesis_hash_b64']
        rnd = int(self.acl.status()['lastRound'])
        sp = transaction.SuggestedParams(0, rnd, rnd + 100, gh)

        # create transaction
        txn = transaction.PaymentTxn(self.account_0, sp, 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")
コード例 #4
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)
コード例 #5
0
ファイル: multisig_offline.py プロジェクト: jsmrcaga/docs
def read_multisig_unsigned_transaction_from_file():
    algod_client = connect_to_network()
    # Change these values with mnemonics
    # mnemonic1 = "PASTE phrase for account 1"
    # mnemonic2 = "PASTE phrase for account 2"
    # mnemonic3 = "PASTE phrase for account 3"

    mnemonic1 = "patrol target joy dial ethics flip usual fatigue bulb security prosper brand coast arch casino burger inch cricket scissors shoe evolve eternal calm absorb school"
    mnemonic2 = "genius inside turtle lock alone blame parent civil depend dinosaur tag fiction fun skill chief use damp daughter expose pioneer today weasel box about silly"
    mnemonic3 = "off canyon mystery cable pluck emotion manual legal journey grit lunch include friend social monkey approve lava steel school mango auto cactus huge ability basket"

    # For ease of reference, add account public and private keys to
    # an accounts dict.

    private_key_1 = mnemonic.to_private_key(mnemonic1)
    account_1 = mnemonic.to_public_key(mnemonic1)

    private_key_2 = mnemonic.to_private_key(mnemonic2)
    account_2 = mnemonic.to_public_key(mnemonic2)

    private_key_3 = mnemonic.to_private_key(mnemonic3)
    account_3 = mnemonic.to_public_key(mnemonic3)

    print("Account 1 address: {}".format(account_1))
    print("Account 2 address: {}".format(account_2))
    print("Account 3 address: {}".format(account_3))

# read from file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    msigs = transaction.retrieve_from_file(dir_path + "/unsigned.mtx")
    mtx = msigs[0]


    # sign the transaction
    mtx.sign(private_key_1)
    mtx.sign(private_key_2)

    # send the transaction
    txid = algod_client.send_raw_transaction(
        encoding.msgpack_encode(mtx))
        # wait for confirmation	
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)  
        print("Transaction information: {}".format(
            json.dumps(confirmed_txn, indent=4)))
        print("Decoded note: {}".format(base64.b64decode(
            confirmed_txn["txn"]["txn"]["note"]).decode()))
    except Exception as err:
        print(err)
コード例 #6
0
ファイル: offline.py プロジェクト: jsmrcaga/docs
def read_signed_transaction_from_file():
    algod_client = connect_to_network()
    # read signed transaction from file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    txns = transaction.retrieve_from_file(dir_path + "/signed.txn")
    signed_txn = txns[0]
    try:
        txid = algod_client.send_transaction(signed_txn)
        print("Signed transaction with txID: {}".format(txid))
    # wait for confirmation
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    except Exception as err:
        print(err)
        return

    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=4)))
    print("Decoded note: {}".format(base64.b64decode(
        confirmed_txn["txn"]["txn"]["note"]).decode()))
コード例 #7
0
ファイル: multisig_offline.py プロジェクト: jsmrcaga/docs
def read_multisig_signed_transaction_from_file():
    algod_client = connect_to_network()
    
    # read from file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    msigs = transaction.retrieve_from_file(dir_path + "/signed.mtx")
    mtx = msigs[0]

    try:
    # send the transaction
        txid = algod_client.send_raw_transaction(
        encoding.msgpack_encode(mtx))        
         # wait for confirmation	       
        confirmed_txn = wait_for_confirmation(algod_client, txid, 4)  
        print("Transaction information: {}".format(
            json.dumps(confirmed_txn, indent=4)))
        print("Decoded note: {}".format(base64.b64decode(
            confirmed_txn["txn"]["txn"]["note"]).decode()))
    except Exception as err:
        print(err)
コード例 #8
0
ファイル: algorealm.py プロジェクト: cusma/algorealm
def sell_card(algod_client: algod.AlgodClient, user: Account):
    trade_gtxn = transaction.retrieve_from_file('trade_raw.gtxn')

    signed_crown_proof = trade_gtxn[0].sign(user.private_key)
    signed_sceptre_proof = trade_gtxn[1].sign(user.private_key)
    signed_royalty_1 = trade_gtxn[3].sign(user.private_key)
    signed_royalty_2 = trade_gtxn[4].sign(user.private_key)

    trade_gtxn[0] = signed_crown_proof
    trade_gtxn[1] = signed_sceptre_proof
    trade_gtxn[3] = signed_royalty_1
    trade_gtxn[4] = signed_royalty_2

    print(f"🤝 Selling the AlgoRealm Special Card for "
          f"{trade_gtxn[2].transaction.amt / 10 ** 6} ALGO:\n")
    try:
        gtxn_id = algod_client.send_transactions(trade_gtxn)
    except AlgodHTTPError:
        quit("You must hold the 👑 Crown and the 🪄 Scepter to sell the Card!\n")
    else:
        return wait_for_confirmation(algod_client, gtxn_id)
コード例 #9
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]
コード例 #10
0
assert(lstx.verify())

# send LogicSigTransaction to network
transaction.write_to_file([lstx], "r_s_1.txn")

stdout, stderr = execute(["goal", "clerk", "tealsign", "--data-b64", base64.b64encode(data),
                          "--lsig-txn", "r_s_1.txn", "--keyfile", key_fn, "--set-lsig-arg-idx",
                          "0"])
if stderr != "":
    print(stderr)
    raise

print(stdout)

lstx = transaction.retrieve_from_file("r_s_1.txn")
txid = acl.send_transactions(lstx)

print("1st withraw Succesfull! txid:{}".format(txid))

# at least sleep to the next round
time.sleep(6) 

sp = acl.suggested_params_as_object()
first_valid = sp.first
data = first_valid.to_bytes(8, byteorder='big')
lease = hash.sha256(data)
lease_bytes = encoding.HexEncoder.decode(lease)

print("first valid: {}".format(first_valid))
コード例 #11
0
ファイル: algorealm.py プロジェクト: cusma/algorealm
def verify_buy_order(seller_address: str):
    trade_gtxn = transaction.retrieve_from_file('trade_raw.gtxn')

    # Check TXN 0: Crown Proof of Ownership
    try:
        assert trade_gtxn[0].type == 'appl'
        assert trade_gtxn[0].index == ASA_STATE_OBSERVER_APP_ID
        assert trade_gtxn[0].app_args[0] == b'AsaAmountEq'
        assert trade_gtxn[0].app_args[1] == b'\x00\x00\x00\x00\x00\x00\x00\x01'
        assert trade_gtxn[0].foreign_assets[0] == CROWN_ID
        assert trade_gtxn[0].accounts[0] == seller_address
        assert trade_gtxn[0].sender == seller_address
        assert trade_gtxn[0].fee <= 1000
        assert trade_gtxn[0].rekey_to is None
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit("Transaction 0 - Crown Proof of Ownership is invalid: {}".format(
            text))

    # Check TXN 1: Sceptre Proof of Ownership
    try:
        assert trade_gtxn[1].type == 'appl'
        assert trade_gtxn[1].index == ASA_STATE_OBSERVER_APP_ID
        assert trade_gtxn[1].app_args[0] == b'AsaAmountEq'
        assert trade_gtxn[1].app_args[1] == b'\x00\x00\x00\x00\x00\x00\x00\x01'
        assert trade_gtxn[1].foreign_assets[0] == SCEPTRE_ID
        assert trade_gtxn[1].accounts[0] == seller_address
        assert trade_gtxn[1].sender == seller_address
        assert trade_gtxn[1].fee <= 1000
        assert trade_gtxn[1].rekey_to is None
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit(
            "Transaction 1 - Sceptre Proof of Ownership is invalid: {}".format(
                text))

    # Check TXN 2: Card Payment
    try:
        assert trade_gtxn[2].transaction.type == 'pay'
        assert trade_gtxn[2].transaction.receiver == seller_address
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit("Transaction 2 - Card Payment is invalid: {}".format(text))

    # Check TXN 3: Royalty 1 Payment
    try:
        assert trade_gtxn[3].type == 'pay'
        assert trade_gtxn[3].sender == seller_address
        assert trade_gtxn[3].receiver == ROYALTY_COLLECTOR_1.address
        assert trade_gtxn[3].fee <= 1000
        assert trade_gtxn[3].rekey_to is None
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit("Transaction 3 - Royalty 1 Payment is invalid: {}".format(text))

    # Check TXN 4: Royalty 3 Payment
    try:
        assert trade_gtxn[4].type == 'pay'
        assert trade_gtxn[4].sender == seller_address
        assert trade_gtxn[4].receiver == ROYALTY_COLLECTOR_2.address
        assert trade_gtxn[4].fee <= 1000
        assert trade_gtxn[4].rekey_to is None
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit("Transaction 4 - Royalty 2 Payment is invalid: {}".format(text))

    # Check TXN 5: Card Transfer
    try:
        assert trade_gtxn[5].transaction.type == 'axfer'
        assert trade_gtxn[5].transaction.index == CARD_ID
        assert trade_gtxn[5].transaction.amount == 1
        assert trade_gtxn[5].transaction.sender == CARD_CONTRACT.address
        assert trade_gtxn[5].transaction.receiver == trade_gtxn[
            2].transaction.sender
        assert trade_gtxn[5].transaction.revocation_target == seller_address
        assert trade_gtxn[5].transaction.fee <= 1000
        assert trade_gtxn[5].transaction.rekey_to is None
    except AssertionError:
        _, _, tb = sys.exc_info()
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]
        quit("Transaction 5 - Card Transfer is invalid: {}".format(text))

    return trade_gtxn