Beispiel #1
0
def sign(priv_key, data):
    acc = Account.from_secret_key_string(priv_key)
    tx_signer = TxSigner(acc, 'ae_uat')
    tx_builder = TxBuilder()
    tx = TxObject(tx=data)
    signature = tx_signer.sign_transaction(tx, None)
    signed = tx_builder.tx_signed([signature], tx, metadata=None)
    return signed.tx
Beispiel #2
0
def account_sign(keystore_name, password, network_id, unsigned_transaction,
                 json_):
    try:
        set_global_options(json_)
        account, _ = _account(keystore_name, password=password)
        if not utils.is_valid_hash(unsigned_transaction, prefix="tx"):
            raise ValueError("Invalid transaction format")
        # force offline mode for the node_client
        txb = TxBuilder()
        txu = txb.parse_tx_string(unsigned_transaction)
        signature = TxSigner(account, network_id).sign_transaction(txu)
        # TODO: better handling of metadata
        txs = txb.tx_signed([signature],
                            txu,
                            metadata={"network_id": network_id})
        # _print_object(txu, title='unsigned transaction')
        _print_object(txs, title='signed transaction')
    except Exception as e:
        _print_error(e, exit_code=1)
Beispiel #3
0
def test_tutorial_offline_tx(chain_fixture):

    # Accounts addresses
    account = Account.generate()

    # --- hide --- override the account for tests
    account = chain_fixture.ALICE
    # /--- hide ---

    # instantiate the transactions builder
    build = TxBuilder()

    # we will be creating 5 transactions for later broadcast TODO: warn about the nonce limit
    txs = []

    # each transaction is going to be a spend
    amount = utils.amount_to_aettos("0.05AE")
    payload = b''

    for i in range(5):
        # increase the account nonce
        account.nonce = account.nonce + 1
        # build the transaction
        tx = build.tx_spend(
            account.get_address(),  # sender
            Account.generate().get_address(),  # random generated recipient
            amount,
            payload,
            defaults.FEE,
            defaults.TX_TTL,
            account.nonce)
        # save the transaction
        txs.append(tx)

    # Sign the transactions
    # define the network_id
    network_id = identifiers.NETWORK_ID_TESTNET

    # --- hide --- override the network_id for tests
    network_id = chain_fixture.NODE_CLI.config.network_id
    # /--- hide ---

    # instantiate a transaction signer
    signer = TxSigner(account, network_id)

    # collect the signed tx for broadcast
    signed_txs = []
    # sign all transactions
    for tx in txs:
        signature = signer.sign_transaction(tx)
        signed_tx = build.tx_signed([signature], tx)
        signed_txs.append(signed_tx)

    # Broadcast the transactions
    NODE_URL = os.environ.get('TEST_URL', 'https://testnet.aeternity.io')

    node_cli = NodeClient(Config(
        external_url=NODE_URL,
        blocking_mode=False,
    ))

    # broadcast all transactions
    for stx in signed_txs:
        node_cli.broadcast_transaction(stx)

    # verify that all transactions have been posted
    for stx in signed_txs:
        height = node_cli.wait_for_transaction(stx)
        assert (height > 0)