-
Notifications
You must be signed in to change notification settings - Fork 15
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
2800556
commit a8d759e
Showing
10 changed files
with
265 additions
and
3 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
Submodule emerald-grpc
updated
from 77ed85 to ee2e55
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
Submodule public
updated
4 files
+0 −7 | chains-meta.yaml | |
+15 −29 | chains.yaml | |
+1 −59 | icons/Goat.svg | |
+62 −62 | icons/getChainIcon.ts |
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
100 changes: 100 additions & 0 deletions
100
src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultTonCenterHttpMethods.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,100 @@ | ||
package io.emeraldpay.dshackle.upstream.calls | ||
|
||
import io.emeraldpay.dshackle.quorum.AlwaysQuorum | ||
import io.emeraldpay.dshackle.quorum.CallQuorum | ||
import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcException | ||
|
||
class DefaultTonCenterHttpMethods : CallMethods { | ||
|
||
// HTTP API section | ||
private val accountHttpMethods = setOf( | ||
getMethod("/getAddressInformation"), | ||
getMethod("/getExtendedAddressInformation"), | ||
getMethod("/getWalletInformation"), | ||
getMethod("/getAddressBalance"), | ||
getMethod("/getAddressState"), | ||
getMethod("/packAddress"), | ||
getMethod("/unpackAddress"), | ||
getMethod("/getTokenData"), | ||
getMethod("/detectAddress"), | ||
) | ||
|
||
private val blockHttpMethods = setOf( | ||
getMethod("/getMasterchainInfo"), | ||
getMethod("/getMasterchainBlockSignatures"), | ||
getMethod("/getShardBlockProof"), | ||
getMethod("/getConsensusBlock"), | ||
getMethod("/lookupBlock"), | ||
getMethod("/shards"), | ||
getMethod("/getBlockHeader"), | ||
getMethod("/getOutMsgQueueSizes"), | ||
) | ||
|
||
private val transactionHttpMethods = setOf( | ||
getMethod("/getTransactions"), | ||
getMethod("/getBlockTransactions"), | ||
getMethod("/getBlockTransactionsExt"), | ||
getMethod("/tryLocateTx"), | ||
getMethod("/tryLocateResultTx"), | ||
getMethod("/tryLocateSourceTx"), | ||
) | ||
|
||
private val getConfigHttpMethods = setOf( | ||
getMethod("/getConfigParam"), | ||
getMethod("/getConfigAll"), | ||
) | ||
|
||
private val runMethodHttpMethods = setOf( | ||
postMethod("/runGetMethod"), | ||
) | ||
|
||
private val sendHttpMethods = setOf( | ||
postMethod("/sendBoc"), | ||
postMethod("/sendBocReturnHash"), | ||
postMethod("/sendQuery"), | ||
postMethod("/estimateFee"), | ||
) | ||
|
||
private val jsonRpcHttpMethods = setOf( | ||
postMethod("/jsonRPC"), | ||
) | ||
|
||
private val allowedHttpMethods: Set<String> = accountHttpMethods + | ||
blockHttpMethods + | ||
transactionHttpMethods + | ||
getConfigHttpMethods + | ||
runMethodHttpMethods + | ||
sendHttpMethods + | ||
jsonRpcHttpMethods | ||
|
||
override fun createQuorumFor(method: String): CallQuorum { | ||
return AlwaysQuorum() | ||
} | ||
|
||
override fun isCallable(method: String): Boolean { | ||
return allowedHttpMethods.contains(method) | ||
} | ||
|
||
override fun getSupportedMethods(): Set<String> { | ||
return allowedHttpMethods.toSortedSet() | ||
} | ||
|
||
override fun isHardcoded(method: String): Boolean { | ||
return false | ||
} | ||
|
||
override fun executeHardcoded(method: String): ByteArray { | ||
throw RpcException(-32601, "Method not found") | ||
} | ||
|
||
override fun getGroupMethods(groupName: String): Set<String> { | ||
return when (groupName) { | ||
"default" -> allowedHttpMethods | ||
else -> emptyList() | ||
}.toSet() | ||
} | ||
|
||
private fun getMethod(method: String) = "GET#$method" | ||
|
||
private fun postMethod(method: String) = "POST#$method" | ||
} |
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
136 changes: 136 additions & 0 deletions
136
src/main/kotlin/io/emeraldpay/dshackle/upstream/toncenter/TonCenterHttpSpecific.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,136 @@ | ||
package io.emeraldpay.dshackle.upstream.toncenter | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import io.emeraldpay.dshackle.Chain | ||
import io.emeraldpay.dshackle.Global | ||
import io.emeraldpay.dshackle.config.ChainsConfig.ChainConfig | ||
import io.emeraldpay.dshackle.data.BlockContainer | ||
import io.emeraldpay.dshackle.data.BlockId | ||
import io.emeraldpay.dshackle.foundation.ChainOptions.Options | ||
import io.emeraldpay.dshackle.reader.ChainReader | ||
import io.emeraldpay.dshackle.upstream.ChainRequest | ||
import io.emeraldpay.dshackle.upstream.SingleValidator | ||
import io.emeraldpay.dshackle.upstream.Upstream | ||
import io.emeraldpay.dshackle.upstream.UpstreamAvailability | ||
import io.emeraldpay.dshackle.upstream.ValidateUpstreamSettingsResult | ||
import io.emeraldpay.dshackle.upstream.generic.AbstractPollChainSpecific | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundService | ||
import io.emeraldpay.dshackle.upstream.rpcclient.RestParams | ||
import reactor.core.publisher.Mono | ||
import java.math.BigInteger | ||
import java.time.Instant | ||
|
||
fun generateRandomString(length: Int): String { | ||
val allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | ||
return (1..length) | ||
.map { allowedChars.random() } | ||
.joinToString("") | ||
} | ||
|
||
object TonCenterHttpSpecific : AbstractPollChainSpecific() { | ||
override fun getFromHeader(data: ByteArray, upstreamId: String, api: ChainReader): Mono<BlockContainer> { | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun listenNewHeadsRequest(): ChainRequest { | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun unsubscribeNewHeadsRequest(subId: String): ChainRequest { | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun lowerBoundService(chain: Chain, upstream: Upstream): LowerBoundService { | ||
return TonCenterLowerBoundService(chain, upstream) | ||
} | ||
|
||
override fun latestBlockRequest(): ChainRequest { | ||
return ChainRequest("GET#/getMasterchainInfo", RestParams.emptyParams()) | ||
} | ||
|
||
override fun parseBlock(data: ByteArray, upstreamId: String, api: ChainReader): Mono<BlockContainer> { | ||
val blockHeader = Global.objectMapper.readValue<TonCenterMasterchainInfo>(data) | ||
|
||
|
||
|
||
return Mono.just( | ||
BlockContainer( | ||
height = blockHeader.result.last.seqno, | ||
hash = BlockId.fromBase64(blockHeader.result.last.root_hash), | ||
difficulty = BigInteger.ZERO, | ||
timestamp = Instant.EPOCH, | ||
full = false, | ||
json = data, | ||
parsed = blockHeader, | ||
transactions = emptyList(), | ||
upstreamId = upstreamId, | ||
parentHash = BlockId.fromBase64(generateRandomString(32)), | ||
), | ||
) | ||
} | ||
|
||
override fun upstreamValidators( | ||
chain: Chain, | ||
upstream: Upstream, | ||
options: Options, | ||
config: ChainConfig, | ||
): List<SingleValidator<UpstreamAvailability>> { | ||
return emptyList() | ||
} | ||
|
||
override fun upstreamSettingsValidators( | ||
chain: Chain, | ||
upstream: Upstream, | ||
options: Options, | ||
config: ChainConfig, | ||
): List<SingleValidator<ValidateUpstreamSettingsResult>> { | ||
// add check generic block | ||
return emptyList() | ||
} | ||
} | ||
|
||
data class TonCenterMasterchainInfoResultLast( | ||
val workchain: Int, | ||
val shard: String, | ||
val seqno: Long, | ||
val root_hash: String, | ||
val file_hash: String, | ||
) | ||
|
||
data class TonCenterMasterchainInfoResult( | ||
val last: TonCenterMasterchainInfoResultLast, | ||
) | ||
|
||
data class TonCenterMasterchainInfo( | ||
val ok: Boolean, | ||
val result: TonCenterMasterchainInfoResult, | ||
) | ||
|
||
class TonCenterMasterchainInfoDeserializer : JsonDeserializer<TonCenterMasterchainInfo>() { | ||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): TonCenterMasterchainInfo { | ||
val node = p.readValueAsTree<JsonNode>() | ||
val ok = node["ok"].booleanValue() | ||
val workchain = node["result"]["last"]["workchain"].intValue() | ||
val shard = node["result"]["last"]["shard"].textValue() | ||
val seqno = node["result"]["last"]["seqno"].longValue() | ||
val root_hash = node["result"]["last"]["root_hash"].textValue() | ||
val file_hash = node["result"]["last"]["file_hash"].textValue() | ||
|
||
return TonCenterMasterchainInfo( | ||
ok, | ||
TonCenterMasterchainInfoResult( | ||
TonCenterMasterchainInfoResultLast( | ||
workchain, | ||
shard, | ||
seqno, | ||
root_hash, | ||
file_hash, | ||
), | ||
), | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/io/emeraldpay/dshackle/upstream/toncenter/TonCenterLowerBoundService.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,15 @@ | ||
package io.emeraldpay.dshackle.upstream.toncenter | ||
|
||
import io.emeraldpay.dshackle.Chain | ||
import io.emeraldpay.dshackle.upstream.Upstream | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundDetector | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundService | ||
|
||
class TonCenterLowerBoundService( | ||
chain: Chain, | ||
upstream: Upstream, | ||
) : LowerBoundService(chain, upstream) { | ||
override fun detectors(): List<LowerBoundDetector> { | ||
return listOf() | ||
} | ||
} |