btc-vision / btc-runtime

Assemblyscript btc runtime
MIT License
4 stars 2 forks source link

fix malformed constructor for byteswriter, fix typing for reader.read… #32

Closed youngslohmlife closed 2 weeks ago

youngslohmlife commented 2 weeks ago

BytesWriter constructor compilation was failing with message:

ERROR TS2564: Property '~lib/@btc-vision/btc-runtime/runtime/buffer/BytesWriter/BytesWriter#buffer' has no initializer and is not assigned in the con
structor before 'this' is used or returned.                                                                                                          
    :                                                                                                                                                
 28 │ private buffer: DataView;                                           
    │         ~~~~~~                                                                                                                                 
    └─ in ~lib/@btc-vision/btc-runtime/runtime/buffer/BytesWriter.ts(28,13)                                                                          
    :                                                                                                                                                
 38 │ this.buffer = new DataView(this.arrayBuffer);                                                                                                  
    │                            ~~~~~~~~~~~~~~~~                                                                                                    
    └─ in ~lib/@btc-vision/btc-runtime/runtime/buffer/BytesWriter.ts(38,36)

Fixed by instantiating intermediate objects in the constructor of BytesWriter prior to assignment to this.

Additionally, BytesReader#readTuple() does not actually compile when used for the error from asc:

ERROR TS2365: Operator '<' cannot be applied to types 'i32' and 'u32'.
     :
 113 │ for (let i = 0; i < length; i++) {
     │                 ~~~~~~~~~~
     └─ in ~lib/@btc-vision/btc-runtime/runtime/buffer/BytesReader.ts(113,25)

Fixed by typing as a u32.