Commit 12771064 authored by Theerathat Pornprinya's avatar Theerathat Pornprinya

Update to final archive

parent cdfe1ec1
This diff is collapsed.
This diff is collapsed.
......@@ -63,6 +63,7 @@ contract CreateProduct {
return _id;
}
// return user information
function getUser(address _addressId) public view returns (address, string, string, string, address[]) {
// need to add check whether user exist
......@@ -88,11 +89,12 @@ contract CreateProduct {
loginAddress = address(0);
}
function newProduct(string description, uint amountToRecoup, uint amountAlreadyRecouped, uint percentage, address movieAddress, address groupAddress, uint stakeholderType) public {
// create new stakes
function newProduct(string title, string description, uint amountToRecoup, uint amountAlreadyRecouped, uint percentage, address movieAddress, address groupAddress, uint stakeholderType) public {
// check login is true first
require(login == true);
address product = new Marketplace(description, amountToRecoup, amountAlreadyRecouped, percentage, movieAddress, groupAddress, stakeholderType, msg.sender);
address product = new Marketplace(title, description, amountToRecoup, amountAlreadyRecouped, percentage, movieAddress, groupAddress, stakeholderType, msg.sender, address(this));
deployedProducts.push(product);
emit ProductCreated(msg.sender, product);
......@@ -101,12 +103,14 @@ contract CreateProduct {
user.stakeholders.push(product);
}
// return stakeholders of a specific client address
function getAllStakeholdersFromUserAddress(address _id) public view returns (address[]) {
uint userId = getUserIdFromAddress(_id);
User storage user = users[userId];
return user.stakeholders;
}
// add the parameter to the stakeholder
function addStakeholderToOwner(address userAddress, address contractAddress) public {
uint userId = getUserIdFromAddress(userAddress);
User storage user = users[userId];
......@@ -133,11 +137,12 @@ contract CreateProduct {
}
}
// return the arrays of available stakes on the market
function getDeployedProducts() public view returns (address[]) {
return deployedProducts;
}
// return number of stakes on the market
function getDeployedProductsCount() public view returns (uint) {
return deployedProducts.length;
}
......@@ -215,6 +220,7 @@ contract Marketplace {
// Attributes for stakeholder
address public manager;
uint public listedPrice;
string public title;
string public productDescription;
ProductCondition public productCondition;
bool public purchased;
......@@ -260,8 +266,9 @@ contract Marketplace {
}
function Marketplace(string description, uint amountToRecoup, uint amountAlreadyRecouped, uint percentageVal, address movieAddressId, address groupAddressId, uint stakeholderTypeVal, address creator) public {
function Marketplace(string _title, string description, uint amountToRecoup, uint amountAlreadyRecouped, uint percentageVal, address movieAddressId, address groupAddressId, uint stakeholderTypeVal, address creator, address factoryContact) public {
manager = creator;
title = _title;
productDescription = description;
productCondition = ProductCondition.NOTDEPLOYED;
fixedAmountToRecoup = amountToRecoup;
......@@ -284,6 +291,7 @@ contract Marketplace {
stakeholderType = StakeholderType.Expense;
}
factoryContractAddress = factoryContact;
// Set highest offer and bidder to initial state
highestBidder = address(0);
highestOfferPrice = 0;
......@@ -412,7 +420,7 @@ contract Marketplace {
}
// withdraw offer from the offerlist
function withdrawOffer(uint id) public {
Offer storage offer = offers[id];
require(msg.sender == offer.offerAddress || msg.sender == manager);
......@@ -421,21 +429,23 @@ contract Marketplace {
delete offers[id];
}
// Accept the highest offer that is listed
function acceptOffer() public restricted {
purchased = true;
offerOwnership(highestBidder);
claimProductOwnershipOffer();
}
// refund buyer by adding to the amountToRefund mapping
function refundBuyer(uint id) public {
Offer storage offer = offers[id];
address refundAddress = offer.offerAddress;
if (refund > 0) {
Offer storage offer = offers[id];
address refundAddress = offer.offerAddress;
if (refund > 0) {
// set refund amount to 0 to prevent user to try to refund again
amountToRefund[refundAddress] = 0;
refundAddress.transfer(refund);
}
}
}
......@@ -461,17 +471,35 @@ contract Marketplace {
function claimProductOwnership() public {
manager.transfer(listedPrice * 1000000000000000000);
//update stakeholders for old first
address oldManager = manager;
manager = newProductOwner;
CreateProduct c = CreateProduct(factoryContractAddress);
c.updateStakeholders(oldManager);
c.updateStakeholders(manager);
newProductOwner = address(0);
productCondition = ProductCondition.NOTDEPLOYED;
delete offers;
highestBidder = address(0);
highestOfferPrice = 0;
highestOfferMessage = "";
}
function claimProductOwnershipOffer() public {
manager.transfer(highestOfferPrice);
address oldManager = manager;
manager = newProductOwner;
CreateProduct c = CreateProduct(factoryContractAddress);
c.updateStakeholders(oldManager);
c.updateStakeholders(manager);
newProductOwner = address(0);
productCondition = ProductCondition.NOTDEPLOYED;
delete offers;
highestBidder = address(0);
highestOfferPrice = 0;
highestOfferMessage = "";
}
function getOfferInfo() public view returns (address, uint, string) {
......@@ -480,7 +508,7 @@ contract Marketplace {
);
}
function getProductInfo() public view returns (address, uint, string, ProductCondition, bool, address, StakeholderType, uint, uint, uint, address, address) {
function getProductInfo() public view returns (address, uint, string, ProductCondition, bool, address, StakeholderType, uint, uint, uint, address, address, string) {
return (
manager,
listedPrice,
......@@ -493,7 +521,8 @@ contract Marketplace {
amountRecouped,
percentage,
movieAddress,
groupAddress
groupAddress,
title
);
}
......
......@@ -4,7 +4,7 @@ import CreateProduct from './build/CreateProduct.json';
const instance = new web3.eth.Contract(
JSON.parse(CreateProduct.interface),
'0x13cf4f41d7A0Fe06C4D8cC92dC5Ef6087C8Ec955'
'0xF4d7CC060db884D89dc388ee0F6D4585ED5348F5'
);
export default instance;
......@@ -814,7 +814,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "597:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -1229,7 +1229,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1076:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -1294,10 +1294,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1059:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -1354,7 +1354,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1113:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -1496,7 +1496,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1191:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -1760,7 +1760,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1350:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -1854,7 +1854,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1407:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -2172,10 +2172,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1584:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -2266,7 +2266,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1661:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -2331,10 +2331,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1631:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -2564,7 +2564,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1786:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -3407,7 +3407,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "597:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -3822,7 +3822,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1076:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -3887,10 +3887,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1059:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -3947,7 +3947,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1113:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -4089,7 +4089,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1191:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -4353,7 +4353,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1350:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -4447,7 +4447,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1407:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -4765,10 +4765,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1584:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -4859,7 +4859,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1661:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -4924,10 +4924,10 @@
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
260,
261
408,
409
],
"referencedDeclaration": 260,
"referencedDeclaration": 408,
"src": "1631:7:0",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
......@@ -5157,7 +5157,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 257,
"referencedDeclaration": 405,
"src": "1786:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
......@@ -5527,12 +5527,12 @@
}
},
"links": {},
"address": "0xbAc6Ab0a86b0Fb2d88A30Be0D2801b261F5F5df1",
"transactionHash": "0x56a7bdd3f10a6019c318420fba96437d3281fdc8f6dc0a90e78236d8273dee6c"
"address": "0x22c005e3A2088aEeD6B3dfEa097aD10d75440E32",
"transactionHash": "0x542820ee1dc64fe3598443c89cd04337023a808075ad04ab5fb09f26814f01d9"
}
},
"schemaVersion": "3.0.23",
"updatedAt": "2020-06-22T06:24:59.251Z",
"updatedAt": "2020-06-22T13:21:53.538Z",
"networkType": "ethereum",
"devdoc": {
"methods": {}
......
......@@ -4148,9 +4148,37 @@
"name": "solc",
"version": "0.5.16+commit.9c3226ce.Emscripten.clang"
},
"networks": {},
"networks": {
"5777": {
"events": {
"0xcb1913a166c275800ee1bc5548f97de4caa1abe905d5e0fadd17ce3da2773e73": {
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "TokensSell",
"type": "event"
}
},
"links": {},
"address": "0x01F43e301480748E83b61F9202F6e645840dcb81",
"transactionHash": "0x1192e98672c70f388d31f75a476e9996c1f248761173e6c093205f9735b23894"
}
},
"schemaVersion": "3.0.23",
"updatedAt": "2020-06-22T09:53:17.812Z",
"updatedAt": "2020-06-22T13:21:53.557Z",
"networkType": "ethereum",
"devdoc": {
"methods": {}
},
......
......@@ -8,7 +8,70 @@
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>FilmChain Tokens Sales Initial Coin Offering</h1>
<div class="container" style="width: 700px;">
<div class="row">
<div class="col-lg-12">
<h1 class="text-center">FilmChain Tokens Sales Initial Coin Offering</h1>
</div>
<hr />
<br />
</div>
<div id="loader">
<p class="text-center">Page Loading...</p>
</div>
<div id="content" class="text-center" style="display: none;">
<h3>
FilmChain Token (FTC)!
</h3>
<br />
<h5>
This is a platform that allows FilmChain Token sales. In order to buy FilmChain Tokens,
insert amount of tokens you want to buy inside the input fields and click Buy Tokens.
</h5>
<h5>
MetaMask
will popup to confirm the transaction with the blockchain.
</h5>
<br />
<p>
1 FilmChain Token = <span class="token-price"></span> Ether.
</p>
<p>
You currently have
<span class="ftc-balance"></span>&nbsp;FTC.
</p>
<br />
<form onSubmit="App.buyTokens(); return false;" role="form">
<div class="form-group">
<div class="input-group">
<input id="numberOfTokens" class="form-control input-lg" type="number" name="number" value="1" min="1" pattern="[0-9]">
</input>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary btn-lg">Buy Tokens</button>
</span>
</div>
</div>
</form>
<br />
<div class="progress">
<div id="progress" class="progress-bar progress-bar-striped active" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
<p><span class="num-sold-tokens"></span> / <span class="tokens-free"></span> tokens sold</p>
<hr />
<p id="accountAddress">
</p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/web3.min.js"></script>
......
console.log("App file is executed");
App = {
web3Provider: null,
contracts: {},
account: '0x0',
loading: false,
tokenPrice: 100000000000000,
numSoldTokens: 0,
tokensFree: 800000,
init: function() {
console.log("App starting...")
return App.initWeb3();
},
initWeb3: function() {
if (typeof web3 !== 'undefined') {
// If a web3 instance is already provided by Meta Mask.
App.web3Provider = web3.currentProvider;
web3 = new Web3(web3.currentProvider);
} else {
// Specify default instance if no web3 instance provided
App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
web3 = new Web3(App.web3Provider);
}
return App.initContracts();
},
initContracts: function() {
$.getJSON("FilmChainTokenSales.json", function(filmChainTokenSales) {
App.contracts.FilmChainTokenSales = TruffleContract(filmChainTokenSales);
App.contracts.FilmChainTokenSales.setProvider(App.web3Provider);
App.contracts.FilmChainTokenSales.deployed().then(function(filmChainTokenSales) {
console.log("FilmChain Token Sale Address:", filmChainTokenSales.address);
});
}).done(function() {
$.getJSON("FilmChainToken.json", function(filmChainToken) {
App.contracts.FilmChainToken = TruffleContract(filmChainToken);
App.contracts.FilmChainToken.setProvider(App.web3Provider);
App.contracts.FilmChainToken.deployed().then(function(filmChainToken) {