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

ts: Support empty account structs #712

Merged
merged 1 commit into from
Sep 11, 2021

Conversation

2501babe
Copy link
Contributor

@2501babe 2501babe commented Sep 11, 2021

i may be a usecase of one, but if you declare a struct like

#[account]
#[derive(Debug, Default)]
pub struct Post {}

then the program builds and deploys fine, idl outputs fine, but when you load the idl in js it does this

/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/coder/common.js:32
        .reduce((a, b) => a + b);
         ^

TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at Object.accountSize (/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/coder/common.js:32:10)
    at new AccountClient (/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/program/namespace/account.js:51:67)
    at /home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/program/namespace/account.js:39:32
    at Array.forEach (<anonymous>)
    at Function.build (/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/program/namespace/account.js:37:22)
    at Function.build (/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/program/namespace/index.js:43:33)
    at new Program (/home/hana/work/hana/circuit/scratch/node_modules/@project-serum/anchor/dist/cjs/program/index.js:57:96)
    at Object.<anonymous> (/home/hana/work/hana/circuit/scratch/index.js:14:17)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)

@armaniferrante armaniferrante merged commit e2bd41b into coral-xyz:master Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants