-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support debot and update to SDK 1.18 (#16)
* Added support debot * Update SDK up to 1.18, fixed test for new devnet
- Loading branch information
Showing
10 changed files
with
263 additions
and
6 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
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/ee/nx01/tonclient/debot/AppDebotBrowser.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,13 @@ | ||
package ee.nx01.tonclient.debot | ||
|
||
interface AppDebotBrowser { | ||
fun log(params: ParamsOfAppDebotBrowserLog) | ||
fun switch(params: ParamsOfAppDebotBrowserSwitch) | ||
fun switchCompleted() | ||
fun showAction(params: ParamsOfAppDebotBrowserShowAction) | ||
fun input(params: ParamsOfAppDebotBrowserInput): ResultOfAppDebotBrowserInput | ||
fun getSigningBox(): ResultOfAppDebotBrowserGetSigningBox | ||
fun invokeDebot(params: ParamsOfAppDebotBrowserInvokeDebot) | ||
fun send(params: ParamsOfAppDebotBrowserSend) | ||
fun approve(params: ParamsOfAppDebotBrowserApprove): ResultOfAppDebotBrowserApprove | ||
} |
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,75 @@ | ||
package ee.nx01.tonclient.debot | ||
|
||
import ee.nx01.tonclient.JsonUtils | ||
import ee.nx01.tonclient.TonClient | ||
|
||
/** | ||
* Module for working with debot. | ||
*/ | ||
class DeBotModule(private val tonClient: TonClient) { | ||
|
||
/** | ||
* Downloads debot smart contract (code and data) from blockchain and creates an instance of Debot Engine for it. | ||
*/ | ||
suspend fun init(params: ParamsOfInit, onResult: (result: ParamsOfAppDebotBrowser) -> Unit): RegisteredDebot { | ||
return tonClient.request("debot.init", params) { | ||
onResult(JsonUtils.read(it)) | ||
} | ||
} | ||
|
||
/** | ||
* Starts the DeBot. | ||
Downloads debot smart contract from blockchain and switches it to | ||
context zero. | ||
This function must be used by Debot Browser to start a dialog with debot. | ||
While the function is executing, several Browser Callbacks can be called, | ||
since the debot tries to display all actions from the context 0 to the user. | ||
When the debot starts SDK registers `BrowserCallbacks` AppObject. | ||
Therefore when `debote.remove` is called the debot is being deleted and the callback is called | ||
with `finish`=`true` which indicates that it will never be used again. | ||
*/ | ||
suspend fun start(params: ParamsOfStart) { | ||
return tonClient.request("debot.start", params) | ||
} | ||
|
||
/** | ||
* Fetches DeBot metadata from blockchain. | ||
* | ||
* Downloads DeBot from blockchain and creates and fetches its metadata. | ||
*/ | ||
suspend fun fetch(params: ParamsOfFetch): ResultOfFetch { | ||
return tonClient.request("debot.fetch", params) | ||
} | ||
|
||
/** | ||
* Executes debot action. | ||
* Calls debot engine referenced by debot handle to execute input action. | ||
* Calls Debot Browser Callbacks if needed. | ||
* # Remarks | ||
* Chain of actions can be executed if input action generates a list of subactions. | ||
*/ | ||
suspend fun execute(params: ParamsOfExecute) { | ||
return tonClient.request("debot.execute", params) | ||
} | ||
|
||
/** | ||
* Sends message to Debot. | ||
* Used by Debot Browser to send response on Dinterface call or from other Debots. | ||
*/ | ||
suspend fun send(params: ParamsOfSend) { | ||
return tonClient.request("debot.send", params) | ||
} | ||
|
||
/** | ||
* Destroys debot handle. | ||
* Removes handle from Client Context and drops debot engine referenced by that handle. | ||
*/ | ||
suspend fun remove(params: ParamsOfRemove) { | ||
return tonClient.request("debot.remove", params) | ||
} | ||
|
||
} |
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,133 @@ | ||
package ee.nx01.tonclient.debot | ||
|
||
data class ParamsOfAppDebotBrowserLog( | ||
val msg: String | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserSwitch( | ||
val contextId: Long | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserShowAction( | ||
val action: DebotAction | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserInput( | ||
val prompt: String | ||
) | ||
|
||
data class ResultOfAppDebotBrowserInput( | ||
val value: String | ||
) | ||
|
||
data class ResultOfAppDebotBrowserGetSigningBox( | ||
val signingBox: Long | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserInvokeDebot( | ||
val debotAddr: String, | ||
val action: DebotAction | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserSend( | ||
val message: String | ||
) | ||
|
||
data class ParamsOfAppDebotBrowserApprove( | ||
val activity: DebotActivity | ||
) | ||
|
||
data class ResultOfAppDebotBrowserApprove( | ||
val approved: Boolean | ||
) | ||
|
||
|
||
enum class AppDebotBrowserMessageType { | ||
Log, Switch, SwitchCompleted, ShowAction, Input, GetSigningBox, InvokeDebot, Send, Approve | ||
} | ||
|
||
data class ParamsOfAppDebotBrowser( | ||
val type: AppDebotBrowserMessageType, | ||
val msg: String? = null, | ||
val contextId: Long? = null, | ||
val action: DebotAction? = null, | ||
val prompt: String? = null, | ||
val debotAddr: String? = null, | ||
val message: String? = null, | ||
val activity: DebotActivity? = null | ||
) | ||
|
||
data class DebotActivity( | ||
val type: String = "Transaction", | ||
val msg: String, | ||
val dst: String, | ||
val out: List<Spending> = listOf(), | ||
val fee: Long, | ||
val setcode: Boolean, | ||
val signkey: String, | ||
val signing_box_handle: Long | ||
) | ||
|
||
data class Spending( | ||
val amount: Long, | ||
val dst: String | ||
) | ||
|
||
data class ParamsOfRemove( | ||
val debotHandle: Long | ||
) | ||
|
||
data class ParamsOfSend( | ||
val debotHandle: Long, | ||
val message: String | ||
) | ||
|
||
data class ParamsOfExecute( | ||
val debotHandle: Long, | ||
val action: DebotAction | ||
) | ||
|
||
data class DebotAction( | ||
val description: String, | ||
val name: String, | ||
val actionType: Long, | ||
val to: Long, | ||
val attributes: String, | ||
val misc: String | ||
) | ||
|
||
data class ResultOfFetch( | ||
val info: DebotInfo | ||
) | ||
|
||
data class ParamsOfFetch( | ||
val address: String | ||
) | ||
|
||
data class ParamsOfStart( | ||
val debotHandle: Long | ||
) | ||
|
||
data class ParamsOfInit( | ||
val address: String | ||
) | ||
|
||
data class RegisteredDebot( | ||
val debotHandle: Long, | ||
val debotAbi: String, | ||
val info: DebotInfo | ||
) | ||
|
||
data class DebotInfo( | ||
val name: String? = null, | ||
val version: String? = null, | ||
val publisher: String? = null, | ||
val caption: String? = null, | ||
val author: String? = null, | ||
val support: String? = null, | ||
val hello: String? = null, | ||
val language: String? = null, | ||
val dabi: String? = null, | ||
val icon: String? = null, | ||
val interfaces: List<String> = listOf() | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
32 changes: 32 additions & 0 deletions
32
src/test/kotlin/ee/nx01/tonclient/debot/DeBotModuleTest.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,32 @@ | ||
package ee.nx01.tonclient.debot | ||
|
||
import ee.nx01.tonclient.NetworkConfig | ||
import ee.nx01.tonclient.TonClient | ||
import ee.nx01.tonclient.TonClientConfig | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldNotBe | ||
|
||
class DeBotModuleTest : StringSpec({ | ||
|
||
"Should be able init and start deboot" { | ||
val client = TonClient(TonClientConfig(network = NetworkConfig("main.ton.dev"))) | ||
|
||
val response = client.debot.init(ParamsOfInit("0:038081930f6b5211ba2c9e36cb28945954c35ccd913872a4b17b2671b83f2a88")) { | ||
println(it) | ||
} | ||
|
||
response shouldNotBe null | ||
|
||
client.debot.start(ParamsOfStart(response.debotHandle)) | ||
|
||
Thread.sleep(3000) | ||
} | ||
|
||
"Should be able fetch" { | ||
val client = TonClient(TonClientConfig(network = NetworkConfig("main.ton.dev"))) | ||
|
||
val response = client.debot.fetch(ParamsOfFetch("0:038081930f6b5211ba2c9e36cb28945954c35ccd913872a4b17b2671b83f2a88")) | ||
|
||
response shouldNotBe null | ||
} | ||
}) |
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