graph-tooling icon indicating copy to clipboard operation
graph-tooling copied to clipboard

Generated input (tuple) struct doesn't compile

Open hbriese opened this issue 4 years ago • 0 comments

Issue

The following generated code fails to compile

Function ABI: hashGroup(Approver[] _approvers)

{
    "inputs": [
      {
        "components": [
          {
            "internalType": "address",
            "name": "addr",
            "type": "address"
          },
          {
            "internalType": "uint256",
            "name": "weight",
            "type": "uint256"
          }
        ],
        "internalType": "struct Approver[]",
        "name": "_approvers",
        "type": "tuple[]"
      }
    ],
    "name": "hashGroup",
    "outputs": [
      {
        "internalType": "bytes32",
        "name": "",
        "type": "bytes32"
      }
    ],
    "stateMutability": "pure",
    "type": "function"
  }

Generated input struct (Approver)

export class Safe__hashGroupInput_approversStruct extends ethereum.Tuple {
  get addr(): Address {
    return this[0].toAddress();
  }

  get weight(): BigInt {
    return this[1].toBigInt();
  }
}

Generated (contract) call function that fails to compile

export class Safe extends ethereum.SmartContract {
    ...

    hashGroup(_approvers: Array<Safe__hashGroupInput_approversStruct>): Bytes {
        let result = super.call(
          "hashGroup",
          "hashGroup((address,uint256)[]):(bytes32)",
          [ethereum.Value.fromTupleArray(_approvers)]                       // TYPE ERROR
        );

        return result[0].toBytes();
      }
}

Manual fix

_approvers is an Array<Safe__hashGroupInput_approversStruct> where Safe__hashGroupInput_approversStruct extends Tuple However fromTupleArray() is expecting an Array<Tuple> Not sure why this causes a type issue as the conversion is to a superclass, but casting it fixes it

As annotated in the generated call, this line causes the compilation to fail: [ethereum.Value.fromTupleArray(_approvers)]

Casting _approvers fixes the type issue, allowing the code to compile [ethereum.Value.fromTupleArray(changetype<Array<ethereum.Tuple>>(_approvers))]

Versions

Graph-cli: v0.22.3 Graph-ts: v0.22.1 apiVersion: 0.0.5

hbriese avatar Oct 14 '21 05:10 hbriese