Skip to content

Commit

Permalink
Serializer fixes (#111)
Browse files Browse the repository at this point in the history
* Fixed optional check

* Update serializer.ts

* Version 1.0.10
  • Loading branch information
aaroncox authored Jul 30, 2024
1 parent af651d2 commit 1fe1cbf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wharfkit/antelope",
"description": "Library for working with Antelope powered blockchains.",
"version": "1.0.9",
"version": "1.0.10",
"homepage": "https://github.com/wharfkit/antelope",
"license": "BSD-3-Clause-No-Military-License",
"main": "lib/antelope.js",
Expand Down
7 changes: 6 additions & 1 deletion src/chain/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {abiDecode, Resolved} from '../serializer/decoder'
import {abiEncode} from '../serializer/encoder'
import {isInstanceOf} from '../utils'
import {ABI} from './abi'

export interface StructConstructor extends ABISerializableConstructor {
new <T extends Struct>(...args: any[]): T
Expand Down Expand Up @@ -49,8 +50,12 @@ export class Struct implements ABISerializableObject {
constructor(object: any) {
const self = this.constructor as typeof Struct
for (const field of self.structFields) {
const isOptional =
typeof field.type === 'string'
? new ABI.ResolvedType(String(field.type)).isOptional
: field.optional
const value = object[field.name]
if (field.optional && !value) continue
if (isOptional && !value) continue
this[field.name] = value
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ suite('serializer', function () {
assert.equal(res1.superInt.toNumber(), 42)
assert.equal(res1.jazz.value, 42)
assert.notProperty(res1, 'maybeJazz')
assert.strictEqual(res1.dumbBool, null)
assert.notProperty(res1, 'dumbBool')
assert.strictEqual(res1.bool, false)
const res2 = Serializer.decode({
object: {name: 'foo'},
Expand Down

0 comments on commit 1fe1cbf

Please sign in to comment.