Skip to content

Commit

Permalink
Hæck Release
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelJet committed Dec 24, 2020
1 parent 0bc2c28 commit c58b083
Show file tree
Hide file tree
Showing 35 changed files with 1,998 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
/integrations
.aeproject-store
.DS_Store
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contribution Guidelines

_Welcome superheroes! It is **awesome** to have you here! Before you start contributing with this project make sure you read our [Code Of Conduct](./CODE_OF_CONDUCT.md), it is really important to make this inclusive and open to everyone, otherwise, it would not be awesome._

[Superchat](https://devpost.com/software/superchat) originated from the ækiti æmbassy participation at [HumanDefiHæck](https://humandefihaeck.devpost.com) in other to build a decentralized fininace secure chat platform, on æternity blockchain where tokens can be sent with minimal loss and optimum security in the form of messages.

## Tips
* Make sure that you are submitting and committing things that are of quality substance, otherwise maintainers can invalidate your pull request.
* You can check the repository `issues` if any to start contributing.
* If you are not sure about how to contribute, you can open an [issue](https://github.com/aekiti/superchat-contract/issues/new) to discuss with the community

## Submitting a pull request
1. Fork and clone the repository.
2. Create a new branch.
3. Add your contribution.
4. Commit and push your fork.
5. Create a new pull request from your forked repository.

## Resources
- [AEproject](https://aeproject.gitbook.io/aeproject)
- [Getting Started Tutorials](https://aeternity.com/documentation-hub/getting-started/hello-world-with-sophia)
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# superchat-contract
Superchat Contract Management System
# Superchat Contract

The defi chat contract management system for the Superchat æpp built by the ækiti æmbassy participant of the HumanDefiHæck.

- [Contributing.md](./CONTRIBUTING.md)
- [Superchat Repo](https://github.com/aekiti/superchat)

## Project setup
```bash
npm install
```

### Starts local node and compliler
> Note: Ensure your docker service is up and running.
```bash
npm run start
```

### Run your unit tests
```bash
npm run aetest
```

## [License](./LICENSE)
```markdown
MIT License

Copyright (c) 2020 ækiti æmbassy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

...
```
21 changes: 21 additions & 0 deletions contracts/DeployedContractData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Superchat Contracts

_The following contracts was deployed to æternity testnet network._

## SuperChatProfile Contract
- Address: ct_2A6EZMuxc8frA5rBLGzSSqqFV31jxaf4VKLQYWj7mHG9XYG2fu
- Owner: ak_jgSwHayBnw7wLTGV3hp7Kec5shxya9ZYVm6kjXbcFAZsvBfgE
- Transaction: th_2kh9Sq9FpVk2DjdVcutMHG2WtThfUpKv22S77zuZRp3PbXS2ej
- CreatedAt: Thu Dec 10 2020 21:29:06 GMT+0100 (West Africa Standard Time)

## SuperChatFriend Contract
- Address: ct_2s3sQek29uo54T3TUe7c4ue835fbQV9vXnyCJdmZgKD67zpsEq
- Owner: ak_jgSwHayBnw7wLTGV3hp7Kec5shxya9ZYVm6kjXbcFAZsvBfgE
- Transaction: th_2Q2i7R53Cv5yguFBem3vY9GHZEVxu1eUqTv1EmoM6c1v6air2q
- CreatedAt: Thu Dec 10 2020 21:30:09 GMT+0100 (West Africa Standard Time)

## SuperChatMessage Contract
- Address: ct_2cw8CMBX55asGoeyAGFcXtuBwdNBULWXpn49vtBzUzZAeY8hmM
- Owner: ak_jgSwHayBnw7wLTGV3hp7Kec5shxya9ZYVm6kjXbcFAZsvBfgE
- Transaction: th_2vxWNHD6mjwNG4WH323pfmNbxRGLeRrn1x4SgHaqDd1YWXZFWF
- CreatedAt: Thu Dec 10 2020 21:31:07 GMT+0100 (West Africa Standard Time)
65 changes: 65 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Superchat Contract

Superchat is a defi chat system for the Superhero æpp built by the ækiti æmbassy participant of the **HumanDefiHæck**. This _README_ aims to explain the three widely used contracts of the chat æpp accordingly to their usage. The three widely used smart contracts arranged in order of user are **_SuperChatProfile_**, **_SuperChatFriend_**, and **_SuperChatMessage_** contract. The SuperChat contract has all the three early mentioned contract functionality in it.

> _Kindly note that these contracts are not security audited and should not be used without a security audit first._
## SuperChatProfile Contract
This contract helps organize the chat æpp user profiles. The state stores all user details using the user `publicKey` as a primary key for user details. The user details include the user name, about, image, and publicKey. Below is the explanation for the contract function and entrypoints:

### register_or_update_profile
Here is a public stateful entrypoint that adds a user to the contract profile state. After execution, it returns the registered user as an object with the details included when the user is registered or updated. The entrypoint takes in 3 string attributes for proper execution; they are the user name, about, and image link.

### empty_profile
Here is a public entrypoint that returns a user object with empty details except for the owner attribute that is equal to the `publicKey` utilizing the entrypoint.

### get_profile
Here is a public entrypoint that returns a user object in two ways. The first way is to check the contract profile state object using the address utilizing the entrypoint since it is the user's primary key. If the user exists in the contract profile state, it returns the user object. If the user does not exist, it returns an empty user object using the early declared `empty_profile()` entryoint.

### get_all_profile
Here is a public entrypoint that returns an array of all registered users where each user is an object. Before the entrypoint returns this array, it checks if the `publicKey` utilizing the entypoint has been registered and save on the profile state property.

## SuperChatFriend Contract
This contract helps the friendship relationship of the chat æpp. It has the friendship starting from sending a friend request to rejecting or accepting friend request and lastly getting users friends. The contract state has properties that make the contract functional. They are the requests and friends property, and lastly, the profile state property helps call the get_all_profile() and empty_profile() entrypoint of the SuperChatProfile contract. Below is the explanation for the contract function and entrypoints:

### send_friend_request
Here is a public stateful entrypoint that returns an array of the user's friend request publicKey. This entrypoint allows a user to send a friend request to another user using his/her publicKey. The entrypoint takes in the friend publicKey, and store it in the field of the present user's friend state request map. This entrypoint relies on two private stateful functions; only_one_friend_request() and modify_friends_request() after using the other publicKey to look through the state request map. The only_one_friend_request() function executes when the friend list of the friend state requests is empty, while the modify_friends_request() executes when the user already has a list of friend requests.

### only_one_friend_request
Here is a private stateful function that returns an array of the user's friend request publicKey. Using the attributes gotten from the send_friend_request entrypoint, it updates the request array of a friend using his/her publicKey when the friend state request is empty.

### modify_friends_request
Here is also another stateful function that returns an array of the user's friend request publicKey. It also uses the attributes gotten from the send_friend_request entrypoint to update the request array of a friend using his/her publicKey when the user already has a list of friend requests.

### get_friend_request
Here is a public entrypoint that returns an array of user objects using the included ProfileContract user object. The entrypoint makes use of the List library to filter through the contract state request map. It could get the user profile due to the mode of connecting the SuperChatProfile contract remotely using the profile state object.

### reject_friend_request
Here is a public stateful entrypoint that returns an array of the user's friend request publicKey. The entrypoint uses user friend publicKey as an attribute to filter through a user friend request list. The filter removes the friend publicKey from the list and then updates the user-friend state request map.

### accept_friend_request
Here is also a public entrypoint that returns an array of the user's friend request publicKey. The entrypoint takes the user-friend publicKey as an attribute to remove the publicKey from the user list of friend requests and add it to the user list of friends and also add it to the user-friend list of friends.

### get_friends
Just as the get_friend_request() entrypoint returns an array of user objects using the included ProfileContract user object, this public entrypoint those the same. The only difference here is, it loops through the contract state friend map.

## SuperChatMessage Contract
This contract is a payable contract has it performs the defi functionalities and more for the chat æpp. It helps organize the chat æpp messages with its state that has a map of message object map. The message object includes the message content, category, amount, time, and sender property that is a user `publicKey`. The first map address primary key is the publicKey of the user that owns the whole message array, while the second address primary key is the `publicKey` of the user that sent the message. Below is the explanation for the contract function and entrypoints:

### update_message_state
Here is a private function that returns exactly the contract message state. This function helps to seamlessly update the contract message state when a new message is sent either from the send_message() or send_fund() stateful entrypoint. The function receives the receiver publicKey and the new message object to add the new message to each user(sender and receiver) state message map.

### send_message
Here is a public stateful entrypoint that returns a message object of the sent message. It takes the receiver publicKey and message content as the argument to first create the new message object that was sent to the private update_message_state function alongside the receiver publicKey to update the message state with the new message.

### get_user_balance
Here is a private function that returns the total AE value of the address utilizing the function.

### send_fund
Here is a public payable stateful entrypoint that also returns a message object of the sent message. The entrypoint helps send tokens to friends on the chat æpp. The entrypoint takes the receiver publicKey, fund description as the argument to update the contract message state map, and the amount to be sent using the Call.value method. Before the contract executes, a check if the user has funds higher than the Call.value executes. With this, a new message object that helps the private update_message_state function just as done in the send_message() entrypoint come in. The difference here is that before the message state object is updated, the amount stipulated using the Call.value method sends to the receiver from the account of the publicKey utilizing the contract.

### get_user_messages
Here is a private function that returns a map of user messages. It makes use of the publcKey utilizing the function to get all of the user messages. If none exists, it returns an empty object.

### get_user_friend_messages
Here is a public entrypoint that returns an array of the contract message object. It makes use of a user friend publicKey to return the friend list of object messages. It makes use of the get_user_messages() private function to get the friend messages. If none exists, it returns an empty array.
Loading

0 comments on commit c58b083

Please sign in to comment.