In the sample code below, I wanted to check the input data (non-empty) using require/assert and create the contract if it passes the two test.
The code is not working. It still creates an instance of a Contract ABC, if I provide just the _name value as input, without the _number.
How do you make the function "create" exit if the require conditions are not met. How would I tweak this code to achieve the above? Do I have to wrap the require condition with an if-then-else to return false if tests fail? Thanks.
pragma solidity ^0.4.15;
contract ABC {
bytes32 public name;
uint public number;
event Log(string _myString);
function ABC (bytes32 _name, uint _number) public {
Log("object created");
name = _name;
number = _number;
}
}
contract XYZ {
ABC myABC;
event Log(string _myString);
function create(bytes32 _name, uint _number) public returns (bool isSuccess) {
Log("checking name");
require(_name != 0);
Log("name valid, now checking number");
require(_number != 0);
Log("name and number non-empty, creating a new contract");
myABC = new ABC(_name,_number);
Log("new contract created");
return true;
}
}