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 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