-
Notifications
You must be signed in to change notification settings - Fork 4
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
0 parents
commit afb2e69
Showing
141 changed files
with
16,213 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.tsol linguist-language=Solidity | ||
*.sol linguist-language=Solidity |
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,7 @@ | ||
/node_modules | ||
/dist | ||
*.log | ||
/demoBot/items/*.abi.json | ||
/demoBot/items/*.tvc | ||
/demoBot/items/~*.* | ||
/demoBot/items/.solc_imports/~*.* |
Large diffs are not rendered by default.
Oops, something went wrong.
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,106 @@ | ||
# My TON wallet (MTW) DeBot engine and embed tool | ||
|
||
<div align="center"> | ||
<img src="./src/debot-browser/assets/img/debot256.png" title="My TON wallet - Debot"> | ||
</div> | ||
|
||
This repository contains source code for DeBot engine that allow interaction with Free Ton (freeTON) blockchain from web pages. | ||
|
||
# Installation additional tools | ||
|
||
To easy make the deployment process you need to install `tondev` | ||
|
||
```console | ||
npm i -tondev | ||
``` | ||
|
||
After this step you can install tonos-cli | ||
|
||
```console | ||
tondev install tonos-cli | ||
``` | ||
|
||
# Creating local debot | ||
|
||
Install Docker | ||
|
||
Run TON OS | ||
```console | ||
npm run run-tonos | ||
``` | ||
|
||
Deploy DeBot on the local blockchain for Windows | ||
```console | ||
./demoBot/deployLocal.ps1 | ||
``` | ||
|
||
Deploy DeBot on the local blockchain for Linux | ||
```console | ||
./demoBot/deployLocal.ps1 | ||
``` | ||
|
||
To test deployed DeBot | ||
|
||
```console | ||
tonos-cli --config ./demoBot/tonos-cli.local-config.json debot fetch 0:dc85009c3cea9bf8849dcd5cb58d36eec5d0fe0aa9c882797483bf3a1b95f0ff | ||
``` | ||
|
||
# Developing process | ||
|
||
To run development process | ||
|
||
```console | ||
npm start | ||
``` | ||
|
||
Navigate in your browser to the http://localhost:10002/debot-browser/index.html to develop "debot browser" | ||
|
||
Navigate in your browser to the http://localhost:10002/embed-tool/index.html to develop "embed tool" | ||
|
||
# Embed tool | ||
|
||
To embed DeBot on any web page you need to select network and enter DeBot address. | ||
You can adjust Debot UI by changing css variables. | ||
Available these variables: | ||
|
||
| Name | Default value | | ||
| --------- | --------- | | ||
| --debot-browser-bg-color | #ffffff | | ||
| --debot-browser-bg-secondary-color | #f3f3f6 | | ||
| --debot-browser-color-primary | #14854F | | ||
| --debot-browser-color-lightGrey | #d2d6dd | | ||
| --debot-browser-color-grey | #747681 | | ||
| --debot-browser-color-darkGrey | #3f4144 | | ||
| --debot-browser-color-error | #d43939 | | ||
| --debot-browser-color-success | #28bd14 | | ||
| --debot-browser-grid-maxWidth | 60rem | | ||
| --debot-browser-grid-gutter | 1rem | | ||
| --debot-browser-font-size | 1rem | | ||
| --debot-browser-font-color | #333333 | | ||
| --debot-browser-font-family-sans | -apple-system, BlinkMacSystemFont, Avenir, "Avenir Next", "Segoe UI", "Roboto", "Oxygen", "Ubuntu" "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif | | ||
| --debot-browser-font-family-mono | monaco, "Consolas", "Lucida Console", monospace | | ||
|
||
Also it is possible to redefine css on elements and create own UI. | ||
|
||
You can select/adjust: | ||
1. network | ||
2. address | ||
3. language (or specify own from external file, you must to use [this template](/src/debot-browser/assets/locales/en.json) for a translation creating) | ||
4. handler way for used cards | ||
5. UI styles | ||
6. Embedding way (tick iframe if need to embed iframe way) | ||
|
||
# Code for embedding | ||
|
||
It is possible to use two ways: | ||
|
||
1. Code for direct embedding. Web element (Component). | ||
2. Iframe. | ||
|
||
For direct embedding way you can use code from "embed tool". | ||
For Iframe need to place code from "embed tool" to any web page. For example on [gist.github.com](https://gist.github.com/) and then insert URL to the Iframe. For example: | ||
|
||
```html | ||
<iframe width="300" height="200" src="SOURCE_FROM_https://gist.github.com/"></iframe> | ||
``` | ||
|
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,5 @@ | ||
log.log | ||
demoBot.abi.json | ||
demoBot.tvc | ||
demoBot.keys.json | ||
address.log |
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,58 @@ | ||
pragma ton-solidity >=0.35.0; | ||
pragma AbiHeader expire; | ||
pragma AbiHeader time; | ||
pragma AbiHeader pubkey; | ||
|
||
abstract contract Debot { | ||
uint8 constant DEBOT_ABI = 1; | ||
|
||
uint8 m_options; | ||
optional(string) m_debotAbi; | ||
|
||
/// @notice Deprecated. For compatibility with old DEngine. | ||
optional(string) m_targetAbi; | ||
|
||
/// @notice Deprecated. For compatibility with old DEngine. | ||
optional(address) m_target; | ||
|
||
/* | ||
* Public debot interface | ||
*/ | ||
|
||
/// @notice DeBot entry point. | ||
function start() public functionID(0x01) virtual; | ||
|
||
/// @notice Returns list of interfaces used by DeBot. | ||
function getRequiredInterfaces() public view virtual returns (uint256[] interfaces); | ||
|
||
/// @notice Returns DeBot metadata. | ||
/// @return name String with name of debot, e.g. "DePool". | ||
/// @return version Semver version of debot, that will be converted to string like "x.y.z". | ||
/// @return publisher String with info about who has deployed debot to blokchain, e.g. "TON Labs". | ||
/// @return key (10-20 ch.) String with short description, e.g. "Work with Smthg". | ||
/// @return author String with name of author of DeBot, e.g. "Ivan Ivanov". | ||
/// @return support Free TON address of author for questions and donations. | ||
/// @return hello String with first messsage with DeBot description. | ||
/// @return language (ISO-639) String with debot interface language, e.g. "en". | ||
/// @return dabi String with debot ABI. | ||
function getDebotInfo() public functionID(0xDEB) view virtual returns ( | ||
string name, string version, string publisher, string key, string author, | ||
address support, string hello, string language, string dabi, bytes icon); | ||
|
||
/// @notice Returns DeBot ABI. | ||
/// Deprecated. | ||
function getDebotOptions() public view returns (uint8 options, string debotAbi, string targetAbi, address targetAddr) { | ||
debotAbi = m_debotAbi.hasValue() ? m_debotAbi.get() : ""; | ||
targetAbi = m_targetAbi.hasValue() ? m_targetAbi.get() : ""; | ||
targetAddr = m_target.hasValue() ? m_target.get() : address(0); | ||
options = m_options; | ||
} | ||
|
||
/// @notice Allow to set debot ABI. Do it before using debot. | ||
function setABI(string dabi) public { | ||
require(tvm.pubkey() == msg.pubkey(), 100); | ||
tvm.accept(); | ||
m_options |= DEBOT_ABI; | ||
m_debotAbi = dabi; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
// Source code https://github.com/extraton/debrowser/tree/master/demoBot | ||
|
||
pragma ton-solidity >=0.35.0; | ||
pragma AbiHeader expire; | ||
pragma AbiHeader time; | ||
pragma AbiHeader pubkey; | ||
|
||
import "./Debot.tsol"; | ||
import "./items/.solc_imports/Menu.sol"; | ||
import "./items/terminal.tsol"; | ||
import "./items/base64.tsol"; | ||
import "./items/hex.tsol"; | ||
import "./items/json.tsol"; | ||
import "./items/qrCode.tsol"; | ||
import "./items/addressInput.tsol"; | ||
import "./items/amountInput.tsol"; | ||
import "./items/numberInput.tsol"; | ||
import "./items/confirmInput.tsol"; | ||
import "./items/userInfo.tsol"; | ||
import "./items/signingBoxInput.tsol"; | ||
import "./items/network.tsol"; | ||
|
||
contract DemoBot is Debot, TerminalItem, QrCodeItem, AddressInputItem, AmountInputItem, | ||
NumberInputItem, ConfirmInputItem, UserInfoItem, signingBoxInputItem, NetworkItem, | ||
JsonItem, Base64Item, HexItem { | ||
bytes m_icon; | ||
|
||
function setIcon(bytes icon) public { | ||
require(msg.pubkey() == tvm.pubkey(), 100); | ||
tvm.accept(); | ||
m_icon = icon; | ||
} | ||
|
||
function start() public functionID(0x01) override { | ||
Menu.select("Hello, I'm the Interfaces Demo Bot!\nWhich one interface you would like to see?", "", [ | ||
MenuItem("Terminal", "Simple input/output", tvm.functionId(terminalStart)), | ||
MenuItem("QR Code", "Allows to scan qrcode and return its data as string", tvm.functionId(qrCodeStart)), | ||
MenuItem("Menu", "Interface for menu", tvm.functionId(toStartFromMenu)), | ||
MenuItem("Address Input", "Allows to input smart contract address", tvm.functionId(addressInputStart)), | ||
MenuItem("Amount Input", "Interface for amount input", tvm.functionId(amountInputStart)), | ||
MenuItem("Number Input", "Interface for number input", tvm.functionId(numberInputStart)), | ||
MenuItem("Confirm Input", "Interface for confirm input", tvm.functionId(confirmInputStart)), | ||
MenuItem("User Info", "Allows to get information about current user.", tvm.functionId(userInfoStart)), | ||
MenuItem("Signing Box Input", "Interface for getting signing box", tvm.functionId(signingBoxInputStart)), | ||
MenuItem("Network", "Interface for network requests.", tvm.functionId(networkStart)), | ||
MenuItem("Json", "Interface for json deserializing.", tvm.functionId(jsonStart)), | ||
MenuItem("Base64", "Interface for base64 encode/decode.", tvm.functionId(base64Start)), | ||
MenuItem("Hex", "Interface for hex encode/decode.", tvm.functionId(hexStart)) | ||
]); | ||
} | ||
|
||
function toStartFromMenu(uint32 index) public functionID(0x02) { | ||
index = index; | ||
Terminal.print(0x01, ""); | ||
} | ||
|
||
function getDebotInfo() public functionID(0xDEB) override view returns ( | ||
string name, string version, string publisher, string key, string author, | ||
address support, string hello, string language, string dabi, bytes icon | ||
) { | ||
name = "Interfaces Debot Demo"; | ||
version = "1.0.0"; | ||
publisher = "TON community"; | ||
key = "Start develop DeBot from here"; | ||
author = "MTW team"; | ||
support = address.makeAddrStd(0, 0x0); | ||
hello = "Hello, I'm the Interfaces Demo DeBot."; | ||
language = "en"; | ||
dabi = m_debotAbi.get(); | ||
icon = m_icon; | ||
} | ||
|
||
function getRequiredInterfaces() public view override returns (uint256[] interfaces) { | ||
} | ||
} |
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,33 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
ROOT_PATH="./demoBot/" | ||
DEBOT_NAME=demoBot | ||
NETWORK="https://net.ton.dev" | ||
|
||
function get_address { | ||
echo $(cat log.log | grep "Raw address:" | cut -d ' ' -f 3) | ||
} | ||
|
||
function genaddr { | ||
tonos-cli genaddr "$ROOT_PATH$1.tvc" "$ROOT_PATH$1.abi.json" --genkey "$ROOT_PATH$1.keys.json" > log.log | ||
} | ||
|
||
echo "Genaddr debot" | ||
genaddr $DEBOT_NAME | ||
DEBOT_ADDRESS=$(get_address) | ||
echo $DEBOT_ADDRESS | ||
|
||
read -p "...Send coins and press enter to continue..." | ||
|
||
DEBOT_ABI=$(cat "$ROOT_PATH$DEBOT_NAME.abi.json" | xxd -ps -c 20000) | ||
ICON=$(cat "$ROOT_PATH"debot.png | xxd -ps -c 20000) | ||
|
||
echo "Deploy debot" | ||
tonos-cli --url $NETWORK deploy "$ROOT_PATH$DEBOT_NAME.tvc" "{}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setABI "{\"dabi\":\"$DEBOT_ABI\"}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setIcon "{\"icon\":\"$ICON\"}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
|
||
echo DONE | ||
echo $DEBOT_ADDRESS > address.log | ||
echo debot $NETWORK/$DEBOT_ADDRESS |
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,46 @@ | ||
$ROOT_PATH="./demoBot/" | ||
$DEBOT_NAME="demoBot" | ||
$GIVER="0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94" | ||
$NETWORK="http://127.0.0.1:7777" | ||
|
||
Write-Host "Genaddr" | ||
tonos-cli genaddr $ROOT_PATH$DEBOT_NAME'.tvc' $ROOT_PATH$DEBOT_NAME'.abi.json' --genkey $ROOT_PATH$DEBOT_NAME'.keys.json' > $ROOT_PATH'log.log' | ||
$DEBOT_ADDRESS=(Get-Content $ROOT_PATH'log.log') | Select-String -Pattern 'Raw address:' -CaseSensitive | ||
$DEBOT_ADDRESS= $DEBOT_ADDRESS -split ':' | ||
$DEBOT_ADDRESS='0:' + $DEBOT_ADDRESS[2] | ||
Write-Host $DEBOT_ADDRESS | ||
|
||
Write-Host "Ask giver" | ||
tonos-cli --url $NETWORK call --abi $ROOT_PATH'local_giver.abi.json' $GIVER sendGrams "{\""dest\"":\""$DEBOT_ADDRESS\"",\""amount\"":10000000000}" | ||
|
||
Write-Host "Deploy debot $DEBOT_ADDRESS" | ||
tonos-cli --url $NETWORK deploy $ROOT_PATH$DEBOT_NAME'.tvc' "{}" --sign $ROOT_PATH$DEBOT_NAME'.keys.json' --abi $ROOT_PATH$DEBOT_NAME'.abi.json' | ||
Write-Host "Set Abi $DEBOT_ADDRESS" | ||
$DEBOT_ABI=(Get-Content $ROOT_PATH$DEBOT_NAME'.abi.json' -Encoding Byte -ReadCount 0) | ||
$output = new-object System.Text.StringBuilder # Using stringBuilder seems faster than $a = $a + "a" ? | ||
$count = $DEBOT_ABI.length # The loop seems much faster when using a pre-set value? | ||
for ($i = 0; $i -le $count-1; $i++) { | ||
$hex = "{0:x}" -f $DEBOT_ABI[$i] | ||
[void]$output.Append($hex.PadLeft(2, "0")) # Pad any single digits | ||
} | ||
$DEBOT_ABI=$output | ||
#Write-Host $DEBOT_ABI | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setABI "{\""dabi\"":\""$DEBOT_ABI\""}" --sign $ROOT_PATH$DEBOT_NAME'.keys.json' --abi $ROOT_PATH$DEBOT_NAME'.abi.json' | ||
Write-Host "Set Icon $DEBOT_ADDRESS" | ||
$ICON=(Get-Content $ROOT_PATH'debot.png' -Encoding Byte -ReadCount 0) | ||
$output = new-object System.Text.StringBuilder # Using stringBuilder seems faster than $a = $a + "a" ? | ||
$count = $ICON.length # The loop seems much faster when using a pre-set value? | ||
for ($i = 0; $i -le $count-1; $i++) { | ||
$hex = "{0:x}" -f $ICON[$i] | ||
[void]$output.Append($hex.PadLeft(2, "0")) # Pad any single digits | ||
} | ||
$ICON=$output | ||
#Write-Host $ICON | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setIcon "{\""icon\"":\""$ICON\""}" --sign $ROOT_PATH$DEBOT_NAME'.keys.json' --abi $ROOT_PATH$DEBOT_NAME'.abi.json' | ||
|
||
Write-Host "Done" | ||
Write-Host $DEBOT_ADDRESS > address.log | ||
Write-Host debot $NETWORK'/'$DEBOT_ADDRESS | ||
|
||
Write-Host "Test that we can connect to the DeBot" | ||
tonos-cli --config $ROOT_PATH'tonos-cli.local-config.json' debot fetch $DEBOT_ADDRESS |
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,37 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
ROOT_PATH="./demoBot/" | ||
DEBOT_NAME=demoBot | ||
GIVER=0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94 | ||
NETWORK="http://127.0.0.1:7777" | ||
|
||
function giver { | ||
tonos-cli --url $NETWORK call --abi "$ROOT_PATH/local_giver.abi.json" $GIVER sendGrams "{\"dest\":\"$1\",\"amount\":10000000000}" | ||
} | ||
|
||
function get_address { | ||
echo $(cat log.log | grep "Raw address:" | cut -d ' ' -f 3) | ||
} | ||
|
||
function genaddr { | ||
tonos-cli genaddr "$ROOT_PATH$1.tvc" "$ROOT_PATH$1.abi.json" --genkey "$ROOT_PATH$1.keys.json" > log.log | ||
} | ||
|
||
echo GENADDR DEBOT | ||
genaddr $DEBOT_NAME | ||
DEBOT_ADDRESS=$(get_address) | ||
|
||
echo ASK GIVER | ||
giver $DEBOT_ADDRESS | ||
DEBOT_ABI=$(cat "$ROOT_PATH$DEBOT_NAME.abi.json" | xxd -ps -c 20000) | ||
ICON=$(cat "$ROOT_PATH"debot.png | xxd -ps -c 20000) | ||
|
||
echo DEPLOY DEBOT $DEBOT_ADDRESS | ||
tonos-cli --url $NETWORK deploy "$ROOT_PATH$DEBOT_NAME.tvc" "{}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setABI "{\"dabi\":\"$DEBOT_ABI\"}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
tonos-cli --url $NETWORK call $DEBOT_ADDRESS setIcon "{\"icon\":\"$ICON\"}" --sign "$ROOT_PATH$DEBOT_NAME.keys.json" --abi "$ROOT_PATH$DEBOT_NAME.abi.json" | ||
|
||
echo DONE | ||
echo $DEBOT_ADDRESS > address.log | ||
echo debot $NETWORK/$DEBOT_ADDRESS |
Oops, something went wrong.