Esempio n. 1
0
        public static async Task <bool> CreateNewAccount(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);
            ulong           id  = msg.Author.Id;
            bool            ret = false;

            //todo: should probably attempt to fetch a wallet with a tag matching the user id before making one
            await Sender.PrivateReply(msg, "You don't have an account. Hold while I create one for you.");

            //create an account
            await new CreateAccount(new CreateAccountRequestData
            {
                Label = id.ToString()
            },
                                    (CreateAccountResponseData r) =>
            {
                Sender.PrivateReply(msg, $"You now have a new account. You can make a deposit to\r\n`{r.Address}`").Wait();
                cfg.UserWalletCache.Add(id, new Tuple <uint, string>(r.Index, r.Address));
                ret = true;
            },
                                    (RequestError e) =>
            {
                Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
            },
                                    cfg.WalletHost, cfg.UserWalletPort).RunAsync();

            return(ret);
        }
Esempio n. 2
0
        public static async Task <string> CreateNewAccount(SocketUser user)
        {
            FusionBotConfig cfg  = ((FusionBotConfig)Globals.Bot.Config);
            string          addr = string.Empty;

            if (cfg.UserWalletCache.ContainsKey(user.Id))
            {
                return(cfg.UserWalletCache[user.Id] == null ? string.Empty : cfg.UserWalletCache[user.Id].Item2);
            }

            cfg.UserWalletCache.Add(user.Id, null);

            await new CreateAccount(new CreateAccountRequestData
            {
                Label = user.Id.ToString()
            },
                                    (CreateAccountResponseData r) =>
            {
                Sender.SendPrivateMessage(user, $"You now have a new account. You can make a deposit to\r\n`{r.Address}`").Wait();
                cfg.UserWalletCache[user.Id] = new Tuple <uint, string>(r.Index, r.Address);
                addr = r.Address;
            },
                                    null, cfg.WalletHost, cfg.UserWalletPort).RunAsync();

            return(addr);
        }
Esempio n. 3
0
        public static async Task <RequestError> PayUser(double amount, ulong sender, ulong recipient)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            RequestError error = null;

            await new Transfer(new TransferRequestData
            {
                AccountIndex = cfg.UserWalletCache[sender].Item1,
                Destinations = new List <TransferDestination> {
                    new TransferDestination {
                        Amount  = amount.ToAtomicUnits(),
                        Address = cfg.UserWalletCache[recipient].Item2
                    }
                }
            }, null, (RequestError e) =>
            {
                error = e;
            },
                               cfg.WalletHost, cfg.UserWalletPort).RunAsync();

            return(error);
        }