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

@@ -4,51 +4,68 @@
deriveindex()
{
trace "Entering deriveindex()..."
trace "Entering deriveindex()..."
local index=${1}
trace "[deriveindex] index=${index}"
local index=${1}
trace "[deriveindex] index=${index}"
local pub32=$DERIVATION_PUB32
local path=$(echo -e "$DERIVATION_PATH" | sed -En "s/n/${index}/p")
# pub32=$(grep "derivation.pub32" config.properties | cut -d'=' -f2)
# path=$(grep "derivation.path" config.properties | cut -d'=' -f2 | sed -En "s/n/${index}/p")
local pub32=$DERIVATION_PUB32
local path=$(echo -e "$DERIVATION_PATH" | sed -En "s/n/${index}/p")
# pub32=$(grep "derivation.pub32" config.properties | cut -d'=' -f2)
# path=$(grep "derivation.path" config.properties | cut -d'=' -f2 | sed -En "s/n/${index}/p")
local data="{\"pub32\":\"${pub32}\",\"path\":\"${path}\"}"
trace "[deriveindex] data=${data}"
local data="{\"pub32\":\"${pub32}\",\"path\":\"${path}\"}"
trace "[deriveindex] data=${data}"
send_to_pycoin "${data}"
return $?
send_to_pycoin "${data}"
return $?
}
derivepubpath() {
trace "Entering derivepubpath()..."
trace "Entering derivepubpath()..."
# {"pub32":"tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk","path":"0/25-30"}
# {"pub32":"tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk","path":"0/25-30"}
send_to_pycoin $1
return $?
send_to_pycoin $1
return $?
}
send_to_pycoin()
{
trace "Entering send_to_pycoin()..."
trace "Entering send_to_pycoin()..."
local data=${1}
local result
local returncode
local data=${1}
local result
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)
returncode=$?
trace_rc ${returncode}
trace "[send_to_pycoin] result=${result}"
result=$(curl -s -H "Content-Type: application/json" -d "${data}" ${PYCOIN_CONTAINER}/derive)
returncode=$?
trace_rc ${returncode}
trace "[send_to_pycoin] result=${result}"
# Output response to stdout before exiting with return code
echo "${result}"
# Output response to stdout before exiting with return code
echo "${result}"
trace_rc ${returncode}
return ${returncode}
trace_rc ${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
. ./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