Skip to content

Commit 381b507

Browse files
committed
Fix NetworkSnapshot field
1 parent 56d7b2f commit 381b507

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

library/src/main/kotlin/one/mixin/bot/api/call/SnapshotCallService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ interface SnapshotCallService {
5454
@GET("/network/snapshots/{id}")
5555
fun networkSnapshotCall(@Path("id") snapshotId: String): Call<MixinResponse<NetworkSnapshot>>
5656

57-
@GET("/network/snapshots/")
57+
@GET("/network/snapshots")
5858
fun networkSnapshotsCall(
5959
@Query("asset") assetId: String,
6060
@Query("offset") offset: String? = null,

library/src/main/kotlin/one/mixin/bot/api/coroutine/SnapshotCoroutineService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface SnapshotCoroutineService {
5353
@GET("/network/snapshots/{id}")
5454
suspend fun networkSnapshot(@Path("id") snapshotId: String): MixinResponse<NetworkSnapshot>
5555

56-
@GET("/network/snapshots/")
56+
@GET("/network/snapshots")
5757
suspend fun networkSnapshots(
5858
@Query("asset") assetId: String,
5959
@Query("offset") offset: String? = null,

library/src/main/kotlin/one/mixin/bot/vo/NetworkSnapshot.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ data class NetworkSnapshot(
88
val asset: Asset,
99
@SerializedName("created_at")
1010
val createdAt: String,
11-
val data: String,
1211
@SerializedName("snapshot_id")
1312
val snapshotId: String,
1413
@SerializedName("source")
@@ -20,4 +19,6 @@ data class NetworkSnapshot(
2019
val traceId: String?,
2120
@SerializedName("opponent_id")
2221
val opponentId: String?,
22+
@SerializedName("data")
23+
val memo: String?,
2324
)

samples/src/main/java/jvmMain/java/Sample.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static void main(String[] args) {
9292
transactionsOpponentKey(client, "XINQTmRReDuPEUAVEyDyE2mBgxa1ojVRAvpYcKs5nSA7FDBBfAEeVRn8s9vAm3Cn1qzQ7JtjG62go4jSJU6yWyRUKHpamWAM", pinToken, pin);
9393

9494
networkSnapshot(client, "c8e73a02-b543-4100-bd7a-879ed4accdfc");
95-
networkSnapshots(client, CNB_assetId);
95+
networkSnapshots(client, CNB_assetId, null, 10, null);
9696

9797
readGhostKey(client);
9898
} catch (InterruptedException | IOException e) {
@@ -306,11 +306,15 @@ private static void networkSnapshot(HttpClient client, String snapshotId) throws
306306
}
307307
}
308308

309-
private static void networkSnapshots(HttpClient client, String assetId) throws IOException {
310-
MixinResponse<List<NetworkSnapshot>> snapshotResponse = client.getSnapshotService().networkSnapshotsCall(assetId, null, 10, "ASC").execute().body();
309+
private static void networkSnapshots(HttpClient client, String assetId, String offset, int limit, String order) throws IOException {
310+
MixinResponse<List<NetworkSnapshot>> snapshotResponse = client.getSnapshotService().networkSnapshotsCall(assetId, offset, limit, order).execute().body();
311311
assert snapshotResponse != null;
312312
if (snapshotResponse.isSuccess()) {
313+
List<NetworkSnapshot> data = snapshotResponse.getData();
313314
System.out.printf("Success: %d%n", Objects.requireNonNull(snapshotResponse.getData()).size());
315+
for (NetworkSnapshot datum : data) {
316+
System.out.println(datum.toString());
317+
}
314318
} else {
315319
System.out.printf("failure: %s", Objects.requireNonNull(snapshotResponse.getError()).getDescription());
316320
}

samples/src/main/java/jvmMain/kotlin/Sample.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ internal suspend fun networkSnapshots(
301301
val snapshotResponse = client.snapshotService.networkSnapshots(assetId, offset, limit, order)
302302
var networkSnapshots: List<NetworkSnapshot>? = null
303303
if (snapshotResponse.isSuccess()) {
304-
networkSnapshots = snapshotResponse.data
305-
println("Network snapshots success: ${snapshotResponse.data?.size}")
304+
networkSnapshots = snapshotResponse.data as List<NetworkSnapshot>
305+
println("Network snapshots success")
306+
for (s in networkSnapshots) {
307+
println(s)
308+
}
306309
} else {
307310
println("Network snapshot failure: ${snapshotResponse.error?.description}")
308311
}

samples/src/main/java/jvmMain/kotlin/UserTransferDemo.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fun main() = runBlocking {
2727
// create alice
2828
val alice = createUser(client, aliceSessionSecret)
2929
alice ?: return@runBlocking
30+
println("alice: $alice")
3031
val aliceToken = SessionToken.EdDSA(
3132
alice.userId, alice.sessionId,
3233
(aliceSessionKey.private as EdDSAPrivateKey).seed.base64Encode()
@@ -48,6 +49,7 @@ fun main() = runBlocking {
4849
// create bob
4950
val bob = createUser(client, bobSessionSecret)
5051
bob ?: return@runBlocking
52+
println("bob: $bob")
5153
val bobToken = SessionToken.EdDSA(
5254
bob.userId, bob.sessionId,
5355
(bobSessionKey.private as EdDSAPrivateKey).seed.base64Encode()
@@ -90,4 +92,14 @@ fun main() = runBlocking {
9092
assert(bobNetworkSnapshots?.find { it.snapshotId == snapshotAlice2Bob.snapshotId } != null)
9193
}
9294

95+
96+
// use bot's token
97+
client.setUserToken(null)
98+
val botNetworkSnapshot = networkSnapshots(client, CNB_ID, limit = 10)
99+
if (snapshotBot2Alice != null) {
100+
assert(botNetworkSnapshot?.find { it.snapshotId == snapshotBot2Alice.snapshotId } != null)
101+
}
102+
if (snapshotAlice2Bob != null) {
103+
assert(botNetworkSnapshot?.find { it.snapshotId == snapshotAlice2Bob.snapshotId } != null )
104+
}
93105
}

0 commit comments

Comments
 (0)