The set of contract-functions give expected behaviour when tested on Remix. But when the same functions are deployed on TestRPC using Truffle & Web3 and accessed using a Web Interface, it doesn't give the required logical output.
The Structures are as follow:
struct ProofEntry {
bytes32 owner;
bytes32 privateKey;
bytes32 previousTrackingId;}
struct registerEntry{
bytes32 owner;
bytes32 privateKey;}
The Mappings required are as follows:
mapping (bytes32 => ProofEntry) proofs; // trackingId to ownerBlock
mapping (string => bytes32) items; // productId to trackingId
mapping (bytes32 => registerEntry) register; // ownerHash to registerEntry
Please consider the following functions: 1] addProduct
function addProduct(string password, string productId) public returns(bool){
if(hasEntry(productId))
return false;
else {
bytes32 owner = keccak256(bytes32ToString(keccak256(password)));
bytes32 privateKey = keccak256(password);
bytes32 previousTrackingId = keccak256("root");
bytes32 trackingId = keccak256(productId);
proofs[trackingId] = ProofEntry(owner, privateKey, previousTrackingId);
register[owner] = registerEntry(owner , privateKey);
items[productId] = trackingId;
productAdded(password,owner,productId);
return true;
}
}
2] getOwner
function getOwner(string productId) constant returns(bytes32) {
bytes32 trackingId = items[productId];
ProofEntry memory record = proofs[trackingId];
return (record.owner);}
Now when I test these functions on Remix,ie by giving a password & productId for addproduct() and giving the productId in getOwner, I get the corresponding Hash of the owner.
But When I deploy it on testRPC using Truffle,Web3 and access it using a WebUI, addproduct() returns true indicating that it has added the product but when I pass the same productId to getOwner(), it returns default value of bytes32 and not the OwnerHash, which indicates that the values have not been reflected in the mappings in the blockchain which i cannot understand why. Need help Urgently!!!!!