commit 3826f041a9b3ca885d0ca8910d1f65ccd8f1c910
parent 465ca4cd8f1ca8a6ebf5bd99d5b10c6cb54a1869
Author: Antoine A <>
Date: Wed, 1 Dec 2021 14:55:29 +0100
API: More error handling
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/script/test_bank.sh b/script/test_bank.sh
@@ -68,7 +68,8 @@ done
echo ""
echo -n "Bad bitcoin address..."
-taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/ADDRESS -a BTC:0.00042 2>&1 | grep -q '(400/26)' && echo " OK" || echo " Failed"
+taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/ADDRESS -a BTC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed"
-#btc-wire-cli nblock
+echo -n "Bad amount..."
+taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/$ADDRESS -a ATC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed"
exit 0
diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs
@@ -94,6 +94,7 @@ async fn main() {
std::thread::spawn(move || {
let rpc = wallet_rpc(network, "wire");
+ let self_addr = rpc.get_new_address(None, None).unwrap();
let mut last_hash: Option<BlockHash> = None;
let confirmation = 1;
@@ -101,9 +102,9 @@ async fn main() {
let txs = rpc
.list_since_block(last_hash.as_ref(), Some(confirmation), None, Some(true))
.unwrap();
- let self_addr = rpc.get_new_address(None, None).unwrap();
last_hash = Some(txs.lastblock);
+ // List all confirmed send and receive transactions since last check
let txs: HashMap<Txid, Category> = txs
.transactions
.into_iter()
@@ -303,10 +304,15 @@ async fn router(
ErrorCode::GENERIC_PARAMETER_MALFORMED,
)
})?;
- let amount: BtcAmount = request.amount.try_into().unwrap();
+ let amount: BtcAmount = request.amount.try_into().map_err(|_| {
+ (
+ StatusCode::BAD_REQUEST,
+ ErrorCode::GENERIC_PARAMETER_MALFORMED,
+ )
+ })?;
client
.send_op_return(&to, amount, request.wtid.as_ref())
- .unwrap();
+ .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, ErrorCode::INVALID))?;
let timestamp = Timestamp::now();
json_response(
StatusCode::OK,