-
Notifications
You must be signed in to change notification settings - Fork 9
/
Service.kt
55 lines (42 loc) · 1.59 KB
/
Service.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example.umlandowallet.data.remote
import com.example.umlandowallet.data.MerkleProof
import com.example.umlandowallet.data.Tx
import com.example.umlandowallet.data.TxResponse
import com.example.umlandowallet.data.TxStatus
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
interface Service {
suspend fun getLatestBlockHash() : String
suspend fun getLatestBlockHeight() : Int
suspend fun broadcastTx(tx: ByteArray) : String
suspend fun getTx(txid: String) : Tx
suspend fun getTxHex(txid: String): String
suspend fun getTxStatus(txid: String) : TxStatus
suspend fun getHeader(hash: String) : String
suspend fun getMerkleProof(txid: String) : MerkleProof
suspend fun connectPeer(pubkeyHex: String, hostname: String, port: Int)
companion object {
fun create() : Service {
return ServiceImpl(
client = HttpClient() {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.HEADERS
}
install(ContentNegotiation) {
json(
json = Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
}
)
}
}
)
}
}
}