Skip to content

Commit 1aafd94

Browse files
committed
wip
1 parent 6b00adb commit 1aafd94

File tree

9 files changed

+7433
-515
lines changed

9 files changed

+7433
-515
lines changed

sol-anchor/idl.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@ func (i *IDL) AccountsAndTypes() []Type {
1717
return append(i.Types, i.Accounts...)
1818
}
1919

20+
func (i *IDL) GetFieldsFromInstructionsEventsTypesAndAccounts() []Field {
21+
fieldList := make([]Field, 0)
22+
for _, inst := range i.Instructions {
23+
fieldList = append(fieldList, inst.Args...)
24+
}
25+
26+
for _, evt := range i.Events {
27+
fieldList = append(fieldList, evt.Fields...)
28+
}
29+
30+
for _, t := range i.Types {
31+
if t.Type.IsStruct() {
32+
fieldList = append(fieldList, t.Type.Struct.Fields...)
33+
}
34+
}
35+
36+
return fieldList
37+
}
38+
39+
func (i *IDL) PrintProtobufNestedTypes() string {
40+
// Collect all the complex types
41+
allFields := i.GetFieldsFromInstructionsEventsTypesAndAccounts()
42+
43+
// Get all types that we should generate
44+
rustTypes := make([]string, 0)
45+
for _, f := range allFields {
46+
rustTypes = append(rustTypes, f.Type.ResolveRustType())
47+
}
48+
// remove duplicates
49+
rustTypes = uniqueStrings(rustTypes)
50+
51+
output := "";
52+
53+
return output
54+
}
55+
2056
func (i *IDL) ProgramID() string {
2157
if i.Metadata.Address != "" {
2258
return i.Metadata.Address
@@ -177,7 +213,7 @@ func CastInRustIfNeeded(rustType string) string {
177213
return "u64"
178214
}
179215

180-
return ""
216+
return rustType
181217
}
182218

183219
func toSnakeCase(str string, initialUnderscore bool) string {

0 commit comments

Comments
 (0)