Skip to content

Commit 28af481

Browse files
committed
Revert "fix: change NativeScripts type to array"
This reverts commit b651933.
1 parent e14bc76 commit 28af481

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

conway-cddl/yaml/conway.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ Vkeywitnesses:
17541754
item: Vkeywitness
17551755

17561756
NativeScripts:
1757-
type: array
1757+
type: set
17581758
item: NativeScript
17591759

17601760
BootstrapWitnesses:

src/generated.ts

+36-5
Original file line numberDiff line numberDiff line change
@@ -8997,14 +8997,20 @@ export class NativeScriptSource {
89978997
export class NativeScripts {
89988998
private items: NativeScript[];
89998999
private definiteEncoding: boolean;
9000+
private nonEmptyTag: boolean;
90009001

9001-
constructor(items: NativeScript[], definiteEncoding: boolean = true) {
9002+
private setItems(items: NativeScript[]) {
90029003
this.items = items;
9004+
}
9005+
9006+
constructor(definiteEncoding: boolean = true, nonEmptyTag: boolean = true) {
9007+
this.items = [];
90039008
this.definiteEncoding = definiteEncoding;
9009+
this.nonEmptyTag = nonEmptyTag;
90049010
}
90059011

90069012
static new(): NativeScripts {
9007-
return new NativeScripts([]);
9013+
return new NativeScripts();
90089014
}
90099015

90109016
len(): number {
@@ -9016,20 +9022,45 @@ export class NativeScripts {
90169022
return this.items[index];
90179023
}
90189024

9019-
add(elem: NativeScript): void {
9025+
add(elem: NativeScript): boolean {
9026+
if (this.contains(elem)) return true;
90209027
this.items.push(elem);
9028+
return false;
9029+
}
9030+
9031+
contains(elem: NativeScript): boolean {
9032+
for (let item of this.items) {
9033+
if (arrayEq(item.to_bytes(), elem.to_bytes())) {
9034+
return true;
9035+
}
9036+
}
9037+
return false;
90219038
}
90229039

90239040
static deserialize(reader: CBORReader, path: string[]): NativeScripts {
9041+
let nonEmptyTag = false;
9042+
if (reader.peekType(path) == "tagged") {
9043+
let tag = reader.readTaggedTag(path);
9044+
if (tag != 258) {
9045+
throw new Error("Expected tag 258. Got " + tag);
9046+
} else {
9047+
nonEmptyTag = true;
9048+
}
9049+
}
90249050
const { items, definiteEncoding } = reader.readArray(
90259051
(reader, idx) =>
9026-
NativeScript.deserialize(reader, [...path, "Elem#" + idx]),
9052+
NativeScript.deserialize(reader, [...path, "NativeScript#" + idx]),
90279053
path,
90289054
);
9029-
return new NativeScripts(items, definiteEncoding);
9055+
let ret = new NativeScripts(definiteEncoding, nonEmptyTag);
9056+
ret.setItems(items);
9057+
return ret;
90309058
}
90319059

90329060
serialize(writer: CBORWriter): void {
9061+
if (this.nonEmptyTag) {
9062+
writer.writeTaggedTag(258);
9063+
}
90339064
writer.writeArray(
90349065
this.items,
90359066
(writer, x) => x.serialize(writer),

0 commit comments

Comments
 (0)