Skip to content

xdr: optional typedef generates an invalid xdr_generated.go #61

@abuiles

Description

@abuiles

Protocol 14 includes a new type called SponsorshipDescriptor which is defined as an alias to an Optional AccountId

typedef AccountID* SponsorshipDescriptor;

The code generated by xdrgen produces an invalid output (see failure here stellar/go@3b2053c)

As a temporary workaround, I removed the marshaling/unmarshaling methods from SponsorshipDescriptor which solves the problem and makes the type behave as expected, which is an optional field -- when reading from a raw XDR it will try to read the first 4 bytes to determine if it is void or not and then read the content.

abuiles/go@5c48fa9

This unblocks stellar/go#2864 and allows us to move forward with Protocol 14 support.

This seems like a bug on xdrgen when compiling to go (it does the right thing in JS), maybe for optional typedefs we don't need marshaling and unmarshalling since we can delegate to the struct being referenced.

I also put a simple demo here https://github.com/abuiles/xdr-test/blob/master/src/main.go which shows a similar XDR definition working fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions