private void miDelete_Click(object sender, RoutedEventArgs e) { //Get the clicked MenuItem var menuItem = (MenuItem)sender; //Get the ContextMenu to which the menuItem belongs var contextMenu = (ContextMenu)menuItem.Parent; //Find the placementTarget var item = (DataGrid)contextMenu.PlacementTarget; //Get the underlying item, that you cast to your object that is bound //to the DataGrid (and has subject and state as property) var toDeleteFromBindedList = (PaymentAccount)item.SelectedCells[0].Item; // unregister this account int issuerId = toDeleteFromBindedList.IssuerId; string requestUri = string.Format("issuer/api/{0}/accounts/unregister", issuerId); var unregisterRequest = new UnregisterRequest { Address = toDeleteFromBindedList.Address }; unregisterRequest.Signature = CryptoHelper.Sign(toDeleteFromBindedList.PrivateKey, unregisterRequest.ToMessage()); HttpContent content = new StringContent(JsonHelper.Serialize(unregisterRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); m_Wallet.PaymentAccounts.Remove(toDeleteFromBindedList); this.UpdateAddressDataGrid(); this.Save(); }
private void RemoveOldAddressForExchange(string account) { // unregister this account int issuerId = FiatCoinHelper.GetIssuerId(account); string requestUri = string.Format("issuer/api/{0}/accounts/unregister", issuerId); var unregisterRequest = new UnregisterRequest { Address = account }; unregisterRequest.Signature = CryptoHelper.Sign(m_Wallet.PaymentAccounts[exchangePayFrom.SelectedIndex].PrivateKey, unregisterRequest.ToMessage()); HttpContent content = new StringContent(JsonHelper.Serialize(unregisterRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); m_Wallet.PaymentAccounts.Remove(m_Wallet.PaymentAccounts[exchangePayFrom.SelectedIndex]); this.UpdateAddressDataGrid(); this.Save(); }
public void IssuerControllerTest() { int issuerId = 1942; int sourceIssuerId = 1942; int destIssuerId = 1010; // step1: create two account // first string privateKey, publicKey; CryptoHelper.GenerateKeyPair(out privateKey, out publicKey); string fingerPrint = CryptoHelper.Hash(publicKey); string address = FiatCoinHelper.ToAddress(sourceIssuerId, fingerPrint); var account = new PaymentAccount { Address = address, IssuerId = sourceIssuerId, CurrencyCode = "USD", PublicKey = publicKey, PrivateKey = privateKey }; // second string privateKey2, publicKey2; CryptoHelper.GenerateKeyPair(out privateKey2, out publicKey2); string fingerPrint2 = CryptoHelper.Hash(publicKey2); string address2 = FiatCoinHelper.ToAddress(destIssuerId, fingerPrint2); var account2 = new PaymentAccount { Address = address2, IssuerId = destIssuerId, CurrencyCode = "USD", PublicKey = publicKey, PrivateKey = privateKey }; // step2: register string requestUri = string.Format("issuer/api/{0}/accounts/register", issuerId); var registerRequest = new RegisterRequest { PaymentAccount = account }; HttpContent content = new StringContent(JsonHelper.Serialize(registerRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); // step3: fund requestUri = string.Format("issuer/api/{0}/accounts/fund", issuerId); var fundRequest = new FundRequest { PaymentTransaction = new PaymentTransaction { IssuerId = issuerId, Source = FiatCoinHelper.EncodeIssuerId(issuerId), Dest = address, Amount = 100.00m, CurrencyCode = "USD", MemoData = "fund with CC" } }; content = new StringContent(JsonHelper.Serialize(fundRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); // step4: get this account & verify requestUri = string.Format("issuer/api/{0}/accounts/get", issuerId); var getRequest = new GetAccountRequest { Address = address }; content = new StringContent(JsonHelper.Serialize(getRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); var jsonString = response.Content.ReadAsStringAsync(); var account3 = JsonConvert.DeserializeObject<PaymentAccount>(jsonString.Result); Assert.AreEqual(account.Address, account3.Address); Assert.AreEqual(account.PublicKey, account3.PublicKey); Assert.AreEqual(100.00m, account3.Balance); // step5: direct pay requestUri = string.Format("issuer/api/{0}/accounts/pay", issuerId); var payRequest = new DirectPayRequest { PaymentTransaction = new PaymentTransaction { IssuerId = issuerId, Source = address, Dest = address2, Amount = 10.00m, CurrencyCode = "USD", MemoData = "surface" } }; payRequest.Signature = CryptoHelper.Sign(privateKey, payRequest.ToMessage()); content = new StringContent(JsonHelper.Serialize(payRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); // step6: get & verify requestUri = string.Format("issuer/api/{0}/accounts/get", issuerId); getRequest = new GetAccountRequest { Address = address }; content = new StringContent(JsonHelper.Serialize(getRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); jsonString = response.Content.ReadAsStringAsync(); account3 = JsonConvert.DeserializeObject<PaymentAccount>(jsonString.Result); Assert.AreEqual(90.00m, account3.Balance); // step7: delete this account requestUri = string.Format("issuer/api/{0}/accounts/unregister", issuerId); var unregisterRequest = new UnregisterRequest { Address = address }; unregisterRequest.Signature = CryptoHelper.Sign(privateKey, unregisterRequest.ToMessage()); content = new StringContent(JsonHelper.Serialize(unregisterRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; response.EnsureSuccessStatusCode(); // step8: get & verify requestUri = string.Format("issuer/api/{0}/accounts/get", issuerId); getRequest = new GetAccountRequest { Address = address }; content = new StringContent(JsonHelper.Serialize(getRequest)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = HttpClient.PostAsync(requestUri, content).Result; Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }