99using ChainSafe . Gaming . Evm . Signers ;
1010using ChainSafe . Gaming . Evm . Transactions ;
1111using ChainSafe . Gaming . Web3 ;
12-
1312using ChainSafe . Gaming . Web3 . Core ;
1413using ChainSafe . Gaming . Web3 . Core . Debug ;
1514using ChainSafe . Gaming . Web3 . Environment ;
@@ -32,22 +31,15 @@ public class LootboxService : ILootboxService, ILifecycleParticipant
3231 private Contract contract ;
3332 private Dictionary < string , RewardType > rewardTypeByTokenAddress ;
3433
35- public LootboxService (
36- LootboxServiceConfig config ,
37- IContractBuilder contractBuilder ,
38- IRpcProvider rpcProvider )
34+ public LootboxService ( LootboxServiceConfig config , IContractBuilder contractBuilder , IRpcProvider rpcProvider )
3935 {
4036 this . rpcProvider = rpcProvider ;
4137 this . config = config ;
4238 this . contractBuilder = contractBuilder ;
4339 }
4440
45- public LootboxService (
46- LootboxServiceConfig config ,
47- IContractBuilder contractBuilder ,
48- IRpcProvider rpcProvider ,
49- ISigner signer )
50- : this ( config , contractBuilder , rpcProvider )
41+ public LootboxService ( LootboxServiceConfig config , IContractBuilder contractBuilder , IRpcProvider rpcProvider ,
42+ ISigner signer ) : this ( config , contractBuilder , rpcProvider )
5143 {
5244 this . signer = signer ;
5345 }
@@ -92,8 +84,7 @@ public async Task<List<uint>> GetLootboxTypes()
9284
9385 if ( bigIntTypes . Any ( v => v > int . MaxValue ) )
9486 {
95- throw new Web3Exception (
96- "Internal Error. Lootbox type is greater than int.MaxValue." ) ;
87+ throw new Web3Exception ( "Internal Error. Lootbox type is greater than int.MaxValue." ) ;
9788 }
9889
9990 var types = bigIntTypes . Select ( bigInt => ( uint ) bigInt ) . ToList ( ) ;
@@ -110,15 +101,12 @@ public async Task<uint> BalanceOf(uint lootboxType)
110101
111102 public async Task < uint > BalanceOf ( string account , uint lootboxType )
112103 {
113- var response = await this . contract . Call (
114- "balanceOf" ,
115- new object [ ] { account , lootboxType } ) ;
104+ var response = await this . contract . Call ( "balanceOf" , new object [ ] { account , lootboxType } ) ;
116105 var bigIntBalance = ( BigInteger ) response [ 0 ] ;
117106
118107 if ( bigIntBalance > int . MaxValue )
119108 {
120- throw new Web3Exception (
121- "Internal Error. Balance is greater than int.MaxValue." ) ;
109+ throw new Web3Exception ( "Internal Error. Balance is greater than int.MaxValue." ) ;
122110 }
123111
124112 var balance = ( uint ) bigIntBalance ;
@@ -132,8 +120,7 @@ public async Task<BigInteger> CalculateOpenPrice(uint lootboxType, uint lootboxC
132120 var rawGasPrice = ( await this . rpcProvider . GetGasPrice ( ) ) . AssertNotNull ( "gasPrice" ) . Value ;
133121 var safeGasPrice = ( rawGasPrice * 2 ) + BigInteger . Divide ( rawGasPrice , new BigInteger ( 2 ) ) ; // 300%
134122
135- var response = await this . contract . Call (
136- "calculateOpenPrice" ,
123+ var response = await this . contract . Call ( "calculateOpenPrice" ,
137124 new object [ ] { 50000 + ( GasPerUnit * rewardCount ) , safeGasPrice , rewardCount , } ) ;
138125 var openPrice = ( BigInteger ) response [ 0 ] ;
139126
@@ -153,17 +140,17 @@ public async Task<uint> OpeningLootboxType()
153140 var playerAddress = this . GetCurrentPlayerAddress ( ) ;
154141
155142 // This response is actually very different from all the others since it returns several components
156- var response = ( List < ParameterOutput > ) ( await this . contract . Call ( "getOpenerRequestDetails" , new object [ ] { playerAddress } ) ) [ 0 ] ;
143+ var response =
144+ ( List < ParameterOutput > ) ( await this . contract . Call ( "getOpenerRequestDetails" ,
145+ new object [ ] { playerAddress } ) ) [ 0 ] ;
157146 var address = ( string ) response [ 0 ] . Result ;
158147 var unitsToGet = ( BigInteger ) response [ 1 ] . Result ;
159148 var lootboxType = ( ( List < BigInteger > ) response [ 2 ] . Result ) [ 0 ] ;
160149 if ( ! string . IsNullOrEmpty ( address ) && unitsToGet == 0 )
161150 {
162151 // we can early return here, but, it's not necessary since unitstoget will be 0 regardless and this
163152 // call will fulfill every request that's been missing.
164- await this . contract . Send (
165- "recoverBoxes" ,
166- new object [ ] { playerAddress } ) ;
153+ await this . contract . Send ( "recoverBoxes" , new object [ ] { playerAddress } ) ;
167154 }
168155
169156 if ( unitsToGet > uint . MaxValue )
@@ -179,8 +166,7 @@ public async Task OpenLootbox(uint lootboxType, uint lootboxCount = 1)
179166 var rewardCount = lootboxType * lootboxCount ;
180167 var openPrice = await this . CalculateOpenPrice ( lootboxCount , lootboxCount ) ;
181168
182- await this . contract . Send (
183- "open" ,
169+ await this . contract . Send ( "open" ,
184170 new object [ ] { 50000 + ( GasPerUnit * rewardCount ) , new [ ] { lootboxType } , new [ ] { lootboxCount } } ,
185171 new TransactionRequest { Value = new HexBigInteger ( openPrice ) } ) ;
186172 }
@@ -194,9 +180,7 @@ public async Task<bool> CanClaimRewards()
194180
195181 public async Task < bool > CanClaimRewards ( string account )
196182 {
197- var response = await this . contract . Call (
198- "canClaimRewards" ,
199- new object [ ] { account } ) ;
183+ var response = await this . contract . Call ( "canClaimRewards" , new object [ ] { account } ) ;
200184 var canClaimRewards = ( bool ) response [ 0 ] ;
201185
202186 return canClaimRewards ;
@@ -214,9 +198,7 @@ public async Task<LootboxRewards> ClaimRewards(string account)
214198 var ( _, receipt ) = await this . contract . SendWithReceipt ( "claimRewards" , new object [ ] { account } ) ;
215199 var logs = receipt . Logs . Select ( jToken => JsonConvert . DeserializeObject < FilterLog > ( jToken . ToString ( ) ) ) ;
216200 var eventAbi = EventExtensions . GetEventABI < RewardsClaimedEvent > ( ) ;
217- var eventLogs = logs
218- . Select ( log => eventAbi . DecodeEvent < RewardsClaimedEvent > ( log ) )
219- . Where ( l => l != null ) ;
201+ var eventLogs = logs . Select ( log => eventAbi . DecodeEvent < RewardsClaimedEvent > ( log ) ) . Where ( l => l != null ) ;
220202
221203 if ( ! eventLogs . Any ( ) )
222204 {
@@ -239,15 +221,13 @@ LootboxRewards ExtractRewards(IEnumerable<EventLog<RewardsClaimedEvent>> eventLo
239221 case RewardType . Erc20 :
240222 rewards . Erc20Rewards . Add ( new Erc20Reward
241223 {
242- ContractAddress = eventData . TokenAddress ,
243- AmountRaw = eventData . Amount ,
224+ ContractAddress = eventData . TokenAddress , AmountRaw = eventData . Amount ,
244225 } ) ;
245226 break ;
246227 case RewardType . Erc721 :
247228 rewards . Erc721Rewards . Add ( new Erc721Reward
248229 {
249- ContractAddress = eventData . TokenAddress ,
250- TokenId = eventData . TokenId ,
230+ ContractAddress = eventData . TokenAddress , TokenId = eventData . TokenId ,
251231 } ) ;
252232 break ;
253233 case RewardType . Erc1155 :
@@ -261,8 +241,7 @@ LootboxRewards ExtractRewards(IEnumerable<EventLog<RewardsClaimedEvent>> eventLo
261241 case RewardType . Erc1155Nft :
262242 rewards . Erc1155NftRewards . Add ( new Erc1155NftReward
263243 {
264- ContractAddress = eventData . TokenAddress ,
265- TokenId = eventData . TokenId ,
244+ ContractAddress = eventData . TokenAddress , TokenId = eventData . TokenId ,
266245 } ) ;
267246 break ;
268247 case RewardType . Unset :
0 commit comments