Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions smartcontract/contracts/SmartContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -130,4 +132,7 @@ contract SmartContract {
}
return (contractIds, suppliers, prices, timesToComplete);
}
/*function returnArg(uint arg) constant returns (bytes32){
return arg;
}*/
}
3 changes: 2 additions & 1 deletion smartcontractui/src/components/EthereumSetup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions smartcontractui/src/containers/ContractTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -37,17 +45,17 @@ 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(','),
qty: String(data[2]).split(','),
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);
Expand Down Expand Up @@ -97,7 +105,7 @@ class ContractTable extends Component {
SubComponent={(row) => {
return (
<div>
Additional Field: {ETHEREUM_CLIENT.toAscii(this.state.ef1)}
Additional Field: {hex2a(smartContract.getFieldByContractID(row.index))}
</div>
)
}}/>
Expand Down