예제 #1
0
def balance(request):

    username = request.session['email']
    pwd = request.session['pwd']
    seed = username+pwd
    wallet = Wallet(None)
    wallet.generate_wallet(seed)
    addr = wallet.get_address()
    simba = get_simba_instance('https://api.simbachain.com/v1/w2c2/',wallet,'9bfc30e1f72bab8ed718176a64f47cb0f32123c00479552bd068578265ed406c'
,'')

    method_params = { 'addr':addr}
    resp = simba.call_method('getBalance',method_params)
    try:
        final_resp = simba.wait_for_success_or_error(resp.transaction_id)
        print("Successful? {}".format(final_resp))

    except Exception as e1:
        print("Failure! {}".format(e1))

    transaction_id = resp.transaction_id

    txn = simba.get_transaction(transaction_id)
    encoded = to_bytes(hexstr=txn['receipt']['logs'][0]['data'])

    decoded = decode_abi(['int','int','int'], encoded)

    if(decoded[2]==0):
        return render(request,'profile.html',{'name':request.session['name'],'email':request.session['email'],'mno':request.session['phone'],'address':request.session['address'],'balance':'Check Balance Failed'})

    b = str(decoded[0])+" Ecoins and "+str(decoded[1])+" Fcoins"

    return render(request,'profile.html',{'name':request.session['name'],'email':request.session['email'],'mno':request.session['phone'],'address':request.session['address'],'balance':b})
예제 #2
0
def register(request):

    Name = request.POST['name']
    Mno = request.POST['phone']
    email = request.POST['email']
    pwd = request.POST['pwd']
    seed = email+pwd
    wallet = Wallet(None)
    wallet.generate_wallet(seed)
    addr = wallet.get_address()

    c = Customer(address = addr,name=Name,phone=Mno,email=email,password = pwd,Ecoins=1000,Fcoins=1000)


    l = len(Customer.objects.filter(address=addr))
    if l != 0 :
        return HttpResponse("Signup UnSuccessful user already exists")

    c.save()

    simba = get_simba_instance('https://api.simbachain.com/v1/w2c2/',wallet,'9bfc30e1f72bab8ed718176a64f47cb0f32123c00479552bd068578265ed406c'
,'')
    #with open('wallet.pkl','wb') as output:
        #pickle.dump(wallet,output,pickle.HIGHEST_PROTOCOL)
    #with open('simba.pkl','wb') as output:
        #pickle.dump(simba,output,pickle.HIGHEST_PROTOCOL)


    method_params = { 'name':Name , 'mno':Mno , 'addr':addr}
    resp = simba.call_method('CreateEntity',method_params)
    try:
        final_resp = simba.wait_for_success_or_error(resp.transaction_id)
        print("Successful? {}".format(final_resp))

    except Exception as e1:
        print("Failure! {}".format(e1))

    transaction_id = resp.transaction_id

    txn = simba.get_transaction(transaction_id)
    encoded = to_bytes(hexstr=txn['receipt']['logs'][0]['data'])

    decoded = decode_abi(['int'], encoded)
    print(decoded)
    if(decoded[0]==1):
        request.session['name'] = Name
        request.session['phone'] = Mno
        request.session['email'] = email
        request.session['pwd'] = pwd  
        request.session['address'] = addr

        return render(request,'profile.html',{'name':request.session['name'],'email':request.session['email'],'mno':request.session['phone'],'address':request.session['address'] , 'balance':"Check Balance"})
예제 #3
0
def AcceptRequest(request):

    uuid = request.POST['uuid']
    frm = request.POST['from']
    username = request.session['email']
    pwd = request.session['pwd']
    seed = username+pwd
    wallet = Wallet(None)
    wallet.generate_wallet(seed)
    addr = wallet.get_address()

    l = len(Waste.objects.filter(uuid=uuid))

    if l == 0 :
        return HttpResponse("UUID does not exists")

    l = len(Customer.objects.filter(address=frm))

    if l==0 :
        return HttpResponse("Address does not exist")

    w = (Waste.objects.filter(uuid=uuid))[0]


    simba = get_simba_instance('https://api.simbachain.com/v1/w2c2/',wallet,'9bfc30e1f72bab8ed718176a64f47cb0f32123c00479552bd068578265ed406c','')

    method_params = {'uuid':uuid,'addr':addr }

    resp = simba.call_method('AcceptRequest',method_params)
    try:
        final_resp = simba.wait_for_success_or_error(resp.transaction_id)
        print("Successful? {}".format(final_resp))

    except Exception as e1:
        print("Failure! {}".format(e1))

    transaction_id = resp.transaction_id

    txn = simba.get_transaction(transaction_id)
    encoded = to_bytes(hexstr=txn['receipt']['logs'][0]['data'])
    decoded = decode_abi(['int'], encoded)

    if(decoded[0]==1):
        w.Ownedby = addr
        w.save()
        return render(request,'profile.html',{'name':request.session['name'],'email':request.session['email'],'mno':request.session['phone'],'address':request.session['address'],'balance':'Check Balance'})
    elif(decoded[0]==-1):
        return HttpResponse("No Request Received")
    elif(decoded[0]==0):
        return HttpResponse("Insufficient Balance") 
예제 #4
0
def CreateWaste(request):
    uuid = request.POST['uuid']
    wtype = request.POST['type']
    weight = request.POST['weight']

    username = request.session['email']
    pwd = request.session['pwd']
    seed = username+pwd

    wallet = Wallet(None)
    wallet.generate_wallet(seed)
    addr = wallet.get_address()

    c = Waste(uuid = uuid,wtype=wtype,weight = weight,Createdby = addr,Ownedby = addr)

    l = len(Waste.objects.filter(uuid=uuid))

    if l != 0 :
        return HttpResponse("UUID already exists")
    c.save()

    simba = get_simba_instance('https://api.simbachain.com/v1/w2c2/',wallet,'9bfc30e1f72bab8ed718176a64f47cb0f32123c00479552bd068578265ed406c'
,'')

    if wtype == 'Energy':
        wtype = 0
    elif wtype == "Fertilizer":
        wtype = 1


    method_params = { 'uuid':uuid ,'wtype':wtype,'weight':weight,'addr':addr }
    resp = simba.call_method('CreateWaste',method_params)
    try:
        final_resp = simba.wait_for_success_or_error(resp.transaction_id)
        print("Successful? {}".format(final_resp))

    except Exception as e1:
        print("Failure! {}".format(e1))

    transaction_id = resp.transaction_id

    txn = simba.get_transaction(transaction_id)
    encoded = to_bytes(hexstr=txn['receipt']['logs'][0]['data'])
    decoded = decode_abi(['int'], encoded)

    if(decoded[0]==1):
        return render(request,'profile.html',{'name':request.session['name'],'email':request.session['email'],'mno':request.session['phone'],'address':request.session['address'],'balance':'Check Balance'})
    else:
        return HttpResponse("UUID already exists") 
예제 #5
0
def test_002(test_globals):
    """
    Get a SIMBAChain instance to perform all future actions with.
    Requires a URL and an API_KEY to the SIMBAChain API

    Get the balance for this wallet, and add funds.
    In this example it's pointless however, it's PoA

    Args:
        test_globals : a convenience object to hold the SIMBA instance and wallet
    """
    print('Running a test to get a SIMBAChain instance')
    wallet = test_globals.wallet

    simba = get_simba_instance(
        'https://api.simbachain.com/v1/libSimba-SimbaChat-Quorum/', wallet,
        '04d1729f7144873851a745d2ae85639f55c8e3de5aea626a2bcd0055c01ba6fc', '')

    balance = simba.get_balance()
    print("Balance: {}".format(json.dumps(balance)))

    result = simba.add_funds()
    if result['poa']:
        print("Didn't add funds. PoA network {}".format(json.dumps(result)))
    elif result['faucet_url']:
        print("Didn't add funds: External faucet: {} - {}".format(
            result['faucet_url'], json.dumps(result)))
        print(
            "To top up, you need to ask the user to visit the url in `faucet_url`"
        )
    else:
        print(
            "Funded - May take up to a minute for the transaction to process: "
            .format(json.dumps(result)))

    test_globals.simba = simba
예제 #6
0
def track(request):

    uuid = request.POST['uuid']
    uuid_filter = uuid
    username = request.session['email']
    password = request.session['pwd']
    seed = username+password
    wallet = Wallet(None)
    wallet.generate_wallet(seed)    
    simba = get_simba_instance('https://api.simbachain.com/v1/w2c2/',wallet,'9bfc30e1f72bab8ed718176a64f47cb0f32123c00479552bd068578265ed406c','')
    method_params = {'uuid':uuid}
    result_pages = simba.get_method_transactions('CreateWaste', method_params)

    res = result_pages.data()
    timestamp = []
    uuid = []
    by = []
    wtype = []
    weight = []
    status = []

    for t in res:

        param = t['payload']['inputs']
        if(param['uuid']==uuid_filter):
            timestamp.append(t['timestamp'])
       
            uuid.append(param['uuid'])
            #wtype.append(param['wtype'])
            if (param['wtype']=='0'):
                wtype.append('Energy')
            elif (param['wtype']=='1'):
                wtype.append('Fertilizer')
            weight.append(param['weight'])
            by.append(param['addr'])
            data = t['receipt']['logs'][0]['data']
            encoded = to_bytes(hexstr=data)
            decoded = decode_abi(['int'], encoded)
            if(decoded[0]==1):
                status.append("Successful")
            elif(decoded[0]==0):
                status.append("Failed")

    row1 = zip(timestamp, uuid,by, wtype,weight,status)

    result_pages = simba.get_method_transactions('AcceptRequest', method_params)
    res = result_pages.data()
    timestamp = []
    to = []
    uuid = []
    wtype = []
    weight = []
    status = []

    for t in res:

        param = t['payload']['inputs']
        if(param['uuid']==uuid_filter):

            timestamp.append(t['timestamp'])
            uuid.append(param['uuid'])
            to.append(param['addr'])
            w = (Waste.objects.filter(uuid = param['uuid']))[0]
            wtype.append(w.wtype)
            weight.append(w.weight)
            data = t['receipt']['logs'][0]['data']
            encoded = to_bytes(hexstr=data)
            decoded = decode_abi(['int'], encoded)
            if(decoded[0]==1):
                status.append("Successful")
            elif(decoded[0]==0):
                status.append("Failed")

    row2 = zip(timestamp,uuid,to,wtype,weight,status)
    return render(request,'track.html',{'row1':row1,'row2':row2})