Ejemplo n.º 1
0
def edit(id):
    contract = Contract.get_by_id(id)
    form = ContractForm()
    if contract.owner_id == current_user.id:
        return render_template('editar.html', contract = contract, form = form)
    flash ('No eres el dueño de este contrato')
    return render_template('contract.html')
Ejemplo n.º 2
0
def onSale(id):
    contract = Contract.get_by_id(id)
    if (contract.onSale==False):
        Contract.onSale_True(contract)
        flash('Contrato puesto a la venta')
        return redirect (url_for('contract'))
    
    flash ('El contrato ya se encuentra a la venta')
    return redirect (url_for('contract'))
Ejemplo n.º 3
0
def update(id):
    contract = Contract.get_by_id(id)
    form = ContractForm()
    if form.validate_on_submit():
        title = form.title.data
        description = form.description.data
        price = form.price.data

        Contract.update_title(contract, title)
        Contract.update_description(contract, description)
        Contract.update_price(contract, price)
        flash ('Contrato actualizado')
Ejemplo n.º 4
0
def buy(id):

    contract = Contract.get_by_id(id) #instancio contrato 
    user = User.get_by_id(current_user.id) #instancio comprador
    if (contract.owner_id == current_user.id):
        flash('Usted es el dueño de este contrato')
        return render_template('newContract.html') 

    walletV =  Wallet.get_by_idownerunico(contract.owner_id) 
    acctV = w3.eth.account.privateKeyToAccount(walletV.key) #direccion vendedor

    walletC = Wallet.get_by_idownerunico(current_user.id)
    acctC = w3.eth.account.privateKeyToAccount(walletC.key) #direccion comprador

    signed_txn = w3.eth.account.signTransaction(dict(
    nonce=w3.eth.getTransactionCount(str(acctC.address)),
    gasPrice=w3.eth.gasPrice,
    gas=100000,
    to=str(acctV.address),  
    value=int(contract.price),
    data=b'',
    ),
    str(walletC.key),
    )
    tx_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    hash = w3.toHex(tx_receipt['transactionHash'])
    Contract.update_idowner(contract, current_user.id)
    Contract.onSale_False(contract)
    #contract_instance = w3.eth.contract(address= contract.address, abi = abi)
    #tx_hash2 = contract_instance.functions.setOwner(acctC.address).transact()

    #tx_receipt2 = w3.eth.waitForTransactionReceipt(tx_hash2)
    #hash2 = w3.toHex(tx_receipt2['transactionHash'])

    flash('Contract adquired')
    return render_template('newContract.html', hash=hash) #hash2 = hash2
Ejemplo n.º 5
0
def delete(id):
    contract = Contract.get_by_id(id)
    db.session.delete(contract)
    db.session.commit()
    flash('Contrato eliminado')
    return redirect (url_for('contract'))