Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions workshop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions workshop/abstraction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity >=0.4.0 <0.6.0;
contract vehicle {
function noOfWheels() public view returns (uint);
}

contract Car is vehicle {
function noOfWheels() public view returns (uint){ return 4; }
}
122 changes: 122 additions & 0 deletions workshop/arraySample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
pragma solidity ^0.5.0;
pragma experimental "ABIEncoderV2";

contract Arrays {

uint[3] fixedSimpleArr; // fixed sized array
uint[] simpleDynamicArr; // dynamic array
uint[3][3] fixedSized; // fixed sized 2D array
uint[][3] arrayDynamic; // dynamic array with each element an array with 3
uint[3][] dynamicArray; // fixed sized array with each element a dynamic
uint[][] dynamicArr; // dynamic array with dynamic array elemnts.
uint[3][3][3] threeDArr;
constructor () public {
fixedSimpleArr = [1,2,3];
uint j;
for (uint i=0;i<3;i++){
j = i+1;
fixedSized[i] = [j*1, j*2, j*3];
}
uint[3] memory temp = [uint(1),2,3];
arrayDynamic[0] = new uint[](4);
arrayDynamic[1] = [1,2,3,4,5,6,7,8];
arrayDynamic[2] = temp;
dynamicArray = new uint[2][](3);
dynamicArray = [[1,2], [6,7], [9,0]];
threeDArr = [
[[1,2,3], [4,5,6], [7,8,9]],
[[10,11,12], [13,14,15], [16,17,18]],
[[19,20,21], [22,23,24], [25,26,27]]
];
}

function setFixedSimpleArr(uint[3] memory simpleArr) public {
fixedSimpleArr = simpleArr;
}

// This function is illegal
function setSimpleDynamicArr(uint[] memory simpleArr) public {
simpleDynamicArr = simpleArr;
}

function setFixedSized(uint[3][3] memory inputArr) public {
fixedSized = inputArr;
}

function setDynamicArray(uint[3][] memory inputArr) public {
dynamicArray = inputArr;
}

// This function is illegal
function setArrayDynamic(uint[][3] memory inputArr) public {
arrayDynamic = inputArr;
}

// This function is illegal
function setDynamicArr(uint[][] memory inputArr) public {
dynamicArr = inputArr;
}

function setThreeDArr(uint[3][3][3] memory inputArr) public {
threeDArr = inputArr;
}

function getFixedSimpleArr() public view returns (uint[3] memory) {
return fixedSimpleArr;
}

function getSimpleDynamicArr() public view returns (uint[] memory) {
return simpleDynamicArr;
}

function getFixedSized() public view returns (uint[3][3] memory) {
return fixedSized;
}

function getDynamicArray() public view returns (uint[3][] memory) {
return dynamicArray;
}

// This function is illegal
function getArrayDynamic() public view returns (uint[][3] memory) {
return arrayDynamic;
}

// This function is illegal
function getDynamicArr() public view returns (uint[][] memory) {
return dynamicArr;
}

function getThreeDArr() public view returns (uint[3][3][3] memory) {
return threeDArr;
}

function getElementFixedSimpleArr(uint i) public view returns (uint) {
return fixedSimpleArr[i];
}

// This function is illegal
function getElementSimpleDynamicArr(uint i) public view returns (uint) {
return simpleDynamicArr[i];
}

function getElementFixedSized(uint i, uint j) public view returns (uint) {
return fixedSized[i][j];
}

function getElementDynamicArray(uint i, uint j) public view returns (uint) {
return dynamicArray[i][j];
}

function getElementArrayDynamic(uint i, uint j) public view returns (uint) {
return arrayDynamic[i][j];
}

function getElementDynamicArr(uint i, uint j) public view returns (uint) {
return dynamicArr[i][j];
}

function getElementThreeDArr(uint i, uint j, uint k) public view returns (uint) {
return threeDArr[i][j][k];
}
}
16 changes: 16 additions & 0 deletions workshop/assgnmnt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity ^0.5.9;
contract C {
uint index;
function f() public pure returns (uint, bool, uint) {
return (7, true, 2);
}
function g() public returns(uint) {
(uint x, , uint y) = f();
(x, y) = (y, x);
(index, , ) = f(); // Sets the index to 7
return index;
}
function get() public view returns(uint) {
return index;
}
}
15 changes: 15 additions & 0 deletions workshop/complex.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.5.9;
pragma experimental "ABIEncoderV2";
contract complexSol {
struct cx {
int256 x;
int256 y;
}
cx result;
function complexAddition(cx memory a, cx memory b) public view returns(cx memory){
cx memory res;
res.x = a.x + b.x;
res.y = a.y + b.y;
return res;
}
}
49 changes: 49 additions & 0 deletions workshop/inherit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// pragma solidity >=0.4.0 <0.6.0;

// contract C {
// uint private data;

// function f(uint a) public pure returns(uint b) { return a + 1; }
// function setData(uint a) public { data = a; }
// function getData() public view returns(uint) { return data; }
// function compute(uint a, uint b) external pure returns (uint) { return a + b; }
// }

// // This will not compile
// contract D {
// function readData() public {
// C c = new C();
// uint local = c.f(7); // error: member `f` is not visible
// c.setData(3);
// local = c.getData();
// local = c.compute(3, 5); // error: member `compute` is not visible
// }
// }



// pragma solidity >=0.4.0 <0.6.0;

// contract C {
// uint public data = 42;
// }

// contract Caller {
// C c = new C();
// function f() public view returns (uint) {
// return c.data();
// }
// }




// contract E is C {
// function g() public {
// C c = new C();
// uint val = compute(3, 5); // access to internal member (from derived to parent contract)
// }
// }



38 changes: 38 additions & 0 deletions workshop/p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const Web3 = require('web3');
const solc = require('solc');
const fs = require('fs');
const path = require('path');
// var web3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
const p = path.resolve(__dirname, "reciept.sol");
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
// web3.eth.getAccounts().then(console.log);
const source = fs.readFileSync(p, 'UTF-8');
const input = {
language: 'Solidity',
sources: {
'reciept.sol': {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
const pbi = JSON.parse(solc.compile(JSON.stringify(input)));

const abi = pbi.contracts['reciept.sol'].ClientReceipt.abi;
const ClientReceipt = new web3.eth.Contract(abi, "0x989CD4D7a3374EEf60f038027C22cf876E27f066");
ClientReceipt.methods.deposit("0x7e5605F81c51B813089D19950FF087136a1E7cBF").send({ from: "0x7e5605F81c51B813089D19950FF087136a1E7cBF" }).then((result) => {
if (result){}
console.log("result:", result);
});

web3.eth.getAccounts().then(e => {
web3.eth.getBalance(e);
});

// console.log("0th acc.", )
Loading