public void DoTransactionTest() { MicroCashAddress address1 = new MicroCashAddress("micro(QSM3PKS3EOZBUZO4A)cash"); MicroCashAddress address2 = new MicroCashAddress("micro(IZ2P65UBDJKTV6ZIN)cash"); MicroCashAddress address3 = new MicroCashAddress("micro(R7MEB3HTYHB55XLO2)cash"); MicroCashAddress address4 = new MicroCashAddress("micro(JZBHXGUIISIID5JWS)cash"); try { //feed the 3 seed accounts SendTX(m_ThinUser.m_Accounts[0], address2.GetAddressBytes(), 50); SendTX(m_ThinUser.m_Accounts[0], address3.GetAddressBytes(), 50); SendTX(m_ThinUser.m_Accounts[0], address4.GetAddressBytes(), 50); //send 50 to #3 so it has 100 SendTX(m_ThinUser.m_Accounts[1], address3.GetAddressBytes(), 50); //send 100 to #4 so it has 150 SendTX(m_ThinUser.m_Accounts[2], address4.GetAddressBytes(), 100); //send 50 back to #2 and #3 SendTX(m_ThinUser.m_Accounts[3], address2.GetAddressBytes(), 50); SendTX(m_ThinUser.m_Accounts[3], address3.GetAddressBytes(), 50); //send back SendTX(m_ThinUser.m_Accounts[1], address1.GetAddressBytes(), 50); SendTX(m_ThinUser.m_Accounts[2], address1.GetAddressBytes(), 50); SendTX(m_ThinUser.m_Accounts[3], address1.GetAddressBytes(), 50); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void createPaymentCode(object sender, EventArgs e) { bool bAmount=true; if (m_SendToAmount.Text.Length <= 0) bAmount = false; string addrstr = m_SendTo.Text; if (m_SendTo.Items.IndexOf(addrstr) >= 0) addrstr = GetInfoFromAddressBook(true,addrstr); MicroCashAddress address = new MicroCashAddress(addrstr); if (address.IsValid() == false) { MessageBox.Show("Please enter a valid address to send to", "Error Creating Payment Code"); return; } System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); address.SetInfo(encoding.GetBytes(m_TXInfo.Text)); if (bAmount) { address.SetAmount((Int64)(Convert.ToDouble(m_SendToAmount.Text) * 10000)); m_SendTo.Text = address.GetPaymentCodeString(); } else { m_SendTo.Text = address.GetAddressInfoString(); } }
public string GetAddressString() { MicroCashAddress outaddr = new MicroCashAddress(AddressBytes); return outaddr.GetAddressString(); }
private void sendto_textchange(object sender, EventArgs e) { bool bValid = false; if (GetInfoFromAddressBook(true,m_SendTo.Text) != null) bValid = true; if (bValid == false) { MicroCashAddress address = new MicroCashAddress(m_SendTo.Text); if (address.IsPaymentCode) { m_SendToAmount.ReadOnly = true; m_TXInfo.ReadOnly = true; m_CreatePaymentCodeButton.Enabled = false; m_TXInfo.Text = address.GetPaymentAmountInfoString(); m_SendToAmount.Text = DoBalanceString(address.GetPaymentAmount()); } else if (address.IsLongAddress()) { m_TXInfo.ReadOnly = true; m_CreatePaymentCodeButton.Enabled = false; m_TXInfo.Text = address.GetPaymentAmountInfoString(); m_SendToAmount.ReadOnly = false; } else { m_CreatePaymentCodeButton.Enabled = true; m_SendToAmount.ReadOnly = false; m_TXInfo.ReadOnly = false; m_TXInfo.Text = ""; m_SendToAmount.Text = ""; } bValid = address.IsValid(); } if(bValid) m_SendTo.ForeColor = Color.FromArgb(0,0,0); else m_SendTo.ForeColor = Color.FromArgb(255,0,0); }
private void sendFunds(object sender, EventArgs e) { try { if (m_SendToAmount.Text.Length <= 0) { MessageBox.Show("Please enter an amount to send", "Error Creating Payment"); return; } string addrstr = m_SendTo.Text; if (m_SendTo.Items.IndexOf(addrstr) >= 0) { addrstr = GetInfoFromAddressBook(true, addrstr); } MicroCashAddress address = new MicroCashAddress(addrstr); if (address.IsValid() == false) { MessageBox.Show("Please enter a valid address to send to", "Error Creating Payment"); return; } int nAccount = m_SendFrom.SelectedIndex; Account account = m_ThinUser.m_Accounts[nAccount]; SendTxResult result = null; if (address.IsPaymentCode) { //send a payment code style transaction result = account.SendTx(address); } else { //attempt to parse the send amount text box double amount = 0; if (!Double.TryParse(m_SendToAmount.Text, out amount)) MessageBox.Show(String.Format("Could not convert {0} to a number!", m_SendToAmount.Text), "Unable to Parse!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //convert the tx info text box, if populated byte[] info = null; if (!string.IsNullOrEmpty(m_TXInfo.Text)) info = UTF8Encoding.Default.GetBytes(m_TXInfo.Text); //send custom transaction result = account.SendTx(address, amount, info); } if (result != null && result.IsSent == true) { m_SendToAmount.Text = ""; m_SendTo.Text = ""; m_TXInfo.Text = ""; m_bUpdateNow = true; MessageBox.Show("Transaction sent!"); } else { MessageBox.Show(result.ErrorMessage, "Error sending transaction"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
internal SendTxResult SendTx(MicroCashAddress address, double amount, byte[] info) { MicroCashTransaction tx = new MicroCashTransaction(); Array.Copy(m_KeyPair.PublicKeyBytes, 1, tx.m_Extra1, 0, 64); //this isnt always sent, but may as well just copy it tx.m_dwAddressID = this.AddressId; if (tx.m_dwAddressID == 0) { tx.m_dwType = 1; } tx.m_FromAddress = m_KeyPair.GetAddressBytes(); tx.m_RecvAddress = address.GetAddressBytes(); tx.m_qAmount = (Int64)(amount * 10000); if (info != null) { int nLen = info.Length; if (nLen > 8) nLen = 8; for (int x = 0; x < 8; x++) tx.m_Info[x] = 0; Array.Copy(info, tx.m_Info, nLen); } byte[] hash = tx.GetHash(false); //string s = MicroCashFunctions.ToHex(hash); tx.m_Signature = m_KeyPair.Sign(hash); MicroCashRpcClient mcrpc = new MicroCashRpcClient(GlobalSettings.RpcUrl); SendTransactionRpcResponse sendtx = mcrpc.SendTransaction(MicroCashHelper.ToHex(tx.GetByteBuffer(true))); SendTxResult result = new SendTxResult(); result.IsSent = sendtx.sent; result.ErrorMessage = mcrpc.ErrorMessage; return result; }
internal SendTxResult SendTx(MicroCashAddress paymentCodeAddress) { if (!paymentCodeAddress.IsPaymentCode) throw new ArgumentException("Address is not a payment code!", "paymentCodeAddress"); double amount = paymentCodeAddress.GetPaymentAmount() / 10000.0000; byte[] info = new byte[8]; Array.Copy(paymentCodeAddress.GetInfoBytes(), info, 8); return SendTx(paymentCodeAddress, amount, info); }