Skip to content

Commit 54ff4ea

Browse files
authored
Merge pull request #25 from XYOracleNetwork/feature/schema-cleanup
schema cleanup
2 parents 6641891 + d05c7bb commit 54ff4ea

File tree

9 files changed

+44
-24
lines changed

9 files changed

+44
-24
lines changed

sdk/src/androidTest/java/network/xyo/client/node/client/NodeClientTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
77
import network.xyo.client.lib.TestConstants
88
import network.xyo.client.account.Account
99
import network.xyo.client.archivist.wrapper.ArchivistWrapper
10+
import network.xyo.client.boundwitness.XyoBoundWitnessBodyJson
1011
import network.xyo.client.payload.XyoPayload
1112
import org.junit.Before
1213
import org.junit.Test
@@ -68,7 +69,7 @@ class NodeClientTest {
6869
assertEquals(errors, null)
6970

7071
if (response != null) {
71-
assertEquals(response.bw?.schema, "network.xyo.boundwitness")
72+
assertEquals(response.bw?.schema, XyoBoundWitnessBodyJson.schema)
7273
} else {
7374
throw(Error("Response should not be null"))
7475
}

sdk/src/androidTest/java/network/xyo/client/witness/LocationWitnessTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class LocationWitnessTest {
3535
val locationPayload = witness.observe(context)?.first()
3636

3737
assertInstanceOf<XyoLocationPayload>(locationPayload)
38-
assert(locationPayload.schema == "network.xyo.location.android")
38+
assert(locationPayload.schema == XyoLocationPayload.schema)
3939
assert(locationPayload.currentLocation !== null)
4040
assert(locationPayload.currentLocation?.coords?.latitude !== null)
4141
assert(locationPayload.currentLocation?.coords?.longitude !== null)
4242

4343
val locationRawPayload = witness.observe(context)?.get(1)
4444
assertInstanceOf<XyoLocationPayloadRaw>(locationRawPayload)
45-
assert(locationRawPayload.schema == "network.xyo.location.android.raw")
45+
assert(locationRawPayload.schema == XyoLocationPayloadRaw.schema)
4646

4747
assert(locationPayload._sources?.first() == locationRawPayload.hash())
4848
}

sdk/src/main/java/network/xyo/client/archivist/wrapper/ArchivistGetQueryPayload.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ package network.xyo.client.archivist.wrapper
33
import network.xyo.client.payload.XyoPayload
44

55
open class ArchivistGetQueryPayload(val hashes: List<String>): XyoPayload() {
6-
override var schema = "network.xyo.query.archivist.get"
6+
override var schema = ArchivistGetQueryPayload.schema
7+
8+
companion object {
9+
val schema = "network.xyo.query.archivist.get"
10+
}
711
}

sdk/src/main/java/network/xyo/client/archivist/wrapper/ArchivistInsertQueryPayload.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ import network.xyo.client.payload.XyoPayload
44

55

66
class ArchivistInsertQueryPayload(): XyoPayload() {
7-
override var schema = "network.xyo.query.archivist.insert"
7+
override var schema = ArchivistInsertQueryPayload.schema
8+
9+
companion object {
10+
val schema = "network.xyo.query.archivist.insert"
11+
}
812
}

sdk/src/main/java/network/xyo/client/boundwitness/XyoBoundWitnessBodyJson.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import network.xyo.client.payload.XyoPayload
66
@JsonClass(generateAdapter = true)
77
open class XyoBoundWitnessBodyJson(): XyoBoundWitnessBodyInterface, XyoPayload() {
88
override var schema: String
9-
get() = "network.xyo.boundwitness"
9+
get() = XyoBoundWitnessBodyJson.schema
1010
set(value) = Unit
1111
final override var addresses = emptyList<String>()
1212
final override var payload_hashes = emptyList<String>()
@@ -25,4 +25,8 @@ open class XyoBoundWitnessBodyJson(): XyoBoundWitnessBodyInterface, XyoPayload()
2525
this.payload_schemas = payload_schemas
2626
this.timestamp = timestamp
2727
}
28+
29+
companion object {
30+
val schema = "network.xyo.boundwitness"
31+
}
2832
}

sdk/src/main/java/network/xyo/client/payload/XyoPayload.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open class XyoPayload(): Payload, XyoSerializable() {
1212
// Note: Has to be var because "Moshi does not consider a val as a serializable member because
1313
// it cannot be symmetrically deserialized."
1414
// see - https://github.com/square/moshi/issues/1803
15-
override var schema: String = "network.xyo.missing.schema"
15+
override var schema: String = "network.xyo.base.schema"
1616

1717
@Throws(XyoValidationException::class)
1818
open fun validate() {

sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayload.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package network.xyo.client.witness.location.info
33
import com.squareup.moshi.JsonClass
44
import network.xyo.client.payload.Payload
55
import network.xyo.client.payload.XyoPayload
6+
import network.xyo.client.witness.system.info.XyoSystemInfoPayload
67

78
interface XyoLocationPayloadMetaInterface : Payload {
89
var _sources: List<String>?
@@ -31,14 +32,15 @@ class XyoLocationPayload(
3132
override var _sources: List<String>?
3233
): XyoPayload(), XyoLocationPayloadMetaInterface {
3334
override var schema: String
34-
get() = "network.xyo.location.android"
35+
get() = XyoLocationPayload.schema
3536
set(value) = Unit
3637

3738
override fun hash(): String {
3839
return sha256String(this)
3940
}
4041

4142
companion object {
43+
val schema = "network.xyo.location"
4244
fun detect(currentLocation: CurrentLocation?, _sources: List<String>?): XyoLocationPayload {
4345
return XyoLocationPayload(currentLocation, _sources)
4446
}

sdk/src/main/java/network/xyo/client/witness/location/info/XyoLocationPayloadRaw.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ open class XyoLocationPayloadRaw(
3939
val extras: Map<String, Any?>? = null
4040
): XyoPayload() {
4141
override var schema: String
42-
get() = "network.xyo.location.android.raw"
42+
get() = XyoLocationPayloadRaw.schema
4343
set(value) = Unit
4444

4545
override fun hash(): String {
4646
return sha256String(this)
4747
}
4848

49-
5049
companion object {
50+
val schema = "network.xyo.location.android"
5151
fun detect(
5252
provider: String?,
5353
latitude: Double,

sdk/src/main/java/network/xyo/client/witness/system/info/XyoSystemInfoPayload.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@ import network.xyo.client.payload.XyoPayload
1010
class XyoSystemInfoPayload(
1111
val device: XyoSystemInfoDevice? = null,
1212
val network: XyoSystemInfoNetwork? = null,
13-
val os: XyoSystemInfoOs? = null,
14-
): XyoPayload () {
15-
override var schema: String
16-
get() = "network.xyo.system.info.android"
17-
set(value) = Unit
13+
val os: XyoSystemInfoOs? = null
14+
): XyoPayload () {
15+
override var schema: String
16+
get() = XyoSystemInfoPayload.schema
17+
set(value) = Unit
1818

19-
companion object {
19+
override fun hash(): String {
20+
return sha256String(this)
21+
}
2022

21-
@RequiresApi(Build.VERSION_CODES.M)
22-
fun detect(context: Context): XyoSystemInfoPayload {
23-
return XyoSystemInfoPayload(
24-
XyoSystemInfoDevice.detect(context),
25-
XyoSystemInfoNetwork.detect(context),
26-
XyoSystemInfoOs.detect(context)
27-
)
28-
}
23+
companion object {
24+
val schema = "network.xyo.system.info.android"
25+
26+
@RequiresApi(Build.VERSION_CODES.M)
27+
fun detect(context: Context): XyoSystemInfoPayload {
28+
return XyoSystemInfoPayload(
29+
XyoSystemInfoDevice.detect(context),
30+
XyoSystemInfoNetwork.detect(context),
31+
XyoSystemInfoOs.detect(context)
32+
)
2933
}
34+
}
3035
}

0 commit comments

Comments
 (0)