Skip to content

Commit

Permalink
refactor: network prefix function
Browse files Browse the repository at this point in the history
  • Loading branch information
szhygulin committed May 22, 2024
1 parent 25360be commit 7287295
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/BTCDepositAddressDeriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ contract BTCDepositAddressDeriver {
BitcoinNetwork _network
) public virtual {

string memory _hrp;

if (_network == BitcoinNetwork.TESTNET) {
_hrp = 'tb';
} else if (_network == BitcoinNetwork.MAINNET) {
_hrp = 'bc';
} else if (_network == BitcoinNetwork.REGTEST) {
_hrp = 'brct';
}
string memory _hrp = getNetworkPrefix(_network);

networkHrp = _hrp;

Expand All @@ -73,6 +65,24 @@ contract BTCDepositAddressDeriver {
emit SeedChanged(_btcAddr1, _btcAddr2, _hrp);
}

// get address prefix from network type
function getNetworkPrefix(
BitcoinNetwork _network
) public pure returns (string memory) {

string memory _hrp;

if (_network == BitcoinNetwork.TESTNET) {
_hrp = 'tb';
} else if (_network == BitcoinNetwork.MAINNET) {
_hrp = 'bc';
} else if (_network == BitcoinNetwork.REGTEST) {
_hrp = 'brct';
}

return _hrp;
}

// Derive pubkey's (x,y) coordinates from taproot address
function parseBTCTaprootAddress(
string memory _hrp,
Expand Down

0 comments on commit 7287295

Please sign in to comment.