public void RefKUtxoList(bool bCommited, UTXOPool utxopool) { LogHelper.WriteMethodLog(true); Dictionary <string, List <UTXO> > dicKeysUtxoList = new Dictionary <string, List <UTXO> >(); if (bCommited) { dicKeysUtxoList = this.dicComitkeysUtxoList; } else { dicKeysUtxoList = this.dicUnComitkeysUtxoList; } DirectoryInfo KeyFolder = new DirectoryInfo(AppSettings.XXPKeysFolder); FileInfo[] files = KeyFolder.GetFiles("pubkey?.pem"); if (dicKeysUtxoList.Count == 0) {// 初始化 foreach (FileInfo fi in files) { //this.dickeyValue.Add(fi.Name, 0); if (!this.dicKey2Hash.ContainsKey(fi.Name)) { this.dicKey2Hash.Add(fi.Name, this.pubkey2Hash(fi.FullName)); } List <UTXO> lstKeyUtxo = new List <UTXO>(); dicKeysUtxoList.Add(fi.Name, lstKeyUtxo); } } else {//先清空,赋零, dicKeysUtxoList.Clear(); foreach (FileInfo fi in files) { //this.dickeyValue[fi.Name] = 0; List <UTXO> lstKeyUtxo = new List <UTXO>(); dicKeysUtxoList.Add(fi.Name, lstKeyUtxo); } } // 再根据utxopool重新计算每个key对应的value foreach (UTXO utxo in utxopool.getAllUTXO()) { Output output = utxopool.getTxOutput(utxo); foreach (FileInfo fi in files) { string pukhash = string.Empty; this.dicKey2Hash.TryGetValue(fi.Name, out pukhash); if (output.scriptPubKey.IndexOf(pukhash) >= 0) { //deleted by fdp 181224 key corresponding value calculate from utxo list //if(this.dickeyValue.ContainsKey(fi.Name)) //{ // double dvalue = 0; // this.dickeyValue.TryGetValue(fi.Name, out dvalue); // this.dickeyValue[fi.Name] = dvalue + output.value; //} //else //{ // this.dickeyValue[fi.Name] = output.value; //} List <UTXO> lstTemp = new List <UTXO>(); dicKeysUtxoList.TryGetValue(fi.Name, out lstTemp); lstTemp.Add(utxo); dicKeysUtxoList[fi.Name] = lstTemp; break; } } } LogHelper.WriteMethodLog(false); }
public void RefKUtxoList(bool bCommited, UTXOPool utxopool) { LogHelper.WriteMethodLog(true); Dictionary <string, List <UTXO> > keysUtxoList = new Dictionary <string, List <UTXO> >(); Dictionary <UTXO, Output> dicMsUTXOPool = new Dictionary <UTXO, Output>(); if (bCommited) { keysUtxoList = this.dicComitkeysUtxoList; dicMsUTXOPool = this.dicComitMsUTXOPool; } else { keysUtxoList = this.dicUnComitkeysUtxoList; dicMsUTXOPool = this.dicUnComitMsUTXOPool; } DirectoryInfo KeyFolder = new DirectoryInfo(AppSettings.XXPKeysFolder); FileInfo[] files = KeyFolder.GetFiles("pubkey?.pem"); if (keysUtxoList.Count == 0) {// 初始化 foreach (FileInfo fi in files) { //this.dickeyValue.Add(fi.Name, 0); if (!this.dicKeyHash.ContainsKey(fi.Name)) { this.dicKeyHash.Add(fi.Name, this.pubkey2Hash(fi.FullName)); } List <UTXO> lstKeyUtxo = new List <UTXO>(); keysUtxoList.Add(fi.Name, lstKeyUtxo); } } else {//先清空,赋零, keysUtxoList.Clear(); foreach (FileInfo fi in files) { //this.dickeyValue[fi.Name] = 0; List <UTXO> lstKeyUtxo = new List <UTXO>(); keysUtxoList.Add(fi.Name, lstKeyUtxo); } // Multisign dicMsUTXOPool.Clear(); } // 再根据utxopool重新计算每个key对应的value foreach (UTXO utxo in utxopool.getAllUTXO()) { Output output = utxopool.getTxOutput(utxo); foreach (FileInfo fi in files) { string pukhash = string.Empty; this.dicKeyHash.TryGetValue(fi.Name, out pukhash); if (output.scriptPubKey.IndexOf(pukhash) >= 0) { // MultiSign if (output.scriptPubKey.IndexOf("OP_CHECKMULTISIG") >= 0) { dicMsUTXOPool.Add(utxo, output); } else { List <UTXO> lstTemp = new List <UTXO>(); keysUtxoList.TryGetValue(fi.Name, out lstTemp); lstTemp.Add(utxo); keysUtxoList[fi.Name] = lstTemp; } break; } } } LogHelper.WriteMethodLog(false); }