Exemple #1
0
def flood(ctx, account, ops, txs, to):
    from bitsharesbase.operations import Transfer
    from bitshares.transactionbuilder import TransactionBuilder
    assert ctx.bitshares.rpc.chain_params[
        "prefix"] == "TEST", "Flooding only on the testnet. Please switch the API to node testnet.bitshares.eu"
    account = Account(account, bitshares_instance=ctx.bitshares)
    to_account = Account(to, bitshares_instance=ctx.bitshares)
    tx = TransactionBuilder(bitshares_instance=ctx.bitshares)

    txcnt = 0
    while txcnt < txs or txs < 0:
        txcnt += 1
        for j in range(0, ops):
            tx.appendOps(
                Transfer(
                    **{
                        "fee": {
                            "amount": 0,
                            "asset_id": "1.3.0"
                        },
                        "from": account["id"],
                        "to": to_account["id"],
                        "amount": {
                            "amount": 1,
                            "asset_id": "1.3.0"
                        },
                        "memo": None
                    }))
        tx.appendSigner(account, "active")
        tx.broadcast()
        click.echo(tx["signatures"])
Exemple #2
0
def broadcast(ctx, filename):
    if filename:
        tx = filename.read()
    else:
        tx = sys.stdin.read()
    tx = TransactionBuilder(eval(tx), bitshares_instance=ctx.bitshares)
    tx.broadcast()
    pprint(tx.json())
Exemple #3
0
def send_claim(ctx, claim_expiration):

    proposalBuilder = ProposalBuilder("vel-ma", claim_expiration
                                      or 2 * 24 * 60 * 60)

    tx = TransactionBuilder(eval(proposalBuilder.json()),
                            bitshares_instance=ctx.bitshares)
    tx.broadcast()
    print_tx(tx.json())
Exemple #4
0
def broadcast(ctx, filename):
    """ Broadcast a json-formatted transaction
    """
    if filename:
        tx = filename.read()
    else:
        tx = sys.stdin.read()
    tx = TransactionBuilder(eval(tx), bitshares_instance=ctx.bitshares)
    tx.broadcast()
    print_tx(tx.json())
Exemple #5
0
def broadcast_transaction(signed_transaction, bitshares_instance=None):
    if type(signed_transaction) == str:
        signed_transaction = json.loads(signed_transaction)

    tx = TransactionBuilder(
        signed_transaction,
        bitshares_instance=bitshares_instance
    )

    # Only broadcast if case 2 || 3
    assert len(tx.json()["operations"]) == 1, "Only one op per transaction allowed"
    from_account = tx.json()["operations"][0][1]["from"]
    to_account = tx.json()["operations"][0][1]["to"]

    # insert all transactions into storage
    storage = _get_os()

    def map_operation(tx, op_in_tx, operation):
        assert operation[0] == 0, "We only deal with transfers!"
        j = dict(
            op=operation,
            decoded_memo=tx["decoded_memo"],
            expiration=tx["expiration"],
            op_in_tx=op_in_tx,
            transaction_id=tx["transaction_id"]
        )
        if tx.get("incident_id", None) is not None:
            j["incident_id"] = tx["incident_id"]
        return operation_formatter.decode_operation(j)

    for op_in_tx, operation in enumerate(tx.get("operations", [])):
        storage.insert_operation(map_operation(tx, op_in_tx, operation))

    exception_occured = None
    try:
        # check validity
        tx.verify_authority()
    except Exception as e:
        exception_occured = e

    if exception_occured is None and from_account != to_account:
        try:
            tx = tx.broadcast()
            if tx.get("id", None):
                return {"hash": tx["id"] + ":" + str(tx["trx_num"]), "block": tx["block_num"]}
            else:
                return {"hash": "no_id_given", "block": -1}
        except UnhandledRPCError as e:
            if "insufficient_balance" in str(e):
                raise NotEnoughBalanceException()
            elif "amount.amount > 0" in str(e):
                raise AmountTooSmallException()
            elif "now <= trx.expiration" in str(e):
                raise TransactionExpiredException()
            else:
                raise e
        except Exception as e:
            exception_occured = e

    if exception_occured:
        # this operation might not exist
        for op_in_tx, operation in enumerate(tx.get("operations", [])):
            storage.flag_operation_failed(map_operation(tx, op_in_tx, operation),
                                          str(exception_occured))
        raise exception_occured

    if from_account == to_account:
        block_num = bitshares_instance.rpc.get_dynamic_global_properties()['last_irreversible_block_num']
        # This happens in case of virtual consolidation transactions/transfers
        for op_in_tx, operation in enumerate(tx.get("operations", [])):
            op = map_operation(tx, op_in_tx, operation)
            op["block_num"] = block_num + (op_in_tx + 1) * 0.1
            op["tx_in_block"] = 0
            op["fee_value"] = 0
            storage.flag_operation_completed(op)
        return {"hash": "virtual_transfer", "block": op["block_num"]}
    else:
        raise Exception("This should be unreachable")