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 . ./trace.sh
. ./sendtobitcoinnode.sh . ./sendtobitcoinnode.sh
. ./bitcoin.sh
createbatcher() { createbatcher() {
trace "Entering createbatcher()..." trace "Entering createbatcher()..."
@@ -159,6 +160,9 @@ addtobatch() {
local webhook_url=$(echo "${request}" | jq ".webhookUrl") local webhook_url=$(echo "${request}" | jq ".webhookUrl")
trace "[addtobatch] webhook_url=${webhook_url}" trace "[addtobatch] webhook_url=${webhook_url}"
# Let's lowercase bech32 addresses
address=$(lowercase_if_bech32 "${address}")
local isvalid local isvalid
isvalid=$(validateaddress "${address}" | jq ".result.isvalid") isvalid=$(validateaddress "${address}" | jq ".result.isvalid")
if [ "${isvalid}" != "true" ]; then if [ "${isvalid}" != "true" ]; then
@@ -191,7 +195,7 @@ addtobatch() {
response='{"result":null,"error":{"code":-32700,"message":"batcher not found","data":'${request}'}}' response='{"result":null,"error":{"code":-32700,"message":"batcher not found","data":'${request}'}}'
else else
# Check if address already pending for this batcher... # 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 if [ -n "${inserted_id}" ]; then
response='{"result":null,"error":{"code":-32700,"message":"Duplicated address","data":'${request}'}}' response='{"result":null,"error":{"code":-32700,"message":"Duplicated address","data":'${request}'}}'

View File

@@ -4,51 +4,68 @@
deriveindex() deriveindex()
{ {
trace "Entering deriveindex()..." trace "Entering deriveindex()..."
local index=${1} local index=${1}
trace "[deriveindex] index=${index}" trace "[deriveindex] index=${index}"
local pub32=$DERIVATION_PUB32 local pub32=$DERIVATION_PUB32
local path=$(echo -e "$DERIVATION_PATH" | sed -En "s/n/${index}/p") local path=$(echo -e "$DERIVATION_PATH" | sed -En "s/n/${index}/p")
# pub32=$(grep "derivation.pub32" config.properties | cut -d'=' -f2) # pub32=$(grep "derivation.pub32" config.properties | cut -d'=' -f2)
# path=$(grep "derivation.path" config.properties | cut -d'=' -f2 | sed -En "s/n/${index}/p") # path=$(grep "derivation.path" config.properties | cut -d'=' -f2 | sed -En "s/n/${index}/p")
local data="{\"pub32\":\"${pub32}\",\"path\":\"${path}\"}" local data="{\"pub32\":\"${pub32}\",\"path\":\"${path}\"}"
trace "[deriveindex] data=${data}" trace "[deriveindex] data=${data}"
send_to_pycoin "${data}" send_to_pycoin "${data}"
return $? return $?
} }
derivepubpath() { derivepubpath() {
trace "Entering derivepubpath()..." trace "Entering derivepubpath()..."
# {"pub32":"tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk","path":"0/25-30"} # {"pub32":"tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk","path":"0/25-30"}
send_to_pycoin $1 send_to_pycoin $1
return $? return $?
} }
send_to_pycoin() send_to_pycoin()
{ {
trace "Entering send_to_pycoin()..." trace "Entering send_to_pycoin()..."
local data=${1} local data=${1}
local result local result
local returncode local returncode
trace "[send_to_pycoin] curl -s -H \"Content-Type: application/json\" -d \"${data}\" ${PYCOIN_CONTAINER}/derive" trace "[send_to_pycoin] curl -s -H \"Content-Type: application/json\" -d \"${data}\" ${PYCOIN_CONTAINER}/derive"
result=$(curl -s -H "Content-Type: application/json" -d "${data}" ${PYCOIN_CONTAINER}/derive) result=$(curl -s -H "Content-Type: application/json" -d "${data}" ${PYCOIN_CONTAINER}/derive)
returncode=$? returncode=$?
trace_rc ${returncode} trace_rc ${returncode}
trace "[send_to_pycoin] result=${result}" trace "[send_to_pycoin] result=${result}"
# Output response to stdout before exiting with return code # Output response to stdout before exiting with return code
echo "${result}" echo "${result}"
trace_rc ${returncode} trace_rc ${returncode}
return ${returncode} 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 . ./trace.sh
. ./sql.sh . ./sql.sh
. ./bitcoin.sh
unwatchrequest() { unwatchrequest() {
trace "Entering unwatchrequest()..." trace "Entering unwatchrequest()..."
@@ -11,6 +12,10 @@ unwatchrequest() {
local unconfirmedCallbackURL=${3} local unconfirmedCallbackURL=${3}
local confirmedCallbackURL=${4} local confirmedCallbackURL=${4}
local returncode 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}" trace "[unwatchrequest] Unwatch request id ${watchid} on address ${address} with url0conf ${unconfirmedCallbackURL} and url1conf ${confirmedCallbackURL}"
if [ "${watchid}" != "null" ]; then if [ "${watchid}" != "null" ]; then

View File

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

View File

@@ -19,6 +19,10 @@ watchrequest() {
local inserted local inserted
local id_inserted local id_inserted
local result 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}" trace "[watchrequest] Watch request on address (\"${address}\"), cb 0-conf (${cb0conf_url}), cb 1-conf (${cb1conf_url}) with event_message=${event_message}"
local isvalid local isvalid