예제 #1
0
        /// <summary>
        /// 挖矿产出
        /// </summary>
        /// <returns></returns>
        private TransactionOutput MiningOutput(uint blockIndex, Wallet wallet)
        {
            miningOutput = new MiningOutputLedger
            {
                AssetId    = Blockchain.GoverningToken.Hash,
                Value      = MiningSubsidy.GetMiningSubsidy(blockIndex),
                ScriptHash = MiningParams.PoSAddress.Length > 0 ? MiningParams.PoSAddress[blockIndex % (uint)MiningParams.PoSAddress.Length].ToScriptHash() : wallet.GetChangeAddress()
            };

            return(new TransactionOutput
            {
                AssetId = miningOutput.AssetId,
                Value = miningOutput.Value,
                ScriptHash = miningOutput.ScriptHash
            });
        }
예제 #2
0
        private void AddMiningTransaction(Wallet wallet, uint blockIndex, List <TransactionOutput> outputs, List <TransactionAttribute> attributes)
        {
            MiningOutput miningOutput = new MiningOutput
            {
                AssetId = Blockchain.GoverningToken.Hash,
                Value   = MiningSubsidy.GetMiningSubsidy(blockIndex),
                //ScriptHash = MiningParams.PoSAddressOfMainNet.Length > 0 ? MiningParams.PoSAddressOfMainNet[blockIndex % (uint)MiningParams.PoSAddressOfMainNet.Length].ToScriptHash() : wallet.GetChangeAddress()
                ScriptHash = MiningParams.PoSAddressOfTestNet.Length > 0 ? MiningParams.PoSAddressOfTestNet[blockIndex % (uint)MiningParams.PoSAddressOfTestNet.Length].ToScriptHash() : wallet.GetChangeAddress()
            };

            TransactionOutput output = new TransactionOutput
            {
                AssetId    = miningOutput.AssetId,
                Value      = miningOutput.Value,
                ScriptHash = miningOutput.ScriptHash
            };

            byte[] signatureOfMining = null;

            //Signature
            WalletAccount account = wallet.GetAccount(wallet.GetChangeAddress());

            if (account?.HasKey == true)
            {
                byte[]  hashDataOfMining = miningOutput.GetHashData();
                KeyPair key = account.GetKey();
                signatureOfMining = Crypto.Default.Sign(hashDataOfMining, key.PrivateKey, key.PublicKey.EncodePoint(false).Skip(1).ToArray());
            }

            if (signatureOfMining != null)
            {
                attributes.Add(new TransactionAttribute
                {
                    Usage = TransactionAttributeUsage.MinerSignature,
                    Data  = signatureOfMining
                });

                outputs.Add(output);
            }
        }