Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer fixes #111

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading