Esempio n. 1
0
        private static async Task RunDebotAsync()
        {
            using var client = TonClientNodeSe.Create(new SerilogLogger());

            var targetAbi = TonUtil.LoadAbi($"contracts/{DebotTarget}.abi.json");
            var targetTvc = TonUtil.LoadTvc($"contracts/{DebotTarget}.tvc");
            var debotAbi  = TonUtil.LoadAbi($"contracts/{Debot}.abi.json");
            var debotTvc  = TonUtil.LoadTvc($"contracts/{Debot}.tvc");

            var keys = await client.Crypto.GenerateRandomSignKeysAsync();

            var targetAddr = await client.DeployWithGiverAsync(new ParamsOfEncodeMessage
            {
                Abi       = targetAbi,
                DeploySet = new DeploySet
                {
                    Tvc = targetTvc
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                },
                CallSet = new CallSet
                {
                    FunctionName = "constructor"
                }
            });

            Log.Information("Target addr: {Addr}", targetAddr);

            var debotAddr = await client.DeployWithGiverAsync(new ParamsOfEncodeMessage
            {
                Abi       = debotAbi,
                DeploySet = new DeploySet
                {
                    Tvc = debotTvc
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                },
                CallSet = new CallSet
                {
                    FunctionName = "constructor",
                    Input        = new
                    {
                        debotAbi  = JsonConvert.SerializeObject((debotAbi as Abi.Contract).Value).ToHexString(),
                        targetAbi = JsonConvert.SerializeObject((targetAbi as Abi.Contract).Value).ToHexString(),
                        targetAddr
                    }.ToJson()
                }
            });

            Log.Information("Debot addr: {Addr}", debotAddr);

            var debot = new DemoDebot(client, debotAddr, keys);
            await debot.StartAsync();
        }
Esempio n. 2
0
        private Func <ParamsOfAppDebotBrowser, Task <ResultOfAppDebotBrowser> > GetCallback()
        {
            return(async(p) =>
            {
                switch (p)
                {
                case ParamsOfAppDebotBrowser.Log log:
                    Console.WriteLine(log.Msg);
                    return null;

                case ParamsOfAppDebotBrowser.Switch sw:
                    if (sw.ContextId == 255)     // STATE_EXIT
                    {
                        _finished = true;
                    }
                    _actions = new List <DebotAction>();
                    return null;

                case ParamsOfAppDebotBrowser.SwitchCompleted sw:
                    return null;

                case ParamsOfAppDebotBrowser.ShowAction show:
                    var action = show.Action;
                    _actions.Add(action);
                    Console.WriteLine($"{_actions.Count}: {action.Description}");
                    return null;

                case ParamsOfAppDebotBrowser.Input input:
                    Console.Write($"{input.Prompt}: ");
                    var value = Console.ReadLine();
                    return new ResultOfAppDebotBrowser.Input
                    {
                        Value = value
                    };

                case ParamsOfAppDebotBrowser.GetSigningBox s:
                    var signingBox = await _client.Crypto.GetSigningBoxAsync(_keys);

                    return new ResultOfAppDebotBrowser.GetSigningBox
                    {
                        SigningBox = signingBox.Handle
                    };

                case ParamsOfAppDebotBrowser.InvokeDebot invoke:
                    var debot = new DemoDebot(_client, _address, _keys);
                    await debot.FetchAsync(invoke.Action);

                    return new ResultOfAppDebotBrowser.InvokeDebot();

                default:
                    throw new NotSupportedException($"Parameter type {p.GetType()} is not supported");
                }
            });
        }