Esempio n. 1
0
def create_proposals(node, proposals, wif=None):
    logger.info("Creating proposals...")
    from beembase.operations import Create_proposal
    for proposal in proposals:
        logger.info("New proposal ==> ({},{},{},{},{},{},{})".format(
            proposal['creator'], 
            proposal['receiver'], 
            proposal['start_date'], 
            proposal['end_date'],
            proposal['daily_pay'],
            "Proposal from account {}".format(proposal['creator']),
            get_permlink(proposal['creator'])
        ))

        op = Create_proposal(
            **{
                'creator' : proposal['creator'], 
                'receiver' : proposal['receiver'], 
                'start_date' : proposal['start_date'], 
                'end_date' : proposal['end_date'],
                'daily_pay' : proposal['daily_pay'],
                'subject' : "Proposal from account {}".format(proposal['creator']),
                'permlink' : get_permlink(proposal['creator'])
            }
        )
        node.finalizeOp(op, proposal['creator'], "active")
    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 5)
    else:
        hive_utils.common.wait_n_blocks(node.rpc.url, 5)
Esempio n. 2
0
def create_proposals(node, accounts, start_date, end_date, wif=None):
    logger.info("Creating proposals...")
    from beembase.operations import Create_proposal
    for acnt in accounts:
        logger.info("New proposal ==> ({},{},{},{},{},{},{})".format(
            acnt['name'], 
            acnt['name'], 
            start_date, 
            end_date,
            "24.000 TBD",
            "Proposal from account {}".format(acnt['name']),
            test_utils.get_permlink(acnt['name'])
        ))
        op = Create_proposal(
            **{
                'creator' : acnt['name'], 
                'receiver' : acnt['name'], 
                'start_date' : start_date, 
                'end_date' : end_date,
                'daily_pay' : "24.000 TBD",
                'subject' : "Proposal from account {}".format(acnt['name']),
                'permlink' : test_utils.get_permlink(acnt['name'])
            }
        )
        node.finalizeOp(op, acnt['name'], "active")
    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 5)
    else:
        hive_utils.common.wait_n_blocks(node.rpc.url, 5)
Esempio n. 3
0
def transfer_assets_to_treasury(node, from_account, treasury_account, amount, asset, wif=None):
    from beem.account import Account
    logger.info("Transfer from {} to {} amount {} {}".format(from_account, 
        treasury_account, amount, asset)
    )
    acc = Account(from_account, hive_instance=node)
    acc.transfer(treasury_account, amount, asset, memo = "initial transfer")
    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 5)
    else:
        hive_utils.common.wait_n_blocks(node.rpc.url, 5)
Esempio n. 4
0
def calculate_propsal_budget( node, treasury, wif = None) -> int:
    if wif is not None:
        from datetime import timedelta
        period = date_from_iso(node.get_dynamic_global_properties(False)["next_maintenance_time"]) - timedelta(seconds=4)
        logger.info(f"Fast-forwarding to: {date_to_iso(period)}")
        hive_utils.debug_generate_blocks_until(node.rpc.url, wif, date_to_iso(period), False)

    v = int(print_balance(node, [{'name' : treasury}])[0])

    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 1)

    return round(( v * 0.01 ) / 24.0)
Esempio n. 5
0
def create_posts(node, accounts, wif=None):
    logger.info("Creating posts...")
    for acnt in accounts:
        logger.info("New post ==> ({},{},{},{},{})".format(
            "Hivepy proposal title [{}]".format(acnt['name']),
            "Hivepy proposal body [{}]".format(acnt['name']), acnt['name'],
            get_permlink(acnt['name']), "proposals"))
        node.post("Hivepy proposal title [{}]".format(acnt['name']),
                  "Hivepy proposal body [{}]".format(acnt['name']),
                  acnt['name'],
                  permlink=get_permlink(acnt['name']),
                  tags="proposals")
    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 5)
    else:
        hive_utils.common.wait_n_blocks(node.rpc.url, 5)
def vote_proposals(node, accounts, wif):
    logger.info("Voting proposals...")
    from beembase.operations import Update_proposal_votes
    for acnt in accounts:
        proposal_set = [0, 1, 2, 3, 4]
        logger.info("Account {} voted for proposals: {}".format(
            acnt["name"], ",".join(str(x) for x in proposal_set)))
        op = Update_proposal_votes(**{
            'voter': acnt["name"],
            'proposal_ids': proposal_set,
            'approve': True
        })
        node.finalizeOp(op, acnt["name"], "active")
    if wif is not None:
        hive_utils.debug_generate_blocks(node.rpc.url, wif, 5)
    else:
        hive_utils.common.wait_n_blocks(node.rpc.url, 5)
        node.run_hive_node(["--enable-stale-production"])
    try:
        if node is None or node.is_running():
            node_client = Hive(node = [node_url], no_broadcast = False, 
                keys = keys
            )

            # create accounts
            test_utils.create_accounts(node_client, args.creator, accounts)
            # tranfer to vesting
            test_utils.transfer_to_vesting(node_client, args.creator, accounts, "300.000", 
                "TESTS"
            )
            logger.info("Wait 30 days for full voting power")
            hive_utils.debug_quick_block_skip(node_client, wif, (30 * 24 * 3600 / 3))
            hive_utils.debug_generate_blocks(node_client.rpc.url, wif, 10)
            # transfer assets to accounts
            test_utils.transfer_assets_to_accounts(node_client, args.creator, accounts, 
                "400.000", "TESTS", wif
            )

            test_utils.transfer_assets_to_accounts(node_client, args.creator, accounts, 
                "400.000", "TBD", wif
            )

            logger.info("Balances for accounts after initial transfer")
            test_utils.print_balance(node_client, accounts)
            # transfer assets to treasury
            test_utils.transfer_assets_to_treasury(node_client, args.creator, args.treasury, 
                "999950.000", "TBD", wif
            )
    for account in accounts:
        keys.append(account["private_key"])

    if node is not None:
        node.run_hive_node(["--enable-stale-production"])
    try:
        if node is None or node.is_running():
            node_client = Hive(node=[node_url], no_broadcast=False, keys=keys)

            # create accounts
            test_utils.create_accounts(node_client, args.creator, accounts)
            # tranfer to vesting
            test_utils.transfer_to_vesting(node_client, args.creator, accounts,
                                           "300.000", "TESTS")
            logger.info("Wait 30 days for full voting power")
            hive_utils.debug_generate_blocks(node_client.rpc.url, wif,
                                             30 * 24 * 3600 / 3 + 10)
            # transfer assets to accounts
            test_utils.transfer_assets_to_accounts(node_client, args.creator,
                                                   accounts, "400.000",
                                                   "TESTS", wif)

            test_utils.transfer_assets_to_accounts(node_client, args.creator,
                                                   accounts, "400.000", "TBD",
                                                   wif)

            logger.info("Balances for accounts after initial transfer")
            test_utils.print_balance(node_client, accounts)
            # transfer assets to treasury
            test_utils.transfer_assets_to_treasury(node_client, args.creator,
                                                   args.treasury,
                                                   "1000000.000", "TBD", wif)