Skip to content

Commit

Permalink
additional practice
Browse files Browse the repository at this point in the history
  • Loading branch information
MahithChigurupati committed Dec 17, 2022
1 parent 6ba9e23 commit 55ec68f
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
50 changes: 50 additions & 0 deletions alpha.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

contract alpha{

mapping(uint => string) public counter;

constructor(){
counter[1] = "A";
counter[2] = "B";
counter[3] = "C";
counter[4] = "D";
counter[5] = "E";
counter[6] = "F";
counter[7] = "G";
counter[8] = "H";
counter[9] = "I";
counter[10] = "J";
counter[11] = "K";
counter[12] = "L";
counter[13] = "M";
counter[14] = "N";
counter[15] = "O";
counter[16] = "P";
counter[17] = "Q";
counter[18] = "R";
counter[19] = "S";
counter[20] = "T";
counter[21] = "U";
counter[22] = "V";
counter[23] = "W";
counter[24] = "X";
counter[25] = "Y";
counter[26] = "Z";
}



function turnToAlpha(uint[] memory numbers) public view returns(string memory){

string memory finalWord = "";
for(uint i=0;i<numbers.length;i++){
finalWord = string.concat(finalWord, counter[numbers[i]]);
}
return finalWord;

}

}
22 changes: 22 additions & 0 deletions events.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

contract events{

event log1(uint a, address ad, string text);
event log2(uint indexed a, address ad, string text);
event log3(uint a, address ad, string indexed text);

function callLog1() public{
emit log1(5, 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, "test" );
}

function callLog2() public{
emit log2(5, 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, "test" );
}

function callLog3() public{
emit log3(5, 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, "test" );
}
}
76 changes: 76 additions & 0 deletions multiSign.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

contract multiSign{

address[] public owners;
mapping(address => bool) public ownerList;
mapping(uint => mapping(address => bool)) public alreadyVoted;
uint public approvalsNeeded;

struct transaction{
address sendTo;
uint amount;
uint approvals;
bool execution;
}

transaction[] public proposedTransactions;

constructor(){
ownerList[msg.sender] = true;
owners.push(msg.sender);
}

receive() external payable{}

modifier onlyOwner{
require(ownerList[msg.sender] == true, "Only owner is allowed");
_;
}

function setApprovalsNeeded(uint need) public {
approvalsNeeded = need;
}

function addOwner(address newOwner) onlyOwner public {
owners.push(newOwner);
ownerList[newOwner] = true;
}

function proposeTransaction(address to, uint value) public {
proposedTransactions.push(transaction({
sendTo: to,
amount: value,
approvals: 0,
execution: false
}));

}

function voteTransaction(uint index) onlyOwner public {
require(alreadyVoted[index][msg.sender]==false, "Already voted");
proposedTransactions[index].approvals += 1;
alreadyVoted[index][msg.sender] = true;
}

function revokeVote(uint index) onlyOwner public {
require(alreadyVoted[index][msg.sender]==true, "No Previous vote found to revoke");
proposedTransactions[index].approvals -= 1;
alreadyVoted[index][msg.sender] = false;
}

function executeTx(uint index) onlyOwner public{
require(proposedTransactions[index].approvals >= approvalsNeeded,"No enough approvals");
require(proposedTransactions[index].execution==false, "Already executed");

address payable sender = payable(proposedTransactions[index].sendTo);
(bool tryToSend,) = sender.call{value: proposedTransactions[index].amount, gas: 5000}("");
require(tryToSend== true,"No enough ETH balance");
proposedTransactions[index].execution = true;

}

}

0 comments on commit 55ec68f

Please sign in to comment.