No funded issue found.
Check out the Issue Explorer
Be the OSS Funding you wish to see in the world.
Looking to fund some work? You can submit a new Funded Issue here .
Time left
Opened
Issue Type
Workers Auto Approve
Project Type
Time Commitment
Experience Level
Permissions
Accepted
Reserved For
Add (polling) Reactive Extensions for filters
nethereum
C#, JavaScript, Visual Basic, Solidity, HTML, Batchfile, TypeScript, CSS, Shell, ASP
# Filter changes
Keeping track of incoming changes of the blockchain state is at the moment rather cumbersome. One method of doing so, which we'll focus on in this issue, is by:
1. Registering a new filter using the filter service.
2. Initiate a polling mechanism that periodically looks for any state changes.
3. Parse one or more multiple state changes.
4. Deregister (dispose?) the registered filter when done.
The other method makes use of websockets and subscription services, which out of this issue's scope. It is likely however, that in the future the same proposed extensions can be re-implemented with these techniques.
In addition to this filter polling setup, you'll have to take care of the fact that:
1. Practically all operations are asynchronous.
2. You might want control over the polling logic, such that you can change the polling sample rate as you wish.
3. Parsing filter results often requires single usage of other services such as `BlockService`.
It is possible to encapsulate this complex logic by offering simple observable reactive extensions. Not only simplifies this the creation of filter observers, it also
1. Reduce filter bloat by simply reusing the same polling observable.
2. Simplify unregistering by simply disposing the subscriptions you no longer need.
3. Offers the power and flexibility of combining multiple event streams.
# Suggested extension methods.
My suggestion is to offer the following extensions regarding blocks, transactions and pending transactions:
```
namespace Nethereum.Spelunker.Extensions
{
public static class IEthApiServicePollingExtensions
{
// Creates a stream of the latest blocks with transaction hashes.
public static IObservable GetBlocksWithTransactionHashes(
this IEthApiService eth);
// Creates a stream of the latest blocks with transaction hashes, starting from the given block number.
public static IObservable GetBlocksWithTransactionHashes(
this IEthApiService eth, BigInteger from);
// Creates a stream of the latest blocks with transactions
public static IObservable GetBlocksWithTransactions(
this IEthApiService eth);
// Creates a stream of the latest blocks with transaction hashes, starting from the given block number.
public static IObservable GetBlocksWithTransactions(
this IEthApiService eth, BigInteger from);
// Creates a stream of the latest transactions.
public static IObservable GetTransactions(
this IEthApiService eth);
// Creates a stream of the latest transactions, starting from the given block number.
public static IObservable GetTransactions(
this IEthApiService eth, BigInteger from);
// Creates a stream of the latest pending transactions.
public static IObservable GetPendingTransactions(
this IEthApiService eth);
// Creates a stream of the latest pending transactions, starting from the given block number..
public static IObservable GetPendingTransactions(
this IEthApiService eth, BigInteger from);
}
}
```
# Polling methods
When users can't be bothering configuring a custom polling method, we may simply define a default polling method:
```
public static IObservable DefaultPoller = Observable
.Timer(TimeSpan.FromMilliseconds(100))
.Select(_ => Unit.Default);
```
The extension methods will look for filter changes each time the observable emits a `Unit.Default`.
If the users desires to use their own custom polling logic, we may offer an overloaded extension method that accepts an additional parameter `poller`, for example:
```
public static IObservable GetTransactions(
this IEthApiService eth,
IObservable poller);
```
# Example
```
// Creates a stream that returns viewmodels for the 10 latest mined blocks.
// An alternative method could be achieved by making use of the reactive .Scan() method.
var last10blocksSubscription = Observable
.FromAsync(() => eth.Blocks.GetBlockNumber.SendRequestAsync())
.SelectMany(blockNumber =>
eth.GetBlocksWithTransactionHashes(from: blockNumber.Value - 10))
.ObserveOnDispatcher()
.Select(BlockViewModel.FromBlock)
.Subscribe(block =>
{
Blocks.Add(block);
Blocks = Blocks
.OrderByDescending(b => b.BlockNumber)
.Take(10)
.ToList();
})
// when you're done, you can simply dispose the subscription.
last10blocksSubscription.Dispose();
```

# Last remark
The three suggested streams for blocks, transactions and pending transactions should serve us a solid base for further reactive extensions, such as personal balance changes.
For more inspiration we may look at https://docs.web3j.io/filters.html.
Setup your profile
Tell us a little about you:
Skills
No results found for [[search]] .
Type to search skills..
Bio Required
[[totalcharacter]] / 240
Are you currently looking for work?
[[ option.string ]]
Next
Setup your profile
Our tools are based on the principles of earn (π°), learn (π), and meet (π¬).
Select the ones you are interested in. You can change it later in your settings.
I'm also an organization manager looking for a great community.
Back
Next
Save
Enable your organization profile
Gitcoin products can help grow community around your brand. Create your tribe, events, and incentivize your community with bounties. Announce new and upcoming events using townsquare. Find top-quality hackers and fund them to work with you on a grant.
These are the organizations you own. If you don't see your organization here please be sure that information is public on your GitHub profile. Gitcoin will sync this information for you.
Select the products you are interested in:
Out of the box you will receive Tribes Lite for your organization. Please provide us with a contact email:
Email
Back
Save