ElectrumClient

class ElectrumClient(val chainSelector: ChainSelector, val name: String, val port: Int = DEFAULT_NEXA_SSL_ELECTRUM_PORT, val logName: String = name + ":" + port, autostart: Boolean = true, val useSSL: Boolean = true, connectTimeoutMs: Long = JsonRpc.CONNECT_TIMEOUT, accessTimeoutMs: Long = JsonRpc.ACCESS_TIMEOUT) : JsonRpc

Open a JSON-RPC over TCP connection to an Electrum X server

Constructors

Link copied to clipboard
constructor(chainSelector: ChainSelector, name: String, port: Int = DEFAULT_NEXA_SSL_ELECTRUM_PORT, logName: String = name + ":" + port, autostart: Boolean = true, useSSL: Boolean = true, connectTimeoutMs: Long = JsonRpc.CONNECT_TIMEOUT, accessTimeoutMs: Long = JsonRpc.ACCESS_TIMEOUT)

Types

Link copied to clipboard
@Serializable
data class BalanceReply(val result: ElectrumClient.BalanceResult)
Link copied to clipboard
@Serializable
data class BalanceResult(val confirmed: Int = 0, val unconfirmed: Int = 0)
Link copied to clipboard
@Serializable
data class ErrorCodeMessage(val code: Int, val message: String)
Link copied to clipboard
@Serializable
data class ErrorCodeReply(val error: ElectrumClient.ErrorCodeMessage, val id: Int, val jsonrpc: String)
Link copied to clipboard
@Serializable
data class ErrorReply(val error: String)
Link copied to clipboard
@Serializable
data class FeaturesReply(val result: ElectrumClient.FeaturesResult)
Link copied to clipboard
@Serializable
data class FeaturesResult(val genesis_hash: String, val hash_function: String, val server_version: String, val protocol_max: String, val protocol_min: String, val pruning: Int? = null)
Link copied to clipboard
@Serializable
data class FirstUseReply(val result: ElectrumClient.FirstUseResult)
Link copied to clipboard
@Serializable
data class FirstUseResult(val block_hash: String? = null, val block_height: Int? = null, val tx_hash: String? = null)
Link copied to clipboard
@Serializable
data class GetHistoryReply(val result: List<ElectrumClient.GetHistoryResult>)
Link copied to clipboard
@Serializable
data class GetHistoryResult(val height: Int, val tx_hash: String)
Link copied to clipboard
@Serializable
data class GetTokenHistoryReply(val result: ElectrumClient.TokenHistoryWithCursor)
Link copied to clipboard
@Serializable
data class GetUtxoReply(val result: ElectrumClient.GetUtxoResult)
Link copied to clipboard
@Serializable
data class GetUtxoResult(val amount: Long, val height: Int, val scripthash: String, val status: String, val spent: ElectrumClient.GetUtxoSpentInfo)
Link copied to clipboard
@Serializable
data class GetUtxoSpentInfo(val height: Int?, val tx_hash: String?, val tx_pos: Int?)
Link copied to clipboard
@Serializable
data class HeaderNotification(val params: Array<ElectrumClient.HeaderResult>)
Link copied to clipboard
@Serializable
data class HeaderReply(val result: ElectrumClient.HeaderResult)
Link copied to clipboard
@Serializable
data class HeaderResult(val height: Long, val hex: String)
Link copied to clipboard
@Serializable
data class HeadersReply(val result: ElectrumClient.HeadersResult)
Link copied to clipboard
@Serializable
data class HeadersResult(val count: Int, val hex: String, val max: Int)
Link copied to clipboard
@Serializable
data class ListUnspentReply(val result: Array<ElectrumClient.ListUnspentResult>)
Link copied to clipboard
@Serializable
data class ListUnspentResult(val has_token: Boolean = false, val height: Int, val tx_pos: Int, val tx_hash: String, val outpoint_hash: String? = null, val value: Long)
Link copied to clipboard
@Serializable
data class StringReply(val result: String)
Link copied to clipboard
@Serializable
data class TokenGenesisInfoReply(val result: TokenGenesisInfo)
Link copied to clipboard
@Serializable
data class TokenGetBalanceReply(val result: ElectrumClient.TokenGetBalanceResult)
Link copied to clipboard
@Serializable
data class TokenGetBalanceResult(val confirmed: Map<String, Long>, val unconfirmed: Map<String, Long>, val cursor: String?)
Link copied to clipboard
@Serializable
data class TokenHistoryWithCursor(val cursor: String?, val history: Array<ElectrumClient.GetHistoryResult>)
Link copied to clipboard
Link copied to clipboard
@Serializable
data class TokenListUnspentResult(val unspent: Array<ElectrumClient.UnspentInfo>, val cursor: String?)
Link copied to clipboard
@Serializable
data class UnspentInfo(val group: String, val height: Long, val outpoint_hash: String, val token_amount: Long, val token_id_hex: String, val tx_pos: Long, val value: Long, val tx_hash: String)
Link copied to clipboard
@Serializable
data class VersionReply(val result: List<String>)

Properties

Link copied to clipboard
Link copied to clipboard
val json: Json
Link copied to clipboard
Link copied to clipboard

The version this electrum client supports

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val port: Int
Link copied to clipboard
var reqId: Int
Link copied to clipboard

how long to wait before giving up on a request

Link copied to clipboard
Link copied to clipboard
val useSSL: Boolean = false

Functions

Link copied to clipboard
fun call(method: String, params: List<Any?>?, response: (String?) -> Unit): Int
fun call(method: String, params: List<Any?>?, timeoutInMs: Int): String?
Link copied to clipboard
fun close(reason: String)
Link copied to clipboard
fun features(timeoutInMs: Int = requestTimeout): ElectrumClient.FeaturesResult
Link copied to clipboard
fun getBalance(address: PayAddress, timeoutInMs: Int = requestTimeout): ElectrumClient.BalanceResult
Link copied to clipboard
fun getBchUtxo(hexTxHash: String, outIdx: Int, timeoutInMs: Int = requestTimeout): ElectrumClient.GetUtxoResult
Link copied to clipboard
fun getFirstUse(scriptHash: String, timeoutInMs: Int = requestTimeout): ElectrumClient.FirstUseResult
fun getFirstUse(script: SatoshiScript, timeoutInMs: Int = requestTimeout): ElectrumClient.FirstUseResult

fun getFirstUse(scriptHash: Hash256, timeoutInMs: Int = requestTimeout): ElectrumClient.FirstUseResult

Get confirmed and unconfirmed activity in a script

Link copied to clipboard
fun getHeader(height: Int, timeoutInMs: Int = requestTimeout): ByteArray

Get the serialized header for the block at the supplied height

Link copied to clipboard
fun getHeadersFor(cs: ChainSelector, height: Int, count: Int, timeoutInMs: Int = requestTimeout): List<iBlockHeader>

Return serialized headers for the blocks beginning at the supplied height

Link copied to clipboard
fun getHistory(scriptHash: String, timeoutInMs: Int = requestTimeout): Array<Pair<Int, Hash256>>
fun getHistory(scriptHash: Hash256, timeoutInMs: Int = requestTimeout): Array<Pair<Int, Hash256>>
fun getHistory(script: SatoshiScript, timeoutInMs: Int = requestTimeout): Array<Pair<Int, Hash256>>

Get confirmed and unconfirmed activity in a script

Link copied to clipboard
fun getTip(timeoutInMs: Int = requestTimeout): Pair<iBlockHeader, Long>

Get the current blockchain tip

Link copied to clipboard
fun getTipBytes(timeoutInMs: Int = requestTimeout): Pair<ByteArray, Long>

Get the current blockchain tip

Link copied to clipboard
fun getTokenBalance(address: String, timeoutInMs: Int = requestTimeout): ElectrumClient.TokenGetBalanceResult
fun getTokenBalance(address: PayAddress, timeoutInMs: Int = requestTimeout): ElectrumClient.TokenGetBalanceResult
Link copied to clipboard
fun getTokenGenesisInfo(tokenType: String, timeoutInMs: Int = requestTimeout*2): TokenGenesisInfo
fun getTokenGenesisInfo(tokenType: GroupId, timeoutInMs: Int = requestTimeout): TokenGenesisInfo
Link copied to clipboard
fun getTokenHistory(tokenId: String, cursor: String? = null, timeoutInMs: Int = requestTimeout): Array<Pair<Int, Hash256>>
fun getTokenHistory(tokenId: GroupId, cursor: String? = null, timeoutInMs: Int = requestTimeout): Array<Pair<Int, Hash256>>

Get confirmed and unconfirmed activity in a script

Link copied to clipboard
fun getTokenUnspent(address: String, tokenId: String? = null, cursor: String? = null, timeoutInMs: Int = requestTimeout): ElectrumClient.TokenListUnspentResult
Link copied to clipboard
fun getTx(txHash: String, timeoutInMs: Int = requestTimeout): iTransaction
fun getTx(txHash: Hash256, timeoutInMs: Int = requestTimeout): iTransaction

Get a transaction by hash

Link copied to clipboard
fun getTxAt(height: Int, idx: Int, blockMerkleRoot: Hash256? = null, timeoutInMs: Int = requestTimeout): iTransaction

Get the transaction at the specified block height and offset. Requires multiple server calls.

Link copied to clipboard
fun getTxDetails(txHash: String, timeoutInMs: Int = requestTimeout): JsonElement
Link copied to clipboard
fun getTxHashAt(height: Int, idx: Int, blockMerkleRoot: Hash256? = null, timeoutInMs: Int = requestTimeout): Hash256

Get the transaction hash at the specified block height and offset.

Link copied to clipboard
fun getTxOld(txHash: String, timeoutInMs: Int = requestTimeout): iTransaction
Link copied to clipboard
fun getUtxo(outpointHex: String, timeoutInMs: Int = requestTimeout): ElectrumClient.GetUtxoResult
fun getUtxo(inp: NexaTxInput, timeoutInMs: Int = requestTimeout): ElectrumClient.GetUtxoResult
fun getUtxo(inp: iTxOutpoint, timeoutInMs: Int = requestTimeout): ElectrumClient.GetUtxoResult
Link copied to clipboard
fun listUnspent(destination: PayDestination, timeoutInMs: Int = requestTimeout): List<Spendable>

Get spendable output for a pay destination you own.

Link copied to clipboard
fun nextId(): Int
Link copied to clipboard
fun <T> parse(method: String, params: List<String>?, serializer: KSerializer<T>, response: (T?) -> Unit)
Link copied to clipboard
fun ping(timeoutInMs: Int = requestTimeout)
Link copied to clipboard
fun run()
Link copied to clipboard
fun sendTx(serializedTx: ByteArray, timeoutInMs: Int = requestTimeout): String

Send out a transaction

Link copied to clipboard
fun start()
Link copied to clipboard
fun stop()
Link copied to clipboard
fun subscribe(method: String, params: List<Any?>? = null, response: (String?) -> Unit)
Link copied to clipboard
fun subscribeHeaders(callback: (iBlockHeader) -> Unit)

Subscribe to blockchain headers. Issues a callback with the blockchain tip when a new block is found.

Link copied to clipboard

Unsubscribes from blockchain headers.

Link copied to clipboard
fun version(timeoutInMs: Int = requestTimeout): Pair<String, String>

Get the server version