Skip to content

Commit

Permalink
Merge branch 'master' into fix_build
Browse files Browse the repository at this point in the history
  • Loading branch information
szhygulin authored Jun 20, 2024
2 parents 0b68d38 + e50849e commit 900a328
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
13 changes: 5 additions & 8 deletions script/SetSeed.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ contract SetSeed is Script, AddressReaderWriter {
console.log("BTC_ADDR2:", btcAddr2);

// get network
uint network = vm.envUint("BTC_NETWORK");
console.log("BTC_NETWORK:", network);
uint _network = vm.envUint("Network");
uint8 network = uint8(_network);

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

BTCDepositAddressDeriver deriver = BTCDepositAddressDeriver(
contractAddress
);

// set validators' pubkeys and network prefix
vm.startBroadcast();
BTCDepositAddressDeriver.BitcoinNetwork btcNetwork = BTCDepositAddressDeriver.BitcoinNetwork(network);
deriver.setSeed(
btcAddr1,
btcAddr2,
btcNetwork
);
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 @@ -18,12 +18,6 @@ error CannotParseBtcAddress(

contract BTCDepositAddressDeriver {

enum BitcoinNetwork {
TESTNET,
MAINNET,
REGTEST
}

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

bool public wasSeedSet;
Expand All @@ -49,7 +43,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 @@ -67,7 +67,7 @@ contract BTCDepositAddressDeriverTest is Test {
deriver.setSeed(
"tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3",
"tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz",
BTCDepositAddressDeriver.BitcoinNetwork.TESTNET
0
);

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

string memory btcAddress = deriver.getBTCDepositAddress(
Expand Down

0 comments on commit 900a328

Please sign in to comment.