Skip to content

Commit

Permalink
remove enum (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Viacheslav Zhygulin <[email protected]>
  • Loading branch information
szhygulin and Viacheslav Zhygulin authored Jun 19, 2024
1 parent 7f5c314 commit e50849e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
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

0 comments on commit e50849e

Please sign in to comment.