Skip to content

Commit

Permalink
Merge pull request #1717 from onflow/bastian/fix-dependency-installer
Browse files Browse the repository at this point in the history
Fix fetching of dependencies
  • Loading branch information
turbolent authored Aug 29, 2024
2 parents 5dd8fdd + 86d02cb commit 716b706
Showing 1 changed file with 25 additions and 29 deletions.
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

0 comments on commit 716b706

Please sign in to comment.