9

When trying to make a transaction on a boundContract with geth-api through the library of @karalabe. I am missing a way to get the signer. I only see the interface for signer in the aar but no way to get a implementation of it.

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: java.lang.Exception: no signer to authorize the transaction with
        at go.Seq.throwException(Seq.java:52)
        at org.ethereum.geth.BoundContract.transfer(Native Method)
        at org.ligi.ewallet.MainActivity$onCreate$function$1.invoke(MainActivity.kt:68)
        at org.ligi.ewallet.MainActivity$onCreate$function$1.invoke(MainActivity.kt:27)
        at org.ligi.ewallet.MainActivityKt$sam$OnClickListener$af810d58.onClick(MainActivity.kt:0)
        at android.view.View.performClick(View.java:5697)
        at android.view.View$PerformClick.run(View.java:22526)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7225)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

It happens when trying to trying to invoke transfer on a boundContract

1 Answer 1

2

You can create an implementation of Signer that uses an AccountManager to sign a transaction with.

Here's a sample which assumes your AccountManager contains already unlocked accounts:

final AccountManager am = new AccountManager(this.getFilesDir() + "/keystore", Geth.LightScryptN, Geth.LightScryptP);

Signer mySigner = new Signer() {
    @Override
    public Transaction sign(Address address, Transaction transaction) throws Exception {
        byte[] signature = am.sign(address, transaction.getSigHash().getBytes());
        return transaction.withSignature(signature);
    }
};

And this one uses password strings instead:

final AccountManager am = new AccountManager(this.getFilesDir() + "/keystore", Geth.LightScryptN, Geth.LightScryptP);

Signer mySigner = new Signer() {
    @Override
    public Transaction sign(Address address, Transaction transaction) throws Exception {
        byte[] signature = am.signWithPassphrase(address, "password", transaction.getSigHash().getBytes());
        return transaction.withSignature(signature);
    }
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.