Ejemplo n.º 1
0
def create():
    """
    Creates an escrow which manages mining
    """
    chain = blockchain.chain()
    creator = chain.web3.eth.accounts[0]  # TODO: make it possible to override
    tok = token.get()
    escrow, tx = chain.provider.get_or_deploy_contract(
        ESCROW_NAME,
        deploy_args=[token.get().address] + MINING_COEFF,
        deploy_transaction={'from': creator})
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
    tx = tok.transact({'from': creator}).addMiner(escrow.address)
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
    return escrow
Ejemplo n.º 2
0
def create():
    """
    Creates a contract with tokens and returns it.
    If it was already created, just returns the already existing contract

    :returns:   Token contract object
    """
    chain = blockchain.chain()
    web3 = chain.web3
    creator = web3.eth.accounts[0]  # TODO: make it possible to override

    token, tx = chain.provider.get_or_deploy_contract(
        CONTRACT_NAME,
        deploy_args=[PREMINE, SATURATION],
        deploy_transaction={'from': creator})
    if tx:
        chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)

    return token
Ejemplo n.º 3
0
def lock(amount: int, locktime: int, address: str = None):
    """
    Deposit and lock coins for mining. Creating coins starts after it is done

    :param amount:      Amount of coins to lock (in smallest  indivisible
                            units)
    :param locktime:    Locktime in periods
    :param address:     Optional address to get coins from (accounts[0] by
                        default)
    """
    chain = blockchain.chain()
    address = address or chain.web3.eth.accounts[0]
    escrow = nkms_eth.escrow.get()
    tx = token.get().transact({
        'from': address
    }).approve(escrow.address, amount)
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
    tx = escrow.transact({'from': address}).deposit(amount, locktime)
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
    tx = escrow.transact({'from': address}).switchLock()
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
Ejemplo n.º 4
0
def withdraw(address: str = None):
    chain = blockchain.chain()
    address = address or chain.web3.eth.accounts[0]
    escrow = nkms_eth.escrow.get()
    tx = escrow.transact({'from': address}).withdrawAll()
    chain.wait.for_receipt(tx, timeout=blockchain.TIMEOUT)
Ejemplo n.º 5
0
def get(name=CONTRACT_NAME):
    """
    Gets an existing contract or returns an error
    """
    return blockchain.chain().provider.get_contract(name)