@@ -22,14 +22,16 @@ public partial class EngineWallet : IThirdwebWallet
22
22
private readonly string _walletAddress ;
23
23
private readonly IThirdwebHttpClient _engineClient ;
24
24
private readonly int ? _timeoutSeconds ;
25
+ private readonly bool _forwardLocalGasFees ;
25
26
26
- internal EngineWallet ( ThirdwebClient client , IThirdwebHttpClient engineClient , string engineUrl , string walletAddress , int ? timeoutSeconds )
27
+ internal EngineWallet ( ThirdwebClient client , IThirdwebHttpClient engineClient , string engineUrl , string walletAddress , int ? timeoutSeconds , bool forwardLocalGasFees )
27
28
{
28
29
this . Client = client ;
29
30
this . _engineUrl = engineUrl ;
30
31
this . _walletAddress = walletAddress ;
31
32
this . _engineClient = engineClient ;
32
33
this . _timeoutSeconds = timeoutSeconds ;
34
+ this . _forwardLocalGasFees = forwardLocalGasFees ;
33
35
}
34
36
35
37
#region Creation
@@ -43,7 +45,16 @@ internal EngineWallet(ThirdwebClient client, IThirdwebHttpClient engineClient, s
43
45
/// <param name="walletAddress">The backend wallet address to use.</param>
44
46
/// <param name="timeoutSeconds">The timeout in seconds for the transaction. Defaults to no timeout.</param>
45
47
/// <param name="additionalHeaders">Additional headers to include in requests. Authorization and X-Backend-Wallet-Address automatically included.</param>
46
- public static EngineWallet Create ( ThirdwebClient client , string engineUrl , string authToken , string walletAddress , int ? timeoutSeconds = null , Dictionary < string , string > additionalHeaders = null )
48
+ /// <param name="forwardLocalGasFees">Whether to forward locally calculated gas price/fees to the engine. Defaults to false.</param>
49
+ public static EngineWallet Create (
50
+ ThirdwebClient client ,
51
+ string engineUrl ,
52
+ string authToken ,
53
+ string walletAddress ,
54
+ int ? timeoutSeconds = null ,
55
+ Dictionary < string , string > additionalHeaders = null ,
56
+ bool forwardLocalGasFees = false
57
+ )
47
58
{
48
59
if ( client == null )
49
60
{
@@ -72,7 +83,7 @@ public static EngineWallet Create(ThirdwebClient client, string engineUrl, strin
72
83
73
84
walletAddress = walletAddress . ToChecksumAddress ( ) ;
74
85
75
- var engineClient = Utils . ReconstructHttpClient ( client . HttpClient , new Dictionary < string , string > { { "Authorization" , $ "Bearer { authToken } " } , } ) ;
86
+ var engineClient = Utils . ReconstructHttpClient ( client . HttpClient , new Dictionary < string , string > { { "Authorization" , $ "Bearer { authToken } " } } ) ;
76
87
engineClient . AddHeader ( "X-Backend-Wallet-Address" , walletAddress ) ;
77
88
if ( additionalHeaders != null )
78
89
{
@@ -81,7 +92,7 @@ public static EngineWallet Create(ThirdwebClient client, string engineUrl, strin
81
92
engineClient . AddHeader ( header . Key , header . Value ) ;
82
93
}
83
94
}
84
- var wallet = new EngineWallet ( client , engineClient , engineUrl , walletAddress , timeoutSeconds ) ;
95
+ var wallet = new EngineWallet ( client , engineClient , engineUrl , walletAddress , timeoutSeconds , forwardLocalGasFees ) ;
85
96
Utils . TrackConnection ( wallet ) ;
86
97
return wallet ;
87
98
}
@@ -125,28 +136,25 @@ private object ToEngineTransaction(ThirdwebTransactionInput transaction)
125
136
data = transaction . Data ,
126
137
value = transaction . Value ? . HexValue ?? "0x00" ,
127
138
authorizationList = transaction . AuthorizationList != null && transaction . AuthorizationList . Count > 0
128
- ? transaction . AuthorizationList
129
- . Select (
130
- authorization =>
131
- new
132
- {
133
- chainId = authorization . ChainId . HexToNumber ( ) ,
134
- address = authorization . Address ,
135
- nonce = authorization . Nonce . HexToNumber ( ) ,
136
- yParity = authorization . YParity . HexToNumber ( ) ,
137
- r = authorization . R ,
138
- s = authorization . S
139
- }
140
- )
139
+ ? transaction
140
+ . AuthorizationList . Select ( authorization => new
141
+ {
142
+ chainId = authorization . ChainId . HexToNumber ( ) ,
143
+ address = authorization . Address ,
144
+ nonce = authorization . Nonce . HexToNumber ( ) ,
145
+ yParity = authorization . YParity . HexToNumber ( ) ,
146
+ r = authorization . R ,
147
+ s = authorization . S ,
148
+ } )
141
149
. ToArray ( )
142
150
: null ,
143
151
txOverrides = this . _timeoutSeconds != null || transaction . Gas != null || transaction . GasPrice != null || transaction . MaxFeePerGas != null || transaction . MaxPriorityFeePerGas != null
144
152
? new
145
153
{
146
154
gas = transaction . Gas ? . Value . ToString ( ) ,
147
- gasPrice = transaction . GasPrice ? . Value . ToString ( ) ,
148
- maxFeePerGas = transaction . MaxFeePerGas ? . Value . ToString ( ) ,
149
- maxPriorityFeePerGas = transaction . MaxPriorityFeePerGas ? . Value . ToString ( ) ,
155
+ gasPrice = this . _forwardLocalGasFees ? transaction . GasPrice ? . Value . ToString ( ) : null ,
156
+ maxFeePerGas = this . _forwardLocalGasFees ? transaction . MaxFeePerGas ? . Value . ToString ( ) : null ,
157
+ maxPriorityFeePerGas = this . _forwardLocalGasFees ? transaction . MaxPriorityFeePerGas ? . Value . ToString ( ) : null ,
150
158
timeoutSeconds = this . _timeoutSeconds ,
151
159
}
152
160
: null ,
@@ -271,7 +279,7 @@ public async Task<string> SignTransaction(ThirdwebTransactionInput transaction)
271
279
throw new ArgumentNullException ( nameof ( transaction ) ) ;
272
280
}
273
281
274
- object payload = new { transaction = this . ToEngineTransaction ( transaction ) , } ;
282
+ object payload = new { transaction = this . ToEngineTransaction ( transaction ) } ;
275
283
276
284
var url = $ "{ this . _engineUrl } /backend-wallet/sign-transaction";
277
285
0 commit comments