|
7 | 7 | "fmt" |
8 | 8 | "maps" |
9 | 9 | "reflect" |
10 | | - "slices" |
11 | 10 | "strconv" |
12 | 11 | "strings" |
13 | 12 |
|
@@ -547,19 +546,21 @@ func (s *suiChainReader) prepareArguments(ctx context.Context, argMap map[string |
547 | 546 | if _, ok := pointersMap[appendTag]; !ok { |
548 | 547 | pointersMap[appendTag] = make([]string, 0) |
549 | 548 | } |
| 549 | + |
| 550 | + // TODO: make pointersMap a map of string to map instead of string to array |
| 551 | + // each map to contain the following keys: 'field_name', 'parameter_name', '...' |
| 552 | + // add the field name to the set |
| 553 | + pointersMap[appendTag] = append(pointersMap[appendTag], tag[3]) |
| 554 | + // add the function parameter name to the set |
550 | 555 | pointersMap[appendTag] = append(pointersMap[appendTag], paramConfig.Name) |
551 | 556 | } |
552 | 557 | } |
553 | 558 |
|
554 | 559 | // fetch pointers |
555 | | - pointersSet := []string{} |
556 | | - for pointer := range pointersMap { |
557 | | - // make a read request to the contract |
558 | | - pointersSet = append(pointersSet, pointer) |
559 | | - } |
560 | | - pointersValuesMap, err := s.fetchPointers(ctx, pointersSet, identifier.address, functionConfig.SignerAddress) |
561 | | - if err != nil { |
562 | | - return nil, nil, fmt.Errorf("failed to fetch pointers: %w", err) |
| 560 | + pointersValuesMap := make(map[string]map[string]any) |
| 561 | + for pointerName, pointerVals := range pointersMap { |
| 562 | + |
| 563 | + s.client.GetValuesFromPackageOwnedObjectField(ctx, identifier.address, pointer, []string{pointer}) |
563 | 564 | } |
564 | 565 |
|
565 | 566 | // for each param, if it has a pointer value, add it to the args map |
@@ -593,58 +594,6 @@ func (s *suiChainReader) prepareArguments(ctx context.Context, argMap map[string |
593 | 594 | return args, argTypes, nil |
594 | 595 | } |
595 | 596 |
|
596 | | -// fetchPointers gets all the specified pointers from a specific contract. |
597 | | -// Returns a map of { pointerTag: { ... } } |
598 | | -func (s *suiChainReader) fetchPointers(ctx context.Context, pointers []string, packageId, signerAddress string) (map[string]map[string]any, error) { |
599 | | - pointersValuesMap := make(map[string]map[string]any) |
600 | | - |
601 | | - if slices.Contains(pointers, ccipPointerKey) { |
602 | | - if s.client.CCIPObjectPointerId != "" { |
603 | | - pointersValuesMap[ccipPointerKey] = map[string]any{ |
604 | | - "object_ref_id": s.client.CCIPObjectPointerId, |
605 | | - } |
606 | | - return pointersValuesMap, nil |
607 | | - } |
608 | | - |
609 | | - // only call this if not cached yet |
610 | | - // retrieves ccipPkgID and overwrites packageID |
611 | | - ccipPkgID, err := s.client.GetCCIPPackageId(ctx, packageId, signerAddress) |
612 | | - if err != nil { |
613 | | - return nil, err |
614 | | - } |
615 | | - packageId = ccipPkgID |
616 | | - } |
617 | | - |
618 | | - // fetch owned objects |
619 | | - ownedObjects, err := s.client.ReadOwnedObjects(ctx, packageId, nil) |
620 | | - if err != nil { |
621 | | - return nil, err |
622 | | - } |
623 | | - |
624 | | - for _, obj := range ownedObjects { |
625 | | - if obj.Data.Type == "" { |
626 | | - continue |
627 | | - } |
628 | | - for _, pointer := range pointers { |
629 | | - if strings.Contains(obj.Data.Type, pointer) { |
630 | | - fields := obj.Data.Content.Fields |
631 | | - pointersValuesMap[pointer] = fields |
632 | | - } |
633 | | - } |
634 | | - |
635 | | - // now handle caching separately |
636 | | - if strings.Contains(obj.Data.Type, ccipPointerKey) && s.client.CCIPObjectPointerId == "" { |
637 | | - fields := obj.Data.Content.Fields |
638 | | - if refID, ok := fields["object_ref_id"].(string); ok { |
639 | | - s.client.CCIPObjectPointerId = refID |
640 | | - s.logger.Debugw("Cached ccipObjectRef", "object_ref_id", refID) |
641 | | - } |
642 | | - } |
643 | | - } |
644 | | - |
645 | | - return pointersValuesMap, nil |
646 | | -} |
647 | | - |
648 | 597 | // executeFunction executes the actual function call |
649 | 598 | func (s *suiChainReader) executeFunction(ctx context.Context, parsed *readIdentifier, functionConfig *config.ChainReaderFunction, args []any, argTypes []string) ([]any, error) { |
650 | 599 | s.logger.Debugw("Calling ReadFunction", |
|
0 commit comments