Skip to content

Commit 66b0180

Browse files
committed
Add write-up
1 parent a5a490e commit 66b0180

File tree

3 files changed

+91
-59
lines changed

3 files changed

+91
-59
lines changed

README.md

+6-59
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,11 @@
1-
# svelte app
1+
This Dapp is written as part of my intern with Flex Dapps Pty Ltd.
22

3-
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template-webpack.
3+
The front-end is written in <a href="https://svelte.dev/"> Svelte </a>
44

5-
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
5+
The app uses `IPFS` as a decentralized file storage and `webpack` to facilitate the web functionalities.
66

7-
```bash
8-
npx degit sveltejs/template-webpack svelte-app
9-
cd svelte-app
10-
```
7+
<a href="https://github.com/ipfs/js-ipfs"> JS-IPFS </a> is used to interact with IPFS.
118

12-
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
9+
And, of course, this cannot be a Dapp without using `web3`, find out more <a href="https://web3js.readthedocs.io/en/v1.2.0/index.html"> here </a>.
1310

14-
15-
## Get started
16-
17-
Install the dependencies...
18-
19-
```bash
20-
cd svelte-app
21-
npm install
22-
```
23-
24-
...then start webpack:
25-
26-
```bash
27-
npm run dev
28-
```
29-
30-
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and the page should reload with your changes.
31-
32-
33-
## Deploying to the web
34-
35-
### With [now](https://zeit.co/now)
36-
37-
Install `now` if you haven't already:
38-
39-
```bash
40-
npm install -g now
41-
```
42-
43-
Then, from within your project folder:
44-
45-
```bash
46-
now
47-
```
48-
49-
As an alternative, use the [Now desktop client](https://zeit.co/download) and simply drag the unzipped project folder to the taskbar icon.
50-
51-
### With [surge](https://surge.sh/)
52-
53-
Install `surge` if you haven't already:
54-
55-
```bash
56-
npm install -g surge
57-
```
58-
59-
Then, from within your project folder:
60-
61-
```bash
62-
npm run build
63-
surge public
64-
```
11+
Run this app by installing aforementioned dependencies and `npm run dev`

contracts/ethergram.sol

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
pragma solidity >=0.4.0;
2+
3+
import "./etherpostinterface.sol";
4+
5+
contract EtherGram is EtherPostInterface {
6+
7+
mapping (address => bytes32[]) posts;
8+
9+
mapping (bytes32 => address) posterOf;
10+
11+
mapping (bytes32 => uint) clapCount;
12+
13+
mapping (bytes32 => bytes32[]) comments;
14+
15+
bytes32[] allPosts;
16+
17+
//Chech if the post exists
18+
modifier postExist(bytes32 _ipfsHash) {
19+
require(posterOf[_ipfsHash] != address(0));
20+
_;
21+
}
22+
23+
//Check if the post is new (not exists)
24+
modifier newPost(bytes32 _ipfsHash) {
25+
require(posterOf[_ipfsHash] == address(0));
26+
_;
27+
}
28+
29+
function upload(bytes32 _ipfsHash) public newPost(_ipfsHash) {
30+
31+
posts[msg.sender].push(_ipfsHash);
32+
posterOf[_ipfsHash] = msg.sender;
33+
allPosts.push(_ipfsHash);
34+
35+
emit LogUpload(msg.sender, _ipfsHash);
36+
}
37+
38+
function getAllPosts() public view returns(bytes32[] memory){
39+
return allPosts;
40+
}
41+
42+
function getPostsByUploader(address _uploader) public view returns(bytes32[] memory){
43+
return posts[_uploader];
44+
}
45+
46+
function clap(bytes32 _ipfsHash) public postExist(_ipfsHash) {
47+
clapCount[_ipfsHash]++;
48+
emit LogClap(msg.sender, _ipfsHash);
49+
}
50+
51+
function getClapCount(bytes32 _imageHash) public postExist(_imageHash) returns(uint) {
52+
return clapCount[_imageHash];
53+
}
54+
55+
function comment(bytes32 _imageHash, bytes32 _commentHash) public postExist(_imageHash) {
56+
comments[_imageHash].push(_commentHash);
57+
emit LogComment(msg.sender, _imageHash, _commentHash, now);
58+
}
59+
60+
function getComments(bytes32 _imageHash) public postExist(_imageHash) returns(bytes32[] memory) {
61+
return comments[_imageHash];
62+
}
63+
64+
}

contracts/etherpostinterface.sol

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pragma solidity 0.4.24;
2+
3+
/**
4+
* @title EtherPostInterface
5+
* @author RMIT Online (Flex Dapps)
6+
* @dev EtherPostInterface for storing image uploads, comments and claps.
7+
* IPFS hashes are encoded to bytes32 with Qm removed.
8+
*/
9+
contract EtherPostInterface {
10+
11+
event LogUpload(address uploader, bytes32 ipfsHash);
12+
event LogClap(address clapper, bytes32 ipfsHash);
13+
event LogComment(address commenter, bytes32 imageHash, bytes32 commentHash, uint timestamp);
14+
15+
function upload(bytes32 ipfsHash) public;
16+
// function getUploads(address uploader) public returns(bytes32[] memory);
17+
function clap(bytes32 ipfsHash) public;
18+
function getClapCount(bytes32 ipfsHash) public returns(uint);
19+
function comment(bytes32 imageHash, bytes32 commentHash) public;
20+
function getComments(bytes32 ipfsHash) public returns(bytes32[] memory);
21+
}

0 commit comments

Comments
 (0)