Skip to content

Commit e2d8875

Browse files
committed
Latest Libauth, add P2SH32 support
1 parent 3d48221 commit e2d8875

File tree

13 files changed

+124
-66
lines changed

13 files changed

+124
-66
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"private": true,
55
"devDependencies": {
6-
"@bitauth/libauth": "3.1.0-next.0",
6+
"@bitauth/libauth": "3.1.0-next.1",
77
"@blueprintjs/core": "^5.8.2",
88
"@blueprintjs/icons": "^5.7.0",
99
"@blueprintjs/select": "^5.0.23",

src/editor/Editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export const Editor = connect(
190190
deleteScript={props.deleteScript}
191191
editScript={props.editScript}
192192
frame={computed.scriptEditorFrames[indexFromTop]!}
193-
isP2SH={computed.lockingType === 'p2sh20'}
193+
lockingType={computed.lockingType}
194194
isPushed={computed.isPushed}
195195
scriptDetails={computed.scriptDetails}
196196
setCursorLine={setCursorLine[indexFromTop]!}

src/editor/dialogs/edit-script-dialog/EditScriptDialog.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import '../editor-dialog.css';
22
import { ActionCreators } from '../../../state/reducer';
3-
import { ScriptType } from '../../../state/types';
3+
import {
4+
LockingType,
5+
lockingTypeDescriptions,
6+
lockingTypes,
7+
ScriptType,
8+
} from '../../../state/types';
49
import { toConventionalId } from '../../common';
510

611
import {
@@ -9,6 +14,7 @@ import {
914
Classes,
1015
Dialog,
1116
FormGroup,
17+
HTMLSelect,
1218
InputGroup,
1319
Intent,
1420
Switch,
@@ -21,7 +27,7 @@ export const EditScriptDialog = ({
2127
name,
2228
internalId,
2329
id,
24-
isP2SH,
30+
lockingType,
2531
isPushed,
2632
isOpen,
2733
closeDialog,
@@ -33,8 +39,8 @@ export const EditScriptDialog = ({
3339
name: string;
3440
internalId: string;
3541
id: string;
36-
isP2SH?: boolean;
37-
isPushed?: boolean;
42+
lockingType: LockingType;
43+
isPushed: boolean;
3844
usedIds: string[];
3945
editScript: typeof ActionCreators.editScript;
4046
deleteScript: typeof ActionCreators.deleteScript;
@@ -43,7 +49,7 @@ export const EditScriptDialog = ({
4349
}) => {
4450
const [scriptName, setScriptName] = useState(name);
4551
const [scriptId, setScriptId] = useState(id);
46-
const [scriptIsP2SH, setScriptIsP2SH] = useState(isP2SH);
52+
const [scriptLockingType, setScriptLockingType] = useState(lockingType);
4753
const [scriptIsPushed, setScriptIsPushed] = useState(isPushed);
4854
const [nonUniqueId, setNonUniqueId] = useState('');
4955
const [promptDelete, setPromptDelete] = useState(false);
@@ -55,7 +61,7 @@ export const EditScriptDialog = ({
5561
onOpening={() => {
5662
setScriptName(name);
5763
setScriptId(id);
58-
setScriptIsP2SH(isP2SH);
64+
setScriptLockingType(lockingType);
5965
setNonUniqueId('');
6066
}}
6167
onClose={() => {
@@ -117,22 +123,16 @@ export const EditScriptDialog = ({
117123
)}
118124
{scriptType === 'locking' && (
119125
<FormGroup
120-
helperText={
121-
<span>
122-
If enabled, this script will be nested in the standard P2SH
123-
template.
124-
</span>
125-
}
126+
helperText={lockingTypeDescriptions[scriptLockingType]}
126127
label="Script Mode"
127128
labelFor="script-p2sh"
128129
inline={true}
129130
>
130-
<Switch
131-
checked={scriptIsP2SH}
131+
<HTMLSelect
132132
id="script-p2sh"
133-
label="Enable P2SH"
134-
onChange={() => {
135-
setScriptIsP2SH(!scriptIsP2SH);
133+
options={lockingTypes}
134+
onChange={(e) => {
135+
setScriptLockingType(e.currentTarget.value as LockingType);
136136
}}
137137
/>
138138
</FormGroup>
@@ -212,7 +212,7 @@ export const EditScriptDialog = ({
212212
scriptName === '' ||
213213
(scriptName === name &&
214214
scriptId === id &&
215-
scriptIsP2SH === isP2SH &&
215+
scriptLockingType === lockingType &&
216216
scriptIsPushed === isPushed) ||
217217
(!isTest && scriptId === '')
218218
}
@@ -224,7 +224,7 @@ export const EditScriptDialog = ({
224224
internalId,
225225
name: scriptName,
226226
id: scriptId,
227-
lockingType: scriptIsP2SH ? 'p2sh20' : 'standard',
227+
lockingType: scriptLockingType,
228228
isPushed: scriptIsPushed,
229229
});
230230
closeDialog();

src/editor/dialogs/new-script-dialog/NewScriptDialog.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
ActiveDialog,
55
BaseScriptType,
66
CurrentScripts,
7-
ScriptType,
7+
scriptTypes,
8+
typeDescriptions,
89
} from '../../../state/types';
910
import { createInsecureUuidV4 } from '../../../utils';
1011
import { toConventionalId } from '../../common';
@@ -20,28 +21,6 @@ import {
2021
import { WarningSign } from '@blueprintjs/icons';
2122
import React, { useState } from 'react';
2223

23-
const scriptTypes: { label: string; value: ScriptType }[] = [
24-
{ label: 'Locking Script', value: 'locking' },
25-
{ label: 'Unlocking Script', value: 'unlocking' },
26-
{ label: 'Isolated Script', value: 'isolated' },
27-
{ label: 'Script Test', value: 'test-setup' },
28-
];
29-
30-
const typeDescriptions: { [key in ScriptType]: string } = {
31-
locking:
32-
'Locking scripts hold funds. A locking script is the “challenge” which must be unlocked to spend a transaction output. An “Address” is simply an abstraction for a specific locking script.',
33-
unlocking:
34-
'An unlocking script spends from a locking script. To create a transaction, the spender must provide a valid unlocking script for each input being spent. (A locking script can be unlocked by multiple unlocking scripts.)',
35-
isolated:
36-
'An isolated script is useful for constructions like checksums or re-usable utility scripts (which can be used inside other scripts). Isolated scripts can have script tests, e.g. utility scripts can be tested to ensure they perform a series of operations properly.',
37-
'test-setup':
38-
'A script test is applied to an isolated script. Each script test has a “setup” phase which is evaluated before the tested script, and a “check” phase which is evaluated after. The test passes if the “check” script leaves a single Script Number 1 on the stack.',
39-
tested:
40-
'Something is broken: tested scripts should be created by assigning a test-setup script to an isolated script.',
41-
'test-check':
42-
'Something is broken: script tests should use the `test-setup` type in this dialog.',
43-
};
44-
4524
const hasParent = (scriptType: BaseScriptType) =>
4625
scriptType === 'unlocking' || scriptType === 'test-setup';
4726

src/editor/editor-state.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
CompilationResultSuccess,
2727
createCompiler,
2828
createVirtualMachineBch2023,
29+
createVirtualMachineBch2025,
30+
createVirtualMachineBch2026,
2931
createVirtualMachineBchSpec,
3032
encodeDataPush,
3133
EvaluationSample,
@@ -106,7 +108,11 @@ export const computeEditorState = <
106108
const vm =
107109
state.currentVmId === 'BCH_2023_05'
108110
? createVirtualMachineBch2023()
109-
: createVirtualMachineBchSpec();
111+
: state.currentVmId === 'BCH_2025_05'
112+
? createVirtualMachineBch2025()
113+
: state.currentVmId === 'BCH_2026_05'
114+
? createVirtualMachineBch2026()
115+
: createVirtualMachineBchSpec();
110116
const compiler = createCompiler(configuration);
111117

112118
/**

src/editor/evaluation-viewer/EvaluationViewer.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ const stackItem = (
104104
</Popover>
105105
);
106106

107+
const elideAt = 200;
108+
const splitAt = 100;
109+
const elideDigits = (digits: string) =>
110+
digits.length < elideAt
111+
? digits
112+
: `${digits.slice(0, splitAt)} \u2026 (${digits.length - elideAt} total digits) \u2026 ${digits.slice(-splitAt)}`;
113+
const elideHex = (characters: string) =>
114+
characters.length < elideAt
115+
? characters
116+
: `${characters.slice(0, splitAt)} \u2026 (${(characters.length - 2) / 2} total bytes) \u2026 ${characters.slice(-splitAt)}`;
117+
107118
const getStackItemDisplaySettings = (
108119
item: Uint8Array,
109120
settings: EvaluationViewerSettings,
@@ -122,7 +133,7 @@ const getStackItemDisplaySettings = (
122133
const number = vmNumberToBigInt(item, {
123134
maximumVmNumberByteLength:
124135
settings.vmNumbersDisplayFormat === 'bigint'
125-
? 258
136+
? 10_000
126137
: settings.supportBigInt
127138
? 19
128139
: 8,
@@ -132,17 +143,17 @@ const getStackItemDisplaySettings = (
132143
settings.vmNumbersDisplayFormat === 'integer' ||
133144
settings.vmNumbersDisplayFormat === 'bigint'
134145
) {
135-
return { hex, type: 'number' as const, label: `${number}` };
146+
return { hex, type: 'number' as const, label: elideDigits(`${number}`) };
136147
}
137148
if (settings.vmNumbersDisplayFormat === 'binary') {
138149
return {
139150
hex,
140151
type: 'binary' as const,
141-
label: `0b${binToBinString(item)}`,
152+
label: elideDigits(`0b${binToBinString(item)}`),
142153
};
143154
}
144155
}
145-
return { hex, type: 'hex' as const, label: hex };
156+
return { hex, type: 'hex' as const, label: elideHex(hex) };
146157
};
147158

148159
// TODO: modernize
@@ -378,7 +389,7 @@ const EvaluationLine = ({
378389
);
379390
return stackItem(
380391
itemIndex,
381-
hex,
392+
elideHex(hex),
382393
<span className={`stack-item ${type}`}>
383394
{settings.abbreviateLongStackItems
384395
? abbreviateStackItem(label)
@@ -654,7 +665,7 @@ export const ViewerControls = ({
654665
</Tooltip>
655666
) : evaluationViewerSettings.vmNumbersDisplayFormat === 'bigint' ? (
656667
<Tooltip
657-
content="Showing VM Numbers in integer format (up to 258 bytes)"
668+
content="Showing VM Numbers in integer format (up to maximum length)"
658669
portalClassName="control-tooltip"
659670
position="bottom-right"
660671
>

src/editor/script-editor/ScriptEditor.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@
4747

4848
.script-tag {
4949
font-size: 0.7em;
50-
background-color: #2e7105;
5150
border-radius: 3px;
5251
display: inline-block;
5352
padding: 0.1em 0.5em;
5453
margin-left: 1em;
5554
}
5655

57-
.p2sh-tag {
56+
.locking-type-tag {
5857
text-transform: uppercase;
59-
background-color: #2e7105;
58+
background-color: var(--editor-background-color);
6059
}
6160

6261
.pushed-tag {

src/editor/script-editor/ScriptEditor.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { MonacoMarkerDataRequired } from '../../cash-assembly/editor-tooling';
33
import { ActionCreators } from '../../state/reducer';
44
import {
55
IDESupportedProgramState,
6+
LockingType,
7+
lockingTypeDescriptions,
68
ScriptDetails,
79
VariableDetails,
810
} from '../../state/types';
@@ -202,7 +204,7 @@ const updateMarkers =
202204

203205
export const ScriptEditor = (props: {
204206
frame: ScriptEditorFrame<IDESupportedProgramState>;
205-
isP2SH: boolean;
207+
lockingType: LockingType;
206208
isPushed: boolean;
207209
scriptDetails: ScriptDetails;
208210
variableDetails: VariableDetails;
@@ -803,12 +805,26 @@ export const ScriptEditor = (props: {
803805
{name}
804806
{scriptType === 'test-setup' && <span>&nbsp;(Setup)</span>}
805807
{scriptType === 'test-check' && <span>&nbsp;(Check)</span>}
806-
{props.isP2SH && (
808+
{props.lockingType === 'p2sh20' ? (
807809
<span
808-
className="script-tag p2sh-tag"
809-
title="This is a P2SH script. The P2SH boilerplate is automatically included during compilation."
810+
className="script-tag locking-type-tag"
811+
title={lockingTypeDescriptions.p2sh20}
810812
>
811-
P2SH
813+
P2SH20
814+
</span>
815+
) : props.lockingType === 'p2sh32' ? (
816+
<span
817+
className="script-tag locking-type-tag"
818+
title={lockingTypeDescriptions.p2sh32}
819+
>
820+
P2SH32
821+
</span>
822+
) : (
823+
<span
824+
className="script-tag locking-type-tag"
825+
title={lockingTypeDescriptions.standard}
826+
>
827+
bare
812828
</span>
813829
)}
814830
{props.isPushed && scriptType === 'tested' && (
@@ -870,7 +886,7 @@ export const ScriptEditor = (props: {
870886
id={id}
871887
name={name}
872888
scriptType={scriptType}
873-
isP2SH={props.isP2SH}
889+
lockingType={props.lockingType}
874890
isPushed={props.isPushed}
875891
closeDialog={() => {
876892
setEditScriptDialogIsOpen(false);

src/header/HeaderBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const ideModes: IDESupportedModes[] = [
4747

4848
const vms: IDESupportedVirtualMachine[] = [
4949
{ id: 'BCH_2023_05', name: 'BCH 2023 VM', disabled: false },
50-
// { id: 'BCH_2025_05', name: 'BCH 2025 VM', disabled: false },
51-
// { id: 'BCH_2026_05', name: 'BCH 2026 VM', disabled: false },
50+
{ id: 'BCH_2025_05', name: 'BCH 2025 VM', disabled: false },
51+
{ id: 'BCH_2026_05', name: 'BCH 2026 VM', disabled: true },
5252
{ id: 'BCH_SPEC', name: 'BCH SPEC VM', disabled: false },
5353
{ id: 'BTC_2017_08', name: 'BTC 2017 VM', disabled: true },
5454
{ id: 'BSV_2020_02', name: 'BSV 2020 VM', disabled: true },

src/state/defaults.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export const emptyTemplate: WalletTemplate = {
1515
name: 'Untitled',
1616
entities: {},
1717
scripts: {},
18-
supported: ['BCH_2023_05', 'BCH_SPEC'] as IDESupportedVM[],
18+
supported: [
19+
'BCH_2023_05',
20+
'BCH_2025_05',
21+
'BCH_2026_05',
22+
'BCH_SPEC',
23+
] as IDESupportedVM[],
1924
version: 0 as const,
2025
};
2126

src/state/reducer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class App extends ImmerReducer<AppState> {
527527
) {
528528
this.draftState.currentVmId = firstSupportedVm;
529529
this.draftState.evaluationViewerSettings.supportBigInt =
530-
firstSupportedVm === 'BCH_SPEC';
530+
firstSupportedVm !== 'BCH_2023_05';
531531
}
532532
this.draftState.templateLoadTime = new Date();
533533
this.draftState.currentTemplate = template;
@@ -559,7 +559,8 @@ class App extends ImmerReducer<AppState> {
559559
}
560560
activateVm(vm: IDESupportedVM) {
561561
this.draftState.currentVmId = vm;
562-
this.draftState.evaluationViewerSettings.supportBigInt = vm === 'BCH_SPEC';
562+
this.draftState.evaluationViewerSettings.supportBigInt =
563+
vm !== 'BCH_2023_05';
563564
}
564565
}
565566

0 commit comments

Comments
 (0)