// SPDX-License-Identifier: MIT // solium-disable linebreak-style pragma solidity >= 0.4.22 < 0.9.0;
import "./Ideator.sol"; import "./Investor.sol";
contract ContractOwner { Ideator ideatorObj; Investor investorObj;
struct idea_info {
string code;
string title;
string description;
address ideaOwner;
address [] investors;
uint amount;
}
idea_info [] ideas_arr; // contains multiple ideas
constructor() {
ideatorObj = new Ideator( address(this) );
investorObj = new Investor( address(this) );
}
function saveIdea(string calldata _code, string calldata _title, string calldata _description, address _account) public {
idea_info memory idea;
idea.code = _code;
idea.title = _title;
idea.description = _description;
idea.ideaOwner = _account;
idea.amount = 0;
ideas_arr.push(idea);
}
function getIdeasByIdeatorAddress(address _account) public view returns(idea_info memory tempIdea) {
for(uint8 i=0; i<ideas_arr.length; i++) {
if( ideas_arr[i].ideaOwner == _account ) {
return ideas_arr[i];
}
}
}
function getIdeas() public view returns(idea_info [] memory) {
return ideas_arr;
}
function getIdeaByCode(string calldata _code) public view returns(idea_info memory tempIdea) {
for(uint8 i=0; i<ideas_arr.length; i++) {
if( keccak256(bytes(ideas_arr[i].code)) == keccak256(bytes(_code))) {
return ideas_arr[i];
}
}
}
// call from investor contract
function receiveIdeaDonations(string calldata _code, uint _amount, address _account) public {
for(uint8 i=0; i<ideas_arr.length; i++) {
if( keccak256(bytes(ideas_arr[i].code)) == keccak256(bytes(_code)) ) {
ideas_arr[i].investors.push(_account);
ideas_arr[i].amount += _amount;
}
}
}
// Get All Idea Codes
function getIdeaCodes() public view returns(string [] memory codes) {
codes = new string[](ideas_arr.length);
for(uint8 i=0; i<ideas_arr.length; i++) {
codes[i] = ideas_arr[i].code;
}
return codes;
}
function getIdeaOnInvestor(address _account) public view returns(idea_info memory investorIdea) {
for(uint8 i=0; i<ideas_arr.length; i++) {
for(uint8 j=0; j<ideas_arr[i].investors.length; j++) {
if( ideas_arr[i].investors[j] == _account ) {
return ideas_arr[i];
}
}
}
}
function getIdeatorContractAddress() public view returns(address ideatorAddr) {
ideatorAddr = address(ideatorObj);
}
function getInvestorContractAddress() public view returns(address investorAddr) {
investorAddr = address(investorObj);
}
}
when i call receiveIdeaDonations() from javascript it gives the following results
amount: "0" code: "t0xxv" description: "test desc" ideaOwner: "0x54c78347202247b7EC5a20b1feDf5AE0A9c3B64e" investors: [] title: "test"
above amount is zero and investors array is empty but when testing on remix or command line it works fine