public Dictionary <UTXO, keyPair> GetUtxoDic(string key) { LogHelper.WriteMethodLog(true); Dictionary <UTXO, keyPair> dicUtxoPrikey = new Dictionary <UTXO, keyPair>(); if (key == ConstHelper.BC_All) { foreach (var item in this.dicComitkeysUtxoList) { keyPair kpair = new keyPair(); kpair.PubKeyNmae = item.Key; kpair.PriKeyNmae = this.PkName2PriKeyName(item.Key); foreach (UTXO utxo in item.Value) { dicUtxoPrikey.Add(utxo, kpair); } } } else { List <UTXO> listUtxo = new List <UTXO>(); this.dicComitkeysUtxoList.TryGetValue(key, out listUtxo); keyPair kpair = new keyPair(); kpair.PubKeyNmae = key; kpair.PriKeyNmae = this.PkName2PriKeyName(key); foreach (UTXO utxo in listUtxo) { dicUtxoPrikey.Add(utxo, kpair); } } LogHelper.WriteMethodLog(false); return(dicUtxoPrikey); }
public int GetdicPkHKeypair(ref Dictionary <string, keyPair> dicPkHKeypair) { foreach (var item in this.dicKeyHash) { keyPair kp = new keyPair(item.Key, this.PkName2PriKeyName(item.Key)); dicPkHKeypair.Add(item.Value, kp); } return(0); }
//暂时不用 public bool SignPrimitiveTx(Dictionary <UTXO, keyPair> dicUTXO, ref Transaction PrimitiveTx) { int iInputCount = PrimitiveTx.listInputs.Count; for (int i = 0; i < iInputCount; i++) { if (PrimitiveTx.listInputs[i].ScriptSig == null) { UTXO utxo = new UTXO(PrimitiveTx.listInputs[i].PreTxHash, (uint)PrimitiveTx.listInputs[i].OutputIndex); if (dicUTXO.ContainsKey(utxo)) { keyPair kp = new keyPair(); dicUTXO.TryGetValue(utxo, out kp); string strPriKPath = Path.Combine(AppSettings.XXPKeysFolder, kp.PriKeyNmae); string strPubKPath = Path.Combine(AppSettings.XXPKeysFolder, kp.PubKeyNmae); string strPubValue = FileIOHelper.ReadFromText(strPubKPath); PrimitiveTx.signTrans(strPriKPath, strPubValue, i); } } } return(true); }
public string SignPrimitiveTx(Dictionary <string, keyPair> KeyHashKeypair, ref Transaction PrimitiveTx) { LogHelper.WriteMethodLog(true); bool bHaveSigned = true; foreach (var item in PrimitiveTx.listInputs) { // 只要input有一个没有签名list,就认为没有签名 if (item.lstScriptSig == null) { bHaveSigned = false; break; } else { // 有签名list后 判断自己是否已经签名, bHaveSigned = false; foreach (var item1 in item.lstScriptSig) { string strKeyHash = Cryptor.SHA256(item1.PubKey, item1.PubKey.Length); if (KeyHashKeypair.ContainsKey(strKeyHash)) { bHaveSigned = true; } } } } if (bHaveSigned) { return("Current Primitive Tx'inputs Have signed"); } int iInputCount = PrimitiveTx.listInputs.Count; for (int i = 0; i < iInputCount; i++) { UTXO utxo = new UTXO(PrimitiveTx.listInputs[i].PreTxHash, (uint)PrimitiveTx.listInputs[i].OutputIndex); if (!CommitedUtxoPool.contains(utxo)) { LogHelper.WriteInfoLog(" utxoPool not contain utxo:"); return("Invalid utxo"); //check (1),utox 包含该交易返回false } Output output = CommitedUtxoPool.getTxOutput(utxo); List <string> lstScript = output.scriptPubKey.Split(' ').ToList <string>(); var lstPKHash = (from x in lstScript where x.Substring(0, 3) != "OP_" select x).ToList(); foreach (var item in lstPKHash) { if (KeyHashKeypair.ContainsKey(item)) { keyPair kp = new keyPair(); KeyHashKeypair.TryGetValue(item, out kp); string strPriKPath = Path.Combine(AppSettings.XXPKeysFolder, kp.PriKeyNmae); string strPubKPath = Path.Combine(AppSettings.XXPKeysFolder, kp.PubKeyNmae); string strPubValue = FileIOHelper.ReadFromText(strPubKPath); PrimitiveTx.MultiSignTrans(strPriKPath, strPubValue, i); } } } LogHelper.WriteMethodLog(false); return(ConstHelper.BC_OK); }