Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove enum #12

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions script/SetSeed.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ contract SetSeed is Script {
console.log("BTC_ADDR2:", btcAddr2);

// get network
uint network = vm.envUint("Network");
uint _network = vm.envUint("Network");
uint8 network = uint8(_network);

console.log("Network:", network);

BTCDepositAddressDeriver deriver = BTCDepositAddressDeriver(
Expand All @@ -34,7 +36,7 @@ contract SetSeed is Script {

// set validators' pubkeys and network prefix
vm.startBroadcast();
deriver.setSeed(btcAddr1, btcAddr2, BTCDepositAddressDeriver.BitcoinNetwork(network));
deriver.setSeed(btcAddr1, btcAddr2, network);
vm.stopBroadcast();
}
}
18 changes: 7 additions & 11 deletions src/BTCDepositAddressDeriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ error CannotParseBtcAddress(

contract BTCDepositAddressDeriver {

enum BitcoinNetwork {
TESTNET,
MAINNET,
REGTEST
}

event SeedChanged(string btcAddr1, string btcAddr2, string hrp);

bool public wasSeedSet;
Expand All @@ -48,7 +42,7 @@ contract BTCDepositAddressDeriver {
function setSeed(
string calldata _btcAddr1,
string calldata _btcAddr2,
BitcoinNetwork _network
uint8 _network
) public virtual {

string memory _hrp = getNetworkPrefix(_network);
Expand All @@ -67,17 +61,19 @@ contract BTCDepositAddressDeriver {

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

string memory _hrp;

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

return _hrp;
Expand Down
4 changes: 2 additions & 2 deletions test/BTCDepositAddressDeriver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract BTCDepositAddressDeriverTest is Test {
deriver.setSeed(
"tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3",
"tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz",
BTCDepositAddressDeriver.BitcoinNetwork.TESTNET
0
);

assertEq(deriver.wasSeedSet(), true);
Expand Down Expand Up @@ -97,7 +97,7 @@ contract BTCDepositAddressDeriverTest is Test {
deriver.setSeed(
"tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3",
"tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz",
BTCDepositAddressDeriver.BitcoinNetwork.TESTNET
0
);

string memory btcAddress = deriver.getBTCDepositAddress(
Expand Down