-
Notifications
You must be signed in to change notification settings - Fork 0
New contracts and tests #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aditipolkam
wants to merge
19
commits into
master
Choose a base branch
from
new-features
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c34e757
refactor: :fire: support for sadaiv id
aditipolkam 0039116
Merge remote branch new-features into new-features
aditipolkam 2ea2e92
feat: :sparkles: add functions for new structure
aditipolkam ebeb3c6
refactor: :fire: contracts with diff logic and write tests
aditipolkam 03a1a66
refactor: :fire: modify contracts and add backup test
aditipolkam 7a96384
feat: :clown_face: add owner mapping
aditipolkam d1bdd2a
fix: :bug: add new owner function
aditipolkam 572cb97
refactor: :rotating_light: add deploy script and modify backup contract
aditipolkam 8d44d6c
docs: :bulb: add comments to describe functions
aditipolkam 33212c1
fix: :bug: uid for build mapping and add timestamp
aditipolkam 025084e
feat: :zap: add onlyOwner modifier for adding providers
aditipolkam fa11422
perf: :ambulance: emit build hash identifier
aditipolkam 7ec7f1e
fix: :bug: check if address regsitered before updates
aditipolkam 7688e06
modify: 🛠️contract for forked repo struct
aditipolkam 08774bc
removed need of signatures in contracts
tusharojha 0a16656
upgraded contract with solving infinite gas issue
tusharojha 5b9602a
fixed bug in contract addProvider
tusharojha 8eff20a
add scripts
aditipolkam b874787
Merge branch 'new-features' of https://github.com/sadaiv-ci/contracts…
aditipolkam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", | ||
| "editor.formatOnPaste": false, // required | ||
| "editor.formatOnType": false, // required | ||
| "editor.formatOnSave": true, // optional | ||
| "editor.formatOnSaveMode": "file", // required to format on save | ||
| "files.autoSave": "onFocusChange", // optional but recommended | ||
| "vs-code-prettier-eslint.prettierLast": "false", | ||
| "[solidity]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| } // set as "true" to run 'prettier' last not first | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Deployed Sadaiv verifier contract to: 0xd4E90ed4Da0a05c4552Db27511D467dB2c29C650 | ||
| Deployed Sadaiv Id contract to: 0x1e30A35CdeF1eB258EA7731A44F3AA255AC31Da5 | ||
| Deployed Sadaiv Backup contract to: 0xBFdD75A2098A177AD44A15480Ec20d650d981884 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| contract SadaivBackup { | ||
| mapping(address => bool) public owners; | ||
|
|
||
| constructor() { | ||
| owners[msg.sender] = true; | ||
| } | ||
|
|
||
| modifier onlyOwner() { | ||
| require(owners[msg.sender], "Not authorized!"); | ||
| _; | ||
| } | ||
|
|
||
| function makeOwner(address _address) public onlyOwner { | ||
| owners[_address] = true; | ||
| } | ||
|
|
||
| function checkIfOwner(address _address) public view returns (bool) { | ||
| return owners[_address]; | ||
| } | ||
|
|
||
| struct Build { | ||
| string branch; | ||
| string commitMessage; | ||
| string commitHash; | ||
| string timestamp; | ||
| uint256 contributorGithubId; | ||
| string backupCid; | ||
| string changesCid; //future scope | ||
| } | ||
|
|
||
| struct Repository { | ||
| uint256 id; | ||
| string name; | ||
| string fullname; | ||
| string description; | ||
| uint256 ownerGithubId; | ||
| uint256 size; | ||
| bool forked; | ||
| string defaultBranch; | ||
| string timestamp; | ||
| string[] topics; | ||
| string[] languages; | ||
| } | ||
|
|
||
| mapping(uint256 => Repository) public userRepos; //repoId => repo | ||
| mapping(uint256 => mapping(bytes32 => Build)) public repoBuilds; //repoId => hash(barnch+commitHash) => build | ||
|
|
||
| event NewBuild(Repository repository, Build build, bytes32 buildhash); | ||
|
|
||
| function createNewBuild( | ||
| Repository memory _repo, | ||
| Build memory _build | ||
| ) public onlyOwner { | ||
| userRepos[_repo.id] = _repo; | ||
| bytes32 buildhash = keccak256( | ||
| abi.encodePacked( | ||
| string(abi.encodePacked(_build.branch, _build.commitHash)) | ||
| ) | ||
| ); | ||
| repoBuilds[_repo.id][buildhash] = _build; | ||
| emit NewBuild(_repo, _build, buildhash); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
| import "@openzeppelin/contracts/utils/Counters.sol"; | ||
|
|
||
| interface VerifySignatureInterface { | ||
| function verifySignature( | ||
| address _signer, | ||
| string memory _message, | ||
| bytes memory signature | ||
| ) external returns (bool); | ||
| } | ||
|
|
||
| contract SadaivId { | ||
| mapping(address => bool) public owners; | ||
| VerifySignatureInterface public verifySignatureContract; | ||
| using Counters for Counters.Counter; | ||
| Counters.Counter public sadaivId; | ||
|
|
||
| constructor(address verifyContractAddress) { | ||
| owners[msg.sender] = true; | ||
| verifySignatureContract = VerifySignatureInterface(verifyContractAddress); | ||
| } | ||
|
|
||
| modifier onlyOwner() { | ||
| require(owners[msg.sender], "Not authorized!"); | ||
| _; | ||
| } | ||
|
|
||
| function makeOwner(address _address) public onlyOwner { | ||
| owners[_address] = true; | ||
| } | ||
|
|
||
| function checkIfOwner(address _address) public view returns (bool) { | ||
| return owners[_address]; | ||
| } | ||
|
|
||
| mapping(uint256 => mapping(uint256 => bool)) public sadaivIdToGithubId; | ||
| mapping(address => uint256) public SCWAddressToSadaivId; | ||
| mapping(uint256 => string) public contributorData; //sadaiv id to contributor data cid | ||
|
|
||
| event NewUser(uint256 sadaivId, address scwAddress); | ||
| event NewProfileChange(uint256 sadaivId, string cid); | ||
| event NewProvider(uint256 sadaivId, uint256 provider); | ||
|
|
||
| //register new user(with scw address) if not already registered | ||
| function registerUser( | ||
| string memory message, | ||
| bytes memory signature, | ||
| address signer | ||
| ) public returns (uint256) { | ||
| require( | ||
| verifySignatureContract.verifySignature(signer, message, signature), | ||
| "Address not authorized!" | ||
| ); | ||
| require(SCWAddressToSadaivId[signer] == 0, "Address already registered."); | ||
| sadaivId.increment(); | ||
| SCWAddressToSadaivId[signer] = sadaivId.current(); | ||
| emit NewUser(sadaivId.current(), signer); | ||
| return sadaivId.current(); | ||
| } | ||
|
|
||
| //function to add github account ids for a sadaiv userid | ||
| function addProviders( | ||
| string memory message, | ||
| bytes memory signature, | ||
| address signer, | ||
| uint256 _newId | ||
| ) public onlyOwner { | ||
| require( | ||
| verifySignatureContract.verifySignature(signer, message, signature), | ||
| "Address not authorized!" | ||
| ); | ||
| uint256 _sadaivId = SCWAddressToSadaivId[signer]; | ||
| require( | ||
| !sadaivIdToGithubId[_sadaivId][_newId], | ||
| "Provider already registered." | ||
| ); | ||
| sadaivIdToGithubId[_sadaivId][_newId] = true; | ||
| emit NewProvider(_sadaivId, _newId); | ||
| } | ||
|
|
||
| //change the contributor data cid | ||
| function changeContributorData( | ||
| string memory message, | ||
| bytes memory signature, | ||
| address signer, | ||
| string memory cid | ||
| ) public { | ||
| require( | ||
| verifySignatureContract.verifySignature(signer, message, signature), | ||
| "Address not authorized!" | ||
| ); | ||
| uint256 _sadaivId = SCWAddressToSadaivId[signer]; | ||
| contributorData[_sadaivId] = cid; | ||
|
||
| emit NewProfileChange(_sadaivId, cid); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| //SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| contract VerifySignature { | ||
| function getMessageHash( | ||
| string memory _message | ||
| ) public pure returns (bytes32) { | ||
| return keccak256(abi.encodePacked(_message)); | ||
| } | ||
|
|
||
| function getEthSignedMessageHash( | ||
| bytes32 _messageHash | ||
| ) public pure returns (bytes32) { | ||
| return | ||
| keccak256( | ||
| abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash) | ||
| ); | ||
| } | ||
|
|
||
| function verifySignature( | ||
| address _signer, | ||
| string memory _message, | ||
| bytes memory signature | ||
| ) public pure returns (bool) { | ||
| bytes32 messageHash = getMessageHash(_message); | ||
| bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash); | ||
|
|
||
| return recoverSigner(ethSignedMessageHash, signature) == _signer; | ||
| } | ||
|
|
||
| function recoverSigner( | ||
| bytes32 _ethSignedMessageHash, | ||
| bytes memory _signature | ||
| ) public pure returns (address) { | ||
| (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature); | ||
|
|
||
| return ecrecover(_ethSignedMessageHash, v, r, s); | ||
| } | ||
|
|
||
| function splitSignature( | ||
| bytes memory sig | ||
| ) public pure returns (bytes32 r, bytes32 s, uint8 v) { | ||
| require(sig.length == 65, "invalid signature length"); | ||
|
|
||
| assembly { | ||
| r := mload(add(sig, 32)) | ||
| s := mload(add(sig, 64)) | ||
| v := byte(0, mload(add(sig, 96))) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const hre = require("hardhat"); | ||
|
|
||
| async function main() { | ||
| const address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; | ||
| const backupContractFactory = await hre.ethers.getContractFactory("SadaivBackup"); | ||
| const backupContract = await backupContractFactory.attach(address); | ||
|
|
||
| const repository = { | ||
| name: 'Repo1', | ||
| fullname: 'Fullname1', | ||
| description: 'Description1', | ||
| ownerGithubId: 12345, | ||
| size: 100, | ||
| defaultBranch: 'main', | ||
| topics: ['topic1', 'topic2'], | ||
| language: 'Solidity', | ||
| }; | ||
|
|
||
| const build = { | ||
| branch: 'branch1', | ||
| commitMessage: 'Commit Message1', | ||
| contributorGithubId: 67890, | ||
| cid: 'CID123', | ||
| changesCid: 'CID456', | ||
| }; | ||
|
|
||
| const repoId = 1; | ||
| const commitHash = 'CommitHash123'; | ||
|
|
||
| let txn = await backupContract.createNewBuild(repository, build, repoId, commitHash); | ||
| await txn.wait(); | ||
| console.log("Backed up"); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error); | ||
| process.exitCode = 1; | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.