Skip to content

Commit

Permalink
fixes array input on Project page
Browse files Browse the repository at this point in the history
  • Loading branch information
Yining Hu committed Sep 7, 2023
1 parent 1349dc1 commit 93f5e52
Show file tree
Hide file tree
Showing 12 changed files with 6,510 additions and 8,597 deletions.
245 changes: 112 additions & 133 deletions build/contracts/CarbonToken.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/contracts/FarmRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -10914,7 +10914,7 @@
}
},
"schemaVersion": "3.4.1",
"updatedAt": "2023-08-21T03:59:18.657Z",
"updatedAt": "2023-09-07T04:46:08.296Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",
Expand Down
2 changes: 1 addition & 1 deletion build/contracts/HerdRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -16249,7 +16249,7 @@
}
},
"schemaVersion": "3.4.1",
"updatedAt": "2023-08-21T03:59:09.858Z",
"updatedAt": "2023-09-07T05:40:28.626Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",
Expand Down
2 changes: 1 addition & 1 deletion build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@
},
"networks": {},
"schemaVersion": "3.4.1",
"updatedAt": "2023-08-21T03:59:18.737Z",
"updatedAt": "2023-09-07T05:40:28.644Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",
Expand Down
14,678 changes: 6,248 additions & 8,430 deletions build/contracts/ProjectRegistry.json

Large diffs are not rendered by default.

21 changes: 4 additions & 17 deletions client/emissiontrace/src/components/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class Project extends React.Component {
.then(res => {
const projects = res.data;
this.setState({ projects });
console.log(projects[2].herds)
})
}

Expand Down Expand Up @@ -60,13 +59,6 @@ export default class Project extends React.Component {
});
};

// handleArrayInput = event => {
// this.setState({
// ...this.state,
// [event.target.name]: (event.target.value).split(','),
// })
// }

handleRegister = event => {
event.preventDefault();

Expand All @@ -85,7 +77,6 @@ export default class Project extends React.Component {
baselineend:this.state.baselineend,
projectstart:this.state.projectstart,
projectend:this.state.projectend,
herds:this.state.herds,
gas:300000}, apiConfig)
.then(res => {
console.log(res.data);
Expand All @@ -104,9 +95,11 @@ export default class Project extends React.Component {
},
}

const herdnames = this.state.herds.map(a => a.name);

axios.post(`http://localhost:3000/project/add/herds`,
{projectid:this.state.projectid,
herdids:this.state.herds,
herdids:herdnames,
gas:300000}, apiConfig)
.then(res => {
console.log(res.data);
Expand All @@ -124,7 +117,6 @@ export default class Project extends React.Component {
<th>Baseline End</th>
<th>Project Start</th>
<th>Project End</th>
<th>Herds</th>
</tr>
{
this.state.projects
Expand All @@ -135,7 +127,6 @@ export default class Project extends React.Component {
<td>{parseTimestamp(project.baselineend)}</td>
<td>{parseTimestamp(project.projectstart)}</td>
<td>{parseTimestamp(project.projectend)}</td>
<td>{(project.herds).toString()}</td>
</tr>
)
}
Expand Down Expand Up @@ -163,14 +154,10 @@ export default class Project extends React.Component {
<label className='cbtoken-label'>ProjectID:</label>
<input type="text" name="projectend" onChange={this.handleChange}/>
</div>
{/* <div className='form-div'>
<label className='cbtoken-label'>Herds:</label>
<input type="text" name="herd" onChange={this.handleArrayInput}/>
</div> */}
<button type="submit">Submit</button>
</form>

<h2>Add Herds to a Carbon Offset Project</h2>
<h2>Add/Update Herds</h2>
<form onSubmit={this.handleUpdate}>
<div className='form-div'>
<label className='cbtoken-label'>ProjectID:</label>
Expand Down
22 changes: 13 additions & 9 deletions contracts/carbon/ProjectRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./FarmRegistry.sol";
import "./HerdRegistry.sol";

contract ProjectRegistry {
FarmRegistry public farmregistry;
HerdRegistry public herdregistry;

struct Project {
Expand All @@ -20,6 +18,11 @@ contract ProjectRegistry {
mapping(string => bool) public projectExists;
string[] public allprojects;

constructor(HerdRegistry _herdregistry)
{
herdregistry = _herdregistry;
}

function registerProject(
string memory _projectid,
uint256 _baselinestart,
Expand Down Expand Up @@ -60,26 +63,27 @@ contract ProjectRegistry {
uint256[] memory,
uint256[] memory,
uint256[] memory,
uint256[] memory,
string[][] memory)
uint256[] memory
// string[][] memory
)
{
uint256[] memory blstarts = new uint256[](allprojects.length);
uint256[] memory blends = new uint256[](allprojects.length);
uint256[] memory pjstarts = new uint256[](allprojects.length);
uint256[] memory pjends = new uint256[](allprojects.length);
string[][] memory herd_arrays = new string[][](allprojects.length);
// string[][] memory herd_arrays = new string[][](allprojects.length);

for(uint256 i=0; i<allprojects.length; i++){
blstarts[i] = projects[allprojects[i]].Baselinestart;
blends[i] = projects[allprojects[i]].Baselinestart;
pjstarts[i] = projects[allprojects[i]].Projectstart;
pjends[i] = projects[allprojects[i]].Projectend;

for(uint256 j=0; j<projects[allprojects[i]].Herds.length; j++){
herd_arrays[j][i] = projects[allprojects[i]].Herds[j];
}
// for(uint256 j=0; j<projects[allprojects[i]].Herds.length; j++){
// herd_arrays[j][i] = projects[allprojects[i]].Herds[j];
// }
}

return(allprojects,blstarts,blends,pjstarts,pjends,herd_arrays);
return(allprojects,blstarts,blends,pjstarts,pjends); // herd_arrays
}
}
124 changes: 124 additions & 0 deletions deployment_notes/deploy.bestonchain.20230907
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

Compiling your contracts...
===========================
> Compiling ./contracts/carbon/CarbonToken.sol
> Compiling ./contracts/carbon/ProjectRegistry.sol
> Compilation warnings encountered:

Warning: Unused local variable.
--> project:/contracts/carbon/FeedTracking.sol:56:10:
|
56 | (string memory customer,address customeraddr,uint16 quanti ...
| ^^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/FeedTracking.sol:56:54:
|
56 | ... mory customer,address customeraddr,uint16 quantity,string memory orderstatus,uint256 ...
| ^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/FeedTracking.sol:56:70:
|
56 | ... dress customeraddr,uint16 quantity,string memory orderstatus,uint256 orderdatetime) = seafeedre ...
| ^^^^^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/FeedTracking.sol:56:96:
|
56 | ... quantity,string memory orderstatus,uint256 orderdatetime) = seafeedregistry.querySaleOrder( ...
| ^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:59:14:
|
59 | (string memory ingredient, string memory claimstatus, string ...
| ^^^^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:59:40:
|
59 | ... (string memory ingredient, string memory claimstatus, string memory animalid, string me ...
| ^^^^^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:59:67:
|
59 | ... edient, string memory claimstatus, string memory animalid, string memory orderid, uint16 dmi ...
| ^^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:59:91:
|
59 | ... aimstatus, string memory animalid, string memory orderid, uint16 dmi, uint256 datetime)=fee ...
| ^^^^^^^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:59:114:
|
59 | ... y animalid, string memory orderid, uint16 dmi, uint256 datetime)=feedtracking.qu ...
| ^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:60:14:
|
60 | (uint256 blstart, uint256 blend, uint256 pjstart, uint256 pjend, string[] memory herds)=projectregistry.queryProject(_projectid);
| ^^^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:60:31:
|
60 | (uint256 blstart, uint256 blend, uint256 pjstart, uint256 pjend, string[] memory herds)=projectregistry.queryProject(_projectid);
| ^^^^^^^^^^^^^

,Warning: Unused local variable.
--> project:/contracts/carbon/CarbonToken.sol:60:78:
|
60 | (uint256 blstart, uint256 blend, uint256 pjstart, uint256 pjend, string[] memory herds)=projectregistry.queryProject(_projectid);
| ^^^^^^^^^^^^^^^^^^^^^


> Artifacts written to /home/yih/Documents/dev/beston-dapps/build/contracts
> Compiled successfully using:
- solc: 0.8.7+commit.e28d00a7.Emscripten.clang



Starting migrations...
======================
> Network name: 'bestonchain'
> Network id: 100
> Block gas limit: 1342177280 (0x50000000)


8_deploy_projectreg.js
======================

Replacing 'ProjectRegistry'
---------------------------
> transaction hash: 0xd18ab9a89fcd287b0b0bbed0523648cb35e49eb19478efaded5eeb5fb66200fd
> Blocks: 0 Seconds: 0
> contract address: 0xB63BDB7246c63533309535aF5633244082b9bFeF
> block number: 51590
> block timestamp: 1694065221
> account: 0x63Ac0F252218d7E74A297C52998C999b579bE450
> balance: 0.000000000000005
> gas used: 1515400 (0x171f88)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH

Pausing for 2 confirmations...
------------------------------
> confirmation number: 2 (block: 51592)
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH


Summary
=======
> Total deployments: 1
> Final cost: 0 ETH


File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions migrations/8_deploy_projectreg.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const farm = artifacts.require('FarmRegistry');
const herd = artifacts.require('HerdRegistry');
const project = artifacts.require('ProjectRegistry');

module.exports = function(deployer,network,accounts){
deployer.deploy(project, herd.address, farm.address, {gas: 5200000, from: accounts[4]});
deployer.deploy(project, herd.address, {gas: 5200000, from: accounts[4]});
};
8 changes: 5 additions & 3 deletions server/routers/bestonchain/carbon/projectrouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var providerURL = "http://127.0.0.1:8545";
var provider = new HDWalletProvider(accPrivKeys, providerURL);

var projectregpath = './build/contracts/ProjectRegistry.json';
var projectregaddr = "0x0B1F47Be80B10797452d6313E7344c1e8e81255C";
var projectregaddr = "0xB63BDB7246c63533309535aF5633244082b9bFeF";
var projectreginstance = utils.getContract("addr",projectregaddr,provider,projectregpath); // get the digitaltwin contract instance

router.post('/register',
Expand Down Expand Up @@ -107,8 +107,10 @@ router.post('/add/herds',
console.log(`Failed to add herds to project: ${projectid}, Txn hash: ${txnhash}`);
console.log(error);

if (error.message.includes("Project does not exists")) {
if (error.message.includes("Project does not exist")) {
response.write(JSON.stringify({"Txn":txnhash, "server_response":"Txn reverted. Please enter an existing Project ID."}));
} else if (error.message.includes("Herd does not exist")) {
response.write(JSON.stringify({"Txn":txnhash, "server_response":"Txn reverted. Please only enter existing Herd IDs."}));
} else {
response.write(JSON.stringify({"Txn":txnhash, "server_response":"Please check transaction parameters."}));
}
Expand Down Expand Up @@ -164,7 +166,7 @@ router.get('/view/projects',
project.baselineend = result[2][i];
project.projectstart = result[3][i];
project.projectend = result[4][i];
project.herds = result[5][i];
// project.herds = result[5][i];
projectarray.push({...project});
}
console.log(projectarray);
Expand Down

0 comments on commit 93f5e52

Please sign in to comment.