-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainActivity.java
157 lines (129 loc) · 6.03 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.example.liquid_test_2;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.crux.sdk.CruxClient;
import com.crux.sdk.model.*;
//import com.crux.sdk.model.CruxAddress;
//import com.crux.sdk.model.CruxClientError;
//import com.crux.sdk.model.CruxClientInitConfig;
//import com.crux.sdk.model.CruxClientResponseHandler;
//import com.crux.sdk.model.CruxIDState;
//import com.crux.sdk.model.CruxPutAddressMapSuccess;
import java.io.IOException;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
runScript(this);
} catch (IOException | CruxClientError e) {
e.printStackTrace();
}
}
public String runScript(final Context androidContextObject) throws IOException, CruxClientError {
CruxClientInitConfig.Builder configBuilder = new CruxClientInitConfig.Builder()
.setWalletClientName("cruxdev")
.setPrivateKey("cdf2d276caf0c9c34258ed6ebd0e60e0e8b3d9a7b8a9a717f2e19ed9b37f7c6f");
CruxClient client;
try {
client = new CruxClient(configBuilder, androidContextObject);
} catch(CruxClientError e) {
Toast.makeText(androidContextObject, "Client caught and reraised:" + e.errorMessage, Toast.LENGTH_LONG).show();
System.out.println("use debug version for development");
return null;
}
final String testAvailabilityCruxId = "yadu007";
client.isCruxIDAvailable(testAvailabilityCruxId, new CruxClientResponseHandler<Boolean>() {
@Override
public void onResponse(Boolean successResponse) {
System.out.println("--------isCruxIDAvailable-------");
System.out.println(successResponse);
if (successResponse == Boolean.TRUE) {
System.out.println(testAvailabilityCruxId + " is available");
} else {
System.out.println(testAvailabilityCruxId + " is not available");
}
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.err.println(failureResponse.errorCode);
System.err.println(failureResponse.errorMessage);
}
});
client.registerCruxID("dev_umang5", new CruxClientResponseHandler<Void>() {
@Override
public void onResponse(Void successResponse) {
System.out.println("--------registerCruxID-------");
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.err.println(failureResponse.errorCode);
System.err.println(failureResponse.errorMessage);
}
});
client.getCruxIDState(new CruxClientResponseHandler<CruxIDState>() {
@Override
public void onResponse(CruxIDState successResponse) {
System.out.println("--------getCruxIDState-------");
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.err.println(failureResponse.errorCode);
System.err.println(failureResponse.errorMessage);
}
});
client.getAddressMap(new CruxClientResponseHandler<HashMap<String, CruxAddress>>() {
@Override
public void onResponse(HashMap<String, CruxAddress> successResponse) {
System.out.println("--------getAddressMap-------");
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.err.println(failureResponse.errorCode);
System.err.println(failureResponse.errorMessage);
}
});
final String testResolveAddressCruxId = "[email protected]";
client.resolveCurrencyAddressForCruxID(testResolveAddressCruxId, "xrp", new CruxClientResponseHandler<CruxAddress>() {
@Override
public void onResponse(CruxAddress successResponse) {
System.out.println("--------resolveCurrencyAddressForCruxID-------");
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.out.println(failureResponse);
}
});
HashMap<String, CruxAddress> newAddressMap = getCurrencyMap();
client.putAddressMap(newAddressMap, new CruxClientResponseHandler<CruxPutAddressMapSuccess>() {
@Override
public void onResponse(CruxPutAddressMapSuccess successResponse) {
System.out.println("--------putAddressMap-------");
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.err.println(failureResponse.errorCode);
System.err.println(failureResponse.errorMessage);
}
});
return null;
}
private HashMap<String, CruxAddress> getCurrencyMap() {
HashMap<String, CruxAddress> currencyMap = new HashMap<String, CruxAddress>();
// Add currency and address
currencyMap.put("btc", new CruxAddress("1HX4KvtPdg9QUYwQE1kNqTAjmNaDG7w82V", null));
currencyMap.put("eth", new CruxAddress("0x0a2311594059b468c9897338b027c8782398b481", null));
currencyMap.put("tron", new CruxAddress("TG3iFaVvUs34SGpWq8RG9gnagDLTe1jdyz", null));
currencyMap.put("xrp", new CruxAddress("rpfKAA2Ezqoq5wWo3XENdLYdZ8YGziz48h", "7777"));
return currencyMap;
}
}