Skip to content

Commit

Permalink
added simnet network (#29)
Browse files Browse the repository at this point in the history
* added simnet network

* fix bug

---------

Co-authored-by: Viacheslav Zhygulin <[email protected]>
  • Loading branch information
szhygulin and Viacheslav Zhygulin authored Jul 6, 2024
1 parent 4c27632 commit 5d770d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 5d770d6

Please sign in to comment.