Skip to content

Commit 7e6d93b

Browse files
committed
feat(utxo-staking): add coreDao devnet chain id
Ticket: SC-356
1 parent 224061e commit 7e6d93b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

modules/utxo-staking/src/coreDao/opReturn.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { payments, networks } from '@bitgo/utxo-lib';
22

3+
export const CORE_DAO_DEVNET_CHAIN_ID = Buffer.from('0458', 'hex');
34
// Source: https://docs.coredao.org/docs/Learn/products/btc-staking/design
45
export const CORE_DAO_TESTNET_CHAIN_ID = Buffer.from('045b', 'hex');
56
export const CORE_DAO_MAINNET_CHAIN_ID = Buffer.from('045c', 'hex');
@@ -77,7 +78,7 @@ export function createCoreDaoOpReturnOutputScript({
7778
}
7879
const versionBuffer = Buffer.alloc(1, version);
7980

80-
if (!(chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) {
81+
if (!(chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) {
8182
throw new Error('Invalid chain ID');
8283
}
8384

@@ -122,7 +123,7 @@ export function createCoreDaoOpReturnOutputScript({
122123

123124
const payment = payments.embed({
124125
data: [data],
125-
network: chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) ? networks.testnet : networks.bitcoin,
126+
network: chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) ? networks.testnet : networks.bitcoin,
126127
});
127128
if (!payment.output) {
128129
throw new Error('Unable to create OP_RETURN output');
@@ -166,10 +167,14 @@ export function parseCoreDaoOpReturnOutputScript(script: Buffer): OpReturnParams
166167

167168
// Decode chainId
168169
const chainId = Buffer.from(dataBuffer.subarray(offset, offset + 2));
169-
if (!(chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) {
170-
throw new Error(
171-
`Invalid ChainID: ${chainId.toString('hex')}. Must be either 0x045b (testnet) or 0x045c (mainnet).`
172-
);
170+
if (
171+
!(
172+
chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) ||
173+
chainId.equals(CORE_DAO_MAINNET_CHAIN_ID) ||
174+
chainId.equals(CORE_DAO_TESTNET_CHAIN_ID)
175+
)
176+
) {
177+
throw new Error(`Invalid ChainID: ${chainId.toString('hex')}. Must be either 0x0458 (devnet) or 0x045c (mainnet).`);
173178
}
174179
offset += 2;
175180

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6a4c505341542b01045bde60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1a9e209f5ea0036c8c2f41078a3cebee57d8a47d501041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac
1+
6a4c505341542b010458de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1a9e209f5ea0036c8c2f41078a3cebee57d8a47d501041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac

modules/utxo-staking/test/unit/coreDao/opReturn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('OP_RETURN', function () {
238238
assert.deepStrictEqual(
239239
createCoreDaoOpReturnOutputScript({
240240
version: 1,
241-
chainId: Buffer.from('045b', 'hex'),
241+
chainId: Buffer.from('0458', 'hex'),
242242
delegator: Buffer.from('de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1', 'hex'),
243243
validator: Buffer.from('a9e209f5ea0036c8c2f41078a3cebee57d8a47d5', 'hex'),
244244
fee: 1,
@@ -315,7 +315,7 @@ describe('OP_RETURN', function () {
315315
});
316316

317317
it('should fail if the chainId is incorrect', function () {
318-
const script = defaultScript.replace('045b', '0454');
318+
const script = defaultScript.replace('0458', '0454');
319319
assert.throws(() => parseCoreDaoOpReturnOutputScript(Buffer.from(script, 'hex')));
320320
});
321321
});

0 commit comments

Comments
 (0)