private void button3_Click(object sender, EventArgs e) { ContractParametersContext context; JObject json1 = JObject.Parse(textBox2.Text); if (json1.ContainsProperty("hex")) { context = ContractParametersContext.FromJson(json1); } else { ContractTransaction tx1 = JsonToRequest(json1); ContractTransaction tx2 = JsonToRequest(JObject.Parse(textBox3.Text)); context = new ContractParametersContext(new ContractTransaction { Attributes = new TransactionAttribute[0], Inputs = tx1.Inputs.Concat(tx2.Inputs).ToArray(), Outputs = tx1.Outputs.Concat(tx2.Outputs).ToArray() }); } Program.CurrentWallet.Sign(context); if (context.Completed) { context.Verifiable.Scripts = context.GetScripts(); ContractTransaction tx = (ContractTransaction)context.Verifiable; Program.CurrentWallet.SaveTransaction(tx); Program.LocalNode.Relay(tx); InformationBox.Show(tx.Hash.ToString(), Strings.TradeSuccessMessage, Strings.TradeSuccessCaption); } else { InformationBox.Show(context.ToString(), Strings.TradeNeedSignatureMessage, Strings.TradeNeedSignatureCaption); } }
private void button2_Click(object sender, EventArgs e) { IEnumerable <CoinReference> inputs; IEnumerable <TransactionOutput> outputs; JObject json = JObject.Parse(textBox2.Text); if (json.ContainsProperty("hex")) { ContractTransaction tx_mine = JsonToRequest(JObject.Parse(textBox3.Text)); ContractTransaction tx_others = (ContractTransaction)ContractParametersContext.FromJson(json).Verifiable; inputs = tx_others.Inputs.Except(tx_mine.Inputs); List <TransactionOutput> outputs_others = new List <TransactionOutput>(tx_others.Outputs); foreach (TransactionOutput output_mine in tx_mine.Outputs) { TransactionOutput output_others = outputs_others.FirstOrDefault(p => p.AssetId == output_mine.AssetId && p.Value == output_mine.Value && p.ScriptHash == output_mine.ScriptHash); if (output_others == null) { MessageBox.Show(Strings.TradeFailedFakeDataMessage, Strings.Failed, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } outputs_others.Remove(output_others); } outputs = outputs_others; } else { ContractTransaction tx_others = JsonToRequest(json); inputs = tx_others.Inputs; outputs = tx_others.Outputs; } try { if (inputs.Select(p => Blockchain.Singleton.GetTransaction(p.PrevHash).Outputs[p.PrevIndex].ScriptHash).Distinct().Any(p => Program.CurrentWallet.Contains(p))) { MessageBox.Show(Strings.TradeFailedInvalidDataMessage, Strings.Failed, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch { MessageBox.Show(Strings.TradeFailedNoSyncMessage, Strings.Failed, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } outputs = outputs.Where(p => Program.CurrentWallet.Contains(p.ScriptHash)); using (TradeVerificationDialog dialog = new TradeVerificationDialog(outputs)) { button3.Enabled = dialog.ShowDialog() == DialogResult.OK; } }
private void button2_Click(object sender, EventArgs e) { IEnumerable <CoinReference> inputs; IEnumerable <TransactionOutput> outputs; JObject json = JObject.Parse(textBox2.Text); if (json.ContainsProperty("hex")) { ContractTransaction tx_mine = JsonToRequest(JObject.Parse(textBox3.Text)); ContractTransaction tx_others = (ContractTransaction)ContractParametersContext.FromJson(json).Verifiable; inputs = tx_others.Inputs.Except(tx_mine.Inputs); List <TransactionOutput> outputs_others = new List <TransactionOutput>(tx_others.Outputs); foreach (TransactionOutput output_mine in tx_mine.Outputs) { TransactionOutput output_others = outputs_others.FirstOrDefault(p => p.AssetId == output_mine.AssetId && p.Value == output_mine.Value && p.ScriptHash == output_mine.ScriptHash); if (output_others == null) { MessageBox.Show(LanHelper.LocalLanguage("Validation failed, the counterparty falsified the transaction content!"), LanHelper.LocalLanguage("Failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } outputs_others.Remove(output_others); } outputs = outputs_others; } else { ContractTransaction tx_others = JsonToRequest(json); inputs = tx_others.Inputs; outputs = tx_others.Outputs; } try { if (inputs.Select(p => Blockchain.Singleton.GetTransaction(p.PrevHash).Outputs[p.PrevIndex].ScriptHash).Distinct().Any(p => Program.CurrentWallet.Contains(p))) { MessageBox.Show(LanHelper.LocalLanguage("Validation failed, the counterparty generated illegal transaction content!"), LanHelper.LocalLanguage("Failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch { MessageBox.Show(LanHelper.LocalLanguage("Validation failed, invalid transaction or unsynchronized blockchain, please try again when synchronized!"), LanHelper.LocalLanguage("Failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } outputs = outputs.Where(p => Program.CurrentWallet.Contains(p.ScriptHash)); using (TradeVerificationDialog dialog = new TradeVerificationDialog(outputs)) { button3.Enabled = dialog.ShowDialog() == DialogResult.OK; } }
/// <summary> /// append signature for multi address tx /// </summary> /// <param name="signContext"></param> /// <returns></returns> public async Task <object> AppendSignature(string signContext) { if (CurrentWallet == null) { return(Error(ErrorCode.WalletNotOpen)); } ContractParametersContext context; try { context = ContractParametersContext.FromJson(signContext.DeserializeJson <JObject>(), Helpers.GetDefaultSnapshot()); } catch (Exception e) { return(Error(ErrorCode.InvalidPara)); } if (CurrentWallet.SignContext(context)) { return(context.SafeSerialize()); } return(Error(ErrorCode.SignFail, context.SafeSerialize())); }
private void button3_Click(object sender, EventArgs e) { ContractParametersContext context; JObject json1 = JObject.Parse(textBox2.Text); if (json1.ContainsProperty("hex")) { context = ContractParametersContext.FromJson(json1); } else { ContractTransaction tx1 = JsonToRequest(json1); ContractTransaction tx2 = JsonToRequest(JObject.Parse(textBox3.Text)); context = new ContractParametersContext(new ContractTransaction { Attributes = new TransactionAttribute[0], Inputs = tx1.Inputs.Concat(tx2.Inputs).ToArray(), Outputs = tx1.Outputs.Concat(tx2.Outputs).ToArray() }); } Program.CurrentWallet.Sign(context); if (context.Completed) { ContractTransaction tx = (ContractTransaction)context.Verifiable; tx.Witnesses = context.GetWitnesses(); Program.CurrentWallet.ApplyTransaction(tx); Program.OXSystem.LocalNode.Tell(new LocalNode.Relay { Inventory = tx }); InformationBox.Show(tx.Hash.ToString(), LanHelper.LocalLanguage("Transaction sent, this is the TXID:"), LanHelper.LocalLanguage("Trade Success")); } else { InformationBox.Show(context.ToString(), LanHelper.LocalLanguage("Transaction generated, please send the following information to the counterparty for signing:"), LanHelper.LocalLanguage("Need Signature")); } }