Created
September 25, 2017 15:00
-
-
Save aquiladev/1d93a64257193899f5ad654beb64c97e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleTransactionSigningInterceptor : RequestInterceptor | |
{ | |
private readonly AccountSignerTransactionManager _signer; | |
public SimpleTransactionSigningInterceptor(string privateKey, Web3 web3) | |
{ | |
_signer = new AccountSignerTransactionManager(web3.Client, privateKey); | |
} | |
public override async Task<object> InterceptSendRequestAsync<TResponse>(Func<RpcRequest, string, Task<TResponse>> interceptedSendRequestAsync, RpcRequest request, string route = null) | |
{ | |
if (request.Method == "eth_sendTransaction") | |
{ | |
TransactionInput transaction = (TransactionInput)request.RawParameters[0]; | |
return await SignAndSendTransaction(transaction).ConfigureAwait(false); | |
} | |
return await base.InterceptSendRequestAsync(interceptedSendRequestAsync, request, route).ConfigureAwait(false); | |
} | |
public override async Task<object> InterceptSendRequestAsync<T>(Func<string, string, object[], Task<T>> interceptedSendRequestAsync, string method, string route = null, params object[] paramList) | |
{ | |
if (method == "eth_sendTransaction") | |
{ | |
TransactionInput transaction = (TransactionInput)paramList[0]; | |
return await SignAndSendTransaction(transaction).ConfigureAwait(false); | |
} | |
return await base.InterceptSendRequestAsync(interceptedSendRequestAsync, method, route, paramList).ConfigureAwait(false); | |
} | |
private async Task<string> SignAndSendTransaction(TransactionInput transaction) | |
{ | |
return await _signer.SendTransactionAsync(transaction).ConfigureAwait(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment