These are chat archives for Nethereum/Nethereum

11th
Dec 2018
Uberflew
@Uberflew
Dec 11 2018 09:47
When I'm using a normal Account to store accounts, how can I save it for later use? In the case that I don't want to use Parity or Geth. Can I save the keysotre file? If so, how?
Roy
@Shammah
Dec 11 2018 10:41
@juanfranblanco > Probably Observables could be created of Events, but this may hinder the learning curve.
You could use Observable.FromEventPattern<>()
so it's not that big of a barrier I suppose
Juan Blanco
@juanfranblanco
Dec 11 2018 10:43
yeah i thought so
but what i meant by learning curve, the fact that you have the observable there for you already
@Uberflew check the KeyStore
also note that is slow on purpose, so you may want to adjust the cost, but lower the security
Roy
@Shammah
Dec 11 2018 10:55
Probably. But for a moment I thought you'd add event-based streaming support for .net standard 1.1, and then create something like Nethereum.Reactive in .net standard 2.0 that would expose observable extensions, including simple low-level event-to-observable functions. But from the looks of it you've already built in some Rx functionality in JsonRpc.WebSocketStreamingClient.
I'll look some more into your two commits tonight (oh and wired010's commits as well)
Juan Blanco
@juanfranblanco
Dec 11 2018 11:10
yeah all it is being refactored
@wired010 will merge with current, eventing will be supported as part of core
(will be refactored)
and yes the reactive one with .netstandard 2.0
but my thought was to create a generic class that accepts each subscriber listener implementation avoiding the user to go through the hoops
Juan Blanco
@juanfranblanco
Dec 11 2018 11:17
so mainly moving to this
var disposable = Observable.FromEventPattern<StreamingEventArgs<Block>>(h => blockHeaderSubscription2.SubscriptionDataResponse += h,
                h => blockHeaderSubscription2.SubscriptionDataResponse -= h).Subscribe(x =>
                 Console.WriteLine("New Block from observable from event : " + x.EventArgs.Response.BlockHash)
                );
from this
 blockHeaderSubscription.GetSubscriptionDataResponsesAsObservable().Subscribe(block =>
                Console.WriteLine("New Block: " + block.BlockHash));
it is not great
@Shammah @Wired010
Juan Blanco
@juanfranblanco
Dec 11 2018 11:26
"@wired010 will merge with current, eventing will be supported as part of core" means, his commit will be merged with the current
Roy
@Shammah
Dec 11 2018 11:27
You could write an extension method when refactoring, such that you get: blockHeaderSubscription.ToObservable().Subscribe(block => Console.WriteLine("New Block: " + block.BlockHash));
You'll still have easy access to the observable, while not having to bother with observables inside WebSocketStreamingClient
public static IObservable<Block> ToObservable(this EthNewBlockHeadersEventSubscription sub) => Observable
    .FromEventPattern<StreamingEventArgs<Block>>(
        h => sub.SubscriptionDataResponse += h,
        h => sub.SubscriptionDataResponse -= h)
    .Select(x => x.EventArgs.Response);
Juan Blanco
@juanfranblanco
Dec 11 2018 11:33
yeah thought of that too, good point on selecting the Response much neater, i was missing that to be convinced
Juan Blanco
@juanfranblanco
Dec 11 2018 11:45
@Shammah so any good thoughts on how to handle OnComplete when using Events
that does not involve creating an event for completion per each response
Roy
@Shammah
Dec 11 2018 11:59
Never ending observables are perfectly valid. I'm unsure if it for example makes sense to 'complete' a block subscription, as the blockchain continuously grows. But if you insist, you could for example add a .Take(1), or.First()` operator, which simply takes the first incoming event and then calls OnComplete()
... or .Single(), one of those is blocking and deprecated, but you get my point
Juan Blanco
@juanfranblanco
Dec 11 2018 12:48
oh the point is that I can use streaming connections too for simple rpc calls
hence the question, but I wanted to signal everything from the class
Stef Heyenrath
@StefH
Dec 11 2018 12:48
@a7coretryan My code-generation is still using older Nethereum; I still need to upgrade.
Juan Blanco
@juanfranblanco
Dec 11 2018 12:50
i am just need all the justifications of why not to have another class with subjects, with onnext, onerror, oncomplete
and the subscriptions
Roy
@Shammah
Dec 11 2018 13:02
I'll have a look tonight, as I'm at work. My gut feeling tells me it should be possible to get at least rid of the subjects (this is preferred, mostly because they also implement IDisposable, meaning every class using subjects should also be IDisposable). One small thing I can say about line 102 in https://github.com/Nethereum/Nethereum/blob/master/src/Nethereum.JsonRpc.WebSocketStreamingClient/RpcStreamingSubscriptionObservableHandler.cs#L71 is that you don't need to call OnCompleted() after calling OnError() ;)
Juan Blanco
@juanfranblanco
Dec 11 2018 13:03
ha ha yeah
Roy
@Shammah
Dec 11 2018 13:05
My first intuition would be to create an Observable with the previously mentioned FromEventPattern, and split it in 3 observables using .GroupBy() on the type of TResponse. One for subscribe, one for unsubscribe and one for the data. But I'm just blabbering now without real thought.
Lyon.Nee
@LyonNee
Dec 11 2018 15:37
Hello ! How do I get the parameters I entered when calling the contract method?
image.png
@juanfranblanco
Dave Whiffin
@Dave-Whiffin
Dec 11 2018 15:47
@LyonNee Hi, do you want to retrieve one of your transactions from a block and decode the inputs? If so - there is an extension method in Nethereum.Contracts.Extensions. (using Nethereum.Web 3)
var functionInput = transaction.DecodeTransactionToFunctionMessage<PublishFunction>(); //Nethereum.RPC.Eth.DTOs.Transaction
Lyon.Nee
@LyonNee
Dec 11 2018 15:48
thanks
@Dave-Whiffin Do you have demo code?
Dave Whiffin
@Dave-Whiffin
Dec 11 2018 15:55
@LyonNee Have you already got DTO's to describe your functions? You would normally use these when invoking the function - but you can also use them to decode a transaction.
    public partial class PublishFunction : PublishFunctionBase { }

    [Function("publish")]
    public class PublishFunctionBase : FunctionMessage
    {
        [Parameter("address", "retailer", 1)]
        public virtual string Retailer { get; set; }
        [Parameter("string", "stdPromoJson", 2)]
        public virtual string StdPromoJson { get; set; }
    }
            var transactionHash = "<put your hash here>";
            var transaction = await web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(transactionHash);
            var functionInput = transaction.DecodeTransactionToFunctionMessage<PublishFunction>();
Tom Ryan
@a7coretryan
Dec 11 2018 17:40
@juanfranblanco as a follow-up -- @Dave-Whiffin was gracious enough to help yesterday on trying to figure out why creating a filter using an indexed field doesn't work on an Azure Parity PoA node. I built some code and showed how it worked in Geth. Can you explain why that might be and what should be my next steps? I don't want to build some one off as this seems to be basic functionality that should work.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:01
Hi @a7coretryan I tested it with Parity PoA the other day and the other issue was found on the workbook example was with nulls
this has been fixed
have you ran that with PoA?
that is the updated workbook
just change your account / private key + url
Tom Ryan
@a7coretryan
Dec 11 2018 18:04
So the fix was it the sample?
in*
Juan Blanco
@juanfranblanco
Dec 11 2018 18:04
oh the issue I had on the sample
was as I mentioned the other day
having a filter with a topic null and another with value
did not have any other issues
Tom Ryan
@a7coretryan
Dec 11 2018 18:05
ok -- yes, so I went back and made an adjustment to my code with what you suggested and I still got the same nothing response. I will take a closer look at your docs you reference above.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:06
how many nodes are you running?
it might be the load balancer is
Tom Ryan
@a7coretryan
Dec 11 2018 18:07
BTW, all my testing has been against the Azure Parity PoA. Right now I am only running a single node just to get through some of these basics.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:07
the loadbalancer is hitting another node
Tom Ryan
@a7coretryan
Dec 11 2018 18:08
why then do the other calls work fine?
Juan Blanco
@juanfranblanco
Dec 11 2018 18:08
I might ask about the configuration, but you may want to use GetAllChanges passing the block range as opposed to filters
when you create a filter you create a "subscription" with a specific node
so if you hit another they won't have any request matching that filter id
Tom Ryan
@a7coretryan
Dec 11 2018 18:09
in our consortium I will have our node along with others who join. I am setting the filter on our node.
I currently have no plans to set up a filter on other nodes.
btw, GetAllChanges with a block range does indeed work. That I did test.
but my idea was to set up a filter looking for what a specific member publishes (OnPublish Event) and act on what they publish.
Tom Ryan
@a7coretryan
Dec 11 2018 18:17
I can certainly change that model and just call GetAllChanges then parse the return data for the publisher and then act on that (and that may indeed be what I eventually do) but it still leaves me wondering why I can't get GetFilterChanges to work. I will take a closer look at your workbook and make sure I didn't botch something.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:17
on GetAllChanges you can pass a filter topic to it too
GetFilterChanges what it does is retrieve the changes since you setup the filter
so it wont return any previous one before you set the filter
that might be the issue
Tom Ryan
@a7coretryan
Dec 11 2018 18:20
yes, that is the way I understood it and have designed this. Very applicable to what I'm writing basically an observable that only returns to subscribers what has changed from the last call.
...so I have made sure I sent an OnPublish event AFTER I set up the filter to make sure it should pick something up.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:28
ok
so i have ran the workbook agains the poa i left running in azure again
and filters work indeed
image.png
it worked the other day, but i doubted myself (always can find a reason)
Stef Heyenrath
@StefH
Dec 11 2018 18:31
@a7coretryan I've updated the code generation to correctly generate Event DTO's compatible with Nethereum 3...
Juan Blanco
@juanfranblanco
Dec 11 2018 18:31
also if you see the workbook it explains (and demonstrates) how if you run the filter before sending the txn you don't get any
Tom Ryan
@a7coretryan
Dec 11 2018 18:31
hmmm...so I only have a single indexed field so when I setup the filter I only use this single non-null topic. so when you mention above that I need to send a null topic then my actual non-null topic -- so I have to include a null topic to get this to work?
Juan Blanco
@juanfranblanco
Dec 11 2018 18:32
no
if you don't have any fields in your filter it should return all changes for that contract / event
Tom Ryan
@a7coretryan
Dec 11 2018 18:33
yes, understood. But I'm sending a publisher Address (the publisher of the content) into the filter...code looks like this...
          var mfrinputfilter = onPublishEvent.CreateFilterInput(new[] { mfrWalletAddress });
            //NewFilterInput mfrinputfilter = onPublishEvent.CreateFilterInput<string>(mfrWalletAddress);//, BlockParameter.CreateEarliest(), BlockParameter.CreateLatest());//BlockParameter.CreateEarliest(), BlockParameter.CreateLatest());
            HexBigInteger filterid = await onPublishEvent.CreateFilterAsync(mfrinputfilter);
my DTO definition looks like this...
    [Event("OnPublish")]
    public class OnPublishEvent : IEventDTO
    {
        [Parameter ("address", "retailer", 1, true)]
        public string Retailer { get; set; }

        [Parameter("string", "stdPromoJson", 2, false)]
        public string PromotionJson { get; set; }

    }
the I call GetFilterChanges like this...
            var log = await onPublishEvent.GetFilterChanges(filterID); 
Juan Blanco
@juanfranblanco
Dec 11 2018 18:36
image.png
here is a sample with no topics just for filter for the contract
ok have you made any transaction in between?
Tom Ryan
@a7coretryan
Dec 11 2018 18:38
yes, made sure after the creation of the filter I call the contract to emit the OnPublish event.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:38
was the transaction succeful?
did you get the receipt?
Tom Ryan
@a7coretryan
Dec 11 2018 18:39
yes, I wait for the receipt.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:39
and the status is 1
of the receipt
Tom Ryan
@a7coretryan
Dec 11 2018 18:39
let me dbl check that.
I believe so my block explorer shows the transaction
Juan Blanco
@juanfranblanco
Dec 11 2018 18:40
yeah but i would not trust that
Tom Ryan
@a7coretryan
Dec 11 2018 18:40
...and if I call GetAllChanges I get the transaction
Juan Blanco
@juanfranblanco
Dec 11 2018 18:40
a transaction can be in the blockchain but an error can occur
ah interesting :)
if you call GetAllChanges using the same filterInput
mfrinputfilter
Tom Ryan
@a7coretryan
Dec 11 2018 18:42
no -- list this...
            NewFilterInput allinputfilter = onPublishEvent.CreateFilterInput(BlockParameter.CreateEarliest(), BlockParameter.CreateLatest());
            var log = await onPublishEvent.GetAllChanges(allinputfilter);
Juan Blanco
@juanfranblanco
Dec 11 2018 18:42
ah does it work if you use the other filter?
(filterinput)
it defaults regardless to earliest, latest
so your address should be included
Tom Ryan
@a7coretryan
Dec 11 2018 18:43
yes, I think I tried this case with no success.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:43
ok so the problem is in the filterinput
Tom Ryan
@a7coretryan
Dec 11 2018 18:43
Well -- it seems to be that.
Juan Blanco
@juanfranblanco
Dec 11 2018 18:44
is it the retailerAddress the same as the WalletAddress
Tom Ryan
@a7coretryan
Dec 11 2018 18:44
yes
retailerAddress == Retailer Wallet Address
Juan Blanco
@juanfranblanco
Dec 11 2018 18:45
which is mfrWalletAddress
Tom Ryan
@a7coretryan
Dec 11 2018 18:45
correct
If you give me a few minutes I can get my Azure VM setup and you can hit it yourself.
Juan Blanco
@juanfranblanco
Dec 11 2018 19:08
hi im going to go in a second, although I have just realised i deleted all my resources from my POA
i could have used those
Tom Ryan
@a7coretryan
Dec 11 2018 19:08
no problem -- I will keep looking to see if I've done something incorrectly.
I appreciate the help.
Juan Blanco
@juanfranblanco
Dec 11 2018 19:12
if you can post a whole gist https://gist.github.com/
i might be able to spot it
Tom Ryan
@a7coretryan
Dec 11 2018 19:18
@juanfranblanco -- let me see what I learn and I will let you know.
Juan Blanco
@juanfranblanco
Dec 11 2018 19:30
ok
Roy
@Shammah
Dec 11 2018 21:36
@juanfranblanco I made a small mockup on how you can completely avoid the ISubjects and manual managing of observable handlers by simply extending on the working event-based RPC Streams
So by using composition instead of inheritance over your existing event-based code you can accomplish the same with less complexity
Had to use Observable.Create not only to also make use of your exceptions in the events, but also to invoke OnCompleted for the data stream when you unsubscribe
Roy
@Shammah
Dec 11 2018 21:42
Didn't have time yet to avoid having to call SubscribeAsync() for the events afterwards, can possible be refactored as well
Also haven't looked into your two special cases that are covered by EthBlockNumberObservableHandler and EthGetBalanceObservableHandler
I could also add some more .ToObservable() extension methods for clarity. EDIT Done, that was easy
Roy
@Shammah
Dec 11 2018 21:52
Let's see how far I can go for the other ObserverHandlers before the night
Roy
@Shammah
Dec 11 2018 22:19
Oh, you haven't made use of RpcStreamingResponseEventHandler, no wonder I got confused
In that case I'll leave it be for now; RPC over streaming can be done on some other day. You may find the branch over at https://github.com/Shammah/Nethereum/tree/observables
Roy
@Shammah
Dec 11 2018 22:55

Didn't have time yet to avoid having to call SubscribeAsync() for the events afterwards, can possible be refactored as well

Oh and by that I mean, once the first subscription is made it should call that function. But for now it's protected and a bit hidden away.