1

Is there any way to initialise a 2D array in a Hyperledger .cto file?

What I want to do:

o String[][] csv optional

But its thowing an error - and will only allow:

o String[] csv optional

Does anyone know how to get around this? Or does anyone know how to do an array of arrays?

Urko
  • 1,479
  • 1
  • 14
  • 20
Simon Mullaney
  • 447
  • 2
  • 5
  • 21

1 Answers1

2

Could you try this, with a concept:

concept S1 {
  o String[] csv
}

asset S2 identified by sID {
  o String sID
  o S1 [] s1 
}

Example data would look like:

{
  "$class": "org.acme.model.S2",
  "sID": "SR26",
  "s1": [{"csv":["a","b"]},{"csv":["c","d"]}]
}
R Thatcher
  • 5,550
  • 1
  • 7
  • 15
  • Thanks for the reply R Thatcher, I tried what you detailed above. Im having problems associating a value to s1 though: ex for a simple 2x2 array: `s1= [["part id", "part name"],["1", "Wing"]];` I get this error however: ` s1 has value ["part id","part name"] (object) expected type String[]` Is there something I'm doing wrong? – Simon Mullaney Feb 16 '18 at 13:20
  • I would suggest trying my model AND example data in Playground. It is not a real 2D array - just a suggestion of how you could achieve something similar. – R Thatcher Feb 16 '18 at 15:00