Skip to content

Commit

Permalink
Merge pull request #25 from XYOracleNetwork/feature/schema-cleanup
Browse files Browse the repository at this point in the history
schema cleanup
  • Loading branch information
jonesmac authored Nov 21, 2024
2 parents 6641891 + d05c7bb commit 54ff4ea
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
import network.xyo.client.lib.TestConstants
import network.xyo.client.account.Account
import network.xyo.client.archivist.wrapper.ArchivistWrapper
import network.xyo.client.boundwitness.XyoBoundWitnessBodyJson
import network.xyo.client.payload.XyoPayload
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -68,7 +69,7 @@ class NodeClientTest {
assertEquals(errors, null)

if (response != null) {
assertEquals(response.bw?.schema, "network.xyo.boundwitness")
assertEquals(response.bw?.schema, XyoBoundWitnessBodyJson.schema)
} else {
throw(Error("Response should not be null"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class LocationWitnessTest {
val locationPayload = witness.observe(context)?.first()

assertInstanceOf<XyoLocationPayload>(locationPayload)
assert(locationPayload.schema == "network.xyo.location.android")
assert(locationPayload.schema == XyoLocationPayload.schema)
assert(locationPayload.currentLocation !== null)
assert(locationPayload.currentLocation?.coords?.latitude !== null)
assert(locationPayload.currentLocation?.coords?.longitude !== null)

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

assert(locationPayload._sources?.first() == locationRawPayload.hash())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ package network.xyo.client.archivist.wrapper
import network.xyo.client.payload.XyoPayload

open class ArchivistGetQueryPayload(val hashes: List<String>): XyoPayload() {
override var schema = "network.xyo.query.archivist.get"
override var schema = ArchivistGetQueryPayload.schema

companion object {
val schema = "network.xyo.query.archivist.get"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ import network.xyo.client.payload.XyoPayload


class ArchivistInsertQueryPayload(): XyoPayload() {
override var schema = "network.xyo.query.archivist.insert"
override var schema = ArchivistInsertQueryPayload.schema

companion object {
val schema = "network.xyo.query.archivist.insert"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import network.xyo.client.payload.XyoPayload
@JsonClass(generateAdapter = true)
open class XyoBoundWitnessBodyJson(): XyoBoundWitnessBodyInterface, XyoPayload() {
override var schema: String
get() = "network.xyo.boundwitness"
get() = XyoBoundWitnessBodyJson.schema
set(value) = Unit
final override var addresses = emptyList<String>()
final override var payload_hashes = emptyList<String>()
Expand All @@ -25,4 +25,8 @@ open class XyoBoundWitnessBodyJson(): XyoBoundWitnessBodyInterface, XyoPayload()
this.payload_schemas = payload_schemas
this.timestamp = timestamp
}

companion object {
val schema = "network.xyo.boundwitness"
}
}
2 changes: 1 addition & 1 deletion sdk/src/main/java/network/xyo/client/payload/XyoPayload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class XyoPayload(): Payload, XyoSerializable() {
// Note: Has to be var because "Moshi does not consider a val as a serializable member because
// it cannot be symmetrically deserialized."
// see - https://github.com/square/moshi/issues/1803
override var schema: String = "network.xyo.missing.schema"
override var schema: String = "network.xyo.base.schema"

@Throws(XyoValidationException::class)
open fun validate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network.xyo.client.witness.location.info
import com.squareup.moshi.JsonClass
import network.xyo.client.payload.Payload
import network.xyo.client.payload.XyoPayload
import network.xyo.client.witness.system.info.XyoSystemInfoPayload

interface XyoLocationPayloadMetaInterface : Payload {
var _sources: List<String>?
Expand Down Expand Up @@ -31,14 +32,15 @@ class XyoLocationPayload(
override var _sources: List<String>?
): XyoPayload(), XyoLocationPayloadMetaInterface {
override var schema: String
get() = "network.xyo.location.android"
get() = XyoLocationPayload.schema
set(value) = Unit

override fun hash(): String {
return sha256String(this)
}

companion object {
val schema = "network.xyo.location"
fun detect(currentLocation: CurrentLocation?, _sources: List<String>?): XyoLocationPayload {
return XyoLocationPayload(currentLocation, _sources)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ open class XyoLocationPayloadRaw(
val extras: Map<String, Any?>? = null
): XyoPayload() {
override var schema: String
get() = "network.xyo.location.android.raw"
get() = XyoLocationPayloadRaw.schema
set(value) = Unit

override fun hash(): String {
return sha256String(this)
}


companion object {
val schema = "network.xyo.location.android"
fun detect(
provider: String?,
latitude: Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import network.xyo.client.payload.XyoPayload
class XyoSystemInfoPayload(
val device: XyoSystemInfoDevice? = null,
val network: XyoSystemInfoNetwork? = null,
val os: XyoSystemInfoOs? = null,
): XyoPayload () {
override var schema: String
get() = "network.xyo.system.info.android"
set(value) = Unit
val os: XyoSystemInfoOs? = null
): XyoPayload () {
override var schema: String
get() = XyoSystemInfoPayload.schema
set(value) = Unit

companion object {
override fun hash(): String {
return sha256String(this)
}

@RequiresApi(Build.VERSION_CODES.M)
fun detect(context: Context): XyoSystemInfoPayload {
return XyoSystemInfoPayload(
XyoSystemInfoDevice.detect(context),
XyoSystemInfoNetwork.detect(context),
XyoSystemInfoOs.detect(context)
)
}
companion object {
val schema = "network.xyo.system.info.android"

@RequiresApi(Build.VERSION_CODES.M)
fun detect(context: Context): XyoSystemInfoPayload {
return XyoSystemInfoPayload(
XyoSystemInfoDevice.detect(context),
XyoSystemInfoNetwork.detect(context),
XyoSystemInfoOs.detect(context)
)
}
}
}

0 comments on commit 54ff4ea

Please sign in to comment.