mobile: fix mobile interface (#19180)
* mobile: fix mobile interface * mobile, accounts: generate correct java binding * accounts: fix java type binding * mobile: support integer slice * accounts/abi/bind, cmd/abigen: implement java binding tests
This commit is contained in:
1 parent
fd072c2fd1
commit
6069b1a5f5
9 files changed
+908
-238
No files matched your search
+83
-128
@@ -38,7 +38,6 @@ type Lang int
|
||||
const (
|
||||
LangGo Lang = iota
|
||||
LangJava
|
||||
LangObjC
|
||||
)
|
||||
|
||||
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
|
||||
@@ -164,124 +163,62 @@ var bindType = map[Lang]func(kind abi.Type) string{
|
||||
LangJava: bindTypeJava,
|
||||
}
|
||||
|
||||
// Helper function for the binding generators.
|
||||
// It reads the unmatched characters after the inner type-match,
|
||||
// (since the inner type is a prefix of the total type declaration),
|
||||
// looks for valid arrays (possibly a dynamic one) wrapping the inner type,
|
||||
// and returns the sizes of these arrays.
|
||||
//
|
||||
// Returned array sizes are in the same order as solidity signatures; inner array size first.
|
||||
// Array sizes may also be "", indicating a dynamic array.
|
||||
func wrapArray(stringKind string, innerLen int, innerMapping string) (string, []string) {
|
||||
remainder := stringKind[innerLen:]
|
||||
//find all the sizes
|
||||
matches := regexp.MustCompile(`\[(\d*)\]`).FindAllStringSubmatch(remainder, -1)
|
||||
parts := make([]string, 0, len(matches))
|
||||
for _, match := range matches {
|
||||
//get group 1 from the regex match
|
||||
parts = append(parts, match[1])
|
||||
}
|
||||
return innerMapping, parts
|
||||
}
|
||||
|
||||
// Translates the array sizes to a Go-lang declaration of a (nested) array of the inner type.
|
||||
// Simply returns the inner type if arraySizes is empty.
|
||||
func arrayBindingGo(inner string, arraySizes []string) string {
|
||||
out := ""
|
||||
//prepend all array sizes, from outer (end arraySizes) to inner (start arraySizes)
|
||||
for i := len(arraySizes) - 1; i >= 0; i-- {
|
||||
out += "[" + arraySizes[i] + "]"
|
||||
}
|
||||
out += inner
|
||||
return out
|
||||
}
|
||||
|
||||
// bindTypeGo converts a Solidity type to a Go one. Since there is no clear mapping
|
||||
// from all Solidity types to Go ones (e.g. uint17), those that cannot be exactly
|
||||
// mapped will use an upscaled type (e.g. *big.Int).
|
||||
func bindTypeGo(kind abi.Type) string {
|
||||
stringKind := kind.String()
|
||||
innerLen, innerMapping := bindUnnestedTypeGo(stringKind)
|
||||
return arrayBindingGo(wrapArray(stringKind, innerLen, innerMapping))
|
||||
}
|
||||
|
||||
// The inner function of bindTypeGo, this finds the inner type of stringKind.
|
||||
// (Or just the type itself if it is not an array or slice)
|
||||
// The length of the matched part is returned, with the translated type.
|
||||
func bindUnnestedTypeGo(stringKind string) (int, string) {
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(stringKind, "address"):
|
||||
return len("address"), "common.Address"
|
||||
|
||||
case strings.HasPrefix(stringKind, "bytes"):
|
||||
parts := regexp.MustCompile(`bytes([0-9]*)`).FindStringSubmatch(stringKind)
|
||||
return len(parts[0]), fmt.Sprintf("[%s]byte", parts[1])
|
||||
|
||||
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
|
||||
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(stringKind)
|
||||
// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go one.
|
||||
func bindBasicTypeGo(kind abi.Type) string {
|
||||
switch kind.T {
|
||||
case abi.AddressTy:
|
||||
return "common.Address"
|
||||
case abi.IntTy, abi.UintTy:
|
||||
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(kind.String())
|
||||
switch parts[2] {
|
||||
case "8", "16", "32", "64":
|
||||
return len(parts[0]), fmt.Sprintf("%sint%s", parts[1], parts[2])
|
||||
return fmt.Sprintf("%sint%s", parts[1], parts[2])
|
||||
}
|
||||
return len(parts[0]), "*big.Int"
|
||||
|
||||
case strings.HasPrefix(stringKind, "bool"):
|
||||
return len("bool"), "bool"
|
||||
|
||||
case strings.HasPrefix(stringKind, "string"):
|
||||
return len("string"), "string"
|
||||
|
||||
return "*big.Int"
|
||||
case abi.FixedBytesTy:
|
||||
return fmt.Sprintf("[%d]byte", kind.Size)
|
||||
case abi.BytesTy:
|
||||
return "[]byte"
|
||||
case abi.FunctionTy:
|
||||
// todo(rjl493456442)
|
||||
return ""
|
||||
default:
|
||||
return len(stringKind), stringKind
|
||||
// string, bool types
|
||||
return kind.String()
|
||||
}
|
||||
}
|
||||
|
||||
// Translates the array sizes to a Java declaration of a (nested) array of the inner type.
|
||||
// Simply returns the inner type if arraySizes is empty.
|
||||
func arrayBindingJava(inner string, arraySizes []string) string {
|
||||
// Java array type declarations do not include the length.
|
||||
return inner + strings.Repeat("[]", len(arraySizes))
|
||||
}
|
||||
|
||||
// bindTypeJava converts a Solidity type to a Java one. Since there is no clear mapping
|
||||
// from all Solidity types to Java ones (e.g. uint17), those that cannot be exactly
|
||||
// bindTypeGo converts solidity types to Go ones. Since there is no clear mapping
|
||||
// from all Solidity types to Go ones (e.g. uint17), those that cannot be exactly
|
||||
// mapped will use an upscaled type (e.g. BigDecimal).
|
||||
func bindTypeJava(kind abi.Type) string {
|
||||
stringKind := kind.String()
|
||||
innerLen, innerMapping := bindUnnestedTypeJava(stringKind)
|
||||
return arrayBindingJava(wrapArray(stringKind, innerLen, innerMapping))
|
||||
func bindTypeGo(kind abi.Type) string {
|
||||
// todo(rjl493456442) tuple
|
||||
switch kind.T {
|
||||
case abi.ArrayTy:
|
||||
return fmt.Sprintf("[%d]", kind.Size) + bindTypeGo(*kind.Elem)
|
||||
case abi.SliceTy:
|
||||
return "[]" + bindTypeGo(*kind.Elem)
|
||||
default:
|
||||
return bindBasicTypeGo(kind)
|
||||
}
|
||||
}
|
||||
|
||||
// The inner function of bindTypeJava, this finds the inner type of stringKind.
|
||||
// (Or just the type itself if it is not an array or slice)
|
||||
// The length of the matched part is returned, with the translated type.
|
||||
func bindUnnestedTypeJava(stringKind string) (int, string) {
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(stringKind, "address"):
|
||||
parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
|
||||
if len(parts) != 2 {
|
||||
return len(stringKind), stringKind
|
||||
}
|
||||
if parts[1] == "" {
|
||||
return len("address"), "Address"
|
||||
}
|
||||
return len(parts[0]), "Addresses"
|
||||
|
||||
case strings.HasPrefix(stringKind, "bytes"):
|
||||
parts := regexp.MustCompile(`bytes([0-9]*)`).FindStringSubmatch(stringKind)
|
||||
if len(parts) != 2 {
|
||||
return len(stringKind), stringKind
|
||||
}
|
||||
return len(parts[0]), "byte[]"
|
||||
|
||||
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
|
||||
//Note that uint and int (without digits) are also matched,
|
||||
// bindBasicTypeJava converts basic solidity types(except array, slice and tuple) to Java one.
|
||||
func bindBasicTypeJava(kind abi.Type) string {
|
||||
switch kind.T {
|
||||
case abi.AddressTy:
|
||||
return "Address"
|
||||
case abi.IntTy, abi.UintTy:
|
||||
// Note that uint and int (without digits) are also matched,
|
||||
// these are size 256, and will translate to BigInt (the default).
|
||||
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(stringKind)
|
||||
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(kind.String())
|
||||
if len(parts) != 3 {
|
||||
return len(stringKind), stringKind
|
||||
return kind.String()
|
||||
}
|
||||
// All unsigned integers should be translated to BigInt since gomobile doesn't
|
||||
// support them.
|
||||
if parts[1] == "u" {
|
||||
return "BigInt"
|
||||
}
|
||||
|
||||
namedSize := map[string]string{
|
||||
@@ -291,20 +228,48 @@ func bindUnnestedTypeJava(stringKind string) (int, string) {
|
||||
"64": "long",
|
||||
}[parts[2]]
|
||||
|
||||
//default to BigInt
|
||||
// default to BigInt
|
||||
if namedSize == "" {
|
||||
namedSize = "BigInt"
|
||||
}
|
||||
return len(parts[0]), namedSize
|
||||
|
||||
case strings.HasPrefix(stringKind, "bool"):
|
||||
return len("bool"), "boolean"
|
||||
|
||||
case strings.HasPrefix(stringKind, "string"):
|
||||
return len("string"), "String"
|
||||
|
||||
return namedSize
|
||||
case abi.FixedBytesTy, abi.BytesTy:
|
||||
return "byte[]"
|
||||
case abi.BoolTy:
|
||||
return "boolean"
|
||||
case abi.StringTy:
|
||||
return "String"
|
||||
case abi.FunctionTy:
|
||||
// todo(rjl493456442)
|
||||
return ""
|
||||
default:
|
||||
return len(stringKind), stringKind
|
||||
return kind.String()
|
||||
}
|
||||
}
|
||||
|
||||
// bindTypeJava converts a Solidity type to a Java one. Since there is no clear mapping
|
||||
// from all Solidity types to Java ones (e.g. uint17), those that cannot be exactly
|
||||
// mapped will use an upscaled type (e.g. BigDecimal).
|
||||
func bindTypeJava(kind abi.Type) string {
|
||||
switch kind.T {
|
||||
case abi.ArrayTy, abi.SliceTy:
|
||||
// Explicitly convert multidimensional types to predefined type in go side.
|
||||
inner := bindTypeJava(*kind.Elem)
|
||||
switch inner {
|
||||
case "boolean":
|
||||
return "Bools"
|
||||
case "String":
|
||||
return "Strings"
|
||||
case "Address":
|
||||
return "Addresses"
|
||||
case "byte[]":
|
||||
return "Binaries"
|
||||
case "BigInt":
|
||||
return "BigInts"
|
||||
}
|
||||
return inner + "[]"
|
||||
default:
|
||||
return bindBasicTypeJava(kind)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +294,7 @@ func bindTopicTypeGo(kind abi.Type) string {
|
||||
// funcionality as for simple types, but dynamic types get converted to hashes.
|
||||
func bindTopicTypeJava(kind abi.Type) string {
|
||||
bound := bindTypeJava(kind)
|
||||
if bound == "String" || bound == "Bytes" {
|
||||
if bound == "String" || bound == "byte[]" {
|
||||
bound = "Hash"
|
||||
}
|
||||
return bound
|
||||
@@ -348,18 +313,8 @@ func namedTypeJava(javaKind string, solKind abi.Type) string {
|
||||
switch javaKind {
|
||||
case "byte[]":
|
||||
return "Binary"
|
||||
case "byte[][]":
|
||||
return "Binaries"
|
||||
case "string":
|
||||
return "String"
|
||||
case "string[]":
|
||||
return "Strings"
|
||||
case "boolean":
|
||||
return "Bool"
|
||||
case "boolean[]":
|
||||
return "Bools"
|
||||
case "BigInt[]":
|
||||
return "BigInts"
|
||||
default:
|
||||
parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(solKind.String())
|
||||
if len(parts) != 4 {
|
||||
|
||||
@@ -960,7 +960,7 @@ var bindTests = []struct {
|
||||
|
||||
// Tests that packages generated by the binder can be successfully compiled and
|
||||
// the requested tester run against it.
|
||||
func TestBindings(t *testing.T) {
|
||||
func TestGolangBindings(t *testing.T) {
|
||||
// Skip the test if no Go command can be found
|
||||
gocmd := runtime.GOROOT() + "/bin/go"
|
||||
if !common.FileExist(gocmd) {
|
||||
@@ -1011,3 +1011,400 @@ func TestBindings(t *testing.T) {
|
||||
t.Fatalf("failed to run binding test: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that java binding generated by the binder is exactly matched.
|
||||
func TestJavaBindings(t *testing.T) {
|
||||
var cases = []struct {
|
||||
name string
|
||||
contract string
|
||||
abi string
|
||||
bytecode string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"test",
|
||||
`
|
||||
pragma experimental ABIEncoderV2;
|
||||
pragma solidity ^0.5.2;
|
||||
|
||||
contract test {
|
||||
function setAddress(address a) public returns(address){}
|
||||
function setAddressList(address[] memory a_l) public returns(address[] memory){}
|
||||
function setAddressArray(address[2] memory a_a) public returns(address[2] memory){}
|
||||
|
||||
function setUint8(uint8 u8) public returns(uint8){}
|
||||
function setUint16(uint16 u16) public returns(uint16){}
|
||||
function setUint32(uint32 u32) public returns(uint32){}
|
||||
function setUint64(uint64 u64) public returns(uint64){}
|
||||
function setUint256(uint256 u256) public returns(uint256){}
|
||||
function setUint256List(uint256[] memory u256_l) public returns(uint256[] memory){}
|
||||
function setUint256Array(uint256[2] memory u256_a) public returns(uint256[2] memory){}
|
||||
|
||||
function setInt8(int8 i8) public returns(int8){}
|
||||
function setInt16(int16 i16) public returns(int16){}
|
||||
function setInt32(int32 i32) public returns(int32){}
|
||||
function setInt64(int64 i64) public returns(int64){}
|
||||
function setInt256(int256 i256) public returns(int256){}
|
||||
function setInt256List(int256[] memory i256_l) public returns(int256[] memory){}
|
||||
function setInt256Array(int256[2] memory i256_a) public returns(int256[2] memory){}
|
||||
|
||||
function setBytes1(bytes1 b1) public returns(bytes1) {}
|
||||
function setBytes32(bytes32 b32) public returns(bytes32) {}
|
||||
function setBytes(bytes memory bs) public returns(bytes memory) {}
|
||||
function setBytesList(bytes[] memory bs_l) public returns(bytes[] memory) {}
|
||||
function setBytesArray(bytes[2] memory bs_a) public returns(bytes[2] memory) {}
|
||||
|
||||
function setString(string memory s) public returns(string memory) {}
|
||||
function setStringList(string[] memory s_l) public returns(string[] memory) {}
|
||||
function setStringArray(string[2] memory s_a) public returns(string[2] memory) {}
|
||||
|
||||
function setBool(bool b) public returns(bool) {}
|
||||
function setBoolList(bool[] memory b_l) public returns(bool[] memory) {}
|
||||
function setBoolArray(bool[2] memory b_a) public returns(bool[2] memory) {}
|
||||
}`,
|
||||
`[{"constant":false,"inputs":[{"name":"u16","type":"uint16"}],"name":"setUint16","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"b_a","type":"bool[2]"}],"name":"setBoolArray","outputs":[{"name":"","type":"bool[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"a_a","type":"address[2]"}],"name":"setAddressArray","outputs":[{"name":"","type":"address[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"bs_l","type":"bytes[]"}],"name":"setBytesList","outputs":[{"name":"","type":"bytes[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u8","type":"uint8"}],"name":"setUint8","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u32","type":"uint32"}],"name":"setUint32","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"b","type":"bool"}],"name":"setBool","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i256_l","type":"int256[]"}],"name":"setInt256List","outputs":[{"name":"","type":"int256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u256_a","type":"uint256[2]"}],"name":"setUint256Array","outputs":[{"name":"","type":"uint256[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"b_l","type":"bool[]"}],"name":"setBoolList","outputs":[{"name":"","type":"bool[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"bs_a","type":"bytes[2]"}],"name":"setBytesArray","outputs":[{"name":"","type":"bytes[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"a_l","type":"address[]"}],"name":"setAddressList","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i256_a","type":"int256[2]"}],"name":"setInt256Array","outputs":[{"name":"","type":"int256[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"s_a","type":"string[2]"}],"name":"setStringArray","outputs":[{"name":"","type":"string[2]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"s","type":"string"}],"name":"setString","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u64","type":"uint64"}],"name":"setUint64","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i16","type":"int16"}],"name":"setInt16","outputs":[{"name":"","type":"int16"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i8","type":"int8"}],"name":"setInt8","outputs":[{"name":"","type":"int8"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u256_l","type":"uint256[]"}],"name":"setUint256List","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i256","type":"int256"}],"name":"setInt256","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i32","type":"int32"}],"name":"setInt32","outputs":[{"name":"","type":"int32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"b32","type":"bytes32"}],"name":"setBytes32","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"s_l","type":"string[]"}],"name":"setStringList","outputs":[{"name":"","type":"string[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"u256","type":"uint256"}],"name":"setUint256","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"bs","type":"bytes"}],"name":"setBytes","outputs":[{"name":"","type":"bytes"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"a","type":"address"}],"name":"setAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"i64","type":"int64"}],"name":"setInt64","outputLine truncated
|
||||
`608060405234801561001057600080fd5b5061265a806100206000396000f3fe608060405234801561001057600080fd5b50600436106101e1576000357c0100000000000000000000000000000000000000000000000000000000900480637fcaf66611610116578063c2b12a73116100b4578063da359dc81161008e578063da359dc814610666578063e30081a014610696578063e673eb32146106c6578063fba1a1c3146106f6576101e1565b8063c2b12a73146105d6578063c577796114610606578063d2282dc514610636576101e1565b80639a19a953116100f05780639a19a95314610516578063a0709e1914610546578063a53b1c1e14610576578063b7d5df31146105a6576101e1565b80637fcaf66614610486578063822cba69146104b657806386114cea146104e6576101e1565b806322722302116101835780635119655d1161015d5780635119655d146103c65780635be6b37e146103f65780636aa482fc146104265780637173b69514610456576101e1565b806322722302146103365780632766a755146103665780634d5ee6da14610396576101e1565b806316c105e2116101bf57806316c105e2146102765780631774e646146102a65780631c9352e2146102d65780631e26fd3314610306576101e1565b80630477988a146101e6578063118a971814610216578063151f547114610246575b600080fd5b61020060048036036101fb9190810190611599565b610726565b60405161020d9190611f01565b60405180910390f35b610230600480360361022b919081019061118d565b61072d565b60405161023d9190611ca6565b60405180910390f35b610260600480360361025b9190810190611123565b61073a565b60405161026d9190611c69565b60405180910390f35b610290600480360361028b9190810190611238565b610747565b60405161029d9190611d05565b60405180910390f35b6102c060048036036102bb919081019061163d565b61074e565b6040516102cd9190611f6d565b60405180910390f35b6102f060048036036102eb91908101906115eb565b610755565b6040516102fd9190611f37565b60405180910390f35b610320600480360361031b91908101906113cf565b61075c565b60405161032d9190611de5565b60405180910390f35b610350600480360361034b91908101906112a2565b610763565b60405161035d9190611d42565b60405180910390f35b610380600480360361037b9190810190611365565b61076a565b60405161038d9190611da8565b60405180910390f35b6103b060048036036103ab91908101906111b6565b610777565b6040516103bd9190611cc1565b60405180910390f35b6103e060048036036103db91908101906111f7565b61077e565b6040516103ed9190611ce3565b60405180910390f35b610410600480360361040b919081019061114c565b61078b565b60405161041d9190611c84565b60405180910390f35b610440600480360361043b9190810190611279565b610792565b60405161044d9190611d27565b60405180910390f35b610470600480360361046b91908101906112e3565b61079f565b60405161047d9190611d64565b60405180910390f35b6104a0600480360361049b9190810190611558565b6107ac565b6040516104ad9190611edf565b60405180910390f35b6104d060048036036104cb9190810190611614565b6107b3565b6040516104dd9190611f52565b60405180910390f35b61050060048036036104fb919081019061148b565b6107ba565b60405161050d9190611e58565b60405180910390f35b610530600480360361052b919081019061152f565b6107c1565b60405161053d9190611ec4565b60405180910390f35b610560600480360361055b919081019061138e565b6107c8565b60405161056d9190611dc3565b60405180910390f35b610590600480360361058b91908101906114b4565b6107cf565b60405161059d9190611e73565b60405180910390f35b6105c060048036036105bb91908101906114dd565b6107d6565b6040516105cd9190611e8e565b60405180910390f35b6105f060048036036105eb9190810190611421565b6107dd565b6040516105fd9190611e1b565b60405180910390f35b610620600480360361061b9190810190611324565b6107e4565b60405161062d9190611d86565b60405180910390f35b610650600480360361064b91908101906115c2565b6107eb565b60405161065d9190611f1c565b60405180910390f35b610680600480360361067b919081019061144a565b6107f2565b60405161068d9190611e36565b60405180910390f35b6106b060048036036106ab91908101906110fa565b6107f9565b6040516106bd9190611c4e565b60405180910390f35b6106e060048036036106db9190810190611506565b610800565b6040516106ed9190611ea9565b60405180910390f35b610710600480360361070b91908101906113f8565b610807565b60405161071d9190611e00565b60405180910390f35b6000919050565b61073561080e565b919050565b610742610830565b919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b610772610852565b919050565b6060919050565b610786610874565b919050565b6060919050565b61079a61089b565b919050565b6107a76108bd565b919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b6000919050565b6060919050565b6000919050565b6000919050565b6000919050565b6040805190810160405280600290602082028038833980820191505090505090565b6040805190810160405280600290602082028038833980820191505090505090565b6040805190810160405280600290602082028038833980820191505090505090565b60408051908101604052806002905b60608152602001906001900390816108835790505090565b6040805190810160405280600290602082028038833980820191505090505090565b60408051908101604052806002905b60608152602001906001900390816108cc5790505090565b60006108f082356124f2565b905092915050565b600082601f830112151561090b57600080fd5b600261091e61091982611fb5565b611f88565b9150818385602084028201111561093457600080fd5b60005b83811015610964578161094a88826108e4565b845260208401935060208301925050600181019050610937565b5050505092915050565b600082601f830112151561098157600080fd5b813561099461098f82611fd7565b611f88565b9150818183526020840193506Line truncated
|
||||
`
|
||||
// This file is an automatically generated Java binding. Do not modify as any
|
||||
// change will likely be lost upon the next re-generation!
|
||||
|
||||
package bindtest;
|
||||
|
||||
import org.ethereum.geth.*;
|
||||
|
||||
|
||||
public class Test {
|
||||
// ABI is the input ABI used to generate the binding from.
|
||||
public final static String ABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"u16\",\"type\":\"uint16\"}],\"name\":\"setUint16\",\"outputs\":[{\"name\":\"\",\"type\":\"uint16\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"b_a\",\"type\":\"bool[2]\"}],\"name\":\"setBoolArray\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a_a\",\"type\":\"address[2]\"}],\"name\":\"setAddressArray\",\"outputs\":[{\"name\":\"\",\"type\":\"address[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"bs_l\",\"type\":\"bytes[]\"}],\"name\":\"setBytesList\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"u8\",\"type\":\"uint8\"}],\"name\":\"setUint8\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"u32\",\"type\":\"uint32\"}],\"name\":\"setUint32\",\"outputs\":[{\"name\":\"\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"b\",\"type\":\"bool\"}],\"name\":\"setBool\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i256_l\",\"type\":\"int256[]\"}],\"name\":\"setInt256List\",\"outputs\":[{\"name\":\"\",\"type\":\"int256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"u256_a\",\"type\":\"uint256[2]\"}],\"name\":\"setUint256Array\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"b_l\",\"type\":\"bool[]\"}],\"name\":\"setBoolList\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"bs_a\",\"type\":\"bytes[2]\"}],\"name\":\"setBytesArray\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a_l\",\"type\":\"address[]\"}],\"name\":\"setAddressList\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i256_a\",\"type\":\"int256[2]\"}],\"name\":\"setInt256Array\",\"outputs\":[{\"name\":\"\",\"type\":\"int256[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"s_a\",\"type\":\"string[2]\"}],\"name\":\"setStringArray\",\"outputs\":[{\"name\":\"\",\"type\":\"string[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"s\",\"type\":\"string\"}],\"name\":\"setString\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"u64\",\"type\":\"uint64\"}],\"name\":\"setUint64\",\"outputs\":[{\"name\":\"\",\"type\":\"uint64\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i16\",\"type\":\"int16\"}],\"name\":\"setInt16\",\"outputs\":[{\"name\":\"\",\"type\":\"int16\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i8\",\"type\":\"int8\"}],\"name\":\"setInt8\",\"outputs\":[{\"name\":\"\",\"type\":\"int8\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"u256_l\",\"type\":\"uint256[]\"}],\"name\":\"setUint256List\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i256\",\"type\":\"int256\"}],\"name\":\"setInt256\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"i32\",\"type\":\"int32\"}],\"name\":\"setInt32\",\"outputs\":[{\"name\":\"\",\"type\":\"int32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"b32\",\"type\":\"bytes32\"}],\"name\":\"setBytes32\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constanLine truncated
|
||||
|
||||
|
||||
// BYTECODE is the compiled bytecode used for deploying new contracts.
|
||||
public final static String BYTECODE = "0x608060405234801561001057600080fd5b5061265a806100206000396000f3fe608060405234801561001057600080fd5b50600436106101e1576000357c0100000000000000000000000000000000000000000000000000000000900480637fcaf66611610116578063c2b12a73116100b4578063da359dc81161008e578063da359dc814610666578063e30081a014610696578063e673eb32146106c6578063fba1a1c3146106f6576101e1565b8063c2b12a73146105d6578063c577796114610606578063d2282dc514610636576101e1565b80639a19a953116100f05780639a19a95314610516578063a0709e1914610546578063a53b1c1e14610576578063b7d5df31146105a6576101e1565b80637fcaf66614610486578063822cba69146104b657806386114cea146104e6576101e1565b806322722302116101835780635119655d1161015d5780635119655d146103c65780635be6b37e146103f65780636aa482fc146104265780637173b69514610456576101e1565b806322722302146103365780632766a755146103665780634d5ee6da14610396576101e1565b806316c105e2116101bf57806316c105e2146102765780631774e646146102a65780631c9352e2146102d65780631e26fd3314610306576101e1565b80630477988a146101e6578063118a971814610216578063151f547114610246575b600080fd5b61020060048036036101fb9190810190611599565b610726565b60405161020d9190611f01565b60405180910390f35b610230600480360361022b919081019061118d565b61072d565b60405161023d9190611ca6565b60405180910390f35b610260600480360361025b9190810190611123565b61073a565b60405161026d9190611c69565b60405180910390f35b610290600480360361028b9190810190611238565b610747565b60405161029d9190611d05565b60405180910390f35b6102c060048036036102bb919081019061163d565b61074e565b6040516102cd9190611f6d565b60405180910390f35b6102f060048036036102eb91908101906115eb565b610755565b6040516102fd9190611f37565b60405180910390f35b610320600480360361031b91908101906113cf565b61075c565b60405161032d9190611de5565b60405180910390f35b610350600480360361034b91908101906112a2565b610763565b60405161035d9190611d42565b60405180910390f35b610380600480360361037b9190810190611365565b61076a565b60405161038d9190611da8565b60405180910390f35b6103b060048036036103ab91908101906111b6565b610777565b6040516103bd9190611cc1565b60405180910390f35b6103e060048036036103db91908101906111f7565b61077e565b6040516103ed9190611ce3565b60405180910390f35b610410600480360361040b919081019061114c565b61078b565b60405161041d9190611c84565b60405180910390f35b610440600480360361043b9190810190611279565b610792565b60405161044d9190611d27565b60405180910390f35b610470600480360361046b91908101906112e3565b61079f565b60405161047d9190611d64565b60405180910390f35b6104a0600480360361049b9190810190611558565b6107ac565b6040516104ad9190611edf565b60405180910390f35b6104d060048036036104cb9190810190611614565b6107b3565b6040516104dd9190611f52565b60405180910390f35b61050060048036036104fb919081019061148b565b6107ba565b60405161050d9190611e58565b60405180910390f35b610530600480360361052b919081019061152f565b6107c1565b60405161053d9190611ec4565b60405180910390f35b610560600480360361055b919081019061138e565b6107c8565b60405161056d9190611dc3565b60405180910390f35b610590600480360361058b91908101906114b4565b6107cf565b60405161059d9190611e73565b60405180910390f35b6105c060048036036105bb91908101906114dd565b6107d6565b6040516105cd9190611e8e565b60405180910390f35b6105f060048036036105eb9190810190611421565b6107dd565b6040516105fd9190611e1b565b60405180910390f35b610620600480360361061b9190810190611324565b6107e4565b60405161062d9190611d86565b60405180910390f35b610650600480360361064b91908101906115c2565b6107eb565b60405161065d9190611f1c565b60405180910390f35b610680600480360361067b919081019061144a565b6107f2565b60405161068d9190611e36565b60405180910390f35b6106b060048036036106ab91908101906110fa565b6107f9565b6040516106bd9190611c4e565b60405180910390f35b6106e060048036036106db9190810190611506565b610800565b6040516106ed9190611ea9565b60405180910390f35b610710600480360361070b91908101906113f8565b610807565b60405161071d9190611e00565b60405180910390f35b6000919050565b61073561080e565b919050565b610742610830565b919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b610772610852565b919050565b6060919050565b610786610874565b919050565b6060919050565b61079a61089b565b919050565b6107a76108bd565b919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b6000919050565b6000919050565b6000919050565b6060919050565b6000919050565b6060919050565b6000919050565b6000919050565b6000919050565b6040805190810160405280600290602082028038833980820191505090505090565b6040805190810160405280600290602082028038833980820191505090505090565b6040805190810160405280600290602082028038833980820191505090505090565b60408051908101604052806002905b60608152602001906001900390816108835790505090565b6040805190810160405280600290602082028038833980820191505090505090565b60408051908101604052806002905b60608152602001906001900390816108cc5790505090565b60006108f082356124f2565b905092915050565b600082601f830112151561090b57600080fd5b600261091e61091982611fb5565b611f88565b9150818385602084028201111561093457600080fd5b60005b83811015610964578161094a88826108e4565b845260208401935060208301925050600181019050610937565b5050505092915050565b600082601f830112151561098157600080fd5b813561099461098f82611fd75Line truncated
|
||||
|
||||
// deploy deploys a new Ethereum contract, binding an instance of Test to it.
|
||||
public static Test deploy(TransactOpts auth, EthereumClient client) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(0);
|
||||
|
||||
return new Test(Geth.deployContract(auth, ABI, Geth.decodeFromHex(BYTECODE), client, args));
|
||||
}
|
||||
|
||||
// Internal constructor used by contract deployment.
|
||||
private Test(BoundContract deployment) {
|
||||
this.Address = deployment.getAddress();
|
||||
this.Deployer = deployment.getDeployer();
|
||||
this.Contract = deployment;
|
||||
}
|
||||
|
||||
|
||||
// Ethereum address where this contract is located at.
|
||||
public final Address Address;
|
||||
|
||||
// Ethereum transaction in which this contract was deployed (if known!).
|
||||
public final Transaction Deployer;
|
||||
|
||||
// Contract instance bound to a blockchain address.
|
||||
private final BoundContract Contract;
|
||||
|
||||
// Creates a new instance of Test, bound to a specific deployed contract.
|
||||
public Test(Address address, EthereumClient client) throws Exception {
|
||||
this(Geth.bindContract(address, ABI, client));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// setAddress is a paid mutator transaction binding the contract method 0xe30081a0.
|
||||
//
|
||||
// Solidity: function setAddress(address a) returns(address)
|
||||
public Transaction setAddress(TransactOpts opts, Address a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setAddress(a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setAddress" , args);
|
||||
}
|
||||
|
||||
// setAddressArray is a paid mutator transaction binding the contract method 0x151f5471.
|
||||
//
|
||||
// Solidity: function setAddressArray(address[2] a_a) returns(address[2])
|
||||
public Transaction setAddressArray(TransactOpts opts, Addresses a_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setAddresses(a_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setAddressArray" , args);
|
||||
}
|
||||
|
||||
// setAddressList is a paid mutator transaction binding the contract method 0x5be6b37e.
|
||||
//
|
||||
// Solidity: function setAddressList(address[] a_l) returns(address[])
|
||||
public Transaction setAddressList(TransactOpts opts, Addresses a_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setAddresses(a_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setAddressList" , args);
|
||||
}
|
||||
|
||||
// setBool is a paid mutator transaction binding the contract method 0x1e26fd33.
|
||||
//
|
||||
// Solidity: function setBool(bool b) returns(bool)
|
||||
public Transaction setBool(TransactOpts opts, boolean b) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBool(b);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBool" , args);
|
||||
}
|
||||
|
||||
// setBoolArray is a paid mutator transaction binding the contract method 0x118a9718.
|
||||
//
|
||||
// Solidity: function setBoolArray(bool[2] b_a) returns(bool[2])
|
||||
public Transaction setBoolArray(TransactOpts opts, Bools b_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBools(b_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBoolArray" , args);
|
||||
}
|
||||
|
||||
// setBoolList is a paid mutator transaction binding the contract method 0x4d5ee6da.
|
||||
//
|
||||
// Solidity: function setBoolList(bool[] b_l) returns(bool[])
|
||||
public Transaction setBoolList(TransactOpts opts, Bools b_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBools(b_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBoolList" , args);
|
||||
}
|
||||
|
||||
// setBytes is a paid mutator transaction binding the contract method 0xda359dc8.
|
||||
//
|
||||
// Solidity: function setBytes(bytes bs) returns(bytes)
|
||||
public Transaction setBytes(TransactOpts opts, byte[] bs) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBinary(bs);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBytes" , args);
|
||||
}
|
||||
|
||||
// setBytes1 is a paid mutator transaction binding the contract method 0xfba1a1c3.
|
||||
//
|
||||
// Solidity: function setBytes1(bytes1 b1) returns(bytes1)
|
||||
public Transaction setBytes1(TransactOpts opts, byte[] b1) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBinary(b1);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBytes1" , args);
|
||||
}
|
||||
|
||||
// setBytes32 is a paid mutator transaction binding the contract method 0xc2b12a73.
|
||||
//
|
||||
// Solidity: function setBytes32(bytes32 b32) returns(bytes32)
|
||||
public Transaction setBytes32(TransactOpts opts, byte[] b32) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBinary(b32);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBytes32" , args);
|
||||
}
|
||||
|
||||
// setBytesArray is a paid mutator transaction binding the contract method 0x5119655d.
|
||||
//
|
||||
// Solidity: function setBytesArray(bytes[2] bs_a) returns(bytes[2])
|
||||
public Transaction setBytesArray(TransactOpts opts, Binaries bs_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBinaries(bs_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBytesArray" , args);
|
||||
}
|
||||
|
||||
// setBytesList is a paid mutator transaction binding the contract method 0x16c105e2.
|
||||
//
|
||||
// Solidity: function setBytesList(bytes[] bs_l) returns(bytes[])
|
||||
public Transaction setBytesList(TransactOpts opts, Binaries bs_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBinaries(bs_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setBytesList" , args);
|
||||
}
|
||||
|
||||
// setInt16 is a paid mutator transaction binding the contract method 0x86114cea.
|
||||
//
|
||||
// Solidity: function setInt16(int16 i16) returns(int16)
|
||||
public Transaction setInt16(TransactOpts opts, short i16) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setInt16(i16);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt16" , args);
|
||||
}
|
||||
|
||||
// setInt256 is a paid mutator transaction binding the contract method 0xa53b1c1e.
|
||||
//
|
||||
// Solidity: function setInt256(int256 i256) returns(int256)
|
||||
public Transaction setInt256(TransactOpts opts, BigInt i256) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInt(i256);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt256" , args);
|
||||
}
|
||||
|
||||
// setInt256Array is a paid mutator transaction binding the contract method 0x6aa482fc.
|
||||
//
|
||||
// Solidity: function setInt256Array(int256[2] i256_a) returns(int256[2])
|
||||
public Transaction setInt256Array(TransactOpts opts, BigInts i256_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInts(i256_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt256Array" , args);
|
||||
}
|
||||
|
||||
// setInt256List is a paid mutator transaction binding the contract method 0x22722302.
|
||||
//
|
||||
// Solidity: function setInt256List(int256[] i256_l) returns(int256[])
|
||||
public Transaction setInt256List(TransactOpts opts, BigInts i256_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInts(i256_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt256List" , args);
|
||||
}
|
||||
|
||||
// setInt32 is a paid mutator transaction binding the contract method 0xb7d5df31.
|
||||
//
|
||||
// Solidity: function setInt32(int32 i32) returns(int32)
|
||||
public Transaction setInt32(TransactOpts opts, int i32) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setInt32(i32);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt32" , args);
|
||||
}
|
||||
|
||||
// setInt64 is a paid mutator transaction binding the contract method 0xe673eb32.
|
||||
//
|
||||
// Solidity: function setInt64(int64 i64) returns(int64)
|
||||
public Transaction setInt64(TransactOpts opts, long i64) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setInt64(i64);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt64" , args);
|
||||
}
|
||||
|
||||
// setInt8 is a paid mutator transaction binding the contract method 0x9a19a953.
|
||||
//
|
||||
// Solidity: function setInt8(int8 i8) returns(int8)
|
||||
public Transaction setInt8(TransactOpts opts, byte i8) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setInt8(i8);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setInt8" , args);
|
||||
}
|
||||
|
||||
// setString is a paid mutator transaction binding the contract method 0x7fcaf666.
|
||||
//
|
||||
// Solidity: function setString(string s) returns(string)
|
||||
public Transaction setString(TransactOpts opts, String s) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setString(s);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setString" , args);
|
||||
}
|
||||
|
||||
// setStringArray is a paid mutator transaction binding the contract method 0x7173b695.
|
||||
//
|
||||
// Solidity: function setStringArray(string[2] s_a) returns(string[2])
|
||||
public Transaction setStringArray(TransactOpts opts, Strings s_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setStrings(s_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setStringArray" , args);
|
||||
}
|
||||
|
||||
// setStringList is a paid mutator transaction binding the contract method 0xc5777961.
|
||||
//
|
||||
// Solidity: function setStringList(string[] s_l) returns(string[])
|
||||
public Transaction setStringList(TransactOpts opts, Strings s_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setStrings(s_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setStringList" , args);
|
||||
}
|
||||
|
||||
// setUint16 is a paid mutator transaction binding the contract method 0x0477988a.
|
||||
//
|
||||
// Solidity: function setUint16(uint16 u16) returns(uint16)
|
||||
public Transaction setUint16(TransactOpts opts, BigInt u16) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setUint16(u16);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint16" , args);
|
||||
}
|
||||
|
||||
// setUint256 is a paid mutator transaction binding the contract method 0xd2282dc5.
|
||||
//
|
||||
// Solidity: function setUint256(uint256 u256) returns(uint256)
|
||||
public Transaction setUint256(TransactOpts opts, BigInt u256) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInt(u256);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint256" , args);
|
||||
}
|
||||
|
||||
// setUint256Array is a paid mutator transaction binding the contract method 0x2766a755.
|
||||
//
|
||||
// Solidity: function setUint256Array(uint256[2] u256_a) returns(uint256[2])
|
||||
public Transaction setUint256Array(TransactOpts opts, BigInts u256_a) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInts(u256_a);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint256Array" , args);
|
||||
}
|
||||
|
||||
// setUint256List is a paid mutator transaction binding the contract method 0xa0709e19.
|
||||
//
|
||||
// Solidity: function setUint256List(uint256[] u256_l) returns(uint256[])
|
||||
public Transaction setUint256List(TransactOpts opts, BigInts u256_l) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setBigInts(u256_l);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint256List" , args);
|
||||
}
|
||||
|
||||
// setUint32 is a paid mutator transaction binding the contract method 0x1c9352e2.
|
||||
//
|
||||
// Solidity: function setUint32(uint32 u32) returns(uint32)
|
||||
public Transaction setUint32(TransactOpts opts, BigInt u32) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setUint32(u32);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint32" , args);
|
||||
}
|
||||
|
||||
// setUint64 is a paid mutator transaction binding the contract method 0x822cba69.
|
||||
//
|
||||
// Solidity: function setUint64(uint64 u64) returns(uint64)
|
||||
public Transaction setUint64(TransactOpts opts, BigInt u64) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setUint64(u64);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint64" , args);
|
||||
}
|
||||
|
||||
// setUint8 is a paid mutator transaction binding the contract method 0x1774e646.
|
||||
//
|
||||
// Solidity: function setUint8(uint8 u8) returns(uint8)
|
||||
public Transaction setUint8(TransactOpts opts, BigInt u8) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces(1);
|
||||
Interface arg0 = Geth.newInterface();arg0.setUint8(u8);args.set(0,arg0);
|
||||
|
||||
return this.Contract.transact(opts, "setUint8" , args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
`,
|
||||
},
|
||||
}
|
||||
for i, c := range cases {
|
||||
binding, err := Bind([]string{c.name}, []string{c.abi}, []string{c.bytecode}, "bindtest", LangJava)
|
||||
if err != nil {
|
||||
t.Fatalf("test %d: failed to generate binding: %v", i, err)
|
||||
}
|
||||
if binding != c.expected {
|
||||
t.Fatalf("test %d: generated binding mismatch, has %s, want %s", i, binding, c.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,95 +452,92 @@ const tmplSourceJava = `
|
||||
package {{.Package}};
|
||||
|
||||
import org.ethereum.geth.*;
|
||||
import org.ethereum.geth.internal.*;
|
||||
|
||||
{{range $contract := .Contracts}}
|
||||
public class {{.Type}} {
|
||||
// ABI is the input ABI used to generate the binding from.
|
||||
public final static String ABI = "{{.InputABI}}";
|
||||
public class {{.Type}} {
|
||||
// ABI is the input ABI used to generate the binding from.
|
||||
public final static String ABI = "{{.InputABI}}";
|
||||
|
||||
{{if .InputBin}}
|
||||
// BYTECODE is the compiled bytecode used for deploying new contracts.
|
||||
public final static byte[] BYTECODE = "{{.InputBin}}".getBytes();
|
||||
{{if .InputBin}}
|
||||
// BYTECODE is the compiled bytecode used for deploying new contracts.
|
||||
public final static String BYTECODE = "0x{{.InputBin}}";
|
||||
|
||||
// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
|
||||
public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
|
||||
{{range $index, $element := .Constructor.Inputs}}
|
||||
args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}});
|
||||
{{end}}
|
||||
return new {{.Type}}(Geth.deployContract(auth, ABI, BYTECODE, client, args));
|
||||
}
|
||||
|
||||
// Internal constructor used by contract deployment.
|
||||
private {{.Type}}(BoundContract deployment) {
|
||||
this.Address = deployment.getAddress();
|
||||
this.Deployer = deployment.getDeployer();
|
||||
this.Contract = deployment;
|
||||
}
|
||||
// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
|
||||
public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
|
||||
{{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||
{{end}}
|
||||
return new {{.Type}}(Geth.deployContract(auth, ABI, Geth.decodeFromHex(BYTECODE), client, args));
|
||||
}
|
||||
|
||||
// Ethereum address where this contract is located at.
|
||||
public final Address Address;
|
||||
// Internal constructor used by contract deployment.
|
||||
private {{.Type}}(BoundContract deployment) {
|
||||
this.Address = deployment.getAddress();
|
||||
this.Deployer = deployment.getDeployer();
|
||||
this.Contract = deployment;
|
||||
}
|
||||
{{end}}
|
||||
|
||||
// Ethereum transaction in which this contract was deployed (if known!).
|
||||
public final Transaction Deployer;
|
||||
// Ethereum address where this contract is located at.
|
||||
public final Address Address;
|
||||
|
||||
// Contract instance bound to a blockchain address.
|
||||
private final BoundContract Contract;
|
||||
// Ethereum transaction in which this contract was deployed (if known!).
|
||||
public final Transaction Deployer;
|
||||
|
||||
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
|
||||
public {{.Type}}(Address address, EthereumClient client) throws Exception {
|
||||
this(Geth.bindContract(address, ABI, client));
|
||||
}
|
||||
// Contract instance bound to a blockchain address.
|
||||
private final BoundContract Contract;
|
||||
|
||||
{{range .Calls}}
|
||||
{{if gt (len .Normalized.Outputs) 1}}
|
||||
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
|
||||
public class {{capitalise .Normalized.Name}}Results {
|
||||
{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
|
||||
public {{.Type}}(Address address, EthereumClient client) throws Exception {
|
||||
this(Geth.bindContract(address, ABI, client));
|
||||
}
|
||||
|
||||
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||
//
|
||||
// Solidity: {{.Original.String}}
|
||||
public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||
{{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}});
|
||||
{{end}}
|
||||
|
||||
Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
|
||||
{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}});
|
||||
{{end}}
|
||||
|
||||
if (opts == null) {
|
||||
opts = Geth.newCallOpts();
|
||||
}
|
||||
this.Contract.call(opts, results, "{{.Original.Name}}", args);
|
||||
{{if gt (len .Normalized.Outputs) 1}}
|
||||
{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
|
||||
{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}();
|
||||
{{end}}
|
||||
return result;
|
||||
{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{range .Transacts}}
|
||||
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||
//
|
||||
// Solidity: {{.Original.String}}
|
||||
public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||
{{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}});
|
||||
{{end}}
|
||||
|
||||
return this.Contract.transact(opts, "{{.Original.Name}}" , args);
|
||||
}
|
||||
{{range .Calls}}
|
||||
{{if gt (len .Normalized.Outputs) 1}}
|
||||
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
|
||||
public class {{capitalise .Normalized.Name}}Results {
|
||||
{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||
//
|
||||
// Solidity: {{.Original.String}}
|
||||
public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||
{{end}}
|
||||
|
||||
Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
|
||||
{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}});
|
||||
{{end}}
|
||||
|
||||
if (opts == null) {
|
||||
opts = Geth.newCallOpts();
|
||||
}
|
||||
this.Contract.call(opts, results, "{{.Original.Name}}", args);
|
||||
{{if gt (len .Normalized.Outputs) 1}}
|
||||
{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
|
||||
{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}();
|
||||
{{end}}
|
||||
return result;
|
||||
{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{range .Transacts}}
|
||||
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||
//
|
||||
// Solidity: {{.Original.String}}
|
||||
public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||
{{end}}
|
||||
return this.Contract.transact(opts, "{{.Original.Name}}" , args);
|
||||
}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
`
|
||||
@@ -69,8 +69,6 @@ func main() {
|
||||
lang = bind.LangGo
|
||||
case "java":
|
||||
lang = bind.LangJava
|
||||
case "objc":
|
||||
lang = bind.LangObjC
|
||||
default:
|
||||
fmt.Printf("Unsupported destination language \"%s\" (--lang)\n", *langFlag)
|
||||
os.Exit(-1)
|
||||
|
||||
+36
-4
@@ -19,27 +19,30 @@
|
||||
package geth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
// Signer is an interaface defining the callback when a contract requires a
|
||||
// Signer is an interface defining the callback when a contract requires a
|
||||
// method to sign the transaction before submission.
|
||||
type Signer interface {
|
||||
Sign(*Address, *Transaction) (tx *Transaction, _ error)
|
||||
}
|
||||
|
||||
type signer struct {
|
||||
type MobileSigner struct {
|
||||
sign bind.SignerFn
|
||||
}
|
||||
|
||||
func (s *signer) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
|
||||
sig, err := s.sign(types.HomesteadSigner{}, addr.address, unsignedTx.tx)
|
||||
func (s *MobileSigner) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
|
||||
sig, err := s.sign(types.EIP155Signer{}, addr.address, unsignedTx.tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,6 +76,35 @@ type TransactOpts struct {
|
||||
opts bind.TransactOpts
|
||||
}
|
||||
|
||||
// NewTransactOpts creates a new option set for contract transaction.
|
||||
func NewTransactOpts() *TransactOpts {
|
||||
return new(TransactOpts)
|
||||
}
|
||||
|
||||
// NewKeyedTransactor is a utility method to easily create a transaction signer
|
||||
// from a single private key.
|
||||
func NewKeyedTransactOpts(keyJson []byte, passphrase string) (*TransactOpts, error) {
|
||||
key, err := keystore.DecryptKey(keyJson, passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keyAddr := crypto.PubkeyToAddress(key.PrivateKey.PublicKey)
|
||||
opts := bind.TransactOpts{
|
||||
From: keyAddr,
|
||||
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||
if address != keyAddr {
|
||||
return nil, errors.New("not authorized to sign this account")
|
||||
}
|
||||
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key.PrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tx.WithSignature(signer, signature)
|
||||
},
|
||||
}
|
||||
return &TransactOpts{opts}, nil
|
||||
}
|
||||
|
||||
func (opts *TransactOpts) GetFrom() *Address { return &Address{opts.opts.From} }
|
||||
func (opts *TransactOpts) GetNonce() int64 { return opts.opts.Nonce.Int64() }
|
||||
func (opts *TransactOpts) GetValue() *BigInt { return &BigInt{opts.opts.Value} }
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
// Hash represents the 32 byte Keccak256 hash of arbitrary data.
|
||||
@@ -228,3 +229,13 @@ func (a *Addresses) Set(index int, address *Address) error {
|
||||
func (a *Addresses) Append(address *Address) {
|
||||
a.addresses = append(a.addresses, address.address)
|
||||
}
|
||||
|
||||
// EncodeToHex encodes b as a hex string with 0x prefix.
|
||||
func EncodeToHex(b []byte) string {
|
||||
return hexutil.Encode(b)
|
||||
}
|
||||
|
||||
// DecodeFromHex decodes a hex string with 0x prefix.
|
||||
func DecodeFromHex(s string) ([]byte, error) {
|
||||
return hexutil.Decode(s)
|
||||
}
|
||||
+154
-26
@@ -42,26 +42,82 @@ func NewInterface() *Interface {
|
||||
return new(Interface)
|
||||
}
|
||||
|
||||
func (i *Interface) SetBool(b bool) { i.object = &b }
|
||||
func (i *Interface) SetBools(bs []bool) { i.object = &bs }
|
||||
func (i *Interface) SetString(str string) { i.object = &str }
|
||||
func (i *Interface) SetStrings(strs *Strings) { i.object = &strs.strs }
|
||||
func (i *Interface) SetBinary(binary []byte) { b := common.CopyBytes(binary); i.object = &b }
|
||||
func (i *Interface) SetBinaries(binaries [][]byte) { i.object = &binaries }
|
||||
func (i *Interface) SetAddress(address *Address) { i.object = &address.address }
|
||||
func (i *Interface) SetAddresses(addrs *Addresses) { i.object = &addrs.addresses }
|
||||
func (i *Interface) SetHash(hash *Hash) { i.object = &hash.hash }
|
||||
func (i *Interface) SetHashes(hashes *Hashes) { i.object = &hashes.hashes }
|
||||
func (i *Interface) SetInt8(n int8) { i.object = &n }
|
||||
func (i *Interface) SetInt16(n int16) { i.object = &n }
|
||||
func (i *Interface) SetInt32(n int32) { i.object = &n }
|
||||
func (i *Interface) SetInt64(n int64) { i.object = &n }
|
||||
func (i *Interface) SetUint8(bigint *BigInt) { n := uint8(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint16(bigint *BigInt) { n := uint16(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint32(bigint *BigInt) { n := uint32(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint64(bigint *BigInt) { n := bigint.bigint.Uint64(); i.object = &n }
|
||||
func (i *Interface) SetBigInt(bigint *BigInt) { i.object = &bigint.bigint }
|
||||
func (i *Interface) SetBigInts(bigints *BigInts) { i.object = &bigints.bigints }
|
||||
func (i *Interface) SetBool(b bool) { i.object = &b }
|
||||
func (i *Interface) SetBools(bs *Bools) { i.object = &bs.bools }
|
||||
func (i *Interface) SetString(str string) { i.object = &str }
|
||||
func (i *Interface) SetStrings(strs *Strings) { i.object = &strs.strs }
|
||||
func (i *Interface) SetBinary(binary []byte) { b := common.CopyBytes(binary); i.object = &b }
|
||||
func (i *Interface) SetBinaries(binaries *Binaries) { i.object = &binaries.binaries }
|
||||
func (i *Interface) SetAddress(address *Address) { i.object = &address.address }
|
||||
func (i *Interface) SetAddresses(addrs *Addresses) { i.object = &addrs.addresses }
|
||||
func (i *Interface) SetHash(hash *Hash) { i.object = &hash.hash }
|
||||
func (i *Interface) SetHashes(hashes *Hashes) { i.object = &hashes.hashes }
|
||||
func (i *Interface) SetInt8(n int8) { i.object = &n }
|
||||
func (i *Interface) SetInt16(n int16) { i.object = &n }
|
||||
func (i *Interface) SetInt32(n int32) { i.object = &n }
|
||||
func (i *Interface) SetInt64(n int64) { i.object = &n }
|
||||
func (i *Interface) SetInt8s(bigints *BigInts) {
|
||||
ints := make([]int8, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, int8(bi.Int64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetInt16s(bigints *BigInts) {
|
||||
ints := make([]int16, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, int16(bi.Int64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetInt32s(bigints *BigInts) {
|
||||
ints := make([]int32, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, int32(bi.Int64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetInt64s(bigints *BigInts) {
|
||||
ints := make([]int64, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, bi.Int64())
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetUint8(bigint *BigInt) { n := uint8(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint16(bigint *BigInt) { n := uint16(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint32(bigint *BigInt) { n := uint32(bigint.bigint.Uint64()); i.object = &n }
|
||||
func (i *Interface) SetUint64(bigint *BigInt) { n := bigint.bigint.Uint64(); i.object = &n }
|
||||
func (i *Interface) SetUint8s(bigints *BigInts) {
|
||||
ints := make([]uint8, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, uint8(bi.Uint64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetUint16s(bigints *BigInts) {
|
||||
ints := make([]uint16, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, uint16(bi.Uint64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetUint32s(bigints *BigInts) {
|
||||
ints := make([]uint32, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, uint32(bi.Uint64()))
|
||||
}
|
||||
i.object = &ints
|
||||
}
|
||||
func (i *Interface) SetUint64s(bigints *BigInts) {
|
||||
ints := make([]uint64, 0, bigints.Size())
|
||||
for _, bi := range bigints.bigints {
|
||||
ints = append(ints, bi.Uint64())
|
||||
}
|
||||
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) SetDefaultBool() { i.object = new(bool) }
|
||||
func (i *Interface) SetDefaultBools() { i.object = new([]bool) }
|
||||
@@ -74,22 +130,30 @@ func (i *Interface) SetDefaultAddresses() { i.object = new([]common.Address) }
|
||||
func (i *Interface) SetDefaultHash() { i.object = new(common.Hash) }
|
||||
func (i *Interface) SetDefaultHashes() { i.object = new([]common.Hash) }
|
||||
func (i *Interface) SetDefaultInt8() { i.object = new(int8) }
|
||||
func (i *Interface) SetDefaultInt8s() { i.object = new([]int8) }
|
||||
func (i *Interface) SetDefaultInt16() { i.object = new(int16) }
|
||||
func (i *Interface) SetDefaultInt16s() { i.object = new([]int16) }
|
||||
func (i *Interface) SetDefaultInt32() { i.object = new(int32) }
|
||||
func (i *Interface) SetDefaultInt32s() { i.object = new([]int32) }
|
||||
func (i *Interface) SetDefaultInt64() { i.object = new(int64) }
|
||||
func (i *Interface) SetDefaultInt64s() { i.object = new([]int64) }
|
||||
func (i *Interface) SetDefaultUint8() { i.object = new(uint8) }
|
||||
func (i *Interface) SetDefaultUint8s() { i.object = new([]uint8) }
|
||||
func (i *Interface) SetDefaultUint16() { i.object = new(uint16) }
|
||||
func (i *Interface) SetDefaultUint16s() { i.object = new([]uint16) }
|
||||
func (i *Interface) SetDefaultUint32() { i.object = new(uint32) }
|
||||
func (i *Interface) SetDefaultUint32s() { i.object = new([]uint32) }
|
||||
func (i *Interface) SetDefaultUint64() { i.object = new(uint64) }
|
||||
func (i *Interface) SetDefaultUint64s() { i.object = new([]uint64) }
|
||||
func (i *Interface) SetDefaultBigInt() { i.object = new(*big.Int) }
|
||||
func (i *Interface) SetDefaultBigInts() { i.object = new([]*big.Int) }
|
||||
|
||||
func (i *Interface) GetBool() bool { return *i.object.(*bool) }
|
||||
func (i *Interface) GetBools() []bool { return *i.object.(*[]bool) }
|
||||
func (i *Interface) GetBools() *Bools { return &Bools{*i.object.(*[]bool)} }
|
||||
func (i *Interface) GetString() string { return *i.object.(*string) }
|
||||
func (i *Interface) GetStrings() *Strings { return &Strings{*i.object.(*[]string)} }
|
||||
func (i *Interface) GetBinary() []byte { return *i.object.(*[]byte) }
|
||||
func (i *Interface) GetBinaries() [][]byte { return *i.object.(*[][]byte) }
|
||||
func (i *Interface) GetBinaries() *Binaries { return &Binaries{*i.object.(*[][]byte)} }
|
||||
func (i *Interface) GetAddress() *Address { return &Address{*i.object.(*common.Address)} }
|
||||
func (i *Interface) GetAddresses() *Addresses { return &Addresses{*i.object.(*[]common.Address)} }
|
||||
func (i *Interface) GetHash() *Hash { return &Hash{*i.object.(*common.Hash)} }
|
||||
@@ -98,6 +162,38 @@ func (i *Interface) GetInt8() int8 { return *i.object.(*int8) }
|
||||
func (i *Interface) GetInt16() int16 { return *i.object.(*int16) }
|
||||
func (i *Interface) GetInt32() int32 { return *i.object.(*int32) }
|
||||
func (i *Interface) GetInt64() int64 { return *i.object.(*int64) }
|
||||
func (i *Interface) GetInt8s() *BigInts {
|
||||
val := i.object.(*[]int8)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetInt64(int64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetInt16s() *BigInts {
|
||||
val := i.object.(*[]int16)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetInt64(int64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetInt32s() *BigInts {
|
||||
val := i.object.(*[]int32)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetInt64(int64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetInt64s() *BigInts {
|
||||
val := i.object.(*[]int64)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetInt64(v)})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetUint8() *BigInt {
|
||||
return &BigInt{new(big.Int).SetUint64(uint64(*i.object.(*uint8)))}
|
||||
}
|
||||
@@ -110,6 +206,38 @@ func (i *Interface) GetUint32() *BigInt {
|
||||
func (i *Interface) GetUint64() *BigInt {
|
||||
return &BigInt{new(big.Int).SetUint64(*i.object.(*uint64))}
|
||||
}
|
||||
func (i *Interface) GetUint8s() *BigInts {
|
||||
val := i.object.(*[]uint8)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetUint64(uint64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetUint16s() *BigInts {
|
||||
val := i.object.(*[]uint16)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetUint64(uint64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetUint32s() *BigInts {
|
||||
val := i.object.(*[]uint32)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetUint64(uint64(v))})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetUint64s() *BigInts {
|
||||
val := i.object.(*[]uint64)
|
||||
bigints := NewBigInts(len(*val))
|
||||
for i, v := range *val {
|
||||
bigints.Set(i, &BigInt{new(big.Int).SetUint64(v)})
|
||||
}
|
||||
return bigints
|
||||
}
|
||||
func (i *Interface) GetBigInt() *BigInt { return &BigInt{*i.object.(**big.Int)} }
|
||||
func (i *Interface) GetBigInts() *BigInts { return &BigInts{*i.object.(*[]*big.Int)} }
|
||||
|
||||
@@ -120,9 +248,7 @@ type Interfaces struct {
|
||||
|
||||
// NewInterfaces creates a slice of uninitialized interfaces.
|
||||
func NewInterfaces(size int) *Interfaces {
|
||||
return &Interfaces{
|
||||
objects: make([]interface{}, size),
|
||||
}
|
||||
return &Interfaces{objects: make([]interface{}, size)}
|
||||
}
|
||||
|
||||
// Size returns the number of interfaces in the slice.
|
||||
@@ -131,11 +257,13 @@ func (i *Interfaces) Size() int {
|
||||
}
|
||||
|
||||
// Get returns the bigint 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) {
|
||||
if index < 0 || index >= len(i.objects) {
|
||||
return nil, errors.New("index out of bounds")
|
||||
}
|
||||
return &Interface{i.objects[index]}, nil
|
||||
return &Interface{object: i.objects[index]}, nil
|
||||
}
|
||||
|
||||
// Set sets the big int at the given index in the slice.
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright 2019 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package geth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
func TestInterfaceGetSet(t *testing.T) {
|
||||
var tests = []struct {
|
||||
method string
|
||||
input interface{}
|
||||
expect interface{}
|
||||
}{
|
||||
{"Bool", true, true},
|
||||
{"Bool", false, false},
|
||||
{"Bools", &Bools{[]bool{false, true}}, &Bools{[]bool{false, true}}},
|
||||
{"String", "go-ethereum", "go-ethereum"},
|
||||
{"Strings", &Strings{strs: []string{"hello", "world"}}, &Strings{strs: []string{"hello", "world"}}},
|
||||
{"Binary", []byte{0x01, 0x02}, []byte{0x01, 0x02}},
|
||||
{"Binaries", &Binaries{[][]byte{{0x01, 0x02}, {0x03, 0x04}}}, &Binaries{[][]byte{{0x01, 0x02}, {0x03, 0x04}}}},
|
||||
{"Address", &Address{common.HexToAddress("deadbeef")}, &Address{common.HexToAddress("deadbeef")}},
|
||||
{"Addresses", &Addresses{[]common.Address{common.HexToAddress("deadbeef"), common.HexToAddress("cafebabe")}}, &Addresses{[]common.Address{common.HexToAddress("deadbeef"), common.HexToAddress("cafebabe")}}},
|
||||
{"Hash", &Hash{common.HexToHash("deadbeef")}, &Hash{common.HexToHash("deadbeef")}},
|
||||
{"Hashes", &Hashes{[]common.Hash{common.HexToHash("deadbeef"), common.HexToHash("cafebabe")}}, &Hashes{[]common.Hash{common.HexToHash("deadbeef"), common.HexToHash("cafebabe")}}},
|
||||
{"Int8", int8(1), int8(1)},
|
||||
{"Int16", int16(1), int16(1)},
|
||||
{"Int32", int32(1), int32(1)},
|
||||
{"Int64", int64(1), int64(1)},
|
||||
{"Int8s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Int16s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Int32s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Int64s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Uint8", NewBigInt(1), NewBigInt(1)},
|
||||
{"Uint16", NewBigInt(1), NewBigInt(1)},
|
||||
{"Uint32", NewBigInt(1), NewBigInt(1)},
|
||||
{"Uint64", NewBigInt(1), NewBigInt(1)},
|
||||
{"Uint8s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Uint16s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Uint32s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"Uint64s", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
{"BigInt", NewBigInt(1), NewBigInt(1)},
|
||||
{"BigInts", &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}, &BigInts{[]*big.Int{big.NewInt(1), big.NewInt(2)}}},
|
||||
}
|
||||
|
||||
args := NewInterfaces(len(tests))
|
||||
|
||||
callFn := func(receiver interface{}, method string, arg interface{}) interface{} {
|
||||
rval := reflect.ValueOf(receiver)
|
||||
rval.MethodByName(fmt.Sprintf("Set%s", method)).Call([]reflect.Value{reflect.ValueOf(arg)})
|
||||
res := rval.MethodByName(fmt.Sprintf("Get%s", method)).Call(nil)
|
||||
if len(res) > 0 {
|
||||
return res[0].Interface()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
for index, c := range tests {
|
||||
// In theory the change of iface shouldn't effect the args value
|
||||
iface, _ := args.Get(index)
|
||||
result := callFn(iface, c.method, c.input)
|
||||
if !reflect.DeepEqual(result, c.expect) {
|
||||
t.Errorf("Interface get/set mismatch, want %v, got %v", c.expect, result)
|
||||
}
|
||||
// Check whether the underlying value in args is still zero
|
||||
iface, _ = args.Get(index)
|
||||
if iface.object != nil {
|
||||
t.Error("Get operation is not write safe")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ package geth
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Strings represents s slice of strs.
|
||||
@@ -52,3 +54,63 @@ func (s *Strings) Set(index int, str string) error {
|
||||
func (s *Strings) String() string {
|
||||
return fmt.Sprintf("%v", s.strs)
|
||||
}
|
||||
|
||||
// Bools represents a slice of bool.
|
||||
type Bools struct{ bools []bool }
|
||||
|
||||
// Size returns the number of bool in the slice.
|
||||
func (bs *Bools) Size() int {
|
||||
return len(bs.bools)
|
||||
}
|
||||
|
||||
// Get returns the bool at the given index from the slice.
|
||||
func (bs *Bools) Get(index int) (b bool, _ error) {
|
||||
if index < 0 || index >= len(bs.bools) {
|
||||
return false, errors.New("index out of bounds")
|
||||
}
|
||||
return bs.bools[index], nil
|
||||
}
|
||||
|
||||
// Set sets the bool at the given index in the slice.
|
||||
func (bs *Bools) Set(index int, b bool) error {
|
||||
if index < 0 || index >= len(bs.bools) {
|
||||
return errors.New("index out of bounds")
|
||||
}
|
||||
bs.bools[index] = b
|
||||
return nil
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (bs *Bools) String() string {
|
||||
return fmt.Sprintf("%v", bs.bools)
|
||||
}
|
||||
|
||||
// Binaries represents a slice of byte slice
|
||||
type Binaries struct{ binaries [][]byte }
|
||||
|
||||
// Size returns the number of byte slice in the slice.
|
||||
func (bs *Binaries) Size() int {
|
||||
return len(bs.binaries)
|
||||
}
|
||||
|
||||
// Get returns the byte slice at the given index from the slice.
|
||||
func (bs *Binaries) Get(index int) (binary []byte, _ error) {
|
||||
if index < 0 || index >= len(bs.binaries) {
|
||||
return nil, errors.New("index out of bounds")
|
||||
}
|
||||
return common.CopyBytes(bs.binaries[index]), nil
|
||||
}
|
||||
|
||||
// Set sets the byte slice at the given index in the slice.
|
||||
func (bs *Binaries) Set(index int, binary []byte) error {
|
||||
if index < 0 || index >= len(bs.binaries) {
|
||||
return errors.New("index out of bounds")
|
||||
}
|
||||
bs.binaries[index] = common.CopyBytes(binary)
|
||||
return nil
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (bs *Binaries) String() string {
|
||||
return fmt.Sprintf("%v", bs.binaries)
|
||||
}
|
||||
Reference in new issue
Block a user