예제 #1
0
def group_transactions() :

    # recover a account    
    passphrase1 = <25-word-passphrase>
    pk_account_a = mnemonic.to_private_key(passphrase1)
    account_a = account.address_from_private_key(pk_account_a)

    # recover b account
    passphrase2 = <25-word-passphrase>
    pk_account_b = mnemonic.to_private_key(passphrase2)
    account_b = account.address_from_private_key(pk_account_b)

    # recover c account
    passphrase3 = <25-word-passphrase>
    pk_account_c = mnemonic.to_private_key(passphrase3)
    account_c = account.address_from_private_key(pk_account_c)

    # connect to node
    acl = connect_to_network()

    # get suggested parameters
    params = acl.suggested_params()
    gen = params["genesisID"]
    gh = params["genesishashb64"]
    last_round = params["lastRound"]
    fee = params["fee"]
    amount = 1000

    # create transaction1
    txn1 = transaction.PaymentTxn(account_a, fee, last_round, last_round+100, gh, account_c, amount)

    # create transaction2
    txn2 = transaction.PaymentTxn(account_b, fee, last_round, last_round+100, gh, account_a, amount)

    # get group id and assign it to transactions
    gid = transaction.calculate_group_id([txn1, txn2])
    txn1.group = gid
    txn2.group = gid

    # sign transaction1
    stxn1 = txn1.sign(pk_account_a)

    # sign transaction2
    stxn2 = txn2.sign(pk_account_b)

    signedGroup =  []
    signedGroup.append(stxn1)
    signedGroup.append(stxn2)

    # send them over network
    sent = acl.send_transactions(signedGroup)
    # print txid
    print(sent)

    # wait for confirmation
    wait_for_confirmation( acl, sent) 
예제 #2
0
def fund_contract(context):
    context.txn = transaction.PaymentTxn(context.accounts[0], context.params,
                                         context.template.get_address(),
                                         context.fund_amt)
    context.txn = context.wallet.sign_transaction(context.txn)
    context.acl.send_transaction(context.txn)
    context.acl.status_after_block(context.acl.status()["lastRound"] + 3)
예제 #3
0
 def test_sign(self):
     mn = ("advice pudding treat near rule blouse same whisper inner " +
           "electric quit surface sunny dismiss leader blood seat " +
           "clown cost exist hospital century reform able sponsor")
     gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
     address = "PNWOET7LLOWMBMLE4KOCELCX6X3D3Q4H2Q4QJASYIEOF7YIPPQBG3YQ5YI"
     close = "IDUTJEUIEVSMXTU4LGTJWZ2UE2E6TIODUKU6UW3FU3UKIQQ77RLUBBBFLA"
     sk = mnemonic.to_private_key(mn)
     pk = account.address_from_private_key(sk)
     txn = transaction.PaymentTxn(pk,
                                  4,
                                  12466,
                                  13466,
                                  gh,
                                  address,
                                  1000,
                                  note=base64.b64decode("6gAVR0Nsv5Y="),
                                  gen="devnet-v33.0",
                                  close_remainder_to=close)
     stx = txn.sign(sk)
     golden = ("gqNzaWfEQPhUAZ3xkDDcc8FvOVo6UinzmKBCqs0woYSfodlmBMfQvGbeU" +
               "x3Srxy3dyJDzv7rLm26BRv9FnL2/AuT7NYfiAWjdHhui6NhbXTNA+ilY2" +
               "xvc2XEIEDpNJKIJWTLzpxZpptnVCaJ6aHDoqnqW2Wm6KRCH/xXo2ZlZc0" +
               "EmKJmds0wsqNnZW6sZGV2bmV0LXYzMy4womdoxCAmCyAJoJOohot5WHIv" +
               "peVG7eftF+TYXEx4r7BFJpDt0qJsds00mqRub3RlxAjqABVHQ2y/lqNyY" +
               "3bEIHts4k/rW6zAsWTinCIsV/X2PcOH1DkEglhBHF/hD3wCo3NuZMQg5/" +
               "D4TQaBHfnzHI2HixFV9GcdUaGFwgCQhmf0SVhwaKGkdHlwZaNwYXk=")
     self.assertEqual(golden, encoding.msgpack_encode(stx))
     txid_golden = "5FJDJD5LMZC3EHUYYJNH5I23U4X6H2KXABNDGPIL557ZMJ33GZHQ"
     self.assertEqual(txn.get_txid(), txid_golden)
예제 #4
0
def unsigned_send(algod_client, addr_sender, addr_receiver, microalgo_amount,
                  validity_range=1000):
    """HELP unsigned_send:
        (AlgodClient, str, str, int, int) - Returns an unsigned PaymentTxn.
    """
    assert type(microalgo_amount) == int and validity_range <= 1000
    # Get network suggested params for transactions.
    params = algod_client.suggested_params()
    first_valid = params.first
    last_valid = first_valid + validity_range
    gh = params.gh
    min_fee = params.min_fee
    assert min_fee <= 1000

    data = {
        "sender": addr_sender,
        "receiver": addr_receiver,
        "fee": min_fee,
        "first": first_valid,
        "last": last_valid,
        "gh": gh,
        "amt": int(microalgo_amount),
        "flat_fee": True,
        }
    return transaction.PaymentTxn(**data)
예제 #5
0
    def send(self) -> "WithdrawTransaction":
        """
        Send the transaction with the parameters given during initialization of the class
        Gets the redis tx id to preserve creation order
        (TODO : create the transaction with the send time and update it when confirmed
                with confirmation time)
        """
        params = self.params

        txn = transaction.PaymentTxn(self.sender.wallet.public_key,
                                     params.min_fee,
                                     params.first,
                                     params.last,
                                     params.gh,
                                     self.destination,
                                     algos_to_microalgos(self.amount),
                                     note=str.encode(self.message),
                                     close_remainder_to=None if not self.close_account else self.destination,
                                     flat_fee=True)

        signed_txn = txn.sign(self.sender.wallet.private_key)

        algod.send_transaction(signed_txn)
        self.time = time_ns() * 1e-6
        self.tx_id = signed_txn.transaction.get_txid()
        self.redis_tx_id = redis.incr("transaction-id")

        console.log(f"Withdrawal #{self.redis_tx_id} sent by {self.sender.name}")
예제 #6
0
def send(algod_client, sender, addr_receiver, microalgo_amount,
         validity_range=1000):
    """HELP send:
        (AlgodClient, dict, str, int, int) - Executes a PaymentTxn.
    """
    assert type(microalgo_amount) == int and validity_range <= 1000
    # Get network suggested params for transactions.
    params = algod_client.suggested_params()
    first_valid = params.first
    last_valid = first_valid + validity_range
    gh = params.gh
    min_fee = params.min_fee
    assert min_fee <= 1000

    data = {
        "sender": sender['pk'],
        "fee": min_fee,
        "first": first_valid,
        "last": last_valid,
        "gh": gh,
        "receiver": addr_receiver,
        "amt": int(microalgo_amount),
        "flat_fee": True
        }

    txn = transaction.PaymentTxn(**data)
    stxn = txn.sign(sender['sk'])
    txid = algod_client.send_transaction(stxn)
    print("Transaction ID:", txid)
    wait_for_tx_confirmation(algod_client, txid)
예제 #7
0
def unsigned_closeto(algod_client, sender, closeto, validity_range=1000):
    """HELP unsigned_closeto:
        (AlgodClient, dict, str, int) - Returns an unsigned PaymentTxn with
        close-to account.
    """
    # Get network suggested params for transactions.
    assert validity_range <= 1000
    params = algod_client.suggested_params()
    first_valid = params.first
    last_valid = first_valid + validity_range
    gh = params.gh
    min_fee = params.min_fee
    assert min_fee <= 1000

    data = {
        "sender": sender,
        "receiver": closeto,
        "fee": min_fee,
        "first": first_valid,
        "last": last_valid,
        "gh": gh,
        "amt": 0,
        "flat_fee": True,
        "close_remainder_to": closeto
        }
    return transaction.PaymentTxn(**data)
예제 #8
0
def create_msigpaytxn(context):
    context.txn = transaction.PaymentTxn(context.msig.address(), context.fee,
                                         context.fv, context.lv, context.gh,
                                         context.to, context.amt,
                                         context.close, context.note,
                                         context.gen)
    context.mtx = transaction.MultisigTransaction(context.txn, context.msig)
예제 #9
0
def send_tokens(receiver_pk, tx_amount):
    params = acl.suggested_params()
    gen_hash = params.gh
    first_valid_round = params.first
    tx_fee = params.min_fee
    last_valid_round = params.last

    #Your code here
    #generate an account
    mnemonic_secret = 'ship floor pattern transfer fiscal diamond maid raise never debate lemon brown siren upset gun sibling lend write cloth success glove shrug cattle ability ivory'
    sk = mnemonic.to_private_key(mnemonic_secret)
    pk = mnemonic.to_public_key(mnemonic_secret)
    print("my public key = ", pk)
    account_info = acl.account_info(pk)

    #prepare and sign the transaction
    tx = transaction.PaymentTxn(pk, tx_fee, first_valid_round,
                                last_valid_round, gen_hash, receiver_pk,
                                tx_amount)
    signed_tx = tx.sign(sk)

    #send the signed transaction
    tx_confirm = acl.send_transaction(signed_tx)
    #acl.status_after_block(first_valid_round+2)
    txid = signed_tx.transaction.get_txid()
    wait_for_confirmation(acl, txid)
    sender_pk = pk

    return sender_pk, txid
예제 #10
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")
예제 #11
0
    def send(self) -> "TipTransaction":
        """
        Perform checks to make sure that the transaction can be done
        before creating it and sending it

        Returns:
            Transaction: returns itself if the transaction was successfully
                         None otherwise
        """
        params = self.params
        txn = transaction.PaymentTxn(self.sender.wallet.public_key,
                                    params.min_fee,
                                    params.first,
                                    params.last,
                                    params.gh,
                                    self.receiver.wallet.public_key,
                                    algos_to_microalgos(self.amount),
                                    note=str.encode(self.message),
                                    flat_fee=True)

        signed_txn = txn.sign(self.sender.wallet.private_key)

        algod.send_transaction(signed_txn)
        self.time = time_ns() * 1e-6
        self.tx_id = signed_txn.transaction.get_txid()
        self.redis_tx_id = redis.incr("transaction-id")

        console.log(f"Transaction #{self.redis_tx_id} sent by {self.sender.name} to {self.receiver.name}")
예제 #12
0
    def test_serialize_txgroup(self):
        address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
        gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
        txn = transaction.PaymentTxn(address,
                                     3,
                                     1,
                                     100,
                                     gh,
                                     address,
                                     1000,
                                     gen="testnet-v1.0",
                                     close_remainder_to=address)
        txid = txn.get_txid().encode()
        txid = base64.decodebytes(txid)

        txgroup = transaction.TxGroup([txid])
        enc = encoding.msgpack_encode(txgroup)
        re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
        self.assertEqual(enc, re_enc)

        txgroup = transaction.TxGroup([txid] * 11)
        enc = encoding.msgpack_encode(txgroup)
        re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
        self.assertEqual(enc, re_enc)

        # check group field serialization
        gid = transaction.calculate_group_id([txn, txn])
        txn.group = gid
        enc = encoding.msgpack_encode(txn)
        re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
        self.assertEqual(enc, re_enc)
예제 #13
0
    def execute(self, address, station, temperature):
        program = base64.b64decode(
            "ASAG0A8BAAWo7Y0CUCYCIPQv9Dp6BUP5IWgVnUMxQ41GHJYlTMUn5MaVgxmacIXBIHiNgRcdCvcgzeloO+LUHFaqn/aCtb6wV9B8WJqe5FcWMQEiDDEQIxIQMQgkEhAxCSgSMQcyAxIQLRclEhAxAiEEDhAuFyEFDhAxCSkSMQcyAxIQMQIhBA0uFyEFDREQERA="
        )

        lsig = transaction.LogicSig(program, args=[[station], [temperature]])
        sender = lsig.address()

        # get suggested parameters
        params = self.algod.suggested_params()
        gh = params["genesishashb64"]
        last_round = params["lastRound"]
        fee = params["fee"]

        txn = transaction.PaymentTxn(
            sender,
            fee,
            last_round,
            last_round + 1000,
            gh,
            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ",
            0,
            close_remainder_to=address)

        # note, transaction is signed by logic only (no delegation)
        # that means sender address must match to program hash
        lstx = transaction.LogicSigTransaction(txn, lsig)
        assert lstx.verify()

        # send them over network
        return self.algod.send_transaction(
            lstx, headers={'content-type': 'application/x-binary'})
예제 #14
0
    def track(self, station: int, temperature: int):
        """
        posts the tracking information to the blockchain
        :param station:
        :param temperature:
        :return:
        """

        # get suggested parameters
        params = self.algod.suggested_params()
        gen = params["genesisID"]
        gh = params["genesishashb64"]
        last_round = params["lastRound"]
        fee = params["fee"]

        note = {'s': station, 't': temperature}

        # create the transaction
        txn = transaction.PaymentTxn(account.address_from_private_key(self.sk),
                                     fee,
                                     last_round,
                                     last_round + 1000,
                                     gh,
                                     self.namespace_address,
                                     0,
                                     note=json.dumps(note).encode())

        # sign it
        stx = txn.sign(self.sk)

        # send it
        return self.algod.send_transaction(
            stx, headers={'content-type': 'application/x-binary'})
예제 #15
0
def default_txn(context, amt, note):
    params = context.acl.suggested_params()
    context.last_round = params["lastRound"]
    if note == "none":
        note = None
    else:
        note = base64.b64decode(note)
    context.txn = transaction.PaymentTxn(context.accounts[0], params["fee"], context.last_round, context.last_round+1000, params["genesishashb64"], context.accounts[1], int(amt), note=note, gen=params["genesisID"])
    context.pk = context.accounts[0]
예제 #16
0
def store_purchase(event, user):
    note_field_bytes = json.dumps(user).encode()

    al = algod.AlgodClient(al_token, al_address)
    params = al.suggested_params()
    gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
    txn = transaction.PaymentTxn(event["address"], 0, params.get("lastRound"), params.get("lastRound")+1000, gh, dapp["address"], 1, note=note_field_bytes)
    txn = txn.sign(event["private_key"])
    return al.send_raw_transaction(txn)
예제 #17
0
def scenario3():
    """
    Alice transfers all her algos to Bob.
    """
    amount = 1
    fee = 1000
    data = (alice, fee, first_valid, last_valid, genesis_hash, bob, amount)
    data_add = {"gen": genesis_id, "flat_fee": True, "close_remainder_to": bob}
    tx = transaction.PaymentTxn(*data, **data_add)
    return tx
예제 #18
0
def algorandSequence():
    algod_address = "https://testnet-algorand.api.purestake.io/ps2"
    algod_token = ""
    headers = {
        "X-API-Key": "zLAOcinLq31BhPezSnHQL3NF7qBwHtku6XwN8igq",
    }

    algod_client = algod.AlgodClient(algod_token, algod_address, headers)
    status = algod_client.status()
    print(json.dumps(status, indent=4))

    passphrase = "thunder fun scout myself talk repeat hurry miracle puppy run vocal vicious shove fever idea lens above diesel action pulp before cigar horror above mass"

    private_key = mnemonic.to_private_key(passphrase)
    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')))

    params = algod_client.suggested_params()
    note = "Hello World".encode()
    receiver = "GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A"

    data = {
        "sender": my_address,
        "receiver": receiver,
        "fee": params.get('minFee'),
        "flat_fee": True,
        "amt": 20,
        "first": params.get('lastRound'),
        "last": params.get('lastRound') + 1000,
        "note": note,
        "gen": params.get('genesisID'),
        "gh": params.get('genesishashb64')
    }

    txn = transaction.PaymentTxn(**data)
    signed_txn = txn.sign(private_key)
    txid = signed_txn.transaction.get_txid()
    print("Signed transaction with txID: {}".format(txid))

    algod_client.send_transaction(
        signed_txn, headers={'content-type': 'application/x-binary'})

    wait_for_confirmation(algod_client, txid)

    try:
        confirmed_txn = algod_client.transaction_info(my_address, txid)
    except Exception as err:
        print(err)
    print("Transaction information: {}".format(
        json.dumps(confirmed_txn, indent=4)))
    print("Decoded note: {}".format(
        base64.b64decode(confirmed_txn.get('noteb64')).decode()))
예제 #19
0
def group_transactions():

    # recover a account
    passphrase1 = os.getenv("MNEMONIC1")
    pk_account_a = mnemonic.to_private_key(passphrase1)
    account_a = account.address_from_private_key(pk_account_a)

    # recover b account
    account_b = "4O6BRAPVLX5ID23AZWV33TICD35TI6JWOHXVLPGO4VRJATO6MZZQRKC7RI"

    # connect to node
    acl = connect_to_network()

    # get suggested parameters
    params = acl.suggested_params()
    gen = params["genesisID"]
    gh = params["genesishashb64"]
    last_round = params["lastRound"]
    fee = params["fee"]
    asset_index = 14035004

    # create transaction1
    txn1 = transaction.PaymentTxn(account_a, fee, last_round, last_round + 100,
                                  gh, account_b, 42000000)

    # create transaction2
    txn2 = transaction.AssetTransferTxn(account_b, fee, last_round,
                                        last_round + 100, gh, account_a, 1,
                                        asset_index)

    # get group id and assign it to transactions
    gid = transaction.calculate_group_id([txn1, txn2])
    txn1.group = gid
    txn2.group = gid

    # sign transaction1
    stxn1 = txn1.sign(pk_account_a)

    # sign transaction2
    with open("buildweb3/step5.lsig", "rb") as f:
        lsig = encoding.future_msgpack_decode(base64.b64encode(f.read()))
    stxn2 = transaction.LogicSigTransaction(txn2, lsig)

    signedGroup = []
    signedGroup.append(stxn1)
    signedGroup.append(stxn2)

    # send them over network
    sent = acl.send_transactions(signedGroup)
    # print txid
    print(sent)

    # wait for confirmation
    wait_for_confirmation(acl, sent)
예제 #20
0
    def test_errors(self):

        # get random private key
        private_key_1, account_1 = account.generate_account()
        private_key_2, account_2 = account.generate_account()
        private_key_3, account_3 = account.generate_account()

        # create transaction
        gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
        txn = transaction.PaymentTxn(account_2, 3, 1234, 1334, gh, account_2,
                                     1000)

        # create multisig address with invalid version
        msig = transaction.Multisig(2, 2, [account_1, account_2])
        self.assertRaises(error.UnknownMsigVersionError, msig.validate)

        # change it to have invalid threshold
        msig.version = 1
        msig.threshold = 3
        self.assertRaises(error.InvalidThresholdError, msig.validate)

        # try to sign multisig transaction
        msig.threshold = 2
        mtx = transaction.MultisigTransaction(txn, msig)
        self.assertRaises(error.BadTxnSenderError, mtx.sign, private_key_1)

        # change sender address to be correct
        txn.sender = msig.address()
        mtx = transaction.MultisigTransaction(txn, msig)

        # try to sign with incorrect private key
        self.assertRaises(error.InvalidSecretKeyError, mtx.sign, private_key_3)

        # create another multisig with different address
        msig_2 = transaction.Multisig(1, 2, [account_2, account_3])

        # try to merge with different addresses
        mtx_2 = transaction.MultisigTransaction(txn, msig_2)
        self.assertRaises(error.MergeKeysMismatchError,
                          transaction.MultisigTransaction.merge, [mtx, mtx_2])

        # create another multisig with same address
        msig_3 = msig_2.get_multisig_account()

        # add mismatched signatures
        msig_2.subsigs[0].signature = "sig2"
        msig_3.subsigs[0].signature = "sig3"

        # try to merge
        self.assertRaises(error.DuplicateSigMismatchError,
                          transaction.MultisigTransaction.merge, [
                              transaction.MultisigTransaction(txn, msig_2),
                              transaction.MultisigTransaction(txn, msig_3)
                          ])
예제 #21
0
def create_paytxn_flat_fee(context):
    context.txn = transaction.PaymentTxn(context.pk,
                                         context.fee,
                                         context.fv,
                                         context.lv,
                                         context.gh,
                                         context.to,
                                         context.amt,
                                         context.close,
                                         context.note,
                                         context.gen,
                                         flat_fee=True)
예제 #22
0
 def test_min_txn_fee(self):
     address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
     gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
     txn = transaction.PaymentTxn(address,
                                  0,
                                  1,
                                  100,
                                  gh,
                                  address,
                                  1000,
                                  note=b'\x00')
     self.assertEqual(constants.min_txn_fee, txn.fee)
예제 #23
0
def genTxns():
    yield transaction.PaymentTxn(
        sender="YK54TGVZ37C7P76GKLXTY2LAH2522VD3U2434HRKE7NMXA65VHJVLFVOE4",
        receiver="RNZZNMS5L35EF6IQHH24ISSYQIKTUTWKGCB4Q5PBYYSTVB5EYDQRVYWMLE",
        fee=0.001,
        flat_fee=True,
        amt=1000000,
        first=5667360,
        last=5668360,
        note="Hello World".encode(),
        gen="testnet-v1.0",
        gh="SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
예제 #24
0
def scenario1():
    """
    Alice sends 100 Algos to Bob with flat fee.
    """

    amount = 100000000
    fee = 1000

    data = (alice, fee, first_valid, last_valid, genesis_hash, bob, amount)
    data_add = {"gen": genesis_id, "flat_fee": True}

    tx = transaction.PaymentTxn(*data, **data_add)
    return tx
예제 #25
0
def scenario2():
    """
    Alice sends 100 Algos to Bob with suggested fee and a 1 KB note.
    """

    amount = 100000000
    note = b''.join(b'a' for item in range(1000))
    data = (alice, fee_per_byte, first_valid, last_valid, genesis_hash, bob,
            amount)
    data_add = {"gen": genesis_id, "note": note}

    tx = transaction.PaymentTxn(*data, **data_add)
    return tx
예제 #26
0
def default_txn(context, amt, note):
    params = context.acl.suggested_params()
    context.last_round = params.first
    if note == "none":
        note = None
    else:
        note = base64.b64decode(note)
    context.txn = transaction.PaymentTxn(context.accounts[0],
                                         params,
                                         context.accounts[1],
                                         int(amt),
                                         note=note)
    context.pk = context.accounts[0]
예제 #27
0
    def test_auction(self):
        # get the default wallet
        wallets = self.kcl.list_wallets()
        wallet_id = None
        for w in wallets:
            if w["name"] == wallet_name:
                wallet_id = w["id"]

        # get a new handle for the wallet
        handle = self.kcl.init_wallet_handle(wallet_id, wallet_pswd)

        # generate account with kmd
        account_1 = self.kcl.generate_key(handle, False)

        # get suggested parameters and fee
        params = self.acl.suggested_params()
        gen = params["genesisID"]
        gh = params["genesishashb64"]
        last_round = params["lastRound"]
        fee = params["fee"]

        # get self.account_0 private key
        private_key_0 = self.kcl.export_key(handle, wallet_pswd,
                                            self.account_0)

        # create bid
        bid = auction.Bid(self.account_0, 10000, 260, "bid_id", account_1,
                          "auc_id")
        sb = bid.sign(private_key_0)
        nf = auction.NoteField(sb, constants.note_field_type_bid)

        # create transaction
        txn = transaction.PaymentTxn(self.account_0,
                                     fee,
                                     last_round,
                                     last_round + 100,
                                     gh,
                                     account_1,
                                     100000,
                                     note=base64.b64decode(
                                         encoding.msgpack_encode(nf)),
                                     gen=gen)

        # sign transaction with account
        signed_account = txn.sign(private_key_0)

        # send transaction
        send = self.acl.send_transaction(signed_account)
        self.assertEqual(send, txn.get_txid())
        del_1 = self.kcl.delete_key(handle, wallet_pswd, account_1)
        self.assertTrue(del_1)
예제 #28
0
    def test_transaction_group(self):
        # get the default wallet
        wallets = self.kcl.list_wallets()
        wallet_id = None
        for w in wallets:
            if w["name"] == wallet_name:
                wallet_id = w["id"]

        # get a new handle for the wallet
        handle = self.kcl.init_wallet_handle(wallet_id, wallet_pswd)

        # get private key
        private_key_0 = self.kcl.export_key(handle, wallet_pswd,
                                            self.account_0)

        # get suggested parameters and fee
        params = self.acl.suggested_params()
        gen = params["genesisID"]
        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,
                                     gen=gen)

        # calculate group id
        gid = transaction.calculate_group_id([txn])
        txn.group = gid

        # sign using kmd
        stxn1 = self.kcl.sign_transaction(handle, wallet_pswd, txn)
        # sign using transaction call
        stxn2 = txn.sign(private_key_0)
        # check that they are the same
        self.assertEqual(encoding.msgpack_encode(stxn1),
                         encoding.msgpack_encode(stxn2))

        try:
            send = self.acl.send_transactions([stxn1])
            self.assertEqual(send, txn.get_txid())
        except error.AlgodHTTPError as ex:
            self.assertIn(
                "TransactionPool.Remember: transaction groups not supported",
                str(ex))
예제 #29
0
 def test_serialize_zero_amt(self):
     address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
     gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
     txn = transaction.PaymentTxn(address,
                                  3,
                                  1,
                                  100,
                                  gh,
                                  address,
                                  0,
                                  note=bytes([1, 32, 200]))
     enc = encoding.msgpack_encode(txn)
     re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
     self.assertEqual(enc, re_enc)
예제 #30
0
def create_transaction(privateKey, my_address, receiver, amount):
    txn = {
        "sender": my_address,
        "receiver": receiver,
        "fee": params.get('minFee'),
        "flat_fee": True,
        "amt": amount,
        "first": params.get('lastRound'),
        "last": params.get('lastRound') + 1000,
        "note": note,
        "gen": params.get('genesisID'),
        "gh": params.get('genesishashb64')
    }

    return transaction.PaymentTxn(**txn)