Skip to content

Commit

Permalink
Merge pull request #85 from DECENTfoundation/develop
Browse files Browse the repository at this point in the history
Fix release
  • Loading branch information
petervanderkadecent authored Jul 22, 2019
2 parents d052bb7 + 9af9782 commit 330379f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import toChainObject
import okhttp3.OkHttpClient

// create API for HTTP
val api = DCoreSdk.createForHttp(OkHttpClient(), "https://testnet-api.dcore.io/")
val api = DCoreSdk.createForHttp(OkHttpClient(), "https://testnet.dcore.io/")
// get account by name, resolves to account id '1.2.28'
val disposable = api.accountApi.get("public-account-10").subscribe { account ->
account.id == "1.2.28".toChainObject()
Expand All @@ -72,7 +72,7 @@ import toChainObject
import okhttp3.OkHttpClient

// create API for websocket
val api = DCoreSdk.createForWebSocket(OkHttpClient(), "wss://testnet-api.dcore.io/")
val api = DCoreSdk.createForWebSocket(OkHttpClient(), "wss://testnet-socket.dcore.io/")
// create account credentials form account id and corresponding private key
val credentials = Credentials("1.2.28".toChainObject(), "5JMpT5C75rcAmuUB81mqVBXbmL1BKea4MYwVK6voMQLvigLKfrE")
// 1 DCT
Expand Down
6 changes: 6 additions & 0 deletions library/src/main/java/ch/decent/sdk/api/NftApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
*
* @return NFT data objects, or [ObjectNotFoundException] if none found
*/
@JvmName("getAllDataKt")
fun <T : NftModel> getAllData(ids: List<ChainObject>, clazz: KClass<T>): Single<List<NftData<T>>> = getAllDataRaw(ids).make(clazz)

/**
Expand Down Expand Up @@ -131,6 +132,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
*
* @return NFT data object, or [ObjectNotFoundException] if none found
*/
@JvmName("getDataKt")
fun <T : NftModel> getData(id: ChainObject, clazz: KClass<T>): Single<NftData<T>> = getAllData(listOf(id), clazz).map { it.single() }

/**
Expand Down Expand Up @@ -210,6 +212,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
*
* @return NFT data instances
*/
@JvmName("getNftBalancesKt")
fun <T : NftModel> getNftBalances(account: ChainObject, nftId: ChainObject, clazz: KClass<T>): Single<List<NftData<T>>> =
getNftBalancesRaw(account, listOf(nftId)).make(clazz)

Expand Down Expand Up @@ -245,6 +248,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
*
* @return NFT data objects
*/
@JvmName("listDataByNftKt")
fun <T : NftModel> listDataByNft(nftId: ChainObject, clazz: KClass<T>): Single<List<NftData<T>>> = listDataByNftRaw(nftId).make(clazz)

/**
Expand Down Expand Up @@ -296,6 +300,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
* When set to other then DCT, the request might fail if the asset is not convertible to DCT or conversion pool is not large enough
*/
@JvmOverloads
@JvmName("createNftCreateOperationKt")
fun <T : NftModel> createNftCreateOperation(
symbol: String,
options: NftOptions,
Expand Down Expand Up @@ -337,6 +342,7 @@ class NftApi internal constructor(api: DCoreApi) : BaseApi(api) {
* When set to other then DCT, the request might fail if the asset is not convertible to DCT or conversion pool is not large enough
*/
@JvmOverloads
@JvmName("createKt")
fun <T : NftModel> create(
credentials: Credentials,
symbol: String,
Expand Down
7 changes: 4 additions & 3 deletions library/src/main/java/ch/decent/sdk/model/AssetData.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ch.decent.sdk.model

import ch.decent.sdk.model.types.Int64
import com.google.gson.annotations.SerializedName
import java.math.BigInteger

data class AssetData(
@SerializedName("id") val id: ChainObject = ObjectType.ASSET_OBJECT.genericId,
@SerializedName("current_supply") val currentSupply: BigInteger,
@SerializedName("asset_pool") val assetPool: BigInteger,
@SerializedName("core_pool") val corePool: BigInteger
@SerializedName("current_supply") @Int64 val currentSupply: Long,
@SerializedName("asset_pool") @Int64 val assetPool: Long,
@SerializedName("core_pool") @Int64 val corePool: Long
)
9 changes: 5 additions & 4 deletions library/src/main/java/ch/decent/sdk/model/NftDataType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName
import java.math.BigInteger
import kotlin.reflect.KType
import kotlin.reflect.full.createType
import kotlin.reflect.full.isSubtypeOf

data class NftDataType(
@SerializedName("type") val type: Type = Type.STRING,
Expand Down Expand Up @@ -33,10 +34,10 @@ data class NftDataType(
@SerializedName("boolean") BOOLEAN(Boolean::class.createType());

companion object {
operator fun get(type: KType): Type = when (type) {
in Type.STRING.types -> STRING
in Type.BOOLEAN.types -> BOOLEAN
in Type.INTEGER.types -> INTEGER
operator fun get(type: KType): Type = when {
Type.STRING.types.any { type.isSubtypeOf(it) } -> STRING
Type.BOOLEAN.types.any { type.isSubtypeOf(it) } -> BOOLEAN
Type.INTEGER.types.any { type.isSubtypeOf(it) } -> INTEGER
else -> throw IllegalArgumentException("type '$type' not supported")
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/ch/decent/sdk/net/rpc/RpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import retrofit2.http.POST
internal class RpcService(url: String, client: OkHttpClient, private val gson: Gson) {

private interface RpcEndpoint {
@POST("rpc")
@POST(".")
fun request(@Body request: RequestBody): Single<ResponseBody>
}

Expand Down
6 changes: 4 additions & 2 deletions library/src/test/java/ch/decent/sdk/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory

object Helpers {
@JvmStatic val testnetWs = "wss://testnet-api.dcore.io"
@JvmStatic val testnetHttp = "https://testnet-api.dcore.io/"
@JvmStatic val testnetWs = "wss://testnet-socket.dcore.io/"
@JvmStatic val testnetHttp = "https://testnet.dcore.io/"
@JvmStatic val stageWs = "wss://stagesocket.decentgo.com:8090"
@JvmStatic val stageHttp = "https://stagesocket.decentgo.com"
@JvmStatic val mainWs = "wss://api.decent.ch"
@JvmStatic val mainHttp = "https://api.decent.ch"
@JvmStatic val dockerWs = "ws://localhost:8090/"
@JvmStatic val dockerHttp = "http://localhost:8090/"
@JvmStatic val wsUrl = dockerWs
Expand Down
30 changes: 30 additions & 0 deletions library/src/test/java/ch/decent/sdk/java/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ch.decent.sdk.DCoreSdk;
import ch.decent.sdk.Helpers;
import ch.decent.sdk.crypto.Address;
import ch.decent.sdk.crypto.Credentials;
import ch.decent.sdk.crypto.ECKeyPair;
import ch.decent.sdk.model.*;
import ch.decent.sdk.model.operation.BaseOperation;
Expand All @@ -14,6 +15,7 @@
import ch.decent.sdk.utils.Utils;
import com.google.gson.Gson;
import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,6 +24,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -223,5 +226,32 @@ public void ValidationApiTest() {

@Test
public void NftApiTest() {
Credentials credentials = new Credentials(ObjectType.ACCOUNT_OBJECT.getGenericId(), Helpers.getPrivate());
api.getNftApi().countAll();
api.getNftApi().countAllData();
api.getNftApi().create(credentials, "NFT", 10, true, "description", NftJava.class, true);

}

class NftJava implements NftModel {

public String string;
public boolean aBoolean;
public short aShort;
public byte aByte;
public int anInt;
public long aLong;

@NotNull
@Override
public List<Object> values() {
return null;
}

@NotNull
@Override
public Map<String, Object> createUpdate() {
return null;
}
}
}

0 comments on commit 330379f

Please sign in to comment.