diff --git a/script/SetSeed.s.sol b/script/SetSeed.s.sol index f512bf4..1be6f8d 100644 --- a/script/SetSeed.s.sol +++ b/script/SetSeed.s.sol @@ -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( @@ -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(); } } diff --git a/src/BTCDepositAddressDeriver.sol b/src/BTCDepositAddressDeriver.sol index dcd0e55..17e36cf 100644 --- a/src/BTCDepositAddressDeriver.sol +++ b/src/BTCDepositAddressDeriver.sol @@ -17,12 +17,6 @@ error CannotParseBtcAddress( contract BTCDepositAddressDeriver { - enum BitcoinNetwork { - TESTNET, - MAINNET, - REGTEST - } - event SeedChanged(string btcAddr1, string btcAddr2, string hrp); bool public wasSeedSet; @@ -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); @@ -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; diff --git a/test/BTCDepositAddressDeriver.t.sol b/test/BTCDepositAddressDeriver.t.sol index a4ca5a5..cae6a4a 100644 --- a/test/BTCDepositAddressDeriver.t.sol +++ b/test/BTCDepositAddressDeriver.t.sol @@ -62,7 +62,7 @@ contract BTCDepositAddressDeriverTest is Test { deriver.setSeed( "tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3", "tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz", - BTCDepositAddressDeriver.BitcoinNetwork.TESTNET + 0 ); assertEq(deriver.wasSeedSet(), true); @@ -97,7 +97,7 @@ contract BTCDepositAddressDeriverTest is Test { deriver.setSeed( "tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3", "tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz", - BTCDepositAddressDeriver.BitcoinNetwork.TESTNET + 0 ); string memory btcAddress = deriver.getBTCDepositAddress(