diff --git a/smartcontract/contracts/SmartContract.sol b/smartcontract/contracts/SmartContract.sol index 505ea33..9bc02e7 100644 --- a/smartcontract/contracts/SmartContract.sol +++ b/smartcontract/contracts/SmartContract.sol @@ -59,13 +59,16 @@ contract SmartContract { bytes32 additional = "Additional Info"; contracts[_cid].extra = additional; contracts[_cid].ef1.push(_extraField); + contracts[_cid].ef1.push("\0"); + contracts[_cid].ef1.push(", "); + contracts[_cid].ef1.push("\0"); return true; } - function getFieldByContractID(uint _cid) constant returns (bytes32[]) { + function getFieldByContractID(uint _cid) constant returns (bytes32[], uint) { if (_cid > contracts.length) { throw; } - return contracts[_cid].ef1; + return (contracts[_cid].ef1, _cid); } function setBidTableContractId(uint _cid) returns (bool success) { @@ -86,7 +89,7 @@ contract SmartContract { bidMap[cid].push(newBid); return true; } - function getContracts() constant returns (uint[], bytes32[], uint[], uint[], uint[], bytes32[]) { + function getContracts() constant returns (uint[], bytes32[], uint[], uint[], uint[], bytes32[], uint) { uint length = contracts.length; uint[] memory contractId = new uint[](length); bytes32[] memory asset = new bytes32[](length); @@ -106,14 +109,13 @@ contract SmartContract { targetPrice[i] = currentContract.targetPrice; targetTime[i] = currentContract.targetTime; extraField1[i] = currentContract.extra; - /*for (uint j = 0; j < currentContract.ef1.length; j++) { additionalInfo[i][j] = currentContract.ef1[j]; }*/ //supplier[i] = currentContract.supplier; /*date[i] = currentContract.date;*/ } - return (contractId, asset, qty, targetPrice, targetTime, extraField1); + return (contractId, asset, qty, targetPrice, targetTime, extraField1, length); } function getBids() constant returns (uint[], bytes32[], uint[], uint[]){ uint length = bidMap[bidTableContractId].length; @@ -130,4 +132,7 @@ contract SmartContract { } return (contractIds, suppliers, prices, timesToComplete); } + /*function returnArg(uint arg) constant returns (bytes32){ + return arg; + }*/ } diff --git a/smartcontractui/src/components/EthereumSetup.js b/smartcontractui/src/components/EthereumSetup.js index e7631da..c51cf7a 100644 --- a/smartcontractui/src/components/EthereumSetup.js +++ b/smartcontractui/src/components/EthereumSetup.js @@ -3,7 +3,8 @@ import Web3 from 'web3'; const ETHEREUM_CLIENT = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")) var smartContractABI = [{"constant":false,"inputs":[{"name":"_cid","type":"uint256"},{"name":"_extraField","type":"bytes32"}],"name":"addField","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_asset","type":"bytes32"},{"name":"_quantity","type":"uint256"},{"name":"_targetPrice","type":"uint256"},{"name":"_targetTime","type":"uint256"}],"name":"addContract","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contracts","outputs":[{"name":"contractId","type":"uint256"},{"name":"asset","type":"bytes32"},{"name":"quantity","type":"uint256"},{"name":"targetPrice","type":"uint256"},{"name":"targetTime","type":"uint256"},{"name":"extra","type":"bytes32"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_cid","type":"uint256"}],"name":"getFieldByContractID","outputs":[{"name":"","type":"bytes32[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getBids","outputs":[{"name":"","type":"uint256[]"},{"name":"","type":"bytes32[]"},{"name":"","type":"uint256[]"},{"name":"","type":"uint256[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getContracts","outputs":[{"name":"","type":"uint256[]"},{"name":"","type":"bytes32[]"},{"name":"","type":"uint256[]"},{"name":"","type":"uint256[]"},{"name":"","type":"uint256[]"},{"name":"","type":"bytes32[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_cid","type":"uint256"}],"name":"setBidTableContractId","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"cid","type":"uint256"},{"name":"_supplier","type":"bytes32"},{"name":"_price","type":"uint256"},{"name":"_bidTime","type":"uint256"}],"name":"bid","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}] -var smartContractAddress = '0x1c30ae871c77655a3764d1a6738b99c3f33ac0ec'; + +var smartContractAddress = '0x8e19fa4266d45623e2d9625f1e367d4674f509af'; const smartContract = ETHEREUM_CLIENT.eth.contract(smartContractABI).at(smartContractAddress); export {ETHEREUM_CLIENT, smartContract}; diff --git a/smartcontractui/src/containers/ContractTable.js b/smartcontractui/src/containers/ContractTable.js index 430ffdb..0892ec3 100644 --- a/smartcontractui/src/containers/ContractTable.js +++ b/smartcontractui/src/containers/ContractTable.js @@ -7,7 +7,15 @@ import 'react-table/react-table.css' import ContractModal from './ContractModal'; import AddFieldModal from './AddFieldModal'; - +function hex2a(hexx) { + var hex = hexx.toString();//force conversion + var str = ''; + for (var i = 0; i < hex.length; i += 2){ + var add = String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + str += add; + } + return str; +} class ContractTable extends Component { constructor(props) { super(props) @@ -37,7 +45,7 @@ class ContractTable extends Component { componentDidMount(){ setInterval(function() { var data = smartContract.getContracts() - var info = smartContract.getFieldByContractID(0) + // var info = smartContract.getFieldByContractID(0) this.setState({ contractId: String(data[0]).split(','), asset: String(data[1]).split(','), @@ -45,9 +53,9 @@ class ContractTable extends Component { tPrice: String(data[3]).split(','), tTime: String(data[4]).split(','), extra: String(data[5]).split(','), - ef1: String(info), + // ef1: String(info), interval: this.state.interval + 1 - }) + }); console.log(ETHEREUM_CLIENT.toAscii(this.state.ef1)) this.render() }.bind(this), 5000); @@ -97,7 +105,7 @@ class ContractTable extends Component { SubComponent={(row) => { return (