-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial smart contract from the hackaton.
A very naive implementation of smart contract that allows match-making between donors and donators in a decentralized manner. Co-authored-by: KDOT2509 <[email protected]>
- Loading branch information
0 parents
commit 06b6982
Showing
6 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,180 @@ | ||
|
||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,soliditytruffle,solidity | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,soliditytruffle,solidity | ||
|
||
### Solidity ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
### SolidityTruffle ### | ||
# depedencies | ||
node_modules | ||
|
||
# testing | ||
|
||
# production | ||
build | ||
build_webpack | ||
|
||
# misc | ||
.DS_Store | ||
npm-debug.log | ||
.truffle-solidity-loader | ||
.vagrant/** | ||
blockchain/geth/** | ||
blockchain/keystore/** | ||
blockchain/history | ||
|
||
#truffle | ||
yarn.lock | ||
package-lock.json | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
# Support for Project snippet scope | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,soliditytruffle,solidity |
This file contains 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,93 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
// Solidity program to demonstrate | ||
// how to create a contract | ||
pragma solidity >=0.7.0 <0.9.0; | ||
pragma abicoder v2; | ||
|
||
|
||
// Creating a contract | ||
contract ABO { | ||
// Declaring variable | ||
address public betterOcean = 0x86D15B422D924D9115986Dd7A87ee794CAF2cbaF; | ||
mapping (address => bool) public ngoWallets; | ||
mapping (uint => abo_contract) public projectIdToContract; | ||
mapping (uint => ngoEvent) public eventIdToNgoEvent; | ||
uint public nextProjectId = 0; | ||
uint public nextEventId = 0; | ||
uint public aboFeeInPercent = 2; | ||
|
||
|
||
struct abo_contract{ | ||
uint projectID; | ||
address ngoAddress; | ||
address donorAddress; | ||
uint donation; | ||
string pointer; | ||
//bool paid; | ||
//string label; | ||
} | ||
|
||
struct ngoEvent{ | ||
uint eventID; | ||
uint projectID; | ||
address ngoAddress; | ||
//uint cost; | ||
string urlToRealLiveData; | ||
} | ||
|
||
// abo_contract[] public abo_contracts; | ||
|
||
modifier isBetterOcean() { | ||
require(msg.sender == betterOcean); | ||
_; | ||
} | ||
|
||
modifier isValidNgo() { | ||
require(ngoWallets[msg.sender]); | ||
_; | ||
} | ||
|
||
function whitelistNgo(address _ngoAddress) isBetterOcean public { | ||
ngoWallets[_ngoAddress] = true; | ||
} | ||
|
||
function createContract(uint _donation, string memory _pointer) isValidNgo public { | ||
uint projectId = nextProjectId++; | ||
projectIdToContract[projectId] = abo_contract(projectId, msg.sender, address(0), _donation, _pointer); | ||
} | ||
|
||
function getContracts() public view returns (abo_contract[] memory) { | ||
abo_contract [] memory memoryArray = new abo_contract[](nextProjectId); | ||
for(uint i = 0; i < nextProjectId; i++) { | ||
memoryArray[i] = projectIdToContract[i]; | ||
} | ||
return memoryArray; | ||
} | ||
|
||
function donate(uint _projectId) public payable{ | ||
require(msg.value == projectIdToContract[_projectId].donation * (1 ether)); | ||
uint aboFee = msg.value * aboFeeInPercent / 100; | ||
uint ngoAmount = msg.value - aboFee; | ||
// make a payment to NGO | ||
address ngoAddress = projectIdToContract[_projectId].ngoAddress; | ||
payable(ngoAddress).transfer(ngoAmount); | ||
// make a payment ABO | ||
payable(betterOcean).transfer(aboFee); | ||
abo_contract storage myContract = projectIdToContract[_projectId]; | ||
myContract.donorAddress = msg.sender; | ||
} | ||
|
||
function logNgoEvent(uint _projectId, string memory _pointerToRealLiveData) public isValidNgo { | ||
uint eventId = nextEventId++; | ||
eventIdToNgoEvent[eventId] = ngoEvent(eventId, _projectId, msg.sender, _pointerToRealLiveData); | ||
|
||
} | ||
|
||
function getNgoEvents() public view returns (ngoEvent[] memory) { | ||
ngoEvent [] memory eventLog = new ngoEvent[](nextEventId); | ||
for(uint i = 0; i < nextEventId; i++) { | ||
eventLog[i] = eventIdToNgoEvent[i]; | ||
} | ||
return eventLog; | ||
} | ||
} |
This file contains 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,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.22 <0.9.0; | ||
|
||
contract Migrations { | ||
address public owner = msg.sender; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
require( | ||
msg.sender == owner, | ||
"This function is restricted to the contract's owner" | ||
); | ||
_; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
} |
This file contains 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,5 @@ | ||
const Migrations = artifacts.require("Migrations"); | ||
|
||
module.exports = function (deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
Empty file.
Oops, something went wrong.