Skip to content

Commit

Permalink
move client meta to root and construct meta in most derived class
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Dec 9, 2024
1 parent 7c68de2 commit 58bdf00
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BoundWitnessTest {
val bw = BoundWitnessBuilder().signer(Account.random()).payloads(listOf(
TestPayload1()
)).build()
assert(bw._meta.client == "android")
assert(bw.__client == "android")
assert(bw.__signatures.size == 1)
}
}
Expand All @@ -92,8 +92,7 @@ class BoundWitnessTest {
)).build()
val serializedBw = JsonSerializable.toJson(bw)
val bwJson = JSONObject(serializedBw)
val meta = bwJson.get("\$meta") as JSONObject
assert(meta.get("client") == "android")
assert(bwJson.get("\$client") == "android")
assertNotNull(bwJson.get("\$signatures"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PreviousHashStorePrefsRepositoryTest {
this.appContext = InstrumentationRegistry.getInstrumentation().targetContext
}

@OptIn(ExperimentalStdlibApi::class)
@Test
fun testPreviousHashStorePersistence() {
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package network.xyo.client.boundwitness

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import network.xyo.client.payload.model.WithMeta
import network.xyo.client.boundwitness.model.BoundWitnessMeta

@JsonClass(generateAdapter = true)
open class BoundWitness: WithMeta<BoundWitnessMeta>, BoundWitnessFields() {
@Json(name = "\$meta")
override var _meta = BoundWitnessMeta()
open class BoundWitness(client: String? = "android", signatures: List<String> = emptyList()) : BoundWitnessMeta,
BoundWitnessFields() {
@Json(name = "\$client")
final override var __client: String? = client

@Json(name = "\$signatures")
final override var __signatures = signatures
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ open class BoundWitnessBuilder {
bw.previous_hashes = _signers.map {account -> account.previousHash?.toHexString()}
bw.addresses = addresses

// update underscore fields
bw._meta.client = "android"

// construct fields involved in hashing
constructHashableFieldsFields()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.xyo.client.boundwitness

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import network.xyo.client.boundwitness.model.BoundWitnessFields
import network.xyo.client.payload.Payload
Expand All @@ -13,24 +12,18 @@ open class BoundWitnessFields(): BoundWitnessFields, Payload(SCHEMA) {
final override var previous_hashes = emptyList<String?>()
final override var timestamp: Long? = null

// Meta Properties
@Json(name = "\$signatures")
final override var __signatures = emptyList<String>()

constructor (
addresses: List<String>,
previous_hashes: List<String?>,
payload_hashes: List<String>,
payload_schemas: List<String>,
timestamp: Long? = null,
signatures: List<String>,
) : this() {
this.addresses = addresses
this.previous_hashes = previous_hashes
this.payload_hashes = payload_hashes
this.payload_schemas = payload_schemas
this.timestamp = timestamp
this.__signatures = signatures
}

companion object {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ open class QueryBoundWitnessFields(
payload_schemas: List<String>,
val query: String,
timestamp: Long?,
signatures: List<String>,
): BoundWitnessFields(addresses, previous_hashes, payload_hashes, payload_schemas, timestamp, signatures)
): BoundWitnessFields(addresses, previous_hashes, payload_hashes, payload_schemas, timestamp)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ interface BoundWitnessFields : Payload {
// Note: Long is a higher precision type than JavaScript's Number type but it is the default type from
// Kotlin's System.currentTimeMillis().
var timestamp: Long?

// Meta Properties
// Note - these fields will transform the `__` prefix to `$`
var __signatures: List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package network.xyo.client.boundwitness.model
import java.io.Serializable

interface BoundWitnessMeta: Serializable {
var client: String?
var __client: String?
var __signatures: List<String>
}

0 comments on commit 58bdf00

Please sign in to comment.