Lowercasing bech32 addresses

This commit is contained in:
kexkey
2021-02-11 14:06:50 -05:00
parent bc4e4fa26e
commit 738051859e
5 changed files with 64 additions and 30 deletions

View File

@@ -2,6 +2,7 @@
. ./trace.sh
. ./sendtobitcoinnode.sh
. ./bitcoin.sh
createbatcher() {
trace "Entering createbatcher()..."
@@ -159,6 +160,9 @@ addtobatch() {
local webhook_url=$(echo "${request}" | jq ".webhookUrl")
trace "[addtobatch] webhook_url=${webhook_url}"
# Let's lowercase bech32 addresses
address=$(lowercase_if_bech32 "${address}")
local isvalid
isvalid=$(validateaddress "${address}" | jq ".result.isvalid")
if [ "${isvalid}" != "true" ]; then
@@ -191,7 +195,7 @@ addtobatch() {
response='{"result":null,"error":{"code":-32700,"message":"batcher not found","data":'${request}'}}'
else
# Check if address already pending for this batcher...
inserted_id=$(sql "SELECT id FROM recipient WHERE address=\"${address}\" AND tx_id IS NULL AND batcher_id=${batcher_id}")
inserted_id=$(sql "SELECT id FROM recipient WHERE LOWER(address)=LOWER(\"${address}\") AND tx_id IS NULL AND batcher_id=${batcher_id}")
if [ -n "${inserted_id}" ]; then
response='{"result":null,"error":{"code":-32700,"message":"Duplicated address","data":'${request}'}}'

View File

@@ -52,3 +52,20 @@ send_to_pycoin()
return ${returncode}
}
lowercase_if_bech32() {
trace "Entering lowercase_bech32()..."
local address=${1}
# Let's lowercase bech32 addresses
local lowercased_address
lowercased_address=$(echo ${address} | tr '[:upper:]' '[:lower:]')
case "${lowercased_address}" in
bc*|tb*|bcrt*)
address="${lowercased_address}"
trace "[lowercase_if_bech32] lowercased bech32 address=${address}";;
esac
echo "${address}"
}

View File

@@ -2,6 +2,7 @@
. ./trace.sh
. ./sql.sh
. ./bitcoin.sh
unwatchrequest() {
trace "Entering unwatchrequest()..."
@@ -11,6 +12,10 @@ unwatchrequest() {
local unconfirmedCallbackURL=${3}
local confirmedCallbackURL=${4}
local returncode
# Let's lowercase bech32 addresses
address=$(lowercase_if_bech32 "${address}")
trace "[unwatchrequest] Unwatch request id ${watchid} on address ${address} with url0conf ${unconfirmedCallbackURL} and url1conf ${confirmedCallbackURL}"
if [ "${watchid}" != "null" ]; then

View File

@@ -2,6 +2,7 @@
. ./trace.sh
. ./sendtobitcoinnode.sh
. ./bitcoin.sh
spend() {
trace "Entering spend()..."
@@ -19,6 +20,9 @@ spend() {
local subtractfeefromamount=$(echo "${request}" | jq ".subtractfeefromamount")
trace "[spend] subtractfeefromamount=${subtractfeefromamount}"
# Let's lowercase bech32 addresses
address=$(lowercase_if_bech32 "${address}")
local response
local id_inserted
local tx_details

View File

@@ -19,6 +19,10 @@ watchrequest() {
local inserted
local id_inserted
local result
# Let's lowercase bech32 addresses
address=$(lowercase_if_bech32 "${address}")
trace "[watchrequest] Watch request on address (\"${address}\"), cb 0-conf (${cb0conf_url}), cb 1-conf (${cb1conf_url}) with event_message=${event_message}"
local isvalid