Example #1
0
def receive(account, private_key, representative, amount, link):
    request = requests.post(worker["node"],
                            json={
                                "action": "accounts_frontiers",
                                "accounts": [account]
                            })
    previous = frontier(account)
    if previous == "0000000000000000000000000000000000000000000000000000000000000000":
        request = requests.post(worker["node"],
                                json={
                                    "action": "account_key",
                                    "account": account
                                })
        workHash = request.json()["key"]
    else:
        workHash = previous
    block = Block(block_type="state",
                  account=account,
                  representative=representative,
                  previous=previous,
                  balance=balance(worker["account"]) + amount,
                  link=link)
    solveWork = solve_work(workHash, worker["difficulty_receive"])
    if "error" in solveWork:
        return {"error": solveWork["error"]}
    block.work = solveWork["work"]
    block.sign(private_key)
    r = broadcast(block.json())
    return r
Example #2
0
    def create_block(prev_block, private_key, amount):
        account_id = get_account_id(private_key=private_key)
        link_block = legacy_pocketable_block_factory(
            account_id=account_id, amount=amount)

        raw_block = RawBlock(
            account=account_id,
            block_type="receive",
            previous=prev_block.block_hash,
            source=link_block.block_hash)
        raw_block.sign(private_key)
        raw_block.solve_work(difficulty=TEST_DIFFICULTY)

        block = Block(
            block_data=raw_block.to_dict(),
            link_block=link_block,
        )

        return block
Example #3
0
def receive(account, private_key, representative, amount, link, difficulty):
    request = requests.post(node,
                            json={
                                "action": "accounts_frontiers",
                                "accounts": [account]
                            })
    if account in request.json()["frontiers"]:
        previous = request.json()["frontiers"][account]
    else:
        previous = "0000000000000000000000000000000000000000000000000000000000000000"
    block = Block(block_type="state",
                  account=account,
                  representative=representative,
                  previous=previous,
                  balance=balance(worker_account) + amount,
                  link=link)
    block.work = solve_work(frontier(account), difficulty)
    block.sign(private_key)
    r = broadcast(block.json())
    return r
Example #4
0
    def create_link_block(account_id, amount):
        sending_private_key = generate_seed()
        sending_account_id = get_account_id(private_key=sending_private_key)

        block = RawBlock(
            block_type="send",
            account=sending_account_id,
            previous=generate_seed().upper(),
            destination=account_id,
            balance=amount + random.randint(-amount, 2**110)
        )
        block.sign(sending_private_key)
        block.solve_work(difficulty=TEST_DIFFICULTY)

        link_block = LinkBlock(
            block_data=block.to_dict(),
            amount=amount,
            timestamp=Timestamp(
                date=time.time(), source=TimestampSource.WALLET
            )
        )

        return link_block