MCPcopy Create free account
hub / github.com/CashScript/cashscript / createUnlockingBytecode

Function createUnlockingBytecode

packages/cashscript/src/utils.ts:234–249  ·  view source on GitHub ↗
(
  contractType: ContractType,
  contractBytecode: Uint8Array,
  encodedArgs: Uint8Array[],
  selector?: number,
)

Source from the content-addressed store, hash-verified

232
233// ////////// BUILD OBJECTS ///////////////////////////////////////////////////
234export function createUnlockingBytecode(
235 contractType: ContractType,
236 contractBytecode: Uint8Array,
237 encodedArgs: Uint8Array[],
238 selector?: number,
239): Uint8Array {
240 const unlockScript = [...encodedArgs].reverse();
241 if (selector !== undefined) unlockScript.push(encodeInt(BigInt(selector)));
242
243 // P2S inputs do not need to provide the redeem script
244 if (contractType === 'p2s') return scriptToBytecode(unlockScript);
245
246 // Create input script and compile it to bytecode
247 const inputScript = [...unlockScript, contractBytecode];
248 return scriptToBytecode(inputScript);
249}
250
251export function createOpReturnOutput(
252 opReturnData: string[],

Callers 2

util.test.tsFile · 0.85

Calls 2

encodeIntFunction · 0.90
scriptToBytecodeFunction · 0.90

Tested by

no test coverage detected