@btc-vision/btc-runtime 1.2.0 → 1.2.1

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.0",
3
+ "version": "1.2.1",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -64,7 +64,7 @@ export class BytesWriter {
64
64
  }
65
65
 
66
66
  public writeU256(value: u256): void {
67
- this.writeBytesU8Array(value.toBytes());
67
+ this.writeBytesU8Array(value.toUint8Array());
68
68
  }
69
69
 
70
70
  public writeTuple(value: u256[]): void {
@@ -77,19 +77,16 @@ export class BytesWriter {
77
77
  }
78
78
 
79
79
  public writeBytes(value: Uint8Array): void {
80
- this.writeBytesU8Array(changetype<u8[]>(value));
80
+ this.writeBytesU8Array(value);
81
81
  }
82
82
 
83
83
  @inline
84
- public writeBytesU8Array(value: u8[]): void {
84
+ public writeBytesU8Array(value: Uint8Array): void {
85
85
  this.allocSafe(value.length);
86
- const bytes = changetype<Uint8Array>(value).buffer;
87
- memory.copy(
88
- changetype<usize>(this.buffer.buffer) + this.currentOffset,
89
- changetype<usize>(bytes),
90
- <usize>value.length,
91
- );
92
- this.currentOffset += value.length;
86
+
87
+ for (let i = 0; i < value.length; i++) {
88
+ this.writeU8(value[i]);
89
+ }
93
90
  }
94
91
 
95
92
  public writeBytesWithLength(value: Uint8Array): void {
@@ -155,10 +155,10 @@ export class BlockchainEnvironment {
155
155
 
156
156
  public emit(event: NetEvent): void {
157
157
  const data = event.getEventData();
158
- const buffer = new BytesWriter(32 + data.byteLength);
158
+ const buffer = new BytesWriter(event.eventType.length + 6 + data.byteLength);
159
159
 
160
160
  buffer.writeStringWithLength(event.eventType);
161
- buffer.writeBytesWithLength(event.getEventData());
161
+ buffer.writeBytesWithLength(data);
162
162
 
163
163
  emit(buffer.getBuffer());
164
164
  }
@@ -7,6 +7,7 @@ import { Address, ADDRESS_BYTE_LENGTH } from '../../types/Address';
7
7
  export class MintEvent extends NetEvent {
8
8
  constructor(address: Address, amount: u256) {
9
9
  const data: BytesWriter = new BytesWriter(32 + ADDRESS_BYTE_LENGTH);
10
+
10
11
  data.writeAddress(address);
11
12
  data.writeU256(amount);
12
13