Skip to content

Commit 28864a3

Browse files
committed
Address some TODOs about removing old code and add some new TODOs
1 parent 3671a21 commit 28864a3

3 files changed

Lines changed: 7 additions & 35 deletions

File tree

packages/cashscript/src/LibauthTemplate.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import { Contract } from './Contract.js';
3131
import { DebugResults, debugTemplate } from './debugging.js';
3232
import {
3333
HashType,
34+
isContractUnlocker,
3435
isP2PKHUnlocker,
3536
isStandardUnlockableUtxo,
3637
isUnlockableUtxo,
37-
isUtxoP2PKH,
3838
LibauthTokenDetails,
3939
Output,
4040
SignatureAlgorithm,
@@ -280,6 +280,7 @@ export const generateTemplateScenarios = (
280280
const encodedConstructorArgs = contract.encodedConstructorArgs;
281281
const scenarioIdentifier = `${artifact.contractName}_${abiFunction.name}_input${inputIndex}_evaluate`;
282282

283+
// TODO: Update scenario descriptions
283284
const scenarios = {
284285
// single scenario to spend out transaction under test given the CashScript parameters provided
285286
[scenarioIdentifier]: {
@@ -324,6 +325,7 @@ export const generateTemplateScenariosP2PKH = (
324325

325326
const { signature, publicKey } = getSignatureAndPubkeyFromP2PKHInput(libauthTransaction.inputs[inputIndex]);
326327

328+
// TODO: Update scenario descriptions
327329
const scenarios = {
328330
// single scenario to spend out transaction under test given the CashScript parameters provided
329331
[scenarioIdentifier]: {
@@ -459,20 +461,14 @@ export const getLibauthTemplates = (
459461

460462
// We can typecast this because we check that all inputs are standard unlockable at the top of this function
461463
for (const [inputIndex, input] of (txn.inputs as StandardUnlockableUtxo[]).entries()) {
462-
// If template exists on the input, it indicates this is a P2PKH (Pay to Public Key Hash) input
463-
if ('template' in input.unlocker) {
464-
// @ts-ignore TODO: Remove UtxoP2PKH type and only use UnlockableUtxo in Libauth Template generation
465-
input.template = input.unlocker?.template; // Added to support P2PKH inputs in buildTemplate
464+
if (isP2PKHUnlocker(input.unlocker)) {
466465
Object.assign(p2pkhEntities, generateTemplateEntitiesP2PKH(inputIndex));
467466
Object.assign(p2pkhScripts, generateTemplateScriptsP2PKH(inputIndex));
468-
469-
Object.assign(scenarios, generateTemplateScenariosP2PKH(libauthTransaction, csTransaction as any, inputIndex));
470-
467+
Object.assign(scenarios, generateTemplateScenariosP2PKH(libauthTransaction, csTransaction, inputIndex));
471468
continue;
472469
}
473470

474-
// If contract exists on the input, it indicates this is a contract input
475-
if ('contract' in input.unlocker) {
471+
if (isContractUnlocker(input.unlocker)) {
476472
const contract = input.unlocker?.contract;
477473
const abiFunction = input.unlocker?.abiFunction;
478474

@@ -807,23 +803,6 @@ export const generateTemplateScenarioBytecode = (
807803
): WalletTemplateScenarioBytecode | ['slot'] => {
808804
if (insertSlot) return ['slot'];
809805

810-
const p2pkhScriptName = `${p2pkhScriptNameTemplate}_${inputIndex}`;
811-
812-
// This is for P2PKH inputs in the old transaction builder (TODO: remove when we remove old transaction builder)
813-
if (isUtxoP2PKH(input)) {
814-
const { signature, publicKey } = getSignatureAndPubkeyFromP2PKHInput(libauthInput);
815-
816-
return {
817-
script: p2pkhScriptName,
818-
overrides: {
819-
bytecode: {
820-
[`signature_${inputIndex}`]: `0x${binToHex(signature)}`,
821-
[`public_key_${inputIndex}`]: `0x${binToHex(publicKey)}`,
822-
},
823-
},
824-
};
825-
}
826-
827806
if (isUnlockableUtxo(input) && isStandardUnlockableUtxo(input)) {
828807
return generateUnlockingScriptParams(input, libauthInput, p2pkhScriptNameTemplate, inputIndex);
829808
}

packages/cashscript/src/interfaces.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ export function isPlaceholderUnlocker(unlocker: Unlocker): unlocker is Placehold
7575
return 'placeholder' in unlocker;
7676
}
7777

78-
export interface UtxoP2PKH extends Utxo {
79-
template: SignatureTemplate;
80-
}
81-
82-
export function isUtxoP2PKH(utxo: Utxo): utxo is UtxoP2PKH {
83-
return 'template' in utxo;
84-
}
85-
8678
export interface Recipient {
8779
to: string;
8880
amount: bigint;

packages/cashscript/src/network/MockNetworkProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class MockNetworkProvider implements NetworkProvider {
2525
this.options = { updateUtxoSet: true, ...options };
2626

2727
for (let i = 0; i < 3; i += 1) {
28+
// TODO: Don't seed the MockNetworkProvider with any UTXOs
2829
this.addUtxo(aliceAddress, randomUtxo());
2930
this.addUtxo(bobAddress, randomUtxo());
3031
this.addUtxo(carolAddress, randomUtxo());

0 commit comments

Comments
 (0)