Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dash-sdk-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ plugins {
id 'signing'
}

//version '1.0-SNAPSHOT'

repositories {
mavenLocal()
mavenCentral()
Expand All @@ -19,8 +17,6 @@ repositories {
dependencies {
implementation 'org.jetbrains:annotations:20.1.0'
testImplementation 'junit:junit:4.13.2' // Latest JUnit 4
//testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
//testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
testImplementation 'org.dashj:dashj-core:21.1.1'
testImplementation 'com.google.guava:guava:32.0.0-android'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.dashj.platform.sdk;

import org.bitcoinj.core.Base58;
import org.dashj.platform.sdk.base.Result;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -14,6 +12,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

public class DocumentTest extends SdkBaseTest {

Expand Down Expand Up @@ -259,6 +258,50 @@ public void queryTestFail() {
}
}

@Test
public void queryAllTest() {
try {
Identifier dpnsId = new Identifier(dpnsContractId);
ArrayList<WhereClause> where = new ArrayList<>();
ArrayList<OrderClause> orderBy = new ArrayList<>();
// where.add(new WhereClause("normalizedLabel", WhereOperator.StartsWith, new PlatformValue("test")));
where.add(new WhereClause("normalizedParentDomainName", WhereOperator.Equal, new PlatformValue("dash")));
orderBy.add(new OrderClause("normalizedLabel"));
int count = 0;
Start startAfter = null;
do {

Result<List<Document>, String> result = dashsdk.platformMobileFetchDocumentFetchDocumentsWithQueryAndSdk(
sdk,
dpnsId,
"domain",
where,
orderBy,
100,
startAfter
);
List<Document> docs = result.unwrap();
System.out.println("------ query ------");
System.out.println("items: " + docs.size());
docs.forEach(document -> {
Map<String, PlatformValue> props = document.getV0().get_0().getProperties();
System.out.println(props.get("label").getText());
System.out.println(" id: : " + Base58.encode(document.getV0().get_0().getId().getBytes()));
System.out.println(" identity: " + Base58.encode(props.get("records").getMap().get_0().get(new PlatformValue("identity")).getIdentifier().getBytes()));

});
count = docs.size();
if (count > 0) {
startAfter = new Start(docs.get(docs.size() -1).getV0().get_0().getId().getBytes(), true);
System.out.println("start after: " + Base58.encode(startAfter.getStart_after().get_0()));
}
} while (count == 100);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void startsWithQueryTest() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ public void getContestedResources() throws Exception {

@Test
public void getVotePoolsTest() throws Exception {
Identifier dpnsContractid = new Identifier(dpnsContractId);

//SWIGTYPE_p_DashSdk mainnetSdk = dashsdk.platformMobileSdkCreateDashSdk(BigInteger.ZERO, BigInteger.ZERO, false);

Result<VotePollsGroupedByTimeStamp, String> result = dashsdk.platformMobileVotingGetVotepolls(
Result<VotePollsGroupedByTimeStamp, String> result = dashsdk.platformMobileVotingGetVotePolls(
sdk,
new TimestampMillis(System.currentTimeMillis()),
true,
new TimestampMillis(System.currentTimeMillis() + 14 * 24 * 3600 * 1000),
true,
100,
0,
true
);

Expand Down
28 changes: 25 additions & 3 deletions dpp/src/main/java/org/dashj/platform/dapiclient/DapiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class DapiClient(
const val DEFAULT_WAIT_FOR_NODES = 5
const val DEFAULT_HTTP_TIMEOUT = 10L
const val REQUIRED_SUCCESS_RATE = 0.50 // 50%
const val DEFAULT_LIMIT = 100
}
var contextProvider = object : ContextProvider() {
override fun getQuorumPublicKey(
Expand Down Expand Up @@ -1125,13 +1126,34 @@ class DapiClient(
return Vote(result.unwrap())
}

fun getVotePolls(startTime: Long, startTimeIncluded: Boolean = true, endTime:Long, endTimeIncluded: Boolean = true): VotePollsGroupedByTimestamp {
val result = dashsdk.platformMobileVotingGetVotepolls(
/**
* Get vote polls within a specific time frame
*
* @param startTime
* @param startTimeIncluded
* @param endTime
* @param endTimeIncluded
* @param limit Number of records to return (default = 100)
* @param orderAscending
* @return [VotePollsGroupedByTimestamp]
*/
fun getVotePolls(
startTime: Long,
startTimeIncluded: Boolean = true,
endTime:Long,
endTimeIncluded: Boolean = true,
limit: Int = DEFAULT_LIMIT,
orderAscending: Boolean = true
): VotePollsGroupedByTimestamp {
val result = dashsdk.platformMobileVotingGetVotePolls(
rustSdk,
startTime.toTimestampMillis(),
startTimeIncluded,
endTime.toTimestampMillis(),
endTimeIncluded
endTimeIncluded,
limit,
0,
orderAscending
)
return VotePollsGroupedByTimestamp(result.unwrap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.dashj.platform.dpp.util.convertToPlatformValue
import org.dashj.platform.sdk.OrderClause
import org.dashj.platform.sdk.WhereClause
import org.dashj.platform.sdk.WhereOperator
import org.dashj.platform.sdk.platform.Documents
import org.json.JSONArray

/**
Expand All @@ -26,7 +27,7 @@ import org.json.JSONArray
class DocumentQuery private constructor(
var where: List<Any>? = null,
var orderBy: List<List<String>>? = null,
var limit: Int = -1,
var limit: Int = Documents.DOCUMENT_LIMIT,
var startAt: Identifier? = null,
var startAfter: Identifier? = null
) : BaseObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class BlockchainIdentity {
val documentWithVotes = contenders.map[uniqueIdentifier]
?: error("$username does not have $uniqueIdentifier as a contender")

val recoveredDocument = documentWithVotes.seralizedDocument?.let {
val recoveredDocument = documentWithVotes.serializedDocument?.let {
platform.names.deserialize(it)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import kotlin.collections.HashMap
typealias RustDocument = org.dashj.platform.sdk.Document

class Document : BaseObject {

companion object {
const val FIELD_ID = "\$id"
}
var dataContract: DataContract? = null
var id: Identifier
var type: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typealias RustContestedResources = org.dashj.platform.sdk.ContestedResources
typealias RustContestedResource = org.dashj.platform.sdk.ContestedResource


data class ContenderWithSerializedDocument(val identityId: Identifier, val seralizedDocument: ByteArray?, val votes: Int) {
data class ContenderWithSerializedDocument(val identityId: Identifier, val serializedDocument: ByteArray?, val votes: Int) {
constructor(contenderWithSerializedDocument: RustContenderWithSerializedDocument) : this(
Identifier.from(contenderWithSerializedDocument.v0._0.identity_id.bytes),
contenderWithSerializedDocument.v0._0.serialized_document,
Expand Down
7 changes: 4 additions & 3 deletions dpp/src/main/java/org/dashj/platform/dpp/voting/Vote.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dashj.platform.dpp.voting

import org.dashj.platform.dpp.identifier.Identifier
import org.dashj.platform.dpp.util.convertPlatformValue
import org.dashj.platform.dpp.util.convertToPlatformValue
import org.dashj.platform.sdk.ResourceVoteV0

Expand Down Expand Up @@ -101,17 +102,17 @@ abstract class VotePoll {

typealias RustContestedDocumentResourceVotePoll = org.dashj.platform.sdk.ContestedDocumentResourceVotePoll

class ContestedDocumentResourceVotePoll(
data class ContestedDocumentResourceVotePoll(
val dataContractId: Identifier,
val documentTypeName: String,
val indexName: String,
val indexValues: List<Any>
val indexValues: List<String>
): VotePoll() {
constructor(votePoll: RustContestedDocumentResourceVotePoll) : this(
Identifier.from(votePoll.contract_id.bytes),
votePoll.document_type_name,
votePoll.index_name,
votePoll.index_values
votePoll.index_values.map { convertPlatformValue(it).toString() }
)

override fun toNative(): RustVotePoll {
Expand Down
Loading