Skip to content

Commit

Permalink
Changed selector types
Browse files Browse the repository at this point in the history
  • Loading branch information
BlobMaster41 committed Jun 21, 2024
1 parent d9c929a commit 7e84f3c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "@btc-vision/bsi-binary",
"version": "1.0.17",
"version": "1.0.18",
"author": "BlobMaster41",
"description": "OPNet official buffer serialization and deserialization library",
"main": "build/index.js",
Expand Down
27 changes: 5 additions & 22 deletions src/buffer/BinaryReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
i32, MAX_EVENT_DATA_SIZE, MAX_EVENTS,
MethodMap,
PointerStorage,
PropertyABIMap,
Selector,
SelectorsMap,
u16,
Expand Down Expand Up @@ -66,19 +65,6 @@ export class BinaryReader {
return this.readBytes(length);
}

public readSelectors(): PropertyABIMap {
const selectors: PropertyABIMap = new Map();
const length = this.readU16();

for (let i = 0; i < length; i++) {
const selectorData = this.readABISelector();

selectors.set(selectorData.name, selectorData.selector);
}

return selectors;
}

public readABISelector(): ABIRegistryItem {
const name = this.readStringWithLength();
const selector = this.readSelector();
Expand All @@ -91,11 +77,11 @@ export class BinaryReader {

public readViewSelectorsMap(): SelectorsMap {
const map: SelectorsMap = new Map();

const length = this.readU16();

for (let i = 0; i < length; i++) {
const key = this.readAddress();
const value = this.readSelectors();
const key = this.readStringWithLength();
const value = this.readSelector();

map.set(key, value);
}
Expand All @@ -104,14 +90,11 @@ export class BinaryReader {
}

public readMethodSelectorsMap(): MethodMap {
const map: MethodMap = new Map();
const map: MethodMap = new Set();
const length = this.readU16();

for (let i = 0; i < length; i++) {
const key = this.readAddress();
const value = this.readMethodSelectors();

map.set(key, value);
map.add(this.readSelector());
}

return map;
Expand Down
31 changes: 0 additions & 31 deletions src/buffer/BinaryWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
i32,
MethodMap,
PointerStorage,
PropertyABIMap,
Selector,
SelectorsMap,
u16,
Expand Down Expand Up @@ -128,28 +127,6 @@ export class BinaryWriter {
this.writeString(value);
}

public writeViewSelectorMap(map: SelectorsMap): void {
this.writeU16(map.size);

map.forEach(
(value: PropertyABIMap, key: string, _map: Map<string, PropertyABIMap>): void => {
this.writeAddress(key);
this.writeSelectors(value);
},
);
}

public writeMethodSelectorsMap(map: MethodMap): void {
this.writeU16(map.size);

map.forEach(
(value: Set<Selector>, key: Address, _map: Map<Address, Set<Selector>>): void => {
this.writeAddress(key);
this.writeMethodSelectorMap(value);
},
);
}

public getBuffer(clear: boolean = true): Uint8Array {
const buf = new Uint8Array(this.buffer.byteLength);
for (let i: u32 = 0; i < this.buffer.byteLength; i++) {
Expand Down Expand Up @@ -258,14 +235,6 @@ export class BinaryWriter {
});
}

private writeSelectors(value: PropertyABIMap): void {
this.writeU16(value.size);

value.forEach((selector: Selector, key: string, _map: Map<string, Selector>): void => {
this.writeABISelector(key, selector);
});
}

public writeAddressValueTupleMap(map: Map<Address, bigint>): void {
if (map.size > 65535) throw new Error('Map size is too large');

Expand Down
6 changes: 3 additions & 3 deletions src/buffer/types/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface ABIRegistryItem {
}

export type ContractABIMap = Set<Selector>;
export type PropertyABIMap = Map<string, Selector>;
export type SelectorsMap = Map<Address, PropertyABIMap>;
export type MethodMap = Map<Address, ContractABIMap>;
export type SelectorsMap = Map<string, Selector>;

export type MethodMap = Set<Selector>;

export const MAX_EVENT_DATA_SIZE: number = 256; // 256 bytes max
export const MAX_EVENTS: number = 8; // 8 events max per transactions.

0 comments on commit 7e84f3c

Please sign in to comment.