Skip to content

Commit cdc2794

Browse files
committed
updating examples using TransactionHash
1 parent bdeeef9 commit cdc2794

7 files changed

Lines changed: 69 additions & 40 deletions

File tree

etherspace-android-example/src/main/java/cc/etherspace/example/Greeter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package cc.etherspace.example
33
import cc.etherspace.Call
44
import cc.etherspace.Options
55
import cc.etherspace.Send
6-
import cc.etherspace.TransactionReceipt
6+
import cc.etherspace.TransactionHash
77
import kotlinx.coroutines.experimental.Deferred
88
import java.io.IOException
99

1010
interface Greeter {
1111
@Throws(IOException::class)
1212
@Send
13-
fun newGreeting(greeting: String): Deferred<TransactionReceipt>
13+
fun newGreeting(greeting: String): Deferred<TransactionHash>
1414

1515
@Throws(IOException::class)
1616
@Send
17-
fun newGreeting(greeting: String, options: Options): Deferred<TransactionReceipt>
17+
fun newGreeting(greeting: String, options: Options): Deferred<TransactionHash>
1818

1919
@Throws(IOException::class)
2020
@Call

etherspace-android-example/src/main/java/cc/etherspace/example/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package cc.etherspace.example
33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
55
import android.widget.EditText
6+
import kotlinx.coroutines.experimental.Deferred
67
import org.jetbrains.anko.*
78
import org.jetbrains.anko.sdk25.coroutines.onClick
9+
import org.web3j.protocol.core.methods.response.TransactionReceipt
810
import javax.inject.Inject
911

1012
class MainActivity : AppCompatActivity(), AnkoLogger {
@@ -53,7 +55,8 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
5355

5456
private suspend fun newGreeting() {
5557
greeting.isEnabled = false
56-
greeter.newGreeting(greeting.text.toString()).await()
58+
val hash = greeter.newGreeting(greeting.text.toString()).await()
59+
hash.requestTransactionReceipt<Deferred<TransactionReceipt>>().await()
5760
greeting.isEnabled = true
5861
toast("newGreeting: ${greeting.text}")
5962
}

etherspace-java-example/src/main/java/cc/etherspace/example/CompletableFutureExample.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package cc.etherspace.example;
22

3-
import cc.etherspace.*;
4-
import cc.etherspace.calladapter.CompletableFutureCallAdapter;
5-
63
import java.io.IOException;
74
import java.math.BigInteger;
85
import java.util.concurrent.CompletableFuture;
96

7+
import cc.etherspace.Call;
8+
import cc.etherspace.Credentials;
9+
import cc.etherspace.EtherSpace;
10+
import cc.etherspace.Options;
11+
import cc.etherspace.Send;
12+
import cc.etherspace.TransactionHash;
13+
import cc.etherspace.TransactionReceipt;
14+
import cc.etherspace.calladapter.CompletableFutureCallAdapter;
15+
1016
public class CompletableFutureExample {
1117
public static void main(String[] args) throws IOException {
1218
System.out.println("Creating a new instance of Greeter");
@@ -22,9 +28,9 @@ public static void main(String[] args) throws IOException {
2228

2329
System.out.println("Updating greeting to: Hello World");
2430

25-
TransactionReceipt receipt = greeter.newGreeting("Hello World").join();
26-
27-
System.out.println("Transaction returned with hash: " + receipt.getTransactionHash());
31+
TransactionHash hash = greeter.newGreeting("Hello World").join();
32+
hash.<CompletableFuture<TransactionReceipt>>requestTransactionReceipt().join();
33+
System.out.println("Transaction returned with hash: " + hash.getHash());
2834

2935
String greeting = greeter.greet().join();
3036

@@ -33,17 +39,18 @@ public static void main(String[] args) throws IOException {
3339
System.out.println("Updating greeting with higher gas");
3440

3541
Options options = new Options(BigInteger.ZERO, BigInteger.valueOf(5_300_000), BigInteger.valueOf(24_000_000_000L));
36-
receipt = greeter.newGreeting("Hello World", options).join();
42+
hash = greeter.newGreeting("Hello World", options).join();
43+
hash.<CompletableFuture<TransactionReceipt>>requestTransactionReceipt().join();
3744

38-
System.out.println("Transaction returned with hash: " + receipt.getTransactionHash());
45+
System.out.println("Transaction returned with hash: " + hash.getHash());
3946
}
4047

4148
public interface Greeter {
4249
@Send
43-
CompletableFuture<TransactionReceipt> newGreeting(String greeting) throws IOException;
50+
CompletableFuture<TransactionHash> newGreeting(String greeting) throws IOException;
4451

4552
@Send
46-
CompletableFuture<TransactionReceipt> newGreeting(String greeting, Options options) throws IOException;
53+
CompletableFuture<TransactionHash> newGreeting(String greeting, Options options) throws IOException;
4754

4855
@Call
4956
CompletableFuture<String> greet();

etherspace-java-example/src/main/java/cc/etherspace/example/CoroutineExample.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import java.math.BigInteger
1010
interface CoroutineGreeter {
1111
@Throws(IOException::class)
1212
@Send
13-
fun newGreeting(greeting: String): Deferred<TransactionReceipt>
13+
fun newGreeting(greeting: String): Deferred<TransactionHash>
1414

1515
@Throws(IOException::class)
1616
@Send
17-
fun newGreeting(greeting: String, options: Options): Deferred<TransactionReceipt>
17+
fun newGreeting(greeting: String, options: Options): Deferred<TransactionHash>
1818

1919
@Throws(IOException::class)
2020
@Call
@@ -36,9 +36,10 @@ fun main(args: Array<String>) {
3636

3737
println("Updating greeting to: Hello World")
3838

39-
var receipt = greeter.newGreeting("Hello World")
39+
var hash = greeter.newGreeting("Hello World").await()
40+
hash.requestTransactionReceipt<Deferred<TransactionReceipt>>()
4041

41-
println("Transaction returned with hash: ${receipt.await().transactionHash}")
42+
println("Transaction returned with hash: ${hash.hash}")
4243

4344
val greeting = greeter.greet().await()
4445

@@ -47,8 +48,9 @@ fun main(args: Array<String>) {
4748
println("Updating greeting with higher gas")
4849

4950
val options = Options(BigInteger.ZERO, BigInteger.valueOf(5_300_000), BigInteger.valueOf(24_000_000_000L))
50-
receipt = greeter.newGreeting("Hello World", options)
51+
hash = greeter.newGreeting("Hello World", options).await()
52+
hash.requestTransactionReceipt<Deferred<TransactionReceipt>>()
5153

52-
println("Transaction returned with hash: ${receipt.await().transactionHash}")
54+
println("Transaction returned with hash: ${hash.hash}")
5355
}
5456
}

etherspace-java-example/src/main/java/cc/etherspace/example/JavaExample.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package cc.etherspace.example;
22

3-
import cc.etherspace.*;
4-
53
import java.io.IOException;
64
import java.math.BigInteger;
75

6+
import cc.etherspace.Call;
7+
import cc.etherspace.Credentials;
8+
import cc.etherspace.EtherSpace;
9+
import cc.etherspace.Options;
10+
import cc.etherspace.Send;
11+
import cc.etherspace.TransactionHash;
12+
813
public class JavaExample {
914
public static void main(String[] args) throws IOException {
1015
System.out.println("Creating a new instance of Greeter");
@@ -19,9 +24,10 @@ public static void main(String[] args) throws IOException {
1924

2025
System.out.println("Updating greeting to: Hello World");
2126

22-
TransactionReceipt receipt = greeter.newGreeting("Hello World");
27+
TransactionHash hash = greeter.newGreeting("Hello World");
28+
hash.requestTransactionReceipt();
2329

24-
System.out.println("Transaction returned with hash: " + receipt.getTransactionHash());
30+
System.out.println("Transaction returned with hash: " + hash.getHash());
2531

2632
String greeting = greeter.greet();
2733

@@ -30,17 +36,18 @@ public static void main(String[] args) throws IOException {
3036
System.out.println("Updating greeting with higher gas");
3137

3238
Options options = new Options(BigInteger.ZERO, BigInteger.valueOf(5_300_000), BigInteger.valueOf(24_000_000_000L));
33-
receipt = greeter.newGreeting("Hello World", options);
39+
hash = greeter.newGreeting("Hello World", options);
40+
hash.requestTransactionReceipt();
3441

35-
System.out.println("Transaction returned with hash: " + receipt.getTransactionHash());
42+
System.out.println("Transaction returned with hash: " + hash.getHash());
3643
}
3744

3845
public interface Greeter {
3946
@Send
40-
TransactionReceipt newGreeting(String greeting) throws IOException;
47+
TransactionHash newGreeting(String greeting) throws IOException;
4148

4249
@Send
43-
TransactionReceipt newGreeting(String greeting, Options options) throws IOException;
50+
TransactionHash newGreeting(String greeting, Options options) throws IOException;
4451

4552
@Call
4653
String greet();

etherspace-java-example/src/main/java/cc/etherspace/example/KotlinExample.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import java.math.BigInteger
77
interface Greeter {
88
@Throws(IOException::class)
99
@Send
10-
fun newGreeting(greeting: String): TransactionReceipt
10+
fun newGreeting(greeting: String): TransactionHash
1111

1212
@Throws(IOException::class)
1313
@Send
14-
fun newGreeting(greeting: String, options: Options): TransactionReceipt
14+
fun newGreeting(greeting: String, options: Options): TransactionHash
1515

1616
@Throws(IOException::class)
1717
@Call
@@ -31,9 +31,10 @@ fun main(args: Array<String>) {
3131

3232
println("Updating greeting to: Hello World")
3333

34-
var receipt = greeter.newGreeting("Hello World")
34+
var hash = greeter.newGreeting("Hello World")
35+
hash.requestTransactionReceipt<TransactionReceipt>()
3536

36-
println("Transaction returned with hash: ${receipt.transactionHash}")
37+
println("Transaction returned with hash: ${hash.hash}")
3738

3839
val greeting = greeter.greet()
3940

@@ -42,7 +43,8 @@ fun main(args: Array<String>) {
4243
println("Updating greeting with higher gas")
4344

4445
val options = Options(BigInteger.ZERO, BigInteger.valueOf(5_300_000), BigInteger.valueOf(24_000_000_000L))
45-
receipt = greeter.newGreeting("Hello World", options)
46+
hash = greeter.newGreeting("Hello World", options)
47+
hash.requestTransactionReceipt<TransactionReceipt>()
4648

47-
println("Transaction returned with hash: ${receipt.transactionHash}")
49+
println("Transaction returned with hash: ${hash.hash}")
4850
}

etherspace-java-example/src/main/java/cc/etherspace/example/RxJavaExample.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package cc.etherspace.example;
22

3-
import cc.etherspace.*;
4-
import cc.etherspace.calladapter.RxJavaCallAdapter;
5-
import rx.Observable;
6-
73
import java.io.IOException;
84
import java.math.BigInteger;
95

6+
import cc.etherspace.Call;
7+
import cc.etherspace.Credentials;
8+
import cc.etherspace.EtherSpace;
9+
import cc.etherspace.Options;
10+
import cc.etherspace.Send;
11+
import cc.etherspace.TransactionHash;
12+
import cc.etherspace.TransactionReceipt;
13+
import cc.etherspace.calladapter.RxJavaCallAdapter;
14+
import rx.Observable;
15+
1016
public class RxJavaExample {
1117
public static void main(String[] args) throws IOException {
1218
System.out.println("Creating a new instance of Greeter");
@@ -23,6 +29,7 @@ public static void main(String[] args) throws IOException {
2329
System.out.println("Updating greeting to: Hello World");
2430

2531
greeter.newGreeting("Hello World")
32+
.flatMap(TransactionHash::<Observable<TransactionReceipt>>requestTransactionReceipt)
2633
.subscribe(receipt -> System.out.println("Transaction returned with hash: " + receipt.getTransactionHash()));
2734

2835
greeter.greet().subscribe(greeting -> System.out.println("greeting is " + greeting + " now"));
@@ -31,15 +38,16 @@ public static void main(String[] args) throws IOException {
3138

3239
Options options = new Options(BigInteger.ZERO, BigInteger.valueOf(5_300_000), BigInteger.valueOf(24_000_000_000L));
3340
greeter.newGreeting("Hello World", options)
41+
.flatMap(TransactionHash::<Observable<TransactionReceipt>>requestTransactionReceipt)
3442
.subscribe(receipt -> System.out.println("Transaction returned with hash: " + receipt.getTransactionHash()));
3543
}
3644

3745
public interface Greeter {
3846
@Send
39-
Observable<TransactionReceipt> newGreeting(String greeting) throws IOException;
47+
Observable<TransactionHash> newGreeting(String greeting) throws IOException;
4048

4149
@Send
42-
Observable<TransactionReceipt> newGreeting(String greeting, Options options) throws IOException;
50+
Observable<TransactionHash> newGreeting(String greeting, Options options) throws IOException;
4351

4452
@Call
4553
Observable<String> greet();

0 commit comments

Comments
 (0)