예제 #1
0
    def obtain_raw_tx():
#         if old_operation is None:
        _memo = memo.encrypt(memo_plain)
        _expiration = Config.get("bitshares", "transaction_expiration_in_sec", 60 * 60 * 24)  # 24 hours
#         else:
#             memo_encrypted = memo.encrypt(memo_plain)

        op = operations.Transfer(**{
            "fee": {
                "amount": 0,
                "asset_id": "1.3.0"
            },  # will be replaced
            "from": from_account["id"],
            "to": to_account["id"],
            "amount": amount.json(),
            "memo": _memo,
            "prefix": bitshares_instance.prefix
        })

        tx = TransactionBuilder(
            bitshares_instance=bitshares_instance
        )
        tx.appendOps(op)
        tx.set_expiration(_expiration)

        # Build the transaction, obtain fee to be paid
        tx.constructTx()
        return tx.json()
예제 #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())
예제 #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())
예제 #4
0
def sign(ctx, filename):
    if filename:
        tx = filename.read()
    else:
        tx = sys.stdin.read()
    tx = TransactionBuilder(eval(tx), bitshares_instance=ctx.bitshares)
    tx.appendMissingSignatures()
    tx.sign()
    pprint(tx.json())
예제 #5
0
파일: cli.py 프로젝트: kjmeta1/uptick
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())
예제 #6
0
파일: cli.py 프로젝트: kjmeta1/uptick
def sign(ctx, filename):
    """ Sign a json-formatted transaction
    """
    if filename:
        tx = filename.read()
    else:
        tx = sys.stdin.read()
    tx = TransactionBuilder(eval(tx), bitshares_instance=ctx.bitshares)
    tx.appendMissingSignatures()
    tx.sign()
    print_tx(tx.json())
예제 #7
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")