-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1969f4b
commit f1da7a9
Showing
4 changed files
with
157 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
50 changes: 50 additions & 0 deletions
50
web3/src/main/java/com/one/web3/task/decimalmulti/DecimalMultiEvmCallTask.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.one.web3.task.decimalmulti | ||
|
||
import com.one.web3.task.EvmMultiCallV2 | ||
import com.one.web3.task.decimal.functionDecimalEvmOf | ||
import org.bouncycastle.util.encoders.Hex | ||
import org.web3j.abi.FunctionEncoder | ||
import org.web3j.abi.datatypes.Address | ||
import org.web3j.abi.datatypes.DynamicBytes | ||
import org.web3j.abi.datatypes.DynamicStruct | ||
import org.web3j.utils.Numeric | ||
import retrofit2.Retrofit | ||
|
||
class DecimalMultiEvmCallTask(private val retrofit: Retrofit) : DecimalMultiTask, EvmMultiCallV2 { | ||
|
||
override fun providerRetrofit(): Retrofit = retrofit | ||
|
||
override suspend fun executeTask(param: DecimalMultiParam): Map<String, Int> { | ||
|
||
|
||
val staticStruct = hashMapOf<String, DynamicStruct>() | ||
|
||
param.tokenAddressList.map { tokenAddress -> | ||
|
||
val function = functionDecimalEvmOf() | ||
|
||
val encodeDataOfNameFunction = FunctionEncoder.encode(function) | ||
|
||
val struct = DynamicStruct(Address(tokenAddress), DynamicBytes(Hex.decode(encodeDataOfNameFunction.substring(2).toByteArray()))) | ||
|
||
staticStruct.put(tokenAddress, struct) | ||
} | ||
|
||
|
||
val results = hashMapOf<String, Int>() | ||
|
||
readMultiCall(param.multiCallAddress, staticStruct.values.toList(), param.rpcUrls).forEachIndexed { index, result -> | ||
|
||
if (result.success.value != true) return@forEachIndexed | ||
|
||
val key = staticStruct.keys.toList().getOrNull(index) ?: return@forEachIndexed | ||
|
||
val value = Numeric.toBigInt(result.returnData.value).toInt() | ||
|
||
results[key] = value | ||
} | ||
|
||
|
||
return results | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
web3/src/main/java/com/one/web3/task/decimalmulti/DecimalMultiTask.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.one.web3.task.decimalmulti | ||
|
||
import com.one.web3.Param | ||
import com.one.web3.Web3Task | ||
|
||
interface DecimalMultiTask : Web3Task<DecimalMultiParam, Map<String, Int>> | ||
|
||
data class DecimalMultiParam(val tokenAddressList: List<String>, val multiCallAddress: String, override val chainId: Long, override val rpcUrls: List<String>) : Param(chainId, rpcUrls) |