예제 #1
0
        public Transaction Build()
        {
            foreach (Operation operation in _operations)
            {
                _transactionBuilder.AddOperation(operation);
            }
            Transaction transaction = _transactionBuilder.Build();


            transaction.Sign(_baseKeyPair);

            if (_channelKeyPair != null)
            {
                transaction.Sign(_channelKeyPair);
            }

            return(transaction);
        }
예제 #2
0
        private async Task <SubmitTransactionResponse> GetCreateAccountTransaction(string destinationAddress)
        {
            KeyPair         destinationKeyPair = KeyPair.FromAccountId(destinationAddress);
            AccountResponse sourceAccount      = null;
            AccountResponse destinationAccount = null;

            try
            {
                sourceAccount = await GetAccount(_keyPair).ConfigureAwait(false);

                destinationAccount = await GetAccount(destinationKeyPair).ConfigureAwait(false);
            }
            catch (Exception ex) {}


            if (sourceAccount == null)
            {
                throw new Exception("Source account doesn't exists");
            }

            if (destinationAccount != null)
            {
                throw new Exception("Account already exists");
            }


            CreateAccountOperation.Builder createAccountOperationBuilder = new CreateAccountOperation.Builder(destinationKeyPair, "0");
            createAccountOperationBuilder.SetSourceAccount(_keyPair);

            Transaction.Builder transactionBuilder = new Transaction.Builder(new Account(_keyPair, sourceAccount.SequenceNumber));
            transactionBuilder.AddOperation(createAccountOperationBuilder.Build());
            transactionBuilder.AddMemo(new MemoText($"1-{_app_id}"));

            Transaction transaction = transactionBuilder.Build();

            transaction.Sign(_keyPair);

            return(await _server.SubmitTransaction(transaction).ConfigureAwait(false));
        }
예제 #3
0
        public static async void Payout(decimal InflationAmount)
        {
            Network.UseTestNetwork();

            //Get the number of votes you have
            var votes = GetTotalVotes();
            //Get the accounts that voted for you and what you owe them
            var accounts = GetVoterAccounts(InflationAmount, votes);

            decimal sum        = 0;
            decimal percentage = 0;

            KeyPair PoolSource = KeyPair.FromSecretSeed(Configuration["INFLATION_POOL_SECRET"]);
            //KeyPair PoolSource = KeyPair.FromSecretSeed(Environment.GetEnvironmentVariable("INFLATION_POOL_SECRET"));

            AccountResponse sourceAccount = await server.Accounts.Account(PoolSource);

            var     sequenceNumber = sourceAccount.SequenceNumber;
            Account PoolAccount    = new Account(PoolSource, sequenceNumber);

            Transaction.Builder BatchTransaction = new Transaction.Builder(PoolAccount);
            List <Transaction>  Transactions     = new List <Transaction>();

            int batch = 0;

            foreach (var account in accounts)
            {
                //we can only have 100 operations per transaction, this means we need to split up our payouts every 100 people

                //Rounding down because we're greedy pigs that want to keep every last stroop
                var payout        = RoundDown(account.Payout, 7);
                var payoutPercent = RoundDown(account.Percentage, 7);
                //Create the payment operation, we are pulling the 100 stroop fee out of the receipients end.
                //The lowest amount a voting account could possibly contain is 1 lumen
                //1 lumen will earn 0.0001923 lumens per week, so we don't have to worry about the fee being larger than a potential earning!
                var operation = new PaymentOperation.Builder(KeyPair.FromAccountId(account.AccountId), new AssetTypeNative(), (payout - .0000100m).ToString())
                                .SetSourceAccount(PoolSource)
                                .Build();
                BatchTransaction.AddOperation(operation);

                Console.WriteLine($" Account: {account.AccountId} Earned: {payout}XLM (%{payoutPercent})");

                //totalling up our payout/percentages
                sum        += payout;
                percentage += payoutPercent;

                if (batch == 99 || account.Equals(accounts.LastOrDefault()))
                {
                    //This batch is full! we sign it with a memo and our private key and add it to the list of to be processed outgoing transactions.
                    var t = BatchTransaction.AddMemo(Memo.Text($"Sample Memo")).Build();
                    t.Sign(PoolSource);
                    Transactions.Add(t);
                    BatchTransaction = new Transaction.Builder(PoolAccount);
                }
                //Reset the batch
                batch = batch == 99 ? 0 : ++batch;
            }

            Console.WriteLine("Submitting batches to the stellar network...");
            foreach (var t in Transactions)
            {
                //Submit each transaction to the network
                Console.WriteLine($"Submitting batch: {Transactions.IndexOf(t) + 1}...");
                var response = await server.SubmitTransaction(t);

                Console.WriteLine($"Batch submitted.");
                //Console.WriteLine($"Envelope XDR is:");
                //Console.WriteLine($"{response.EnvelopeXdr}");
            }

            Console.WriteLine($"Payed out: {sum} (%{percentage})");
            //Exists the console app after it has found inflation and payed out.
            Console.WriteLine("Exiting");
            Environment.Exit(0);
        }