|
1 | 1 | # @evolution-sdk/evolution |
2 | 2 |
|
| 3 | +## 0.2.3 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#66](https://github.com/IntersectMBO/evolution-sdk/pull/66) [`29c3e4d`](https://github.com/IntersectMBO/evolution-sdk/commit/29c3e4d3bac9b35c1586c6a94d6aee037aeb6d62) Thanks [@solidsnakedev](https://github.com/solidsnakedev)! - Fixed field ordering bug in TSchema.Struct encode function that caused fields to be swapped during CBOR encoding when using NullOr/UndefinedOr. |
| 8 | + |
| 9 | + **Before:** |
| 10 | + |
| 11 | + ```typescript |
| 12 | + const CredentialSchema = TSchema.Union( |
| 13 | + TSchema.Struct({ pubKeyHash: TSchema.ByteArray }, { flatFields: true }), |
| 14 | + TSchema.Struct({ scriptHash: TSchema.ByteArray }, { flatFields: true }) |
| 15 | + ) |
| 16 | + |
| 17 | + const AddressSchema = TSchema.Struct({ |
| 18 | + paymentCredential: CredentialSchema, |
| 19 | + stakeCredential: TSchema.NullOr(TSchema.Integer) |
| 20 | + }) |
| 21 | + |
| 22 | + const Foo = TSchema.Union(TSchema.Struct({ foo: AddressSchema }, { flatFields: true })) |
| 23 | + |
| 24 | + const input = { |
| 25 | + foo: { |
| 26 | + paymentCredential: { pubKeyHash: fromHex("deadbeef") }, |
| 27 | + stakeCredential: null |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + const encoded = Data.withSchema(Foo).toData(input) |
| 32 | + // BUG: Fields were swapped in innerStruct! |
| 33 | + // innerStruct.fields[0] = Constr(1, []) // stakeCredential (null) - WRONG! |
| 34 | + // innerStruct.fields[1] = Constr(0, [...]) // paymentCredential - WRONG! |
| 35 | + ``` |
| 36 | + |
| 37 | + **After:** |
| 38 | + |
| 39 | + ```typescript |
| 40 | + const CredentialSchema = TSchema.Union( |
| 41 | + TSchema.Struct({ pubKeyHash: TSchema.ByteArray }, { flatFields: true }), |
| 42 | + TSchema.Struct({ scriptHash: TSchema.ByteArray }, { flatFields: true }) |
| 43 | + ) |
| 44 | + |
| 45 | + const AddressSchema = TSchema.Struct({ |
| 46 | + paymentCredential: CredentialSchema, |
| 47 | + stakeCredential: TSchema.NullOr(TSchema.Integer) |
| 48 | + }) |
| 49 | + |
| 50 | + const Foo = TSchema.Union(TSchema.Struct({ foo: AddressSchema }, { flatFields: true })) |
| 51 | + |
| 52 | + const input = { |
| 53 | + foo: { |
| 54 | + paymentCredential: { pubKeyHash: fromHex("deadbeef") }, |
| 55 | + stakeCredential: null |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + const encoded = Data.withSchema(Foo).toData(input) |
| 60 | + // FIXED: Fields now in correct order matching schema! |
| 61 | + // innerStruct.fields[0] = Constr(0, [...]) // paymentCredential - CORRECT! |
| 62 | + // innerStruct.fields[1] = Constr(1, []) // stakeCredential (null) - CORRECT! |
| 63 | + ``` |
| 64 | + |
3 | 65 | ## 0.2.2 |
4 | 66 |
|
5 | 67 | ### Patch Changes |
|
0 commit comments