Skip to content

Commit cee4e3f

Browse files
committed
Remove duplicate code from cashscript SDK => utils.ts
1 parent d57af68 commit cee4e3f

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

packages/cashscript/src/utils.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
generateSigningSerializationBch,
99
utf8ToBin,
1010
hexToBin,
11-
flattenBinArray,
1211
LockingBytecodeType,
1312
encodeTransactionOutput,
1413
isHex,
@@ -24,6 +23,7 @@ import {
2423
Op,
2524
Script,
2625
scriptToBytecode,
26+
encodeNullDataScript,
2727
} from '@cashscript/utils';
2828
import {
2929
Utxo,
@@ -302,30 +302,6 @@ export function getNetworkPrefix(network: string): 'bitcoincash' | 'bchtest' | '
302302
}
303303
}
304304

305-
// ////////////////////////////////////////////////////////////////////////////
306-
// For encoding OP_RETURN data (doesn't require BIP62.3 / MINIMALDATA)
307-
function encodeNullDataScript(chunks: (number | Uint8Array)[]): Uint8Array {
308-
return flattenBinArray(
309-
chunks.map((chunk) => {
310-
if (typeof chunk === 'number') {
311-
return new Uint8Array([chunk]);
312-
}
313-
314-
const pushdataOpcode = getPushDataOpcode(chunk);
315-
return new Uint8Array([...pushdataOpcode, ...chunk]);
316-
}),
317-
);
318-
}
319-
320-
function getPushDataOpcode(data: Uint8Array): Uint8Array {
321-
const { byteLength } = data;
322-
323-
if (byteLength === 0) return Uint8Array.from([0x4c, 0x00]);
324-
if (byteLength < 76) return Uint8Array.from([byteLength]);
325-
if (byteLength < 256) return Uint8Array.from([0x4c, byteLength]);
326-
throw new Error('Pushdata too large');
327-
}
328-
329305
const randomInt = (): bigint => BigInt(Math.floor(Math.random() * 10000));
330306

331307
export const randomUtxo = (defaults?: Partial<Utxo>): Utxo => ({

0 commit comments

Comments
 (0)