Skip to content

Commit 94de568

Browse files
crossleSeniorZhai
andauthored
Feature/snapshot (#2)
* Snapshot api * Network snapshot api Co-authored-by: SeniorZhai <[email protected]>
1 parent a9a710a commit 94de568

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ interface SnapshotCallService {
4949
@Query("destination") destination: String? = null,
5050
@Query("tag") tag: String? = null
5151
): Call<MixinResponse<List<Snapshot>>>
52+
53+
@GET("/network/snapshots/{id}")
54+
fun networkSnapshotCall(@Path("id") snapshotId: String): Call<MixinResponse<Snapshot>>
55+
56+
@GET("/network/snapshots/")
57+
fun networkSnapshotsCall(
58+
@Query("asset") assetId: String,
59+
@Query("offset") offset: String? = null,
60+
@Query("limit") limit: Int = LIMIT,
61+
@Query("order") order: String? = null
62+
): Call<MixinResponse<List<Snapshot>>>
5263
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ interface SnapshotCoroutineService {
4848
@Query("destination") destination: String? = null,
4949
@Query("tag") tag: String? = null
5050
): MixinResponse<List<Snapshot>>
51+
52+
@GET("/network/snapshots/{id}")
53+
suspend fun networkSnapshot(@Path("id") snapshotId: String): MixinResponse<Snapshot>
54+
55+
@GET("/network/snapshots/")
56+
suspend fun networkSnapshots(
57+
@Query("asset") assetId: String,
58+
@Query("offset") offset: String? = null,
59+
@Query("limit") limit: Int = SnapshotService.LIMIT,
60+
@Query("order") order: String? = null
61+
): MixinResponse<List<Snapshot>>
5162
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public static void main(String[] args) {
8282
receivers.add("087e91ff-7169-451a-aaaa-5b3297411a4b");
8383
receivers.add("105f6e8b-d249-4b4d-9beb-e03cefaebc37");
8484
transactions(client, receivers, pinToken, pin);
85+
86+
networkSnapshot(client, "c8e73a02-b543-4100-bd7a-879ed4accdfc");
87+
networkSnapshots(client, CNB_assetId);
8588
} catch (InterruptedException | IOException e) {
8689
System.out.println(e.getMessage());
8790
}
@@ -254,4 +257,24 @@ private static void transactions(HttpClient client, List<String> receivers, Stri
254257
System.out.printf("Transactions fail: %s", Objects.requireNonNull(transactionResponse.getError()).getDescription());
255258
}
256259
}
260+
261+
private static void networkSnapshot(HttpClient client, String snapshotId) throws IOException {
262+
MixinResponse<Snapshot> snapshotResponse = client.getSnapshotService().networkSnapshotCall(snapshotId).execute().body();
263+
assert snapshotResponse != null;
264+
if (snapshotResponse.isSuccess()) {
265+
System.out.printf("Success: %s%n", Objects.requireNonNull(snapshotResponse.getData()).getSnapshotId());
266+
} else {
267+
System.out.printf("Fail: %s", Objects.requireNonNull(snapshotResponse.getError()).getDescription());
268+
}
269+
}
270+
271+
private static void networkSnapshots(HttpClient client, String assetId) throws IOException {
272+
MixinResponse<List<Snapshot>> snapshotResponse = client.getSnapshotService().networkSnapshotsCall(assetId, null, 10, "ASC").execute().body();
273+
assert snapshotResponse != null;
274+
if (snapshotResponse.isSuccess()) {
275+
System.out.printf("Success: %d%n", Objects.requireNonNull(snapshotResponse.getData()).size());
276+
} else {
277+
System.out.printf("Fail: %s", Objects.requireNonNull(snapshotResponse.getError()).getDescription());
278+
}
279+
}
257280
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ fun main() = runBlocking {
9898
// Transactions
9999
transactions(client, pinToken)
100100

101+
networkSnapshots(client, CNB_ID)
102+
networkSnapshot(client, "c8e73a02-b543-4100-bd7a-879ed4accdfc")
101103
return@runBlocking
102104
}
103105

@@ -265,4 +267,28 @@ private suspend fun transactions(
265267
} else {
266268
println("Transactions fail")
267269
}
270+
}
271+
272+
private suspend fun networkSnapshot(
273+
client: HttpClient,
274+
snapshotId: String
275+
) {
276+
val snapshotResponse = client.snapshotService.networkSnapshot(snapshotId)
277+
if (snapshotResponse.isSuccess()) {
278+
println("Success: ${snapshotResponse.data?.snapshotId}")
279+
} else {
280+
println("Fail")
281+
}
282+
}
283+
284+
private suspend fun networkSnapshots(
285+
client: HttpClient,
286+
assetId: String
287+
) {
288+
val snapshotResponse = client.snapshotService.networkSnapshots(assetId)
289+
if (snapshotResponse.isSuccess()) {
290+
println("Success: ${snapshotResponse.data?.size}")
291+
} else {
292+
println("Fail: ${snapshotResponse.error?.description}")
293+
}
268294
}

0 commit comments

Comments
 (0)