The problem involves 3 contracts with an interdependence as follows:
library --> ProductContract --> BillingContract
The contracts are structured as follows: (The DataSet.sol contract below is referenced from a solidity example from: https://github.com/chriseth/solidity-examples/blob/master/iterable_mapping.sol
DataSet.sol:
library DataSet {
struct IndexValue { uint keyIndex; uint256 value;}
struct KeyFlag { uint key; bool deleted; }
struct KeyValue { uint key; uint value; }
struct Data {
mapping(uint => IndexValue) data;
KeyFlag[] keys;
//KeyValue[] kvpairs;
uint size;
}
function insert(Data storage self, uint key, uint256 value) returns (bool replaced){
uint keyIndex = self.data[key].keyIndex;
self.data[key].value = value;
if (keyIndex > 0)
return true;
else
{
keyIndex = self.keys.length++;
self.data[key].keyIndex = keyIndex + 1;
self.keys[keyIndex].key = key;
self.size++;
return false;
}
}
function getCurrent(Data storage self) returns(uint index){
return self.size - 1;
}
}
ProductContract.sol:
import "DataSet.sol";
contract ProductContract {
using DataSet for *;
DataSet.Data d;
mapping (uint => uint) IDToVal;
function register (uint p_id, uint val) returns (bool registered) {
IDToVal[p_id] = val;
registered = true;
}
function getVal (uint p_id) returns (uint v) {
return IDToVal[p_id];
}
}
BillingContract.sol:
import "ProductContract.sol";
contract BillingContract {
ProductContract pc;
address PC_Address;
function BillingContract (address p) {
PC_Address = pc;
pc = ProductContract(p);
function getVal (uint p_id) returns (uint v) {
return pc.getVal(p_id);
}
}
This results in an error on compiling:
Error: Library "DataSet" declared twice (will create ambiguities during linking).
library DataSet {
^
Spanning multiple lines.
The other declaration is here: DataSet.sol:3:1:
library DataSet {
^
Spanning multiple lines.
Compiliation failed. See above.
There is a form of transitive dependence on the above contracts - when I try to use all the contracts in a single '.sol' file, the compilation occurs just fine. Is there a way in which the '.sol' files can be separated and compiled properly? Please advise!
BillingContract.sol
also and see if it compilesBillingContract.sol
in the following order - still no resolution for the above error ``` import "DataSet.sol"; import "ProductContract.sol"; ```