I'm trying to make a factory contract that accomplishes two things:
- Create contracts and endow them at creation with specific parameters
- Maintain a mapping of structs with info of all created contracts
Here is my code, then I will explain my question.
pragma solidity ^0.4.18;
import "SimplePurchase.sol"; //this is the child contract being created
contract PurchaseCreator {
struct PurchaseData {
address seller;
uint txnValue;
}
//Creates new child contract & stores info in mapping
function newSimplePurchaseContract(address seller, uint txnValue) isActive public payable returns (SimplePurchase newPurch, uint PurchaseId) {
PurchaseId = nextPurchaseId++;
seller = msg.sender;
txnValue = msg.value;
purchases[PurchaseId] = PurchaseData(seller, txnValue);
newPurch = (new SimplePurchase).value(txnValue)();
return(newPurch, PurchaseId);
}
}
Here are my two questions:
When I create the child contract, is it possible to pass through the seller, txnValue, and PurchaseId from the function newSimplePurchaseContract? I'm currently passing the txnValue, but I'm just not sure if it's possible to pass through anything besides value based on reading the solidity docs.
Can the child contract pass information back to this contract to be added to the mapping? I'd like to hold a "buyer" address in the mapping struct as well, but with the way my user flow is set up, I won't know the buyer until the child contract is created.
Let me know if I'm unclear with my question. I've scoured stack exchange and the solidity docs to try to figure this out and haven't found answers, so I apologize if this is a duplicate.
Thanks for your help!