@btc-vision/btc-runtime 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -187,7 +187,7 @@ export class BytesReader {
187
187
  }
188
188
 
189
189
  public readAddress(): Address {
190
- return this.readString(ADDRESS_BYTE_LENGTH);
190
+ return this.readString(<u16>ADDRESS_BYTE_LENGTH);
191
191
  }
192
192
 
193
193
  public getOffset(): i32 {
@@ -64,7 +64,12 @@ export class BytesWriter {
64
64
  }
65
65
 
66
66
  public writeU256(value: u256): void {
67
- this.writeBytesU8Array(value.toUint8Array());
67
+ this.allocSafe(32);
68
+
69
+ const bytes = value.toUint8Array(true);
70
+ for (let i: i32 = 0; i < 32; i++) {
71
+ this.writeU8(bytes[i] || 0);
72
+ }
68
73
  }
69
74
 
70
75
  public writeTuple(value: u256[]): void {
@@ -77,11 +82,15 @@ export class BytesWriter {
77
82
  }
78
83
 
79
84
  public writeBytes(value: Uint8Array): void {
80
- this.writeBytesU8Array(value);
85
+ this.allocSafe(value.length);
86
+
87
+ for (let i = 0; i < value.length; i++) {
88
+ this.writeU8(value[i]);
89
+ }
81
90
  }
82
91
 
83
92
  @inline
84
- public writeBytesU8Array(value: Uint8Array): void {
93
+ public writeBytesU8Array(value: u8[]): void {
85
94
  this.allocSafe(value.length);
86
95
 
87
96
  for (let i = 0; i < value.length; i++) {
@@ -233,7 +242,7 @@ export class BytesWriter {
233
242
  }
234
243
 
235
244
  private fromAddress(value: Address): Uint8Array {
236
- if (value.length > i32(ADDRESS_BYTE_LENGTH)) {
245
+ if (value.length > ADDRESS_BYTE_LENGTH) {
237
246
  throw new Revert(`Address is too long ${value.length} > ${ADDRESS_BYTE_LENGTH} bytes`);
238
247
  }
239
248
 
@@ -243,7 +252,7 @@ export class BytesWriter {
243
252
  bytes[i] = value.charCodeAt(i);
244
253
  }
245
254
 
246
- if (value.length < i32(ADDRESS_BYTE_LENGTH)) {
255
+ if (value.length < ADDRESS_BYTE_LENGTH) {
247
256
  bytes[value.length] = 0;
248
257
  }
249
258
 
@@ -1,5 +1,5 @@
1
1
  import { Potential } from '../lang/Definitions';
2
2
 
3
- export const ADDRESS_BYTE_LENGTH: u8 = 66;
3
+ export const ADDRESS_BYTE_LENGTH: i32 = 66;
4
4
  export declare type Address = string;
5
5
  export declare type PotentialAddress = Potential<Address>;