def main(rpchost, rpcport, expiration, broadcast, proposer):
    rpc = GrapheneAPI(rpchost, rpcport)
    obj = rpc.get_object("2.0.0")[0]
    new_parameters = deepcopy(obj["parameters"])
    current_fees = obj["parameters"]["current_fees"]["parameters"]
    fees = obj["parameters"]["current_fees"]["parameters"]
    scale = obj["parameters"]["current_fees"]["scale"] / 1e4

    # General change of parameter
    changes = {}

    # Copy old fees
    for f in current_fees:
        changes[getOperationNameForId(f[0])] = f[1].copy()

    # New fees
    new_fee = {"fee": int(0.2 / scale * 1e5), "fee_per_day": int(0.2 / scale * 1e5)}
    changes["htlc_create"] = new_fee
    changes["htlc_redeem"] = new_fee
    changes["htlc_extend"] = new_fee

    tx = rpc.propose_fee_change(
        proposer, formatTimeFromNow(expiration), changes, broadcast
    )
    op = tx["operations"][0][1]["proposed_ops"][0]["op"]

    # New HTLC parameters are in extensions
    op[1]["new_parameters"]["extensions"] = {
        "updatable_htlc_options": {
            "max_preimage_size": 19200,
            "max_timeout_secs": 60 * 60 * 24 * 28,
        }
    }

    ops = [op]
    buildHandle = rpc.begin_builder_transaction()
    for op in ops:
        rpc.add_operation_to_builder_transaction(buildHandle, op)
    rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
    params = rpc.get_object("2.0.0")[0]
    preview = params["parameters"]["committee_proposal_review_period"] or 10
    rpc.propose_builder_transaction2(
        buildHandle, proposer, formatTimeFromNow(expiration), preview, False
    )
    rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")

    # Sign and broadcast
    tx = rpc.sign_builder_transaction(buildHandle, broadcast)

    pprint(tx)
Пример #2
0
def run(n=0):
    client = GrapheneAPI("localhost", 8092, "", "")
    transfer = client.get_prototype_operation("transfer_operation")
    from_account = client.get_account("faucet")
    to_account = client.get_account("xeroc")
    transfer[1]["to"] = to_account["id"]
    transfer[1]["from"] = from_account["id"]
    transfer[1]["amount"]["amount"] = 3

    while True:
        builder = client.begin_builder_transaction()

        for i in range(0, random.randint(100, 500)):
            print(n, end="", flush=True)
            client.add_operation_to_builder_transaction(builder, transfer)
        client.set_fees_on_builder_transaction(builder, "1.3.0")
        print("\nTransfer!")
        client.sign_builder_transaction(builder, True)
        time.sleep(random.randint(0, 3))
                    "asset_id": asset["id"],
                    "amount": numerator
                }
            },
            "maintenance_collateral_ratio": 1200,
            "maximum_short_squeeze_ratio": 1100,
            "core_exchange_rate": {
                "quote": {
                    "asset_id": "1.3.0",
                    "amount": int(denominator * 1.05)
                },
                "base": {
                    "asset_id": asset["id"],
                    "amount": numerator
                }
            }
        }
        handle = rpc.begin_builder_transaction()
        op = [
            19,  # id 19 corresponds to price feed update operation
            {
                "asset_id": asset["id"],
                "feed": price_feed,
                "publisher": account["id"]
            }
        ]
        rpc.add_operation_to_builder_transaction(handle, op)
        rpc.set_fees_on_builder_transaction(handle, "1.3.0")
        tx = rpc.sign_builder_transaction(handle, True)
        print(json.dumps(tx, indent=4))