Beispiel #1
0
        protected override Transaction CreateOutputTransaction()
        {
            var blockReward = new Money(BlockTemplate.CoinbaseValue, MoneyUnit.Satoshi);

            rewardToPool = new Money(BlockTemplate.CoinbaseValue, MoneyUnit.Satoshi);

            var tx = new Transaction();

            blockReward = CreateDashOutputs(tx, blockReward);

            // Distribute funds to configured reward recipients
            var rewardRecipients = new List <RewardRecipient>(poolConfig.RewardRecipients);

            foreach (var recipient in rewardRecipients.Where(x => x.Type != RewardRecipientType.Dev && x.Percentage > 0))
            {
                var recipientAddress = BitcoinUtils.AddressToScript(recipient.Address);
                var recipientReward  = new Money((long)Math.Floor(recipient.Percentage / 100.0m * blockReward.Satoshi));

                rewardToPool -= recipientReward;

                tx.AddOutput(recipientReward, recipientAddress);
            }

            // Finally distribute remaining funds to pool
            tx.Outputs.Insert(0, new TxOut(rewardToPool, poolAddressDestination)
            {
                Value = rewardToPool
            });

            return(tx);
        }
Beispiel #2
0
 public static Out Create(IInOut sourceOut, int divisibility, string shortName)
 {
     return(new Out(
                value: BitcoinUtils.CalculateColoredAssetQuantity(sourceOut.Quantity, divisibility),
                address: sourceOut.Address,
                shortName: shortName));
 }
Beispiel #3
0
            public static string FormatColoredEquivalent(double quantity, AssetViewModel assetViewModel)
            {
                var divisibility = assetViewModel?.Divisibility ?? 0;
                var nameShort    = assetViewModel?.NameShort;

                return($"{nameShort} {BitcoinUtils.CalculateColoredAssetQuantity(quantity, divisibility).ToStringBtcFormat()}");
            }
Beispiel #4
0
        private Money CreateStraksOutputs(Transaction tx, Money reward)
        {
            var treasuryRewardAddress = GetTreasuryRewardAddress();

            if (reward > 0 && treasuryRewardAddress != null)
            {
                var destination    = TreasuryAddressToScriptDestination(treasuryRewardAddress);
                var treasuryReward = new Money(BlockTemplate.CoinbaseTx.TreasuryReward, MoneyUnit.Satoshi);
                tx.AddOutput(treasuryReward, destination);
                reward -= treasuryReward;
            }

            if (ShouldHandleMasternodePayment())
            {
                var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Payee);
                var payeeReward  = BlockTemplate.PayeeAmount.Value;

                reward       -= payeeReward;
                rewardToPool -= payeeReward;

                tx.AddOutput(payeeReward, payeeAddress);
            }

            return(reward);
        }
        public static AssetCoinholdersViewModel Create(AssetViewModel asset,
                                                       IBalanceSummary balanceSummary,
                                                       int?atBlockHeight,
                                                       IDictionary <string, double> addressChanges,
                                                       IEnumerable <IBalanceBlock> blocksWithChanges,
                                                       IBlockHeader currentBlock,
                                                       IBlockHeader atBlockInfo)
        {
            var total            = balanceSummary.AddressSummaries.Sum(p => p.Balance);
            var addressSummaries = balanceSummary.AddressSummaries
                                   .Select(
                p =>
                BalanceAddressSummary.Create(p, total, asset.Divisibility,
                                             addressChanges.ContainsKey(p.Address) ? addressChanges[p.Address] : 0))
                                   .Where(p => p.Balance != 0 || p.ChangeAtBlock != 0)
                                   .OrderByDescending(p => p.Balance)
                                   .ToList();

            return(new AssetCoinholdersViewModel
            {
                Asset = asset,
                AddressSummaries = addressSummaries,
                Total = BitcoinUtils.CalculateColoredAssetQuantity(total, asset.Divisibility),
                Pagination = BlockPagination.Create(blocksWithChanges.Select(p => p.Height), atBlockHeight ?? currentBlock?.Height, currentBlock),
                CoinholdersCount = addressSummaries.Count,
                AtBlockDateTime = (atBlockInfo ?? currentBlock)?.Time.ToUniversalTime()
            });
        }
Beispiel #6
0
 public static In Create(IInOut sourceIn, int divisibility, IEnumerable <IInOut> outs, string shortName)
 {
     return(new In(
                value: BitcoinUtils.CalculateColoredAssetQuantity(sourceIn.Quantity * (-1), divisibility),
                address: sourceIn.Address,
                previousTransactionId: sourceIn.TransactionId,
                shortName: shortName));
 }
Beispiel #7
0
 public static IEnumerable <In> Create(IEnumerable <IInOut> ins, AssetDictionary assetDictionary)
 {
     return(ins.Where(p => p.Value != 0)
            .Select(p => new In(
                        value: BitcoinUtils.SatoshiToBtc(p.Value * (-1)),
                        coloredEquivalentAsset: assetDictionary.Get(p.AssetId),
                        coloredEquivalentQuantityQuantity: p.Quantity,
                        address: p.Address,
                        previousTransactionId: p.TransactionId)));
 }
            private static XlsxTransactionInputOutput Create(BitcoinAddress address,
                                                             ICoin source,
                                                             BlockInformation block,
                                                             uint256 transactionHash,
                                                             IDictionary <string, IAssetDefinition> assetDictionary,
                                                             int index,
                                                             Network network,
                                                             CoinType coinType)
            {
                string coloredAddress = null;

                try
                {
                    coloredAddress = address?.ToColoredAddress()?.ToWif();
                }
                catch
                {
                }
                var result = new XlsxTransactionInputOutput
                {
                    Address         = address?.ToString(),
                    ColoredAddress  = coloredAddress,
                    TransactionHash = transactionHash.ToString(),
                    Index           = index,
                    CoinType        = coinType,
                };

                if (block != null)
                {
                    result.BlockDate = block.BlockTime.UtcDateTime;
                    result.BlockHash = block.BlockId.ToString();
                }
                if (source is ColoredCoin colored)
                {
                    var assetId = colored.AssetId.GetWif(network).ToString();

                    var asset        = assetDictionary.ContainsKey(assetId) ? assetDictionary[assetId] : null;
                    var divisibility = asset?.Divisibility ?? 0;

                    result.ColouredAssetValue = BitcoinUtils.CalculateColoredAssetQuantity(colored.Amount.Quantity, divisibility);
                    result.BtcValue           = BitcoinUtils.SatoshiToBtc(colored.Bearer.Amount.Satoshi);

                    result.ColouredAssetName = asset != null ? asset.Name : assetId;
                }

                if (source is Coin uncolored)
                {
                    result.BtcValue = BitcoinUtils.SatoshiToBtc(uncolored.Amount.Satoshi);
                }

                return(result);
            }
            public static BalanceAddressSummary Create(IBalanceAddressSummary summary, double total, int divisibility, double changesAtBlock)
            {
                var coloredTotal             = BitcoinUtils.CalculateColoredAssetQuantity(total, divisibility);
                var coloredSummaryPerAddress = BitcoinUtils.CalculateColoredAssetQuantity(summary.Balance, divisibility);
                var coloredChangeAtBlock     = BitcoinUtils.CalculateColoredAssetQuantity(changesAtBlock,
                                                                                          divisibility);

                return(new BalanceAddressSummary
                {
                    Address = summary.Address,
                    Balance = coloredSummaryPerAddress,
                    BalancePercenage = Math.Round((coloredSummaryPerAddress / coloredTotal) * 100, 2),
                    ChangeAtBlock = coloredChangeAtBlock
                });
            }
Beispiel #10
0
        private Money CreateDashOutputs(Transaction tx, Money reward)
        {
            if (BlockTemplate.Masternode != null || BlockTemplate.SuperBlocks != null)
            {
                if (!string.IsNullOrEmpty(BlockTemplate.Masternode.Payee))
                {
                    var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Masternode.Payee);
                    var payeeReward  = BlockTemplate.Masternode.Amount;

                    reward       -= payeeReward;
                    rewardToPool -= payeeReward;

                    tx.AddOutput(payeeReward, payeeAddress);
                }

                else if (BlockTemplate.SuperBlocks.Length > 0)
                {
                    foreach (var superBlock in BlockTemplate.SuperBlocks)
                    {
                        var payeeAddress = BitcoinUtils.AddressToDestination(superBlock.Payee);
                        var payeeReward  = superBlock.Amount;

                        // don't substract superblock payment from block reward
                        // superblocks still have the same block reward for miners
                        // and additional superblock outputs

                        /*reward -= payeeReward;
                         * rewardToPool -= payeeReward;*/

                        tx.AddOutput(payeeReward, payeeAddress);
                    }
                }
            }

            if (!string.IsNullOrEmpty(BlockTemplate.Payee))
            {
                var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Payee);
                var payeeReward  = BlockTemplate.PayeeAmount ?? (reward / 2);

                reward       -= payeeReward;
                rewardToPool -= payeeReward;

                tx.AddOutput(payeeReward, payeeAddress);
            }

            return(reward);
        }
            private static XlsxTransactionInputOutput CreateFees(Money fees, BlockInformation block, uint256 transactionHash, int index)
            {
                var result = new XlsxTransactionInputOutput
                {
                    TransactionHash = transactionHash.ToString(),
                    Index           = index,
                    CoinType        = CoinType.Fees,
                    BtcValue        = BitcoinUtils.SatoshiToBtc(fees.Satoshi)
                };

                if (block != null)
                {
                    result.BlockDate = block.BlockTime.UtcDateTime;
                    result.BlockHash = block.BlockId.ToString();
                }

                return(result);
            }
Beispiel #12
0
        private Money CreateDashOutputs(Transaction tx, Money reward)
        {
            if (BlockTemplate.Masternode != null && BlockTemplate.SuperBlocks != null)
            {
                if (!string.IsNullOrEmpty(BlockTemplate.Masternode.Payee))
                {
                    var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Masternode.Payee);
                    var payeeReward  = BlockTemplate.Masternode.Amount;

                    reward       -= payeeReward;
                    rewardToPool -= payeeReward;

                    tx.AddOutput(payeeReward, payeeAddress);
                }

                else if (BlockTemplate.SuperBlocks.Length > 0)
                {
                    foreach (var superBlock in BlockTemplate.SuperBlocks)
                    {
                        var payeeAddress = BitcoinUtils.AddressToDestination(superBlock.Payee);
                        var payeeReward  = superBlock.Amount;

                        reward       -= payeeReward;
                        rewardToPool -= payeeReward;

                        tx.AddOutput(payeeReward, payeeAddress);
                    }
                }
            }

            if (!string.IsNullOrEmpty(BlockTemplate.Payee))
            {
                var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Payee);
                var payeeReward  = BlockTemplate.PayeeAmount ?? (reward / 5);

                reward       -= payeeReward;
                rewardToPool -= payeeReward;

                tx.AddOutput(payeeReward, payeeAddress);
            }

            return(reward);
        }
Beispiel #13
0
        protected override Transaction CreateOutputTransaction()
        {
            var blockReward = new Money(BlockTemplate.CoinbaseValue, MoneyUnit.Satoshi);

            rewardToPool = new Money(BlockTemplate.CoinbaseValue, MoneyUnit.Satoshi);

            var tx = new Transaction();

            blockReward = CreateDashOutputs(tx, blockReward);

            // Distribute funds to configured reward recipients
            var rewardRecipients = new List <RewardRecipient>(poolConfig.RewardRecipients);

            // Tiny donation to MiningCore developer(s)
            if (!clusterConfig.DisableDevDonation &&
                networkType == BitcoinNetworkType.Main &&
                KnownAddresses.DevFeeAddresses.ContainsKey(poolConfig.Coin.Type))
            {
                rewardRecipients.Add(new RewardRecipient
                {
                    Address    = KnownAddresses.DevFeeAddresses[poolConfig.Coin.Type],
                    Percentage = 0.2m
                });
            }

            foreach (var recipient in rewardRecipients.Where(x => x.Percentage > 0))
            {
                var recipientAddress = BitcoinUtils.AddressToScript(recipient.Address);
                var recipientReward  = new Money((long)Math.Floor(recipient.Percentage / 100.0m * blockReward.Satoshi));

                rewardToPool -= recipientReward;

                tx.AddOutput(recipientReward, recipientAddress);
            }

            // Finally distribute remaining funds to pool
            tx.Outputs.Insert(0, new TxOut(rewardToPool, poolAddressDestination)
            {
                Value = rewardToPool
            });

            return(tx);
        }
Beispiel #14
0
        private Money CreateStraksOutputs(Transaction tx, Money reward)
        {
            var treasuryRewardAddress = GetTreasuryRewardAddress();

            if (reward > 0 && treasuryRewardAddress != null)
            {
                var destination    = TreasuryAddressToScriptDestination(treasuryRewardAddress);
                var treasuryReward = new Money(BlockTemplate.CoinbaseTx.TreasuryReward, MoneyUnit.Satoshi);
                tx.AddOutput(treasuryReward, destination);
                reward -= treasuryReward;
            }

            if (!string.IsNullOrEmpty(BlockTemplate.Masternode?.Payee))
            {
                var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Masternode.Payee);
                var payeeReward  = BlockTemplate.Masternode.Amount;

                reward       -= payeeReward;
                rewardToPool -= payeeReward;

                tx.AddOutput(payeeReward, payeeAddress);
            }

            if (!string.IsNullOrEmpty(BlockTemplate.Payee))
            {
                var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.Payee);
                var payeeReward  = BlockTemplate.PayeeAmount ?? reward / 5;

                reward       -= payeeReward;
                rewardToPool -= payeeReward;

                tx.AddOutput(payeeReward, payeeAddress);
            }

            return(reward);
        }
Beispiel #15
0
            public static BitcoinAsset Create(double fees,
                                              bool isCoinBase,
                                              IEnumerable <IInOut> ninjaIn,
                                              IEnumerable <IInOut> ninjaOuts,
                                              AssetDictionary assetDictionary)
            {
                var feesBtc = BitcoinUtils.SatoshiToBtc(fees);

                IEnumerable <AssetInOutBase> ins  = In.Create(ninjaIn, assetDictionary).ToList();
                IEnumerable <AssetInOutBase> outs = Out.Create(ninjaOuts, assetDictionary).ToList();

                IEnumerable <AssetInOutBase> insWithoutChange  = ins.Select(p => p.Clone <In>()).ToList();
                IEnumerable <AssetInOutBase> outsWithoutChange = outs.Select(p => p.Clone <Out>()).ToList();

                decimal coloredEquityIns = 0;

                ins = AssetHelper.RemoveColored(ins, out coloredEquityIns).ToList();

                decimal coloredEquityOuts = 0;

                outs = AssetHelper.RemoveColored(outs, out coloredEquityOuts).ToList();


                bool showChange = false;

                AssetHelper.CalculateWithReturnedChange(ins, outs, ref showChange);

                if (ins.All(p => p.Value == 0) && outs.All(p => p.Value == 0))
                {
                    ins  = ins.Take(1).ToList();
                    outs = outs.Take(1).ToList();
                }
                else
                {
                    ins  = ins.Where(p => p.Value != 0).ToList();
                    outs = outs.Where(p => p.Value != 0).ToList();
                }

                var coloredEquivalentValue = coloredEquityOuts + coloredEquityIns;
                var total = outs.Sum(p => Convert.ToDecimal(p.Value)) + Convert.ToDecimal(feesBtc);

                if (coloredEquivalentValue > 0)
                {
                    total += Convert.ToDecimal(coloredEquivalentValue);
                }

                var totalWithoutChange = outsWithoutChange.Sum(p => Convert.ToDecimal(p.Value)) + Convert.ToDecimal(feesBtc);

                return(new BitcoinAsset
                {
                    Fees = feesBtc,
                    IsCoinBase = isCoinBase,
                    AggregatedIns = AssetHelper.GroupByAddress(ins),
                    AggregatedOuts = AssetHelper.GroupByAddress(outs),
                    AggregatedInsWithoutChange = AssetHelper.GroupByAddress(insWithoutChange),
                    AggregatedOutsWithoutChange = AssetHelper.GroupByAddress(outsWithoutChange),
                    Total = Convert.ToDouble(total),
                    TotalWithoutChange = Convert.ToDouble(totalWithoutChange),
                    ShowWithoutChange = showChange || coloredEquityOuts != 0 || coloredEquityIns != 0,
                    ColoredEquivalentValue = Convert.ToDouble(coloredEquivalentValue)
                });
            }
Beispiel #16
0
 public static Out Create(IInOut @out, AssetViewModel coloredEquivalentAsset)
 {
     return(new Out(value: BitcoinUtils.SatoshiToBtc(@out.Value), address: @out.Address, coloredEquivalentAsset: coloredEquivalentAsset, coloredEquivalentQuantity: @out.Quantity));
 }
 protected virtual IDestination AddressToDestination(string address)
 {
     return(BitcoinUtils.AddressToDestination(address));
 }
        public static IDestination ZeroNodeAddressToScriptDestination(string nodeaddress)
        {
            var zeronodeaddressresult = BitcoinUtils.AddressToDestination(nodeaddress, ZcashNetworks.Instance.Mainnet);

            return(zeronodeaddressresult);
        }