11import "@stdlib/lisp-lists"
22import "@stdlib/gas-payments";
33
4- const ERROR_INVALID_DATA = 0x77;
5- const ERROR_BITMAP_OUT_OF_BOUNDS = 0x78;
4+ const Utils_FACILITY_NAME = "com.chainlink.ton.lib.Utils";
5+ // getFacilityId(stringCrc32(Utils_FACILITY_NAME));
6+ const Utils_FACILITY_ID = 489;
7+
8+ enum Utils_Error {
9+ InvalidData = Utils_FACILITY_ID * 100
10+ BitmapOutOfBounds
11+ }
612
713/// Returns the facility ID for the given CRC32 key (e.g. stringCrc32("com.chainlink.ton.mcms.Timelock")).
814/// Returns a value in range 10..649 (640 values).
@@ -119,7 +125,7 @@ fun Iterator<T>.next(mutate self): T {
119125 var (bits, refs) = self.data.remainingBitsAndRefsCount();
120126 if (bits == 0) {
121127 // for snakeData to be well formed, there should only be one reference
122- assert(refs == 1, ERROR_INVALID_DATA );
128+ assert(refs == 1, Utils_Error.InvalidData );
123129 self.data = self.data.loadRef().beginParse();
124130 }
125131 return self.data.loadAny<T>();
@@ -131,7 +137,7 @@ fun Iterator<T>.next(mutate self): T {
131137fun Iterator<T>.countBytes(self): int {
132138 val maxCells = 128;
133139 val (cellsCount, dataBitsSize, _cellRefs) = self.data.calculateSizeStrict(maxCells);
134- assert(dataBitsSize % 8 == 0, ERROR_INVALID_DATA );
140+ assert(dataBitsSize % 8 == 0, Utils_Error.InvalidData );
135141 return dataBitsSize / 8;
136142}
137143
@@ -141,7 +147,7 @@ fun Iterator<T>.countBytes(self): int {
141147// ExitCodes:
142148// - 0: no error
143149// - 8 (cell overflow): exceeded maxCells
144- // - ERROR_INVALID_DATA : data is invalid (not byte-aligned)
150+ // - Utils_Error.InvalidData : data is invalid (not byte-aligned)
145151@inline
146152fun Iterator<T>.countBytesSafe(self): (int, int) {
147153 try {
@@ -201,13 +207,13 @@ fun Bitmap256.new(): Bitmap256 {
201207
202208@inline
203209fun Bitmap256.set(mutate self, index: int): void {
204- assert(index >= 0 && index < 256, ERROR_BITMAP_OUT_OF_BOUNDS );
210+ assert(index >= 0 && index < 256, Utils_Error.BitmapOutOfBounds );
205211 self.bits = self.bits | (1 << index);
206212}
207213
208214@inline
209215fun Bitmap256.has(self, index: int): bool {
210- assert(index >= 0 && index < 256, ERROR_BITMAP_OUT_OF_BOUNDS );
216+ assert(index >= 0 && index < 256, Utils_Error.BitmapOutOfBounds );
211217 return (self.bits & (1 << index)) != 0;
212218}
213219
@@ -216,7 +222,7 @@ fun Bitmap256.has(self, index: int): bool {
216222fun countAddresses(data: cell): int {
217223 val maxCells = 128;
218224 val (cellsCount, dataBitsSize, cellRefs) = data.calculateSizeStrict(maxCells);
219- assert(dataBitsSize % ADDR_KEY_LEN == 0, ERROR_INVALID_DATA );
225+ assert(dataBitsSize % ADDR_KEY_LEN == 0, Utils_Error.InvalidData );
220226 return dataBitsSize / ADDR_KEY_LEN;
221227}
222228
0 commit comments