Skip to content

Commit

Permalink
Added builder method for IDL string types
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Jan 16, 2025
1 parent 6127ff8 commit 22afa9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/solana/chainreader/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
Seeds: []codec.IdlField{
{
Name: PDAPubKeySeedName,
Type: codec.IdlType{AsString: codec.IdlTypePublicKey},
Type: codec.NewIdlStringType(codec.IdlTypePublicKey),
},
{
Name: PDAUint64SeedName,
Type: codec.IdlType{AsString: codec.IdlTypeU64},
Type: codec.NewIdlStringType(codec.IdlTypeU64),
},
},
},
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
Seeds: []codec.IdlField{
{
Name: PDAPubKeySeedName,
Type: codec.IdlType{AsString: codec.IdlTypePublicKey},
Type: codec.NewIdlStringType(codec.IdlTypePublicKey),
},
},
},
Expand Down
14 changes: 10 additions & 4 deletions pkg/solana/codec/anchoridl.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (env *IdlType) UnmarshalJSON(data []byte) error {

switch v := temp.(type) {
case string:
env.AsString = IdlTypeAsString(v)
env.asString = IdlTypeAsString(v)
case map[string]interface{}:
if len(v) == 0 {
return nil
Expand Down Expand Up @@ -255,15 +255,21 @@ func (env *IdlType) UnmarshalJSON(data []byte) error {

// Wrapper type:
type IdlType struct {
AsString IdlTypeAsString
asString IdlTypeAsString
asIdlTypeVec *IdlTypeVec
asIdlTypeOption *IdlTypeOption
asIdlTypeDefined *IdlTypeDefined
asIdlTypeArray *IdlTypeArray
}

func NewIdlStringType(asString IdlTypeAsString) IdlType {
return IdlType{
asString: asString,
}
}

func (env *IdlType) IsString() bool {
return env.AsString != ""
return env.asString != ""
}
func (env *IdlType) IsIdlTypeVec() bool {
return env.asIdlTypeVec != nil
Expand All @@ -280,7 +286,7 @@ func (env *IdlType) IsArray() bool {

// Getters:
func (env *IdlType) GetString() IdlTypeAsString {
return env.AsString
return env.asString
}
func (env *IdlType) GetIdlTypeVec() *IdlTypeVec {
return env.asIdlTypeVec
Expand Down

0 comments on commit 22afa9f

Please sign in to comment.