Skip to content

Commit

Permalink
Merge pull request #568 from threshold-network/convert-script-pub-key…
Browse files Browse the repository at this point in the history
…-to-btc-address

Convert script pub key to Bitcoin address

Convert the `scriptPubKey` placed on the output of a Bitcoin
transaction to a Bitcoin address. We want to display the Bitcoin
address in UI instead of the output script.
  • Loading branch information
michalsmiarowski authored Jul 13, 2023
2 parents d25ba3d + d07b103 commit 69b9b6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hooks/tbtc/useFetchRedemptionDetails.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useEffect, useState } from "react"
import { useThreshold } from "../../contexts/ThresholdContext"
import { prependScriptPubKeyByLength } from "../../threshold-ts/utils"
import { isValidType } from "../../threshold-ts/utils/chain"
import {
createAddressFromOutputScript,
prependScriptPubKeyByLength,
isValidType,
} from "../../threshold-ts/utils"
import { useGetBlock } from "../../web3/hooks"
import { isEmptyOrZeroAddress } from "../../web3/utils"

Expand Down Expand Up @@ -206,8 +209,10 @@ export const useFetchRedemptionDetails = (
requestedAt: redemptionRequestedEventTimestamp,
completedAt: redemptionCompletedTimestamp,
isTimedOut: false,
// TODO: convert the `scriptPubKey` to address.
btcAddress: "2Mzs2YNphdHmBoE7SE77cGB57JBXveNGtae",
btcAddress: createAddressFromOutputScript(
scriptPubKey,
threshold.tbtc.bitcoinNetwork
),
})

return
Expand Down
1 change: 1 addition & 0 deletions src/threshold-ts/utils/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TransactionHash } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
export {
computeHash160,
createOutputScriptFromAddress,
createAddressFromOutputScript,
} from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { toBcoinNetwork } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin-network"
import {
Expand Down

0 comments on commit 69b9b6f

Please sign in to comment.