Thursday 28 March 2019

EVM Solidity

pragma solidity ^0.4.21;
contract Election{
    struct Canditate{
        string name;
        uint voteCount;
    }
    struct Voter{
        bool authorized;
        bool voted;
        uint vote;
    }
    address public owner;
    string public electionName;
   
    mapping(address => Voter) public Voters;
    Canditate[] public Canditates;
    uint public totalVotes;
   
    modifier ownerOnly(){
        require(msg.sender == owner);
        _;
    }
    function Election(string _name) public {
        owner = msg.sender;
        electionName = _name;
    }
    function getNumberCandidates() public view returns(uint) {
        return Canditates.length;
    }
    function addCandidate(string _name) ownerOnly public {
        Canditates.push(Canditate(_name,0));
    }
    function authorize(address _person) ownerOnly public {
        Voters[_person].authorized = true;
    }
    function vote(uint _voterIndex) public {
        require(!Voters[msg.sender].voted);
        require(Voters[msg.sender].authorized);
       
        Voters[msg.sender].vote = _voterIndex;
        Voters[msg.sender].voted = true;
         Canditates[_voterIndex].voteCount += 1;
         totalVotes += 1;
    }
   
    function end() ownerOnly public {
        selfdestruct(owner);
    }}

Wednesday 27 March 2019

solidity code

pragma solidity ^0.4.0;
contract SimpleStorage{
    uint a;
    uint shop_1=0;
    uint shop_2=0;
    function initial( uint balu)public{
        a = balu;
    }
     function Shop1( uint balu)public{
        a = a-balu;
        shop_1=shop_1+balu;
    }
     function Shop2(uint balu)public{
          a = a-balu;
          shop_2=shop_2+balu;
    }
     function add(uint balu)public{
          a = a+balu;
    }
    function balance()public constant returns(uint){
        return a;
    }
     function shop_1balance()public constant returns(uint){
        return shop_1;
    } function shop_2balance()public constant returns(uint){
        return shop_2;
    }
    
}

Monday 18 March 2019

DHT11

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "       "; //Enter the Auth code which was send by Blink

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "     ";  //Enter your WIFI Name
char pass[] = "     ";  //Enter your WIFI Password

#define DHTPIN 2          // Digital pin 4

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

Sunday 17 March 2019

DT

input=readingSkills[c(1:105),]               
output=ctree(nativeSpeaker~age+shoeSize+score,data=input)
plot(output)

ML1

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

 relation <- lm(y~x)

a <- data.frame(x=170)
result <- predict(relation,a) print(result)

Friday 8 March 2019

Project2

https://hyperledger.github.io/composer/v0.19/tutorials/playground-tutorial.html

Hyperledger - First DAPP


BNA for Basic CU option


It will demonstrates the core functionality of Hyperledger Composer by changing the value of an asset.

Participant - SampleParticipant
               Asset - SampleAsset
               Transaction -  SampleTransaction
               Event  - SampleEvent
SampleAssets are owned by a SampleParticipant, and the value property on a SampleAsset can be modified by submitting a SampleTransaction. The SampleTransaction emits a SampleEvent that notifies applications of the old and new values for each modified SampleAsset.
Create a SampleParticipant participant:
{
  "$class": "org.example.basic.SampleParticipant",
  "participantId": "EMP1",
  "firstName": "Manish",
  "lastName": "Jain"
}

Create a SampleAsset asset:

{
  "$class": "org.example.basic.SampleAsset",
  "assetId": "assetId:1",
  "owner": "resource:org.example.basic.SampleParticipant#EMP1",
  "value": "HP Laptop"
}

Submit a SampleTransaction transaction:
{
  "$class": "org.example.basic.SampleTransaction",
  "asset": "resource:org.example.basic.SampleAsset#assetId:1",
  "newValue": "Dell Laptop"
}

After submitting this transaction, you should now see the transaction in the Transaction Registry and that a SampleEvent has been emitted. As a result, the value of the assetId:1 should now be new value in the Asset Registry.

'o' indicates has-a relationship
'-->' indicates pass by reference


Models/Sample.cto

namespace org.example.basic

asset SampleAsset identified by assetId {
  o String assetId
  --> SampleParticipant owner
  o String value
}

participant SampleParticipant identified by participantId {
  o String participantId
  o String firstName
  o String lastName
}

transaction SampleTransaction {
  --> SampleAsset asset
  o String newValue
}

event SampleEvent {
  --> SampleAsset asset
  o String oldValue
  o String newValue
}


Lib/sample.js

async function sampleTransaction(tx) { 

    // Save the old value of the asset.
    const oldValue = tx.asset.value;

    // Update the asset with the new value.
    tx.asset.value = tx.newValue;

    // Get the asset registry for the asset.
    const assetRegistry = await getAssetRegistry('org.example.basic.SampleAsset');
    // Update the asset in the asset registry.
    await assetRegistry.update(tx.asset);

    // Emit an event for the modified asset.
    let event = getFactory().newEvent('org.example.basic', 'SampleEvent');
    event.asset = tx.asset;
    event.oldValue = oldValue;
    event.newValue = tx.newValue;
    emit(event);
}

Permission.acl

rule EverybodyCanReadEverything {
    description: "Allow all participants read access to all resources"
    participant: "org.example.basic.SampleParticipant"
    operation: READ
    resource: "org.example.basic.*"
    action: ALLOW
}

rule EverybodyCanSubmitTransactions {
    description: "Allow all participants to submit transactions"
    participant: "org.example.basic.SampleParticipant"
    operation: CREATE
    resource: "org.example.basic.SampleTransaction"
    action: ALLOW
}

rule OwnerHasFullAccessToTheirAssets {
    description: "Allow all participants full access to their assets"
    participant(p): "org.example.basic.SampleParticipant"
    operation: ALL
    resource(r): "org.example.basic.SampleAsset"
    condition: (r.owner.getIdentifier() === p.getIdentifier())
    action: ALLOW
}

rule SystemACL {
    description: "System ACL to permit all access"
    participant: "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule NetworkAdminSystem {
    description: "Grant business network administrators full access to system resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}