These are chat archives for Nethereum/Nethereum

10th
Oct 2017
rushinsukhadiya
@rushinsukhadiya
Oct 10 2017 06:32
is there any way get all contacts that has particular value or name?
Juan Blanco
@juanfranblanco
Oct 10 2017 06:33
all contracts with a a particular value or name? No
you can use blockchain storage Nethereum Blockchain storage and based on a specific interface abi
check on changes, events and retrieve the data
if you know the contracts addresses
you could itereate through them and check the storage
but storage is based on the structure of the contract
so contracts that are not the same will not have the same value
rushinsukhadiya
@rushinsukhadiya
Oct 10 2017 06:37
ok
Juan Blanco
@juanfranblanco
Oct 10 2017 06:42
"so contracts that are not the same will not have the same value" -> will not have the same structure, so you wont be able to retrieve the same type of storage value using storageAt
at the end it is simpler to use the abi function calls
and / or index changes in a database so these can be queried
rushinsukhadiya
@rushinsukhadiya
Oct 10 2017 07:32
I have same contracts just holding clientId and their amount
so I want to get all the contracts that has e.g "xyz123" clientId
Juan Blanco
@juanfranblanco
Oct 10 2017 10:32
well you would ideally register them in another contract
ie have another contract that holds a reference to the other contract and from there list them
Chandra Sekhar
@tcsekhar
Oct 10 2017 20:01

Can you please let me know how to pass a blocknumber (HexBigInteger) in a C# web service? I tried BigInteger and String - neither of them seem to be working correctly:

[OperationContract]
public System.Numerics.BigInteger WriteSmartContract(string ComputedHash, string Description, string DateTime, string SenderAddress = "", string Password = "", string EthPoolAddress = "")
{   return(Task.Run(async () => {
                SmartContract s = new SmartContract();
                myProjObj o = await s.WriteSmartContract(ComputedHash,Description,DateTime);
                return o.blocknumber.Value;
            }).Result);  }

[OperationContract]
public string GetStoredStateHash(System.Numerics.BigInteger BlockNumber)
{
    return (Task.Run(async () => {
        SmartContract s = new SmartContract();
        HexBigInteger blocknumber = new HexBigInteger(BlockNumber);
        return s.GetStoredStateHash(blocknumber).Result;
    }).Result.ToString());
}

I use the same Big Integer I got from the WriteSmartContract to pass to the GetStoredStateHash call - but its not working correctly.

Chandra Sekhar
@tcsekhar
Oct 10 2017 21:43

Pls ignore my previous post. Looks like it has nothing to do with the data type conversion.

                SmartContract s = new SmartContract();
                myProjObj o = await s.WriteSmartContract(ComputedHash,Description,DateTime);

                var res1 = s.GetStoredStateHash(o.blocknumber).Result;
                //Here it always works => its using the same instance of the contract - it gets back the stored state value from the block

                SmartContract p = new SmartContract();
                var res2 = p.GetStoredStateHash(o.blocknumber).Result;
                //When I create a new instance of the same contract, it doesn't get back the stored state value from the block

//Here is the code for the GetStoredStateHash function
public async Task<string> GetStoredStateHash(HexBigInteger blockno, string senderaddress = "", string password = "", string ethpooladdress = "")
{
    myProjObj myContract = await InitializeContract(senderaddress, password, ethpooladdress);
    BlockParameter bp = new BlockParameter(blockno);
    return myContract.contract.GetFunction("GetStoredHash").CallAsync<string>(bp).Result;
}

Can you please let me know how to retrieve

a value of a property that was stored in it during a transaction - the last state of the property in the block I mean.

And here is the InitializeContract in the class:

public class SmartContract
{
public myProjObj[] myContract = new myProjObj[0];

public async Task<myProjObj> InitializeContract(string senderaddress, string password, string ethpooladdress)
{
    if (senderaddress == "")
        senderaddress = ConfigurationSettings.AppSettings["ethuserid"].ToString();
    if (password == "")
        password = ConfigurationSettings.AppSettings["ethuserpwd"].ToString();
    if (ethpooladdress == "")
        ethpooladdress = ConfigurationSettings.AppSettings["ethpooladdress"].ToString();
    myProjObj thisContract = null;
    if (myContract != null)
    {
        foreach (myProjObj c in myContract)
        { if (c.senderAddress == senderaddress && c.ethpooladdress == ethpooladdress) thisContract = c; }
    }
    if (thisContract == null)
    {
        thisContract = new myProjObj();
        thisContract.senderAddress = senderaddress;
        thisContract.abi = ConfigurationSettings.AppSettings["abi"].ToString();
        thisContract.ethpooladdress = ethpooladdress;
        var byteCode = ConfigurationSettings.AppSettings["bytecode"].ToString();
        var account = new ManagedAccount(senderaddress, password);
        thisContract.web3 = new Nethereum.Geth.Web3Geth(account, ethpooladdress);
        var transactionHash = await thisContract.web3.Eth.DeployContract.SendRequestAsync(byteCode, senderaddress, new HexBigInteger(900000));
        var receipt = await MineAndGetReceiptAsync(thisContract.web3, transactionHash);
        thisContract.contract = thisContract.web3.Eth.GetContract(thisContract.abi, receipt.ContractAddress);
        Array.Resize(ref myContract, myContract.Length + 1);
        myContract[myContract.Length - 1] = thisContract;
    }
    return thisContract;
}