pragma solidity ^0.4.0;
contract DataStore {
struct DataModel
{
uint id;
bytes32 string1;
bytes32 string2;
bytes32 string3;
uint actorId;
bytes32 string4;
bytes32 string5;
bytes32 string6;
bytes32 string7;
}
mapping(bytes32 => DataModel) dataMapping;
DataModel datamodel;
address owner;
function DataStore()
{
owner = msg.sender;
}
function storeData(bytes32 hash, uint id, bytes32 string1, bytes32 string2, bytes32 string3, uint actorId, bytes32 string4, bytes32 string5, bytes32 string6, bytes32 string7) returns (bool response)
{
if(msg.sender != owner)
{
return false;
}else
{
datamodel.id = id;
datamodel.string1 = string1;
datamodel.string2 = string2;
datamodel.string3 = string3;
datamodel.actorId = actorId;
datamodel.string4 = string4;
datamodel.string5 = string5;
datamodel.string6 = string6;
datamodel.string7 = string7;
dataMapping[hash] = datamodel;
return true;
}
}
function queryData(bytes32 hash) returns (uint, bytes32, bytes32, bytes32, uint, bytes32, bytes32, bytes32, bytes32)
{
if(msg.sender != owner)
{
throw;
}
DataModel model = dataMapping[hash];
return (model.id, model.string1, model.string2, model.string3, model.actorId, model.string4, model.string5, model.string6, model.string7);
}
}
- I have deployed the contract and received the address.
To store data, I write:
DataStore.storeData.sendTransaction("hash", 1, "instrument", "ccy", "er", 64, "st", "end", "ts", "tz", {from: eth.accounts[0]}
I receive:
I1026 18:36:14.659905 eth/api.go:1185] Tx(0xcfd97f6c50c4ecca05e8df6939c17b2d9da01107064ccecf943024dabb8998b2) to: 0x21f3801411da8b93346bb6e2c216159d1e21ff53 "0xcfd97f6c50c4ecca05e8df6939c17b2d9da01107064ccecf943024dabb8998b2"
I start mining using
miner.start()
and let some blocks be mined. Then I stop mining usingminer.stop()
Then I check storage using:
eth.getStorageAt("0x21f3801411da8b93346bb6e2c216159d1e21ff53")
and I get:"0x0000000000000000000000000000000000000000000000000000000000000000"
If I try:
DataStore.queryData("hash")
, I get:invalid address