Skip to content

Commit 9ec0604

Browse files
committed
Merge branch 'develop' into origin/master
2 parents e5a783e + 638188f commit 9ec0604

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3291
-411
lines changed

.flutter-plugins-dependencies

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENCE.md

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.

android/app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ android {
5757
resValue "string", "app_name", "Sentinelx Staging"
5858
debuggable true
5959
}
60+
profile {
61+
applicationIdSuffix ".debug"
62+
resValue "string", "app_name", "Sentinelx Staging"
63+
debuggable true
64+
}
6065
}
6166
splits {
6267

android/app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
android:label="@string/app_name"
1818
android:usesCleartextTraffic="true"
1919
tools:ignore="GoogleAppIndexingWarning">
20+
21+
<provider
22+
android:name="androidx.core.content.FileProvider"
23+
android:authorities="${applicationId}.provider"
24+
android:exported="false"
25+
android:grantUriPermissions="true"
26+
android:readPermission="android.permission.BIND_CHOOSER_TARGET_SERVICE"
27+
>
28+
<meta-data
29+
android:name="android.support.FILE_PROVIDER_PATHS"
30+
android:resource="@xml/qr_file_provider" />
31+
</provider>
32+
33+
2034
<activity
2135
android:name=".MainActivity"
2236
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

android/app/src/main/kotlin/com/invertedx/sentinelx/MainActivity.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.invertedx.sentinelx
22

33
import android.app.NotificationChannel
44
import android.app.NotificationManager
5+
import android.content.Intent
56
import android.os.Build
67
import android.os.Bundle
78
import com.invertedx.sentinelx.channel.ApiChannel
@@ -23,6 +24,8 @@ class MainActivity : FlutterActivity() {
2324

2425
private lateinit var networkChannel: NetworkChannel
2526
private lateinit var onPermissionResultCallback: OnPermissionResult
27+
private lateinit var apiChannel:ApiChannel;
28+
private lateinit var systemChannel: SystemChannel;
2629

2730
override fun onCreate(savedInstanceState: Bundle?) {
2831
super.onCreate(savedInstanceState)
@@ -31,9 +34,12 @@ class MainActivity : FlutterActivity() {
3134
setUpPrefs()
3235
createNotificationChannels()
3336
networkChannel = NetworkChannel(applicationContext, this);
34-
MethodChannel(flutterView, "system.channel").setMethodCallHandler(SystemChannel(applicationContext, this))
37+
apiChannel = ApiChannel(applicationContext);
38+
systemChannel = SystemChannel(applicationContext, this);
39+
40+
MethodChannel(flutterView, "system.channel").setMethodCallHandler(systemChannel)
3541
MethodChannel(flutterView, "crypto.channel").setMethodCallHandler(CryptoChannel(applicationContext))
36-
MethodChannel(flutterView, "api.channel").setMethodCallHandler(ApiChannel(applicationContext))
42+
MethodChannel(flutterView, "api.channel").setMethodCallHandler(apiChannel)
3743
MethodChannel(flutterView, "network.channel").setMethodCallHandler(networkChannel)
3844
QRCameraPlugin.registerWith(this.registrarFor("plugins.sentinelx.qr_camera"), this)
3945

@@ -60,6 +66,7 @@ class MainActivity : FlutterActivity() {
6066

6167
override fun onDestroy() {
6268
networkChannel.dispose()
69+
apiChannel.dispose();
6370
super.onDestroy()
6471
}
6572

@@ -73,6 +80,19 @@ class MainActivity : FlutterActivity() {
7380
)
7481
serviceChannel.setSound(null, null)
7582
getSystemService(NotificationManager::class.java)?.createNotificationChannel(serviceChannel)
83+
84+
val updateChannel = NotificationChannel(
85+
"UPDATE_CHANNEL",
86+
"Update Notifications",
87+
NotificationManager.IMPORTANCE_DEFAULT
88+
)
89+
getSystemService(NotificationManager::class.java)?.createNotificationChannel(updateChannel)
90+
7691
}
7792
}
93+
94+
override fun onNewIntent(intent: Intent?) {
95+
intent?.let { systemChannel.onNotificationIntent(it) }
96+
super.onNewIntent(intent)
97+
}
7898
}

android/app/src/main/kotlin/com/invertedx/sentinelx/SentinelxApp.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.util.Log
44
import org.bitcoinj.core.NetworkParameters
55
import org.bitcoinj.params.MainNetParams
66
import org.bitcoinj.params.TestNet3Params
7+
import org.json.JSONArray
78

89

910
fun Any.e(msg: Any? = "No Message provided") {
@@ -30,6 +31,7 @@ object SentinelxApp {
3031
public var refreshToken = "";
3132
public var dojoEneabled = false
3233
public var dojoUrl = ""
34+
public var netWorkLog = JSONArray();
3335

3436

3537
fun isTestNet(): Boolean {

android/app/src/main/kotlin/com/invertedx/sentinelx/api/ApiService.kt

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.invertedx.sentinelx.api
22

33
import android.content.Context
4-
import android.preference.PreferenceManager
54
import android.util.Log
65
import com.invertedx.sentinelx.BuildConfig
76
import com.invertedx.sentinelx.SentinelxApp
8-
import com.invertedx.sentinelx.i
97
import com.invertedx.sentinelx.tor.TorManager
108
import com.invertedx.sentinelx.utils.LoggingInterceptor
119
import com.invertedx.sentinelx.utils.SentinalPrefs
1210
import io.reactivex.Observable
13-
import okhttp3.FormBody
14-
import okhttp3.OkHttpClient
15-
import okhttp3.Request
16-
import okhttp3.RequestBody
11+
import io.reactivex.Single
12+
import okhttp3.*
13+
import org.json.JSONObject
14+
import java.io.IOException
1715
import java.util.concurrent.TimeUnit
1816
import javax.net.ssl.HostnameVerifier
1917
import javax.net.ssl.SSLContext
@@ -37,18 +35,18 @@ class ApiService(private val applicationContext: Context) {
3735

3836

3937
fun getTxAndXPUBData(XpubOrAddress: String): Observable<String> {
38+
makeClient();
39+
4040
val baseAddress = getBaseUrl()
4141
val url = if (SentinelxApp.accessToken.isNotEmpty()) "${baseAddress}multiaddr?active=$XpubOrAddress&at=${SentinelxApp.accessToken}" else "${baseAddress}multiaddr?active=$XpubOrAddress"
4242

43-
Log.i("API", "CALL url -> $url")
4443
return Observable.fromCallable {
4544
val request = Request.Builder()
4645
.url(url)
4746
.build()
4847
val response = client.newCall(request).execute()
4948
try {
5049
val content = response.body!!.string()
51-
Log.i("API", "response -> $content")
5250
return@fromCallable content
5351
} catch (ex: Exception) {
5452
return@fromCallable "{}"
@@ -68,6 +66,12 @@ class ApiService(private val applicationContext: Context) {
6866
return SentinelxApp.dojoUrl
6967
}
7068

69+
if (SentinalPrefs(applicationContext).dojoKey != null) {
70+
SentinelxApp.accessToken = SentinalPrefs(applicationContext).dojoKey!!
71+
}
72+
if (SentinalPrefs(applicationContext).dojoUrl != null) {
73+
return SentinalPrefs(applicationContext).dojoUrl!!
74+
}
7175
return if (TorManager.getInstance(this.applicationContext)?.isConnected!!) {
7276
if (SentinelxApp.isTestNet()) SAMOURAI_API2_TESTNET_TOR_DIST else SAMOURAI_API2_TOR_DIST
7377
} else {
@@ -88,7 +92,6 @@ class ApiService(private val applicationContext: Context) {
8892
val response = client.newCall(request).execute()
8993
try {
9094
val content = response.body!!.string()
91-
Log.i("API", "response -> $content")
9295
return@fromCallable content
9396
} catch (ex: Exception) {
9497
throw ex
@@ -99,6 +102,9 @@ class ApiService(private val applicationContext: Context) {
99102

100103

101104
fun authenticate(url: String, key: String): Observable<String> {
105+
106+
makeClient();
107+
102108
val targetUrl = "$url/auth/login?apikey=$key"
103109
return Observable.fromCallable {
104110

@@ -119,6 +125,7 @@ class ApiService(private val applicationContext: Context) {
119125

120126

121127
fun getUnspent(xpubOrAddress: String): Observable<String> {
128+
122129
makeClient()
123130

124131
val baseAddress = getBaseUrl()
@@ -141,6 +148,35 @@ class ApiService(private val applicationContext: Context) {
141148
}
142149
}
143150

151+
152+
fun pushTx(hex: String): Observable<String> {
153+
154+
makeClient()
155+
156+
val baseAddress = getBaseUrl()
157+
val baseUrl = if (SentinelxApp.accessToken.isNotEmpty()) "${baseAddress}pushtx/?at=${SentinelxApp.accessToken}" else "${baseAddress}pushtx";
158+
159+
return Observable.fromCallable {
160+
161+
val request = Request.Builder()
162+
.url(baseUrl)
163+
.method("POST", FormBody.Builder()
164+
.add("tx", hex)
165+
.build())
166+
.build()
167+
168+
val response = client.newCall(request).execute()
169+
try {
170+
val content = response.body!!.string()
171+
return@fromCallable content
172+
} catch (ex: Exception) {
173+
throw ex;
174+
}
175+
176+
}
177+
}
178+
179+
144180
fun addHDAccount(xpub: String, bip: String): Observable<String> {
145181

146182
makeClient()
@@ -154,8 +190,6 @@ class ApiService(private val applicationContext: Context) {
154190
.add("segwit", bip)
155191
.build()
156192

157-
Log.i("url", baseUrl.toString())
158-
Log.i("requestBody", requestBody.toString())
159193
return Observable.fromCallable {
160194

161195
val request = Request.Builder()
@@ -166,13 +200,12 @@ class ApiService(private val applicationContext: Context) {
166200
client.connectTimeoutMillis
167201
val response = client.newCall(request).execute()
168202
val content = response.body!!.string()
169-
Log.i("API", "response -> $content")
170203
return@fromCallable content
171204

172205
}
173206
}
174207

175-
208+
176209
fun makeClient() {
177210
val builder = OkHttpClient.Builder()
178211
if (BuildConfig.DEBUG) {
@@ -182,6 +215,7 @@ class ApiService(private val applicationContext: Context) {
182215
getHostNameVerifier(builder)
183216
builder.proxy(TorManager.getInstance(this.applicationContext)?.getProxy())
184217
}
218+
builder.addInterceptor(LogEntry(this))
185219
val prefs = SentinalPrefs(applicationContext)
186220

187221
var timeout = 90L;
@@ -193,6 +227,7 @@ class ApiService(private val applicationContext: Context) {
193227
client = builder.build()
194228
}
195229

230+
196231
@Throws(Exception::class)
197232
private fun getHostNameVerifier(clientBuilder: OkHttpClient.Builder) {
198233

@@ -220,4 +255,70 @@ class ApiService(private val applicationContext: Context) {
220255

221256
}
222257

223-
}
258+
//Generic post request handler
259+
fun postRequest(url: String, requestBody: RequestBody): Single<String> {
260+
return Single.fromCallable {
261+
val request = Request.Builder()
262+
.url(url)
263+
.method("POST", requestBody)
264+
.build()
265+
val response = client.newCall(request).execute()
266+
267+
try {
268+
val content = response.body!!.string()
269+
return@fromCallable content
270+
} catch (ex: Exception) {
271+
throw ex
272+
}
273+
}
274+
275+
}
276+
277+
//Generic get request handler
278+
fun getRequest(url: String): Single<String> {
279+
return Single.fromCallable {
280+
val request = Request.Builder()
281+
.url(url)
282+
.build()
283+
val response = client.newCall(request).execute()
284+
285+
try {
286+
val content = response.body!!.string()
287+
return@fromCallable content
288+
} catch (ex: Exception) {
289+
throw ex
290+
}
291+
}
292+
293+
}
294+
295+
296+
internal class LogEntry(val apiService: ApiService) : Interceptor {
297+
298+
@Throws(IOException::class)
299+
override fun intercept(chain: Interceptor.Chain): Response {
300+
val obj = JSONObject();
301+
val request = chain.request()
302+
val t1 = System.nanoTime()
303+
obj.put("url", request.url.toString());
304+
obj.put("method", request.method);
305+
obj.put("init_time", System.currentTimeMillis());
306+
val response = chain.proceed(request)
307+
val t2 = System.nanoTime()
308+
obj.put("time", (t2 - t1) / 1e6);
309+
obj.put("status", response.code);
310+
obj.put("network", "");
311+
if (SentinelxApp.dojoUrl.isNotBlank()) {
312+
if (SentinelxApp.dojoUrl.contains(request.url.toUri().host)) {
313+
obj.put("network", "DOJO");
314+
}
315+
}
316+
317+
SentinelxApp.netWorkLog.put(obj);
318+
return response
319+
}
320+
}
321+
322+
323+
}
324+

0 commit comments

Comments
 (0)