Skip to content

Commit

Permalink
mobile: started work on java structs
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed May 5, 2020
1 parent 7aabece commit 89153af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2168,9 +2168,13 @@ public class Test {
func TestGenerateBindingingJava(t *testing.T) {
// Generate the test suite for all the contracts
for _, tt := range bindTests {
_, err := Bind([]string{tt.name}, tt.abi, tt.bytecode, nil, "bindtest", LangJava, nil, tt.aliases)
bind, err := Bind([]string{tt.name}, tt.abi, tt.bytecode, nil, "bindtest", LangJava, nil, tt.aliases)
if err != nil {
t.Fatalf("test %s: failed to generate binding: %v", tt.name, err)
}
if err := ioutil.WriteFile("/home/matematik/j-bindings/"+tt.name, []byte(bind), 0600); err != nil {
t.Fatal(err)
}

}
}
20 changes: 14 additions & 6 deletions mobile/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ func (i *Interface) SetUint64s(bigints *BigInts) {
}
i.object = &ints
}
func (i *Interface) SetBigInt(bigint *BigInt) { i.object = &bigint.bigint }
func (i *Interface) SetBigInts(bigints *BigInts) { i.object = &bigints.bigints }
func (i *Interface) SetBigInt(bigint *BigInt) { i.object = &bigint.bigint }
func (i *Interface) SetBigInts(bigints *BigInts) { i.object = &bigints.bigints }
func (i *Interface) SetInterfaces(ifaces *Interfaces) { i.object = &ifaces.objects }

func (i *Interface) SetDefaultBool() { i.object = new(bool) }
func (i *Interface) SetDefaultBools() { i.object = new([]bool) }
Expand Down Expand Up @@ -238,8 +239,9 @@ func (i *Interface) GetUint64s() *BigInts {
}
return bigints
}
func (i *Interface) GetBigInt() *BigInt { return &BigInt{*i.object.(**big.Int)} }
func (i *Interface) GetBigInts() *BigInts { return &BigInts{*i.object.(*[]*big.Int)} }
func (i *Interface) GetBigInt() *BigInt { return &BigInt{*i.object.(**big.Int)} }
func (i *Interface) GetBigInts() *BigInts { return &BigInts{*i.object.(*[]*big.Int)} }
func (i *Interface) GetInterfaces() *Interfaces { return &Interfaces{*i.object.(*[]interface{})} }

// Interfaces is a slices of wrapped generic objects.
type Interfaces struct {
Expand All @@ -256,7 +258,7 @@ func (i *Interfaces) Size() int {
return len(i.objects)
}

// Get returns the bigint at the given index from the slice.
// Get returns the interface at the given index from the slice.
// Notably the returned value can be changed without affecting the
// interfaces itself.
func (i *Interfaces) Get(index int) (iface *Interface, _ error) {
Expand All @@ -266,11 +268,17 @@ func (i *Interfaces) Get(index int) (iface *Interface, _ error) {
return &Interface{object: i.objects[index]}, nil
}

// Set sets the big int at the given index in the slice.
// Set sets the interface at the given index in the slice.
func (i *Interfaces) Set(index int, object *Interface) error {
if index < 0 || index >= len(i.objects) {
return errors.New("index out of bounds")
}
i.objects[index] = object.object
return nil
}

func (i *Interfaces) SetInterfaces(index int, objects *Interfaces) error {
var in Interface
in.SetInterfaces(objects)
return i.Set(index, &in)
}

0 comments on commit 89153af

Please sign in to comment.