These are chat archives for Nethereum/Nethereum

17th
Jul 2017
mick-h
@mick-h
Jul 17 2017 00:41

@juanfranblanco thanks very much.
I'm writing an MVC app connecting to a remote Quorum cluster.
I've been able to connect and read back information using code similar to the following:

public async Task<IActionResult> Info()
        {
            var web3 = new Nethereum.Web3.Web3("http://remote_node:22000");
            var newAccountResult = await web3.Personal.NewAccount.SendRequestAsync("");
            var accounts = await web3.Eth.Accounts.SendRequestAsync();
            var balance = await web3.Eth.GetBalance.SendRequestAsync(accounts[0]);
            ViewData["Message"] = "Response to new account creation was " + newAccountResult;

            return View();
        }

Which all works fine

Now I want to read the log events on the contract so I'm using code like the following:

public async Task<IActionResult> Info()
        {
            var web3 = new Nethereum.Web3.Web3("http://remote_node:22000");
            var assertionTypesRegistry = web3.Eth.GetContract(someABI, someAddress);
            var nsEvent = assertionTypesRegistry.GetEvent("LogNamespacePrefix");
            var filter = assertionTypesRegistry.GetDefaultFilterInput(BlockParameter.CreateEarliest(), BlockParameter.CreateLatest());
            var nsEvents = await nsEvent.GetAllChanges<BlockchainNamespace>(filter);
            var prefixes = nsEvents.Select(e => e.Event.prefix);
            ViewData["Message"] = "Prefixes are is " + string.Join(", ", prefixes);

            return View();
        }

Where I have defined BlockchainNamespace as:

using System;
using System.Numerics;
using Nethereum.ABI.FunctionEncoding.Attributes;

namespace ad_cbh_web.Models
{
     // event LogNamespacePrefix(address namespaceRegistrar, string prefix, string namespace);
     public class BlockchainNamespace
    {
        [Parameter("address", "namespaceRegistrar", 1)]
        public string namespaceRegistrar { get; set; }

          [Parameter("string", "prefix", 2)]
        public string prefix { get; set; }

          [Parameter("string", "namespace", 3)]
        public string @namespace { get; set; }
    }
}

But whenever I try and call that action I get the following:

OverflowException: Value was either too large or too small for an Int32.
System.Numerics.BigInteger.op_Explicit(BigInteger value)
Nethereum.ABI.Decoders.IntTypeDecoder.DecodeInt(Byte[] encoded)
Nethereum.ABI.EncoderDecoderHelpers.GetNumberOfBytes(Byte[] encoded)
Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeOutput(string output, ParameterOutput[] outputParameters)
Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes<T>(string output, T result, PropertyInfo[] properties)
Nethereum.ABI.FunctionEncoding.EventTopicDecoder.DecodeTopics<T>(Object[] topics, string data)
Nethereum.Web3.Event.DecodeAllEvents<T>(FilterLog[] logs)
Nethereum.Web3.Event+<GetAllChanges>d__27.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
ad_cbh_web.Controllers.BlockchainController+<Info>d__2.MoveNext() in BlockchainController.cs

I'm assuming this is a problem with decoding the events in to the provided class, but I can't work out why - no matter what type I try I get errors.

Andres G. Aragoneses
@knocte
Jul 17 2017 05:02
mick-h: please next time use gist or pastebin
Juan Blanco
@juanfranblanco
Jul 17 2017 06:45
@mick-h can you paste that abi and example of data?
Are there any of the outputs indexed?
mick-h
@mick-h
Jul 17 2017 11:40
@knocte I inlined because the recent history seemed to show that as a fairly typical pattern. But yes, I will link in future
mick-h
@mick-h
Jul 17 2017 11:47
@juanfranblanco ABI example: https://pastebin.com/PtvZGRwd
@juanfranblanco Data example: registerNamespacePrefix("so", "https://schema.org/owl#")
Juan Blanco
@juanfranblanco
Jul 17 2017 12:13
@mick-h I cannot see anything wrong.
What version of Nethereum are you using? Abi?
mick-h
@mick-h
Jul 17 2017 12:15
Yeah I can't work it out either. I will re-create it all from scratch - most likely I changed something and just didn't realise. I had trouble decoding from that contract in other languages (python, elixir) also so I suspect I just stuffed something up
Nethereum.Abi 1.0.6
Juan Blanco
@juanfranblanco
Jul 17 2017 12:16
Ah try 2.0.0 rc5
mick-h
@mick-h
Jul 17 2017 12:17
Like my colleague (I work with @brendan87) I had trouble using the Nethereum.Portable package
Oh OK
Is that packaged or should I build from source?
Juan Blanco
@juanfranblanco
Jul 17 2017 12:18
It is packaged
Just use -pre
mick-h
@mick-h
Jul 17 2017 12:19
OK I will give that a go
Juan Blanco
@juanfranblanco
Jul 17 2017 12:20
2.0 is the way to go :) hopefully that fixes your issue
mick-h
@mick-h
Jul 17 2017 12:21
Sounds hopeful :+1: Now to find a Package Console that I can actually type into on VS2017 for Mac...
mick-h
@mick-h
Jul 17 2017 12:47
Alas, same result. But I will re-create from scratch and see if that sheds some more light on it
Juan Blanco
@juanfranblanco
Jul 17 2017 13:09
Paste your data in a gist, I might be able to read it
(not in front of a PC)
mick-h
@mick-h
Jul 17 2017 13:10
Do you mean the contract code?
Juan Blanco
@juanfranblanco
Jul 17 2017 13:25
No the log data
mick-h
@mick-h
Jul 17 2017 13:29
@juanfranblanco looks like I just stuffed something up the first time round. I re-created the contract and ran some data back into it and now it is perfect
In case you're bored, one of the previous data elements was like so: https://pastebin.com/53ZFW7tm
Many thanks for your time, and thanks very much for Nethereum!
Juan Blanco
@juanfranblanco
Jul 17 2017 13:36
No bother, I get bored on hols :)