-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: William Occelli <william.occelli@gmail.com>
- Loading branch information
corentingiraud
committed
Jan 30, 2020
1 parent
feabc27
commit 6eb8fbe
Showing
14 changed files
with
889 additions
and
86 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
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
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,28 @@ | ||
- Messages de validation (success) | ||
- gérer les messages d'erreur qui viennent de solidity | ||
- Creation d'un Will a deux héritiers | ||
- change wei to ether in add message | ||
- gérer la destruction du contract (voir si on peut ne plus l'appeler) | ||
|
||
RAPPORT | ||
- Diagramme de classe | ||
- Diagramme d'état | ||
|
||
A TESTER | ||
- Notion de temps | ||
- Pourcentage de validation #DONE by willy | ||
- Pas de doublon dans les héritiers #DONE by willy | ||
- Ne pas pouvoir déclarer deux fois mort #DONE by willy | ||
|
||
FUTURE WORK: | ||
- Conserver la clé privée de l'utilisateur (conserver un secret dans la block chain) | ||
- (Modifier la liste des héritiers) | ||
- (Modifier le pourcentage d'un héritier) | ||
|
||
Account #0: {e087b47782c968bc3e31a3b1d9196af833501260} keystore:///root/.ethereum/chaine1T/keystore/UTC--2020-01-27T14-18-03.069304925Z--e087b47782c968bc3e31a3b1d9196af833501260 | ||
Account #1: {79dcbbbe41c3b5a1e5ce9029b30478f1be308d96} keystore:///root/.ethereum/chaine1T/keystore/UTC--2020-01-27T16-46-29.621517206Z--79dcbbbe41c3b5a1e5ce9029b30478f1be308d96 | ||
|
||
Contract address: 0xf2c04eabb64d7f183e9a1100ff7550f76c0569a7 | ||
|
||
|
||
0x6493eecd972c1ba7ec0a4fdb783ae090fd55137d |
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,7 @@ | ||
rm -rf contracts/build &&\ | ||
solc contracts/solidity/Smartie.sol --bin --abi --optimize -o contracts/build &&\ | ||
./../../web3j-3.5.0/bin/web3j solidity generate contracts/build/smartie.bin contracts/build/smartie.abi -p fr.insa.smarties -o src/main/java &&\ | ||
chmod 777 src/main/java/fr/insa/smarties/Smartie.java &&\ | ||
mvn clean install | ||
|
||
# java -cp ./target/smarties-1.0-SNAPSHOT-jar-with-dependencies.jar fr.insa.smarties.Launcher '0xe087b47782c968bc3e31a3b1d9196af833501260' |
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 |
---|---|---|
@@ -1,30 +1,124 @@ | ||
pragma solidity ^0.6.1; | ||
pragma solidity 0.4.25; | ||
// pragma experimental ABIEncoderV2; | ||
|
||
contract smartie { | ||
struct Heir { | ||
address addr; | ||
uint percentage; | ||
} | ||
|
||
address payable owner; | ||
Heir public heir; | ||
address owner; | ||
Heir[] public heirs; | ||
address[] heirsThatDeclaredDead; | ||
uint countClaimPercentage; | ||
uint256 inheritanceValue; | ||
bool public isDead; | ||
uint public deathDate; | ||
|
||
constructor(address _address) public { | ||
event LogCoinsSent(address sentTo, uint amount); | ||
event LogDeath(bool isDead, uint nbOfValid); | ||
|
||
constructor(address[] memory _heirsAddr, uint[] memory _heirsPercentage) public payable { | ||
require(msg.value > 1, 'Not enough wei added to contract'); | ||
// Check if the owner declares one or more heir(s) | ||
uint addrLength = _heirsAddr.length; | ||
uint percLength = _heirsPercentage.length; | ||
assert(addrLength > 0 && percLength > 0 && addrLength == percLength); | ||
|
||
// Check if the owner declares a total percentage equal to 100% | ||
uint totalPercentage = 0; | ||
for (uint i = 0; i < percLength; i++){ | ||
// Check duplicates in heirs | ||
for (uint j = 0; j < heirs.length; j++){ | ||
require(heirs[j].addr != _heirsAddr[i], 'Error, the heir has already been declared in the will'); | ||
} | ||
Heir memory heir = Heir(_heirsAddr[i],_heirsPercentage[i]); | ||
heirs.push(heir); | ||
totalPercentage += _heirsPercentage[i]; | ||
} | ||
require(totalPercentage == 100, 'Total percentage not equal to 100'); | ||
owner = msg.sender; | ||
heir.addr = _address; | ||
isDead = false; | ||
countClaimPercentage = 0; | ||
// Set funds | ||
inheritanceValue = msg.value; | ||
} | ||
|
||
function isDeadSaMere() public { | ||
if (msg.sender == heir.addr) { | ||
isDead = true; | ||
function declareDead() public returns (string memory) { | ||
// Check duplicate declarations | ||
for (uint k = 0; k < heirsThatDeclaredDead.length; k++){ | ||
require(heirsThatDeclaredDead[k] != msg.sender, 'Error, the heir has already declared the owner dead'); | ||
} | ||
for (uint i = 0; i < heirs.length; i++){ | ||
// Check if heir is legitimate | ||
if(heirs[i].addr == msg.sender) { | ||
countClaimPercentage += heirs[i].percentage; | ||
heirsThatDeclaredDead.push(heirs[i].addr); | ||
if (countClaimPercentage >= 80) { | ||
isDead = true; | ||
deathDate = block.timestamp; | ||
return 'The owner is officially declared dead, a 7 days latency is needed to claim the will'; | ||
} | ||
return 'The heir officially declared the owner dead. Other heirs will need to declare the owner dead.'; | ||
} | ||
} | ||
} | ||
|
||
function claimWill() public { | ||
require(isDead, 'The owner is not officially dead. Heirs representing at least 80% of the inheritance need to declare the owner dead'); | ||
require((deathDate) <= block.timestamp, 'The latency needed for the will to be claimed is not yet reached, you will have to wait'); | ||
executeContract(); | ||
} | ||
|
||
function addWeiToInheritance() public payable returns(uint256) { | ||
require(msg.sender == owner, 'Only the owner of the contract can add ether'); | ||
require(msg.value >= 1, 'Not enough wei provided'); | ||
inheritanceValue += msg.value; | ||
return address(this).balance; | ||
} | ||
|
||
function removeWeiFromInheritance(uint256 valueToSubstract) public returns(uint256){ | ||
require(msg.sender == owner, 'Only the owner of the contract can add ether'); | ||
require(inheritanceValue >= valueToSubstract, 'Not enough wei in the contract'); | ||
inheritanceValue -= valueToSubstract; | ||
owner.transfer(valueToSubstract); | ||
return address(this).balance; | ||
} | ||
|
||
function displayInheritence() public view returns (uint){ | ||
return address(this).balance; | ||
} | ||
|
||
function deleteWill() public { | ||
function deleteContract() public { | ||
if (msg.sender == owner) { | ||
selfdestruct(owner); | ||
} | ||
} | ||
|
||
function executeContract() public { | ||
uint amount; | ||
for (uint i = 0; i < heirs.length; i++) { | ||
amount = inheritanceValue * heirs[i].percentage; | ||
amount = amount / 100; | ||
heirs[i].addr.transfer(amount); | ||
emit LogCoinsSent(heirs[i].addr, amount); | ||
} | ||
selfdestruct(owner); | ||
} | ||
|
||
function getAddress() public view returns(address) { | ||
return address(this); | ||
} | ||
|
||
function getNumberOfHeirsThatClaimedWill() public view returns(uint) { | ||
return heirsThatDeclaredDead.length; | ||
} | ||
|
||
function getHeirsNumber() public view returns(uint) { | ||
return heirs.length; | ||
} | ||
|
||
function getOwner() public view returns(address) { | ||
return owner; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
40 changes: 40 additions & 0 deletions
40
java-projects/smarties/src/main/java/fr/insa/smarties/Account.java
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,40 @@ | ||
package fr.insa.smarties; | ||
|
||
import org.web3j.crypto.Credentials; | ||
import org.web3j.crypto.WalletUtils; | ||
import org.web3j.crypto.CipherException; | ||
import org.web3j.protocol.core.DefaultBlockParameterName; | ||
import org.web3j.protocol.core.methods.response.EthGetBalance; | ||
import org.web3j.utils.Convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Account { | ||
private String _address; | ||
private Credentials _credentials; | ||
|
||
public Account(String accountPath, String password) throws IOException, CipherException { | ||
this._credentials = WalletUtils.loadCredentials(password, accountPath); | ||
this._address = this._credentials.getAddress(); | ||
} | ||
|
||
public String getBalance() throws InterruptedException, ExecutionException { | ||
EthGetBalance balanceWei = Launcher.web3 | ||
.ethGetBalance(this._address, DefaultBlockParameterName.LATEST) | ||
.sendAsync() | ||
.get(); | ||
BigDecimal balanceInEther = Convert.fromWei(balanceWei.getBalance().toString(), Convert.Unit.ETHER); | ||
return balanceInEther.toString(); | ||
} | ||
|
||
public String getAddress() { | ||
return this._address; | ||
} | ||
|
||
public Credentials getCredentials() { | ||
return this._credentials; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
java-projects/smarties/src/main/java/fr/insa/smarties/Heir.java
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,30 @@ | ||
package fr.insa.smarties; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class Heir { | ||
|
||
private String _address; | ||
private int _percentage; | ||
|
||
public Heir (String address, int percentage) { | ||
this._address = address; | ||
this._percentage = percentage; | ||
} | ||
|
||
public int getPercentage () { | ||
return this._percentage; | ||
} | ||
|
||
public void setPercentage (int percentage) { | ||
this._percentage = percentage; | ||
} | ||
|
||
public String getAddress() { | ||
return this._address; | ||
} | ||
|
||
public void setAddress(String address) { | ||
this._address = address; | ||
} | ||
} |
Oops, something went wrong.