Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api's createpaymentacct error handling #4824

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fc8af8c
Define new grpc bsq/btc balances protos
ghubstan Nov 13, 2020
faf45ec
Add proto wrappers for serving bsq, btc or all balances
ghubstan Nov 13, 2020
4c03b46
Define proto for api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
3e98910
Define proto fapi method 'sendbsq'
ghubstan Nov 13, 2020
9f033ee
Add proto fields to support trade fee currency choice
ghubstan Nov 13, 2020
c1c099c
Implement and test api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
7c2068e
Add teardown to test case
ghubstan Nov 13, 2020
8dc1a74
Remove trailing spaces in blank line
ghubstan Nov 13, 2020
208a37b
Implement and test new getbalance(s) api methods
ghubstan Nov 13, 2020
7f0f949
Resolve unnecessary use of fully qualified name for codacy
ghubstan Nov 13, 2020
0d3b3a6
Stub out api method 'sendbsq' in core
ghubstan Nov 13, 2020
dc3274f
Re comment sendbsq tests so travis ci does not fail
ghubstan Nov 13, 2020
446bd32
Refactor desktop's BsqSendView, share with api
ghubstan Nov 13, 2020
4a90b40
Resolve 'Avoid creating BigDecimal with a decimal' issue for codacy
ghubstan Nov 13, 2020
722460e
Support paying trade fees in bsq or btc (api)
ghubstan Nov 13, 2020
8157f8f
Delete deprecated api test, adjust api build/run doc
ghubstan Nov 13, 2020
7e9ab22
Refactor api getbalance methods.
ghubstan Nov 14, 2020
187a85f
Fix typo
ghubstan Nov 14, 2020
34efc04
Remove unnecessary fully qualified name
ghubstan Nov 14, 2020
530a9f9
Remove unused imports
ghubstan Nov 14, 2020
ec38152
Add api method 'getpaymentmethods'
ghubstan Nov 18, 2020
a465261
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
0046b08
Revert "Avoid codacy issue over use of fully qualified name"
ghubstan Nov 18, 2020
7a7d5ba
Print the payment method id (only)
ghubstan Nov 18, 2020
0e0af20
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
7d0648a
Make codacy happy again
ghubstan Nov 18, 2020
32ed7ac
Add ReflectionUtils to common.util pkg
ghubstan Nov 18, 2020
c25deba
Add new (gson) PaymentAccountTypeAdapter to core.api.model
ghubstan Nov 18, 2020
1f84ad0
Add isCountryBasedPaymentAccount to abstract PaymentAccount
ghubstan Nov 18, 2020
32dd727
Add new PaymentAccountForm to core.api.model
ghubstan Nov 18, 2020
8996fa1
Add boilerplate for new 'getpaymentacctform' api method
ghubstan Nov 18, 2020
dc227ec
Add new api method 'getpaymentacctform' to CLI
ghubstan Nov 18, 2020
fdb89a2
Test new api method 'getpaymentacctform'
ghubstan Nov 18, 2020
35c1c4e
Ensure EXPECTED_FORM.clear() is never skipped
ghubstan Nov 18, 2020
08228d0
Replace existing api method 'createpaymentacct' impl
ghubstan Nov 18, 2020
138822e
Avoid 'unnecessary use of fully qualified name' codacy issue
ghubstan Nov 18, 2020
cb9a68b
Tidy up payment accts api related msgs on CLI
ghubstan Nov 19, 2020
ff887eb
Fix createpaymentacct validation problems
ghubstan Nov 19, 2020
58f1af6
Log server stack traces, pass concise err msgs to CLI
ghubstan Nov 20, 2020
7f3001d
Resolve BsqSendView file conflict
ghubstan Nov 26, 2020
0308bd2
Merge branch 'master' into 16-validate-createpaymentacct
ghubstan Nov 26, 2020
03c67a1
Adjust to changed CoinUtil
ghubstan Nov 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions core/src/main/java/bisq/core/api/model/PaymentAccountForm.java
Expand Up @@ -28,6 +28,8 @@

import com.google.common.annotations.VisibleForTesting;

import org.apache.commons.lang3.StringUtils;

import java.net.URI;
import java.net.URISyntaxException;

Expand Down Expand Up @@ -147,9 +149,9 @@ public File getPaymentAccountForm(String paymentMethodId) {
String json = gson.toJson(paymentAccount); // serializes target to json
outputStreamWriter.write(json);
} catch (Exception ex) {
log.error(format("Could not write json file for a %s account.", paymentMethodId), ex);
throw new IllegalStateException(
format("cannot create a payment account form for a %s payment method", paymentMethodId));
String errMsg = format("cannot create a payment account form for a %s payment method", paymentMethodId);
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException(errMsg);
}
return file;
}
Expand Down Expand Up @@ -184,27 +186,32 @@ public String toJsonString(File jsonFile) {
checkNotNull(jsonFile, "json file cannot be null");
return new String(Files.readAllBytes(Paths.get(jsonFile.getAbsolutePath())));
} catch (IOException ex) {
throw new IllegalStateException(format("cannot read content of file '%s'",
jsonFile.getAbsolutePath()), ex);
String errMsg = format("cannot read json string from file '%s'",
jsonFile.getAbsolutePath());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException(errMsg);
}
}

@VisibleForTesting
public URI getClickableURI(File jsonForm) {
public URI getClickableURI(File jsonFile) {
try {
return new URI("file",
"",
jsonForm.toURI().getPath(),
jsonFile.toURI().getPath(),
null,
null);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException("", ex);
String errMsg = format("cannot create clickable url to file '%s'",
jsonFile.getAbsolutePath());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException(errMsg);
}
}

@VisibleForTesting
public static File getTmpJsonFile(String paymentMethodId) {
File file = null;
File file;
try {
// Creates a tmp file that includes a random number string between the
// prefix and suffix, i.e., sepa_form_13243546575879.json, so there is
Expand All @@ -213,7 +220,10 @@ public static File getTmpJsonFile(String paymentMethodId) {
".json",
Paths.get(getProperty("java.io.tmpdir")).toFile());
} catch (IOException ex) {
log.error("", ex);
String errMsg = format("cannot create json file for a %s payment method",
paymentMethodId);
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException(errMsg);
}
return file;
}
Expand Down
Expand Up @@ -29,6 +29,8 @@
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

import java.util.ArrayList;
Expand Down Expand Up @@ -115,8 +117,10 @@ public void write(JsonWriter out, PaymentAccount account) throws IOException {
out.value("Your " + fieldName.toLowerCase());
}
} catch (Exception ex) {
throw new IllegalStateException(
format("cannot not serialize a %s", account.getClass().getSimpleName()), ex);
String errMsg = format("cannot create a new %s json form",
account.getClass().getSimpleName());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);
}
});
out.endObject();
Expand Down Expand Up @@ -173,15 +177,17 @@ private void invokeSetterMethod(PaymentAccount account, Field field, JsonReader
} else if (isSetterOnPaymentAccountPayloadClass(setter.get(), account)) {
setter.get().invoke(account.getPaymentAccountPayload(), nextStringOrNull(jsonReader));
} else {
String exMsg = format("programmer error: cannot de-serialize json to a '%s' using reflection"
String errMsg = format("programmer error: cannot de-serialize json to a '%s' using reflection"
+ " because the setter method's declaring class was not found.",
account.getClass().getSimpleName());
throw new IllegalStateException(exMsg);
throw new IllegalStateException(errMsg);
}
} catch (IllegalAccessException | InvocationTargetException ex) {
throw new IllegalStateException(
format("programmer error: cannot de-serialize json to a '%s' due to reflection error.",
account.getClass().getSimpleName()), ex);
String errMsg = format("cannot set field value for %s on %s",
field.getName(),
account.getClass().getSimpleName());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);
}
} else {
throw new IllegalStateException(
Expand Down Expand Up @@ -229,9 +235,9 @@ private String nextStringOrNull(JsonReader in) {
return in.nextString();
}
} catch (IOException ex) {
throw new IllegalStateException(
"programmer error: cannot not peek at next string value in json reader.",
ex);
String errMsg = "cannot see next string in json reader";
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);
}
}

Expand All @@ -245,9 +251,9 @@ private Long nextLongOrNull(JsonReader in) {
return in.nextLong();
}
} catch (IOException ex) {
throw new IllegalStateException(
"programmer error: cannot not peek at next long value in json reader.",
ex);
String errMsg = "cannot see next long in json reader";
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);
}
}

Expand Down Expand Up @@ -305,9 +311,11 @@ private Class<? extends PaymentAccountPayload> getPaymentAccountPayloadType() {
return (Class<? extends PaymentAccountPayload>) Class.forName(pkg.getName()
+ "." + paymentAccountType.getSimpleName() + "Payload");
} catch (Exception ex) {
throw new IllegalStateException(
format("programmer error: cannot get payload class for %s",
paymentAccountType.getSimpleName()), ex);
String errMsg = format("cannot get the payload class for %s",
paymentAccountType.getSimpleName());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);

}
}

Expand All @@ -317,16 +325,14 @@ private PaymentAccount initNewPaymentAccount() {
PaymentAccount paymentAccount = (PaymentAccount) constructor.newInstance();
paymentAccount.init();
return paymentAccount;
} catch (NoSuchMethodException ex) {
throw new IllegalStateException(
format("programmer error: no default declared constructor found for class %s",
paymentAccountType.getSimpleName()),
ex);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException ex) {
throw new IllegalStateException(
format("programmer error: cannot instantiate class %s",
paymentAccountType.getSimpleName()),
ex);
} catch (NoSuchMethodException
| IllegalAccessException
| InstantiationException
| InvocationTargetException ex) {
String errMsg = format("cannot instantiate a new %s",
paymentAccountType.getSimpleName());
log.error(StringUtils.capitalize(errMsg) + ".", ex);
throw new IllegalStateException("programmer error: " + errMsg);
}
}
}