From 46b6bce14bcb7ecb8f5467dc5864e2d7bdd1ae4d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 22 Jul 2022 08:35:30 +0200 Subject: [PATCH] IDL: Remove NodeRef and NodeRefMut enums Anchor cannot load idls that include enums with tuple variants. --- idl-fixup.sh | 5 + .../mango-v4/src/state/orderbook/nodes.rs | 4 +- ts/client/src/mango_v4.ts | 96 ------------------- 3 files changed, 7 insertions(+), 98 deletions(-) diff --git a/idl-fixup.sh b/idl-fixup.sh index e5b7572db..bc9275128 100755 --- a/idl-fixup.sh +++ b/idl-fixup.sh @@ -14,3 +14,8 @@ for pair_str in \ perl -0777 -pi -e "s/\{\s*\"defined\":\s*\"${pair[0]}\"\s*\}/\"${pair[1]}\"/g" \ target/idl/mango_v4.json target/types/mango_v4.ts; done + +# Anchor puts all enums in the IDL, independent of visibility. And then it +# errors on enums that have tuple variants. This hack drops these from the idl. +perl -0777 -pi -e 's/ *{\s*"name": "NodeRef(?(?:[^{}[\]]+|\{(?&nested)\}|\[(?&nested)\])*)\},\n//g' \ + target/idl/mango_v4.json target/types/mango_v4.ts; diff --git a/programs/mango-v4/src/state/orderbook/nodes.rs b/programs/mango-v4/src/state/orderbook/nodes.rs index 4fb6791cc..7ffc18b52 100644 --- a/programs/mango-v4/src/state/orderbook/nodes.rs +++ b/programs/mango-v4/src/state/orderbook/nodes.rs @@ -173,12 +173,12 @@ const_assert_eq!(size_of::(), size_of::()); const_assert_eq!(size_of::(), size_of::()); const_assert_eq!(size_of::(), size_of::()); -pub enum NodeRef<'a> { +pub(crate) enum NodeRef<'a> { Inner(&'a InnerNode), Leaf(&'a LeafNode), } -pub enum NodeRefMut<'a> { +pub(crate) enum NodeRefMut<'a> { Inner(&'a mut InnerNode), Leaf(&'a mut LeafNode), } diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index c6a2896ba..0178e3950 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -4048,54 +4048,6 @@ export type MangoV4 = { ] } }, - { - "name": "NodeRef", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Inner", - "fields": [ - { - "defined": "&'aInnerNode" - } - ] - }, - { - "name": "Leaf", - "fields": [ - { - "defined": "&'aLeafNode" - } - ] - } - ] - } - }, - { - "name": "NodeRefMut", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Inner", - "fields": [ - { - "defined": "&'amutInnerNode" - } - ] - }, - { - "name": "Leaf", - "fields": [ - { - "defined": "&'amutLeafNode" - } - ] - } - ] - } - }, { "name": "OrderType", "type": { @@ -8795,54 +8747,6 @@ export const IDL: MangoV4 = { ] } }, - { - "name": "NodeRef", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Inner", - "fields": [ - { - "defined": "&'aInnerNode" - } - ] - }, - { - "name": "Leaf", - "fields": [ - { - "defined": "&'aLeafNode" - } - ] - } - ] - } - }, - { - "name": "NodeRefMut", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Inner", - "fields": [ - { - "defined": "&'amutInnerNode" - } - ] - }, - { - "name": "Leaf", - "fields": [ - { - "defined": "&'amutLeafNode" - } - ] - } - ] - } - }, { "name": "OrderType", "type": {