I want to make a send payment from my wallet.
public static Transaction send(Wallet wallet,String destinationAddress,long satoshis, NetworkParameters parameters)
throws Exception {
Address dest = Address.fromBase58(parameters, destinationAddress);
SendRequest request = SendRequest.to(dest, Coin.valueOf(satoshis));
Wallet.SendResult result = wallet.sendCoins(request);
Transaction endTransaction = result.broadcastComplete.get();
return endTransaction;
}
or tried to make
SendRequest req;
Transaction transaction = new Transaction(parameters);
Coin coinToSpend = Coin.valueOf(600);
//Address addressoSpend = new Address(parameters,"1PSq12YPRBCGwmb2cqqXaGpRrLfotsthPv");
transaction.addOutput(coinToSpend,Address.fromBase58(parameters,"18MQPpjbB5UUwZBT7DALE6Q55pKCtfPCK3"));
req = SendRequest.forTx(transaction);
Wallet.SendResult sendResult = restoredWallet.sendCoins(req);
both of them return
Exception in thread "main" org.bitcoinj.core.InsufficientMoneyException: Insufficient money, missing 0.0004729 BTC
How to make a proper send payment to another BTC address?
The problem actually was with the input and output. In new versions of bitcoinj you should set unput and output ot make transaction. Unfortuanetly, it was not updated on officail page. Here below is the answer for my question:
Coin value = Coin.valueOf(680l);
Address to = Address.fromBase58(parameters, addressTo);
Transaction transaction = new Transaction(parameters);
transaction.addInput(wallet.getUnspents().get(0));// important to add proper input
transaction.addOutput(value, to);
SendRequest request = SendRequest.forTx(transaction);
request.feePerKb = Coin.valueOf(1000);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, request);
Related
I am able to create a CNAME record through the AWS console no problem see picture above. But when I try to do the same thing programmatically with the AWS Route53 SDK I keep getting an
com.amazonaws.services.route53.model.InvalidInputException: Invalid
request (Service: AmazonRoute53; Status Code: 400; Error Code:
InvalidInput; Request ID: 7fd7b5d1-5ea8-11e8-a252-7f474094c446)
Here's my attempted code
private static final String QA_HOSTED_ZONE_ID = "UUIDFromConsole";
GetHostedZoneRequest getHostedZoneRequest = new GetHostedZoneRequest(HOSTED_ZONE_ID);
GetHostedZoneResult result = route53Client.getHostedZone(getHostedZoneRequest);
ResourceRecordSet resourceRecordSet = new
ResourceRecordSet("DN4TheRecordSet", RRType.CNAME);
GeoLocation geoLocation = new GeoLocation();
geoLocation.setContinentCode("NA");
geoLocation.setSubdivisionCode("NY");
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setTTL(50L);
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setSetIdentifier("uniqueid-statecode");Change addStateChange = new Change(ChangeAction.CREATE, resourceRecordSet);
ChangeBatch changeBatch = new ChangeBatch(Arrays.asList(addStateChange));
ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest().withHostedZoneId(HOSTED_ZONE_ID).withChangeBatch(changeBatch);
route53Client.changeResourceRecordSets(changeResourceRecordSetsRequest);
I am also not able to configure the value for the CNAME, meaning where I want to redirect my traffic after it hits the DN4TheRecordSet.This is probably the cause of the invalid error I am receiving in the response.
Please help 🤕
Found the issue.
The InvalidInputException was eluding to the fact of a missing ResourceRecord which corresponds to the value field in the picture above.
Here's the solution above with the addition of a ResourceRecord to the ResourceRecordSet
private static final String QA_HOSTED_ZONE_ID = "UUIDFromConsole";
private static final String REDIRECT_DNS = "DNS to want the cname to route to";
GetHostedZoneRequest getHostedZoneRequest = new GetHostedZoneRequest(HOSTED_ZONE_ID);
GetHostedZoneResult result = route53Client.getHostedZone(getHostedZoneRequest); ResourceRecordSet resourceRecordSet = new ResourceRecordSet("DN4TheRecordSet", RRType.CNAME);
GeoLocation geoLocation = new GeoLocation();
geoLocation.setContinentCode("NA");
geoLocation.setSubdivisionCode("NY");
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setTTL(50L);
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setSetIdentifier("uniqueid-statecode");
resourceRecordSet.setResourceRecords(Arrays.asList(new ResourceRecord(REDIRECT_DNS))); // This line being missing cause the exception
Change addStateChange = new Change(ChangeAction.CREATE, resourceRecordSet);
ChangeBatch changeBatch = new ChangeBatch(Arrays.asList(addStateChange));
ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest().withHostedZoneId(HOSTED_ZONE_ID).withChangeBatch(changeBatch);
route53Client.changeResourceRecordSets(changeResourceRecordSetsRequest);
See Geolocation Syntax section in this page for example of the payload the sdk creates and sends for your request.
I have created Api for Verify mobile and i want to put some logic so
that i can restrict the user who try to verify otp after 4 hours. I
have created two Apis first one send otp to user and the input
parameter is mobile number.
Second API verify that mobile number by comparing the otp inserted by user and that stored in database during first API
#RestController
#RequestMapping("/api/v1")
public class MobileController2 {
private String To = null;
OtpGenerator otp = new OtpGenerator();
#Autowired
private MobileRepository mobileRepository;
Sms sms = new Sms();
Date date = new Date();
Timestamp timestamp1 = new Timestamp(date.getTime());
Calendar cal = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
#PostMapping(value = "/mobile", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Mobile> createMobile(#RequestBody Mobile mobile) {
int hashcode = otp.RandomOtp();
this.To = mobile.getMob();
String Message = hashcode + " is your Pharmerz verification code ";
if (mobileRepository.findByUserid(mobile.getUserid()) != null) {
Mobile mobileprevious = mobileRepository.findByUserid(mobile.getUserid());
mobileprevious.setMob(mobile.getMob());
mobileprevious.setHASHCODE("" + hashcode);
mobileprevious.setUpdated(mobile.getUpdated());
mobileprevious.setVERIFIED(0);
mobileRepository.save(mobileprevious);
sms.sms_generation(To, Message);
return new ResponseEntity<Mobile>(mobileprevious, HttpStatus.OK);
} else {
mobile.setHASHCODE("" + hashcode);
mobile.setVERIFIED(0);
mobileRepository.save(mobile);
sms.sms_generation(To, Message);
return new ResponseEntity<Mobile>(mobile, HttpStatus.OK);
}
}
#PostMapping(value = "/verifymobile", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Mobile> verifyMobile(#RequestBody Mobile mobile) {
String userid = mobile.getUserid();
String userotp = mobile.getHASHCODE();
Mobile mobileobject = mobileRepository.findByUserid(userid);
if (mobileobject.getHASHCODE().equals(userotp)) {
System.out.println("Matched");
mobileobject.setHASHCODE("");
mobileobject.setVERIFIED(1);
mobileRepository.save(mobileobject);
String Acknowledge = "Thank you for verifying on Pharmerz";
sms.sms_generation(To, Acknowledge);
return new ResponseEntity<Mobile>(mobileobject, HttpStatus.OK);
} else {
System.out.println("Miss matched");
return new ResponseEntity<Mobile>(HttpStatus.BAD_REQUEST);
}
}
}
Giving you a non-answer here: learn how to write helpful log messages and how to make use of tools such as debuggers or profilers.
Meaning: nobody can debug such a problem from remote. There could be all kinds of root causes giving you this behavior.
You have to step back and
understand that putting the string "error log" into your error log doesn't help anything.
understand that printing to the console ... is also not a reliable way to attain "logs" of your code. Especially when having the same message "Wrong or Old Otp" in three different places. That's called code duplication and per se a bad practice!
learn to use tools that give you insights about the health of your application.
In other words: the primary goal of logging information within your application is to enable you to debug problems after they took place. Exactly to support you in situations such as this.
I'm trying to set up a payment system with paypal for a site where the charging should not happen at payment confirmation time. I understand this is what the "CREATE" action type is for, you make the payment and then you use the execute payment to actually charge the account. Unfortunately, from what I'm seeing in the sandbox, the buyer gets charged immediately, and the execute payment returns a "paykey already used for a payment" error. The IPN notification similarly tells me the payment has already happened.
I'm currently using adaptive payments with 2 receivers. I'm sending the request from Java, using the code pasted below to get the paykey. Then I redirect the user to paypal and the payment is done (and charged).
Am I missing something?
List<PaymentReceiver> receiverList = setReceiversSingleProject(order);
Element root = new Element("PayRequest");
root.addNamespaceDeclaration("ns2", "http://svcs.paypal.com/types/ap");
// requestEnvelope and errorLanguage
Element requestEnvelopeElement = new Element("requestEnvelope");
Element errorLanguageElement = new Element("errorLanguage");
errorLanguageElement.appendChild(errorLanguage);
requestEnvelopeElement.appendChild(errorLanguageElement);
root.appendChild(requestEnvelopeElement);
// cancelUrl
Element cancelUrlElement = new Element("cancelUrl");
cancelUrlElement.appendChild(themeDisplay.getPortalURL()+"/basket");
root.appendChild(cancelUrlElement);
// actionType
Element actionTypeElement = new Element("actionType");
actionTypeElement.appendChild("CREATE");
root.appendChild(actionTypeElement);
// currencyCode
Element currencyCodeElement = new Element("currencyCode");
String projectCurrency = order.getMainProject().getCurrency();
Currency currency = CurrencyLocalServiceUtil.getCurrency(projectCurrency);
currencyCodeElement.appendChild(currency.getPaypalCode());
root.appendChild(currencyCodeElement);
// receiverList
Element receiverListElement = new Element("receiverList");
for (PaymentReceiver receiver : receiverList) {
Element receiverElement = new Element("receiver");
Element amountElement = new Element("amount");
amountElement.appendChild(String.valueOf(receiver.getAmount()));
Element emailElement = new Element("email");
emailElement.appendChild(receiver.getEmail());
Element primaryElement = new Element("primary");
primaryElement.appendChild(receiver.isPrimary()?"true":"false");
receiverElement.appendChild(amountElement);
receiverElement.appendChild(emailElement);
receiverElement.appendChild(primaryElement);
receiverListElement.appendChild(receiverElement);
}
root.appendChild(receiverListElement);
// returnUrl
Element returnUrlElement = new Element("returnUrl");
returnUrlElement.appendChild(returnURL);
root.appendChild(returnUrlElement);
// notifyUrl
Element notifyUrlElement = new Element("ipnNotificationUrl");
notifyUrlElement.appendChild(notifyURL);
root.appendChild(notifyUrlElement);
// Create document object
Document doc = new Document(root);
String result = doc.toXML();
return result;
This is the DAO I have created:
public Poll updatePoll(int id){
Session s = factory.getCurrentSession();
Transaction t = s.beginTransaction();
Poll poll = (Poll) s.get(Poll.class, id);
Citizen citizen = (Citizen) s.get(Citizen.class, 1);
List<Poll> list = citizen.getPolledList();
boolean check = list.contains(poll);
if(!check){
Query q = s.createSQLQuery("update Poll set poll_count = poll_count + 1 where poll_id = id");
q.executeUpdate();
s.update(poll);
}else{
return poll;
}
s.close();
return poll;
}
This is the Action created:
public String submitVote(){
ServletContext ctx = ServletActionContext.getServletContext();
ProjectDAO dao = (ProjectDAO)ctx.getAttribute("DAO");
Poll poll = dao.updatePoll(poll_id);
String flag = "error";
if (poll != null){
ServletActionContext.getRequest().getSession(true).setAttribute("POLL", poll);
flag = "voted";
}
return flag;
}
I know I have been going horribly wrong and the code I'm posting might be utter rubbish. But I hope the intent is clear, thus if possible please lent me a helping hand. My project is mainly in JSP (Struts 2), jQuery and MySQL 5.1, so please do not suggest PHP codes as I've found earlier.
The framework is used to wrap the servlet stuff from user, you should use its features if you want doing something like
ServletActionContext.getRequest().getSession(true)
But
Map m = ActionContext.getContext().getSession();
With Rally's rest api, how can I query to find a user's email address?
For instance, I have this query to get a defect which contains the full name of the user who opened it and the user who owns the defect:
QueryRequest defectRequest = new QueryRequest("defect");
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId"));
defectRequest.setQueryFilter(new QueryFilter("Project.Name", "=", rallyProjectName).and(new QueryFilter("LastUpdateDate", ">", defectTimestamp.getTimestamp())));
QueryResponse projectDefects = rallyApi.query(defectRequest);
Now I'd like to take the Submitted By and Owner users from the defect and get their email addresses.
Make certain to include the fields "Owner" and "SubmittedBy" on your Fetch for the Defects:
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId", "Owner", "SubmittedBy"));
Then the Owner and SubmittedBy fields on each returned Defect (if populated in Rally and not null) will have a reference to the corresponding User object in Rally. Then your inclination to do a second request for this is spot on. It's easiest to just use that ref and do a GetRequest straight against the ref. Here's how on the Owner field as an example (forgive the clumsy try/catch block - it's catching empty Owner fields):
QueryResponse projectDefects = restApi.query(defectRequest);
if (projectDefects.wasSuccessful()) {
for (JsonElement result : projectDefects.getResults()) {
JsonObject defect = result.getAsJsonObject();
try {
JsonObject ownerJsonObject = defect.get("Owner").getAsJsonObject();
String ownerRef = ownerJsonObject.get("_ref").getAsString();
GetRequest ownerRequest = new GetRequest(ownerRef);
GetResponse ownerResponse = restApi.get(ownerRequest);
JsonObject ownerObj = ownerResponse.getObject();
System.out.println(String.format("Read owner. EmailAddress = %s",
ownerObj.get("EmailAddress").getAsString()));
} catch (java.lang.IllegalStateException ise) {
// System.out.println("IllegalStateException caught: ");
// ise.printStackTrace();
}
}
}