Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetching of dependencies #1717

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions internal/dependencymanager/dependencyinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,44 +316,40 @@ func (di *DependencyInstaller) fetchDependencies(networkName string, address flo
return fmt.Errorf("contracts are nil for account: %s", address)
}

found := false
contract, ok := account.Contracts[contractName]
if !ok {
return fmt.Errorf("contract %s not found at address %s", contractName, address.String())
}

for _, contract := range account.Contracts {
program, err := project.NewProgram(contract, nil, "")
if err != nil {
return fmt.Errorf("failed to parse program: %w", err)
}
program, err := project.NewProgram(contract, nil, "")
if err != nil {
return fmt.Errorf("failed to parse program: %w", err)
}

parsedContractName, err := program.Name()
if err != nil {
return fmt.Errorf("failed to parse contract name: %w", err)
}
parsedContractName, err := program.Name()
if err != nil {
return fmt.Errorf("failed to parse contract name: %w", err)
}

if parsedContractName == contractName {
found = true
if parsedContractName != contractName {
return fmt.Errorf("contract name mismatch: expected %s, got %s", contractName, parsedContractName)
}

if err := di.handleFoundContract(networkName, address.String(), assignedName, parsedContractName, program); err != nil {
return fmt.Errorf("failed to handle found contract: %w", err)
}
if err := di.handleFoundContract(networkName, address.String(), assignedName, contractName, program); err != nil {
return fmt.Errorf("failed to handle found contract: %w", err)
}

if program.HasAddressImports() {
imports := program.AddressImportDeclarations()
for _, imp := range imports {
contractName := imp.Identifiers[0].String()
err := di.fetchDependencies(networkName, flowsdk.HexToAddress(imp.Location.String()), contractName, contractName)
if err != nil {
return err
}
}
if program.HasAddressImports() {
imports := program.AddressImportDeclarations()
for _, imp := range imports {
contractName := imp.Identifiers[0].String()
err := di.fetchDependencies(networkName, flowsdk.HexToAddress(imp.Location.String()), contractName, contractName)
if err != nil {
return err
}
}
}

if !found {
errMsg := fmt.Sprintf("contract %s not found for account %s on network %s", contractName, address, networkName)
di.Logger.Error(errMsg)
}

return nil
}

Expand Down
Loading