Skip to content

Commit

Permalink
Fix bytes size when parsing from IDL (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva authored Aug 4, 2023
1 parent eaa7e20 commit f8f57ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-pandas-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/kinobi': patch
---

Fix bytes size when parsing from IDL
3 changes: 2 additions & 1 deletion src/nodes/TypeNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IDL_TYPE_LEAVES, IdlType } from '../idl';
import { prefixedSize } from '../shared';
import { ArrayTypeNode, arrayTypeNodeFromIdl } from './ArrayTypeNode';
import { BoolTypeNode, boolTypeNode } from './BoolTypeNode';
import { BytesTypeNode, bytesTypeNode } from './BytesTypeNode';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const createTypeNodeFromIdl = (idlType: IdlType): TypeNode => {
if (idlType === 'bool') return boolTypeNode();
if (idlType === 'string') return stringTypeNode();
if (idlType === 'publicKey') return publicKeyTypeNode();
if (idlType === 'bytes') return bytesTypeNode();
if (idlType === 'bytes') return bytesTypeNode(prefixedSize());
return numberTypeNode(idlType);
}

Expand Down
3 changes: 2 additions & 1 deletion test/package/src/generated/types/payloadType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
publicKey as publicKeySerializer,
struct,
tuple,
u32,
u64,
} from '@metaplex-foundation/umi/serializers';

Expand Down Expand Up @@ -55,7 +56,7 @@ export function getPayloadTypeSerializer(
[
'Seeds',
struct<GetDataEnumKindContent<PayloadType, 'Seeds'>>([
['seeds', array(bytes())],
['seeds', array(bytes({ size: u32() }))],
]),
],
[
Expand Down
3 changes: 2 additions & 1 deletion test/package/src/generated/types/taCreateArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
bytes,
string,
struct,
u32,
} from '@metaplex-foundation/umi/serializers';

export type TaCreateArgs = {
Expand All @@ -34,7 +35,7 @@ export function getTaCreateArgsSerializer(
return struct<TaCreateArgs>(
[
['ruleSetName', string()],
['serializedRuleSet', bytes()],
['serializedRuleSet', bytes({ size: u32() })],
],
{ description: 'TaCreateArgs' }
) as Serializer<TaCreateArgsArgs, TaCreateArgs>;
Expand Down

0 comments on commit f8f57ac

Please sign in to comment.