/
DApp.kt
77 lines (69 loc) · 3.25 KB
/
DApp.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* MIT License
* Copyright (c) 2022 Jemshit Iskenderov
*/
package walletconnect.core
import walletconnect.core.session.SessionLifecycle
import walletconnect.core.session.callback.RequestCallback
import walletconnect.core.session.model.SessionRequest
import walletconnect.core.session.model.json_rpc.CustomRpcMethod
import walletconnect.core.session.model.json_rpc.EthRpcMethod
import walletconnect.core.session.model.json_rpc.JsonRpcMethod
import java.lang.reflect.Type
interface DApp : SessionLifecycle {
/**
* Sends [SessionRequest] to Wallet.
* - Not idempotent. Once approved by wallet, consecutive calls to this function is idempotent
* - Wallet responds with same messageId
*/
fun sendSessionRequest(chainId: Int?)
/**
* - Non suspending version of `sendRequest`
* - Send any request such as ETH sendTransaction, sign, wallet specific requests ...
*
* @param[method] one of [EthRpcMethod], [CustomRpcMethod]
* @param[data] list of any model, usually single item
* @param[itemType] Type of item in [data] list (not type of List!)
* @param[onRequested] triggered when request is sent
* @param[onRequestError] triggered if failed to send the request. This is called before global callback
* @param[onCallback] triggered when there is response from peer. Cast the [RequestCallback] to expected subclass.
* This is called before global callback
*/
fun sendRequestAsync(method: JsonRpcMethod,
data: List<Any>,
itemType: Type,
onRequested: (() -> Unit)? = null,
onRequestError: ((String?) -> Unit)? = null,
onCallback: ((RequestCallback) -> Unit)? = null)
/**
* - Suspending version of [sendRequestAsync]
* - Send any request such as ETH sendTransaction, sign, wallet specific requests ...
* - You can store returned messageId mapped to Callback, (`Map<messageId, Callback>`), so when you
* receive response with same messageId, you can get corresponding Callback from Map and invoke it
*
* @param[method] one of [EthRpcMethod], [CustomRpcMethod]
* @param[data] list of any model, usually single item
* @param[itemType] Type of item in [data] list (not type of List!)
*
* @return messageId or null if error
*/
suspend fun sendRequest(method: JsonRpcMethod,
data: List<Any>,
itemType: Type)
: Long?
/**
* Serializes, encrypts and sends payload to the peer
* - Only use after session is approved
* - You can store returned [messageId] mapped to Callback, (`Map<messageId, Callback>`), so when you
* receive response with same [messageId], you can get corresponding Callback from Map and invoke it
* - No callback is invoked
*
* @return messageId or null if error. Response will have same [messageId]
*/
suspend fun encryptPayloadAndPublish(messageId: Long,
payload: Any,
type: Type,
queueIfDisconnected: Boolean = true)
: Long?
fun generateMessageId(): Long
}