1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

updated vm (breaking compatibility)

- updated vm
- new actor scheduler
- updated tonlib
- updated DNS smartcontract
This commit is contained in:
ton 2020-02-28 14:28:47 +04:00
parent 9e4816e7f6
commit e27fb1e09c
100 changed files with 3692 additions and 1299 deletions

View file

@ -49,8 +49,8 @@ class TonTest {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 0,
"root_hash": "VCSXxDHhTALFxReyTZRd8E4Ya3ySOmpOWAS4rBX9XBY=",
"file_hash": "eh9yveSz1qMdJ7mOsO+I+H77jkLr9NpAuEkoJuseXBo="
"root_hash": "F6OpKZKqvqeFp6CQmFomXNMfMj2EnaUSOXN+Mh+wVWk=",
"file_hash": "XplPz01CXAps5qeSWUtxcyBfdAo5zVb1N979KLSKD24="
}
}
}"""
@ -58,29 +58,27 @@ class TonTest {
fun createTestWallet() {
val client = ClientKotlin()
val dir = getContext().getExternalFilesDir(null).toString() + "/";
val words = getContext().getString(R.string.wallet_mnemonic_words).split(" ").toTypedArray();
runBlocking {
client.send(TonApi.Init(TonApi.Options(TonApi.Config(config, "", false, false), dir)))
val info = client.send(TonApi.Init(TonApi.Options(TonApi.Config(config, "", false, false), TonApi.KeyStoreTypeDirectory(dir)))) as TonApi.OptionsInfo;
val key = client.send(TonApi.CreateNewKey("local password".toByteArray(), "mnemonic password".toByteArray(), "".toByteArray())) as TonApi.Key
val walletAddress = client.send(TonApi.TestWalletGetAccountAddress(TonApi.TestWalletInitialAccountState(key.publicKey))) as TonApi.AccountAddress;
val testGiverState = client.send(TonApi.TestGiverGetAccountState()) as TonApi.TestGiverAccountState
val inputKey = TonApi.InputKeyRegular(key, "local password".toByteArray())
val walletAddress = client.send(TonApi.GetAccountAddress(TonApi.WalletV3InitialAccountState(key.publicKey, info.configInfo.defaultWalletId), 1)) as TonApi.AccountAddress
client.send(TonApi.TestGiverSendGrams(walletAddress, testGiverState.seqno, 6660000000, "".toByteArray())) as TonApi.Ok
val giverKey = client.send(TonApi.ImportKey("local password".toByteArray(), "".toByteArray(), TonApi.ExportedKey(words))) as TonApi.Key
val giverInputKey = TonApi.InputKeyRegular(giverKey, "local password".toByteArray())
val giverAddress = client.send(TonApi.GetAccountAddress(TonApi.WalletV3InitialAccountState(giverKey.publicKey, info.configInfo.defaultWalletId), 1)) as TonApi.AccountAddress;
while ((client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateUninited).accountState.balance <= 0L) {
val queryInfo = client.send(TonApi.CreateQuery(giverInputKey, giverAddress, 60, TonApi.ActionMsg(arrayOf(TonApi.MsgMessage(walletAddress, 6660000000, TonApi.MsgDataText("Helo") )), true))) as TonApi.QueryInfo;
client.send(TonApi.QuerySend(queryInfo.id)) as TonApi.Ok;
while ((client.send(TonApi.GetAccountState(walletAddress)) as TonApi.FullAccountState).balance <= 0L) {
delay(1000L)
}
val inputKey = TonApi.InputKey(key, "local password".toByteArray());
client.send(TonApi.TestWalletInit(inputKey)) as TonApi.Ok
while (client.send(TonApi.GenericGetAccountState(walletAddress)) !is TonApi.GenericAccountStateTestWallet) {
delay(1000L)
}
val state = client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateTestWallet
val balance = state.accountState.balance
client.send(TonApi.GenericSendGrams(inputKey, walletAddress, walletAddress, 10, 0, true, "hello".toByteArray())) as TonApi.Ok
while ((client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateTestWallet).accountState.balance == balance) {
val queryInfo2 = client.send(TonApi.CreateQuery(inputKey, walletAddress, 60, TonApi.ActionMsg(arrayOf(), true))) as TonApi.QueryInfo;
client.send(TonApi.QuerySend(queryInfo2.id)) as TonApi.Ok;
while ((client.send(TonApi.GetAccountState(walletAddress)) as TonApi.FullAccountState).accountState !is TonApi.WalletV3AccountState) {
delay(1000L)
}
}

View file

@ -53,29 +53,28 @@ public class TonTestJava {
return result[0];
}
}
String config = "{\n" +
" \"liteservers\": [\n" +
" {\n" +
" \"ip\": 1137658550,\n" +
" \"port\": 4924,\n" +
" \"id\": {\n" +
" \"@type\": \"pub.ed25519\",\n" +
" \"key\": \"peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M=\"\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"validator\": {\n" +
" \"@type\": \"validator.config.global\",\n" +
" \"zero_state\": {\n" +
" \"workchain\": -1,\n" +
" \"shard\": -9223372036854775808,\n" +
" \"seqno\": 0,\n" +
" \"root_hash\": \"VCSXxDHhTALFxReyTZRd8E4Ya3ySOmpOWAS4rBX9XBY=\",\n" +
" \"file_hash\": \"eh9yveSz1qMdJ7mOsO+I+H77jkLr9NpAuEkoJuseXBo=\"\n" +
" }\n" +
" }\n" +
"}";
String config = "{\n"+
" \"liteservers\": [\n"+
" {\n"+
" \"ip\": 1137658550,\n"+
" \"port\": 4924,\n"+
" \"id\": {\n"+
" \"@type\": \"pub.ed25519\",\n"+
" \"key\": \"peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M=\"\n"+
" }\n"+
" }\n"+
" ],\n"+
" \"validator\": {\n"+
" \"@type\": \"validator.config.global\",\n"+
" \"zero_state\": {\n"+
" \"workchain\": -1,\n"+
" \"shard\": -9223372036854775808,\n"+
" \"seqno\": 0,\n"+
" \"root_hash\": \"F6OpKZKqvqeFp6CQmFomXNMfMj2EnaUSOXN+Mh+wVWk=\",\n"+
" \"file_hash\": \"XplPz01CXAps5qeSWUtxcyBfdAo5zVb1N979KLSKD24=\"\n"+
" }\n"+
" }\n"+
"}";
private void appendLog(String log) {
Log.w("XX", log);
@ -84,85 +83,45 @@ public class TonTestJava {
@Test
public void createTestWallet() {
appendLog("start...");
String dir = getContext().getExternalFilesDir(null) + "/";
String[] words = getContext().getString(R.string.wallet_mnemonic_words).split(" ");
JavaClient client = new JavaClient();
Object result = client.send(new TonApi.Init(new TonApi.Options(new TonApi.Config(config, "", false, false), new TonApi.KeyStoreTypeDirectory((dir)))));
if (!(result instanceof TonApi.OptionsInfo)) {
appendLog("failed to set config");
return;
}
appendLog("config set ok");
TonApi.OptionsInfo info = (TonApi.OptionsInfo)result;
TonApi.Key key = (TonApi.Key) client.send(new TonApi.CreateNewKey("local password".getBytes(), "mnemonic password".getBytes(), "".getBytes()));
TonApi.InputKey inputKey = new TonApi.InputKeyRegular(key, "local password".getBytes());
TonApi.AccountAddress walletAddress = (TonApi.AccountAddress)client.send(new TonApi.GetAccountAddress(new TonApi.WalletV3InitialAccountState(key.publicKey, info.configInfo.defaultWalletId), 1));
JavaClient client = new JavaClient();
Object result = client.send(new TonApi.Init(new TonApi.Options(new TonApi.Config(config, "", false, false), getContext().getExternalFilesDir(null) + "/")));
if (!(result instanceof TonApi.Ok)) {
appendLog("failed to set config");
return;
}
appendLog("config set ok");
TonApi.Key key = (TonApi.Key) client.send(new TonApi.CreateNewKey("local password".getBytes(), "mnemonic password".getBytes(), "".getBytes()));
appendLog("got private key");
TonApi.AccountAddress walletAddress = (TonApi.AccountAddress) client.send(new TonApi.TestWalletGetAccountAddress(new TonApi.TestWalletInitialAccountState(key.publicKey)));
appendLog("got account address");
appendLog("sending grams...");
TonApi.TestGiverAccountState testGiverState = (TonApi.TestGiverAccountState) client.send(new TonApi.TestGiverGetAccountState());
result = client.send(new TonApi.TestGiverSendGrams(walletAddress, testGiverState.seqno, 6660000000L, "".getBytes()));
if (!(result instanceof TonApi.Ok)) {
appendLog("failed to send grams");
return;
}
appendLog("grams sent, getting balance");
TonApi.Key giverKey = (TonApi.Key)client.send(new TonApi.ImportKey("local password".getBytes(), "".getBytes(), new TonApi.ExportedKey(words))) ;
TonApi.InputKey giverInputKey = new TonApi.InputKeyRegular(giverKey, "local password".getBytes());
TonApi.AccountAddress giverAddress = (TonApi.AccountAddress)client.send(new TonApi.GetAccountAddress(new TonApi.WalletV3InitialAccountState(giverKey.publicKey, info.configInfo.defaultWalletId), 1));
while (true) {
TonApi.GenericAccountStateUninited accountStateUninited = (TonApi.GenericAccountStateUninited) client.send(new TonApi.GenericGetAccountState(walletAddress));
if (accountStateUninited == null || accountStateUninited.accountState.balance <= 0L) {
try {
Thread.sleep(1000);
} catch (Throwable e) {
appendLog(e.toString());
}
} else {
appendLog(String.format("balance = %d", accountStateUninited.accountState.balance));
break;
appendLog("sending grams...");
TonApi.QueryInfo queryInfo = (TonApi.QueryInfo)client.send(new TonApi.CreateQuery(giverInputKey, giverAddress, 60, new TonApi.ActionMsg(new TonApi.MsgMessage[]{new TonApi.MsgMessage(walletAddress, 6660000000L, new TonApi.MsgDataText("Helo") )}, true)));
result = client.send(new TonApi.QuerySend(queryInfo.id));
if (!(result instanceof TonApi.Ok)) {
appendLog("failed to send grams");
return;
}
appendLog("grams sent, getting balance");
while (true) {
TonApi.FullAccountState state = (TonApi.FullAccountState) client.send(new TonApi.GetAccountState(walletAddress));
if (state.balance <= 0L) {
try {
Thread.sleep(1000);
} catch (Throwable e) {
appendLog(e.toString());
}
} else {
appendLog(String.format("balance = %d", state.balance));
break;
}
TonApi.InputKey inputKey = new TonApi.InputKey(key, "local password".getBytes());
result = client.send(new TonApi.TestWalletInit(inputKey));
if (!(result instanceof TonApi.Ok)) {
return;
}
appendLog("init test wallet ok, getting state...");
while (true) {
TonApi.GenericAccountState accountState = (TonApi.GenericAccountState) client.send(new TonApi.GenericGetAccountState(walletAddress));
if (!(accountState instanceof TonApi.GenericAccountStateTestWallet)) {
try {
Thread.sleep(1000);
} catch (Throwable e) {
appendLog(e.toString());
}
} else {
appendLog("got account state");
break;
}
}
appendLog("sending grams...");
TonApi.GenericAccountStateTestWallet state = (TonApi.GenericAccountStateTestWallet) client.send(new TonApi.GenericGetAccountState(walletAddress));
long balance = state.accountState.balance;
result = client.send(new TonApi.GenericSendGrams(inputKey, walletAddress, walletAddress, 10, 0, true, "hello".getBytes()));
if (!(result instanceof TonApi.Ok)) {
return;
}
appendLog(String.format("grams sent, current balance %d, receving...", balance));
while (true) {
TonApi.GenericAccountStateTestWallet wallet = (TonApi.GenericAccountStateTestWallet) client.send(new TonApi.GenericGetAccountState(walletAddress));
if (wallet == null || wallet.accountState.balance == balance) {
try {
Thread.sleep(1000);
} catch (Throwable e) {
appendLog(e.toString());
}
} else {
appendLog(String.format("grams received, balance = %d", balance));
break;
}
}
appendLog("OK");
}
}
}

View file

@ -1,3 +1,5 @@
<resources>
<string name="app_name">tonlib</string>
<!-- add your wallet mnemonic word. By default it is wallet.v3 with revision=1 -->
<!-- <string name="wallet_mnemonic_words">...</string> -->
</resources>