-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathINethermindApi.cs
More file actions
33 lines (28 loc) · 1.18 KB
/
INethermindApi.cs
File metadata and controls
33 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using Nethermind.Config;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Serialization.Rlp;
using Nethermind.Serialization.Rlp.TxDecoders;
using Nethermind.TxPool;
namespace Nethermind.Api
{
public interface INethermindApi : IApiWithNetwork
{
public T Config<T>() where T : IConfig => ConfigProvider.GetConfig<T>();
(IApiWithNetwork GetFromApi, INethermindApi SetInApi) ForRpc => (this, this);
}
public static class NethermindApiExtensions
{
public static void RegisterTxType<T>(this INethermindApi api, ITxDecoder decoder, ITxValidator validator) where T : TransactionForRpc, IFromTransaction<T>
{
ArgumentNullException.ThrowIfNull(api.TxValidator);
if (decoder.Type != T.TxType) throw new ArgumentException($"TxType mismatch decoder: {decoder.Type}, RPC: {T.TxType}");
api.TxValidator.RegisterValidator(T.TxType, validator);
TxDecoder.Instance.RegisterDecoder(decoder);
TransactionForRpc.RegisterTransactionType<T>();
}
}
}