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

added simnet network #29

Merged
merged 2 commits into from
Jul 6, 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
9 changes: 8 additions & 1 deletion src/BitcoinNetworkEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ library BitcoinNetworkEncoder {
bytes constant BTC_BECH32_MAINNET_BYTES = hex"626331"; // prefix = bc1
bytes constant BTC_BECH32_TESTNET_BYTES = hex"746231"; // prefix = tb1
bytes constant BTC_BECH32_REGTEST_BYTES = hex"6263727431"; // prefix = bcrt1
bytes constant BTC_BECH32_SIMNET_BYTES = hex"736231"; // prefix = sb1

string constant BTC_BECH32_MAINNET = 'bc';
string constant BTC_BECH32_TESTNET = 'tb';
string constant BTC_BECH32_REGTEST = 'brct';
string constant BTC_BECH32_SIMNET = 'sb';

//NB: don't forget to update `lnbtc_ext.go` when changing this enum!
enum Network {
Mainnet,
Testnet,
Regtest
Regtest,
Simnet
}

function getBtcBech32Prefix(Network _network) public pure returns (bytes memory) {
Expand All @@ -26,6 +29,8 @@ library BitcoinNetworkEncoder {
return BTC_BECH32_REGTEST_BYTES;
} else if (_network == Network.Testnet) {
return BTC_BECH32_TESTNET_BYTES;
} else if (_network == Network.Simnet) {
return BTC_BECH32_SIMNET_BYTES;
} else {
revert("Unknown network type");
}
Expand All @@ -38,6 +43,8 @@ library BitcoinNetworkEncoder {
return BTC_BECH32_TESTNET;
} else if (_network == Network.Regtest) {
return BTC_BECH32_REGTEST;
} else if (_network == Network.Simnet) {
return BTC_BECH32_SIMNET;
} else {
revert("Unknown network type");
}
Expand Down
6 changes: 6 additions & 0 deletions src/BitcoinUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ contract BitcoinUtils {
bytes constant BTC_P2SH_TESTNET = hex"6d"; // prefix = m
bytes constant BTC_P2PKH_REGTEST = hex"32"; // prefix = 2
bytes constant BTC_P2SH_REGTEST = hex"6d"; // prefix = m
bytes constant BTC_P2PKH_SIMNET = hex"3f"; // prefix = S
bytes constant BTC_P2SH_SIMNET = hex"7b"; // prefix = s

function getBtcBase58_P2PKH(BitcoinNetworkEncoder.Network network) public pure returns (bytes memory) {
if (network == BitcoinNetworkEncoder.Network.Mainnet) {
Expand All @@ -92,6 +94,8 @@ contract BitcoinUtils {
return BTC_P2PKH_REGTEST;
} else if (network == BitcoinNetworkEncoder.Network.Testnet) {
return BTC_P2PKH_TESTNET;
} else if (network == BitcoinNetworkEncoder.Network.Simnet) {
return BTC_P2PKH_SIMNET;
} else {
revert("Unknown network type");
}
Expand All @@ -104,6 +108,8 @@ contract BitcoinUtils {
return BTC_P2SH_REGTEST;
} else if (network == BitcoinNetworkEncoder.Network.Testnet) {
return BTC_P2SH_TESTNET;
} else if (network == BitcoinNetworkEncoder.Network.Simnet) {
return BTC_P2SH_SIMNET;
} else {
revert("Unknown network type");
}
Expand Down