1
+ // Borrowed from coral-xyz/anchor
2
+ //
3
+ // https://github.com/coral-xyz/anchor/blob/master/ts/packages/anchor/src/coder/borsh/idl.ts
4
+
5
+
1
6
import camelCase from 'camelcase'
2
7
import { Layout } from 'buffer-layout'
3
8
import * as borsh from '@coral-xyz/borsh'
@@ -123,9 +128,9 @@ export class IdlCoder {
123
128
return borsh . struct ( fieldLayouts , name )
124
129
} else if ( typeDef . type . kind === 'enum' ) {
125
130
const variants = typeDef . type . variants . map ( ( variant : IdlEnumVariant ) => {
126
- const name = camelCase ( variant . name )
131
+ const variantName = camelCase ( variant . name )
127
132
if ( variant . fields === undefined ) {
128
- return borsh . struct ( [ ] , name )
133
+ return borsh . struct ( [ ] , variantName )
129
134
}
130
135
const fieldLayouts = variant . fields . map ( ( f : IdlField | IdlType , i : number ) => {
131
136
if ( ! f . hasOwnProperty ( 'name' ) ) {
@@ -137,7 +142,7 @@ export class IdlCoder {
137
142
// the check before would've errored
138
143
return IdlCoder . fieldLayout ( f as IdlField , types )
139
144
} )
140
- return borsh . struct ( fieldLayouts , name )
145
+ return borsh . struct ( fieldLayouts , variantName )
141
146
} )
142
147
143
148
if ( name !== undefined ) {
0 commit comments