Skip to content

Commit

Permalink
init: fix skip_field and wait timer
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Oct 12, 2023
1 parent 1700325 commit 107e389
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cmd/substreams/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -583,8 +584,13 @@ func getProxyContractImplementation(ctx context.Context, address eth.Address, en
}

var response Response
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, nil, fmt.Errorf("unmarshaling: %w", err)

bod, err := io.ReadAll(res.Body)
if err != nil {
return nil, nil, err
}
if err := json.NewDecoder(bytes.NewReader(bod)).Decode(&response); err != nil {
return nil, nil, fmt.Errorf("unmarshaling %s: %w", string(bod), err)
}

timer := timerUntilNextCall(response.Message)
Expand All @@ -609,7 +615,7 @@ func timerUntilNextCall(msg string) *time.Timer {
if strings.HasPrefix(msg, "OK-Missing/Invalid API Key") {
return time.NewTimer(time.Second * 5)
}
return time.NewTimer(time.Millisecond * 500)
return time.NewTimer(time.Millisecond * 400)
}

func getContractABI(ctx context.Context, address eth.Address, endpoint string) (*eth.ABI, string, *time.Timer, error) {
Expand Down Expand Up @@ -655,13 +661,14 @@ func getAndSetContractABIs(ctx context.Context, contracts []*templates.EthereumC
return nil, err
}

<-wait.C
implementationAddress, wait, err := getProxyContractImplementation(ctx, contract.GetAddress(), chain.ApiEndpoint)
if err != nil {
return nil, err
}
<-wait.C

if implementationAddress != nil {
<-wait.C
implementationABI, implementationABIContent, wait, err := getContractABI(ctx, *implementationAddress, chain.ApiEndpoint)
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion codegen/templates/ethereum_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ func generateFieldTransformCode(fieldType eth.SolidityType, fieldAccess string)

case eth.ArrayType:
inner := generateFieldTransformCode(v.ElementType, "x")
if inner == SKIP_FIELD {
return SKIP_FIELD
}
return fmt.Sprintf("%s.into_iter().map(|x| %s).collect::<Vec<_>>()", fieldAccess, inner)

case eth.StructType:
Expand Down Expand Up @@ -553,11 +556,14 @@ func getProtoFieldType(solidityType eth.SolidityType) string {
case eth.ArrayType:
// Flaky, I think we should support a single level of "array"
fieldType := getProtoFieldType(v.ElementType)
if fieldType == "" {
if fieldType == SKIP_FIELD {
return SKIP_FIELD
}
return "repeated " + fieldType

case eth.StructType:
return SKIP_FIELD

default:
return ""
}
Expand Down

0 comments on commit 107e389

Please sign in to comment.