()
77 | val nWords = concatBits.size / 11
78 | for (i in 0 until nWords) {
79 | var index = 0
80 | for (j in 0..10) {
81 | index = index shl 1
82 | if (concatBits[i * 11 + j])
83 | index = index or 0x1
84 | }
85 | words.add(allWords[index])
86 | }
87 |
88 | return words
89 | }
90 |
91 | private fun bytesToBits(data: ByteArray): BooleanArray {
92 | val bits = BooleanArray(data.size * 8)
93 | for (i in data.indices) {
94 | for (j in 0..7) {
95 | bits[i * 8 + j] = (data[i] and (1 shl 7 - j).toByte()) != 0.toByte()
96 | }
97 | }
98 | return bits
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/crypto/hash/Keccak256.java:
--------------------------------------------------------------------------------
1 | // $Id: Keccak256.java 189 2010-05-14 21:21:46Z tp $
2 |
3 | package com.wavesplatform.sdk.crypto.hash;
4 |
5 | /**
6 | * This class implements the Keccak-256 digest algorithm under the
7 | * {@link Digest} API.
8 | *
9 | *
10 | * ==========================(LICENSE BEGIN)============================
11 | *
12 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining
15 | * a copy of this software and associated documentation files (the
16 | * "Software"), to deal in the Software without restriction, including
17 | * without limitation the rights to use, copy, modify, merge, publish,
18 | * distribute, sublicense, and/or sell copies of the Software, and to
19 | * permit persons to whom the Software is furnished to do so, subject to
20 | * the following conditions:
21 | *
22 | * The above copyright notice and this permission notice shall be
23 | * included in all copies or substantial portions of the Software.
24 | *
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
29 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
30 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 | *
33 | * ===========================(LICENSE END)=============================
34 | *
35 | *
36 | * @version $Revision: 189 $
37 | * @author Thomas Pornin <thomas.pornin@cryptolog.com>
38 | */
39 |
40 | public class Keccak256 extends KeccakCore {
41 |
42 | /**
43 | * Create the engine.
44 | */
45 | public Keccak256()
46 | {
47 | }
48 |
49 | /** @see Digest */
50 | public Digest copy()
51 | {
52 | return copyState(new Keccak256());
53 | }
54 |
55 | /** @see Digest */
56 | public int getDigestLength()
57 | {
58 | return 32;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/KeeperKeys.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper
7 |
8 | object KeeperKeys {
9 | object DAppKeys {
10 | const val NAME = "key_keeper_dapp_name"
11 | const val ICON_URL = "key_keeper_dapp_icon_url"
12 | }
13 |
14 | object ActionKeys {
15 | const val ACTION_TYPE = "key_keeper_action_type"
16 | }
17 |
18 | object TransactionKeys {
19 | const val TRANSACTION = "key_keeper_transaction"
20 | }
21 |
22 | object ResultKeys {
23 | const val ERROR_MESSAGE = "key_keeper_error_msg"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/interfaces/BaseTransactionParcelable.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 5/9/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.interfaces
7 |
8 | import android.os.Parcel
9 |
10 | interface BaseTransactionParcelable {
11 | fun writeBaseToParcel(parcel: Parcel)
12 | fun readBaseFromParcel(parcel: Parcel)
13 | }
14 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/interfaces/Keeper.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.interfaces
7 |
8 | import android.content.Context
9 | import android.content.Intent
10 | import androidx.annotation.RestrictTo
11 | import com.wavesplatform.sdk.keeper.model.KeeperDataHolder
12 | import com.wavesplatform.sdk.keeper.model.KeeperIntentResult
13 | import com.wavesplatform.sdk.keeper.model.KeeperProcessData
14 |
15 | interface Keeper {
16 | fun configureDApp(
17 | context: Context,
18 | dAppName: String,
19 | dAppIconUrl: String
20 | )
21 |
22 | fun sign(
23 | activity: androidx.fragment.app.FragmentActivity,
24 | transaction: KeeperTransaction,
25 | callback: KeeperCallback
26 | )
27 |
28 | fun send(
29 | activity: androidx.fragment.app.FragmentActivity,
30 | transaction: KeeperTransaction,
31 | callback: KeeperCallback
32 | )
33 |
34 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
35 | fun finishProcess(
36 | activity: androidx.fragment.app.FragmentActivity,
37 | result: KeeperIntentResult
38 | )
39 |
40 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
41 | fun processData(intent: Intent): KeeperProcessData?
42 |
43 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
44 | fun isKeeperIntent(intent: Intent): Boolean
45 |
46 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
47 | fun keeperDataHolder(): KeeperDataHolder?
48 | }
49 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/interfaces/KeeperCallback.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.interfaces
7 |
8 | import com.wavesplatform.sdk.keeper.model.KeeperResult
9 |
10 | interface KeeperCallback {
11 | fun onSuccess(result: KeeperResult.Success)
12 | fun onFailed(error: KeeperResult.Error)
13 | }
14 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/interfaces/KeeperTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.interfaces
7 |
8 | import android.os.Parcelable
9 |
10 | interface KeeperTransaction : Parcelable
11 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/interfaces/KeeperTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.interfaces
7 |
8 | import android.os.Parcelable
9 |
10 | interface KeeperTransactionResponse : Parcelable
11 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/DApp.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | import android.content.SharedPreferences
9 | import com.wavesplatform.sdk.keeper.KeeperKeys
10 |
11 | data class DApp(var name: String?, var iconUrl: String?) {
12 |
13 | fun save(preferences: SharedPreferences) {
14 | preferences
15 | .edit()
16 | .putString(KeeperKeys.DAppKeys.NAME, name)
17 | .putString(KeeperKeys.DAppKeys.ICON_URL, iconUrl)
18 | .apply()
19 | }
20 |
21 | companion object {
22 | fun restore(preferences: SharedPreferences): DApp {
23 | val dApp = DApp(
24 | preferences.getString(KeeperKeys.DAppKeys.NAME, ""),
25 | preferences.getString(KeeperKeys.DAppKeys.ICON_URL, "")
26 | )
27 |
28 | check(!(dApp.name.isNullOrBlank() || dApp.iconUrl.isNullOrEmpty())) {
29 | "You must configure dApp with WavesSdk.keeper().configureDApp() before use Keeper"
30 | }
31 |
32 | return dApp
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/KeeperActionType.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | enum class KeeperActionType {
9 | SEND,
10 | SIGN;
11 | }
12 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/KeeperDataHolder.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 29/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | data class KeeperDataHolder(val processData: KeeperProcessData)
9 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/KeeperIntentResult.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 2/9/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | import android.os.Parcelable
9 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransaction
10 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransactionResponse
11 | import kotlinx.android.parcel.Parcelize
12 |
13 | sealed class KeeperIntentResult : Parcelable {
14 | @Parcelize
15 | data class SuccessSignResult(val transaction: KeeperTransaction) : KeeperIntentResult()
16 |
17 | @Parcelize
18 | data class ErrorSignResult(val error: String) : KeeperIntentResult()
19 |
20 | @Parcelize
21 | data class SuccessSendResult(val transaction: KeeperTransactionResponse) : KeeperIntentResult()
22 |
23 | @Parcelize
24 | data class ErrorSendResult(val error: String) : KeeperIntentResult()
25 |
26 | @Parcelize
27 | object RejectedResult : KeeperIntentResult()
28 | }
29 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/KeeperProcessData.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransaction
9 |
10 | data class KeeperProcessData(
11 | val actionType: KeeperActionType,
12 | val dApp: DApp,
13 | val transaction: KeeperTransaction?
14 | )
15 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/keeper/model/KeeperResult.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.keeper.model
7 |
8 | sealed class KeeperResult {
9 | data class Success(val transaction: T?) : KeeperResult()
10 | data class Error(val message: String?, val code: Int) : KeeperResult()
11 |
12 | companion object {
13 | const val REJECTED = 1
14 | const val UNKNOWN_ERROR = 2
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/data/AssetsRequest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 9/10/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.data
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | /**
11 | * Assets information
12 | * Get long list of assets info by ids list param
13 | */
14 | data class AssetsRequest(
15 |
16 | /**
17 | * Get assets info by assets ids
18 | */
19 | @SerializedName("ids") var ids: List? = mutableListOf()
20 | )
21 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/data/PairRatesRequest.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.data
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | /**
6 | * Request body to get pairs rates
7 | */
8 | data class PairRatesRequest(
9 |
10 | /**
11 | * Get pairs rates info by amount and price assets
12 | */
13 | @SerializedName("pairs") var pairs: List? = null,
14 | /**
15 | * Timestamp of rate info
16 | */
17 | @SerializedName("timestamp") var timestamp: Long? = null
18 | )
19 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/data/PairRequest.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.data
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | /**
6 | * DEX volume, change24, last trade price
7 | * 1) Get list of pairs info by serialized pairs list
8 | * 2) Get all list of pairs info by limit (sort by volume in WAVES)
9 | */
10 | data class PairRequest(
11 |
12 | /**
13 | * Get pair info by amount and price assets
14 | */
15 | @SerializedName("pairs") var pairs: List? = null,
16 |
17 | /**
18 | * For searching pairs, that have the {searchByAsset} in asset names,
19 | * tickers, id of one asset of the pair.
20 | */
21 | @SerializedName("search_by_asset") var searchByAsset: String? = null,
22 |
23 | /**
24 | * For searching pairs, that have the {searchByAssets} in asset names,
25 | * tickers, id of one asset of the pair.
26 | */
27 | @SerializedName("search_by_assets") var searchByAssets: List? = null,
28 |
29 | /**
30 | * Whether to search assets of pairs exactly or not.
31 | * Parameter position is corresponds to asset position.
32 | */
33 | @SerializedName("match_exactly") var matchExactly: Boolean? = null,
34 |
35 | /**
36 | * How many pairs to await in response.
37 | */
38 | @SerializedName("limit") var limit: Int = 100,
39 |
40 | /**
41 | * Matcher address
42 | */
43 | @SerializedName("matcher") var matcher: String? = null
44 | )
45 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/matcher/CancelAllOrderRequest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.matcher
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.crypto.WavesCrypto
13 |
14 | /**
15 | * Cancel All Orders Request in DEX-matcher
16 | */
17 | class CancelAllOrderRequest(
18 | /**
19 | * Current timestamp
20 | */
21 | @SerializedName("timestamp") var timestamp: Long = 0L,
22 | /**
23 | * Sender address or alias
24 | */
25 | @SerializedName("sender") var sender: String = "",
26 | /**
27 | * Order signature by account private key
28 | */
29 | @SerializedName("signature") var signature: String? = null
30 | ) {
31 |
32 | private fun toBytes(): ByteArray {
33 | return try {
34 | Bytes.concat(
35 | WavesCrypto.base58decode(sender),
36 | Longs.toByteArray(timestamp)
37 | )
38 | } catch (e: Exception) {
39 | Log.e("Wallet", "Couldn't create CancelAllOrderRequest bytes", e)
40 | ByteArray(0)
41 | }
42 | }
43 |
44 | fun sign(privateKey: ByteArray) {
45 | signature = WavesCrypto.base58encode(
46 | WavesCrypto.signBytesWithPrivateKey(toBytes(), WavesCrypto.base58encode(privateKey))
47 | )
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/matcher/CancelOrderRequest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.matcher
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.gson.annotations.SerializedName
11 | import com.wavesplatform.sdk.crypto.WavesCrypto
12 |
13 | /**
14 | * Cancel Order Request in DEX-matcher, decentralized exchange of Waves.
15 | *
16 | * It collects orders from users who created CreateOrderRequest,
17 | * matches and sends it to blockchain it by Exchange transactions.
18 | */
19 | class CancelOrderRequest(
20 | /**
21 | * Order Id of order to cancel
22 | */
23 | @SerializedName("orderId") var orderId: String = "",
24 | /**
25 | * Sender address or alias
26 | */
27 | @SerializedName("sender") var sender: String = "",
28 | /**
29 | * Order signature by account private key
30 | */
31 | @SerializedName("signature") var signature: String? = null
32 | ) {
33 |
34 | private fun toBytes(): ByteArray {
35 | return try {
36 | Bytes.concat(
37 | WavesCrypto.base58decode(sender),
38 | WavesCrypto.base58decode(orderId)
39 | )
40 | } catch (e: Exception) {
41 | Log.e("Wallet", "Couldn't create CancelOrderRequest bytes", e)
42 | ByteArray(0)
43 | }
44 | }
45 |
46 | fun sign(privateKey: ByteArray) {
47 | signature = WavesCrypto.base58encode(
48 | WavesCrypto.signBytesWithPrivateKey(toBytes(), WavesCrypto.base58encode(privateKey))
49 | )
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/matcher/CreateOrderRequest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.matcher
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.WavesSdk
13 | import com.wavesplatform.sdk.crypto.WavesCrypto
14 | import com.wavesplatform.sdk.model.response.matcher.OrderBookResponse
15 | import com.wavesplatform.sdk.utils.SignUtil
16 | import com.wavesplatform.sdk.utils.WavesConstants
17 |
18 | /**
19 | * Create Order Request to DEX-matcher, decentralized exchange of Waves.
20 | * It collects orders from users who created CreateOrderRequest,
21 | * matches and sends it to blockchain it by Exchange transactions.
22 | */
23 | data class CreateOrderRequest(
24 | /**
25 | * Matcher Public Key, available in MatcherService.matcherPublicKey() for DEX
26 | */
27 | @SerializedName("matcherPublicKey") var matcherPublicKey: String = "",
28 | /**
29 | * Account public key of the sender in Base58
30 | */
31 | @SerializedName("senderPublicKey") var senderPublicKey: String = "",
32 | /**
33 | * Exchangeable pair. We sell or buy always amount asset and we always give price asset
34 | */
35 | @SerializedName("assetPair") var assetPair: OrderBookResponse.PairResponse = OrderBookResponse.PairResponse(),
36 | /**
37 | * Order type "buy" or "sell"
38 | */
39 | @SerializedName("orderType") var orderType: String = "buy",
40 | /**
41 | * Price for amount
42 | */
43 | @SerializedName("price") var price: Long = 0L,
44 | /**
45 | * Amount of asset in satoshi
46 | */
47 | @SerializedName("amount") var amount: Long = 0L,
48 | /**
49 | * Unix time of sending of transaction to blockchain, must be in current time +/- 1.5 hour
50 | */
51 | @SerializedName("timestamp") var timestamp: Long = WavesSdk.getEnvironment().getTime(),
52 | /**
53 | * Unix time of expiration of transaction to blockchain
54 | */
55 | @SerializedName("expiration") var expiration: Long = 0L,
56 | /**
57 | * Matcher Fee Asset Id. You can change asset commission
58 | */
59 | @SerializedName("matcherFeeAssetId") var matcherFeeAssetId: String? = null,
60 | /**
61 | * Amount matcher fee of Waves in satoshi
62 | */
63 | @SerializedName("matcherFee") var matcherFee: Long = 300000,
64 | /**
65 | * Version number of the data structure of the transaction.
66 | * The value has to be equal to 2
67 | */
68 | @SerializedName("version") var version: Byte = WavesConstants.VERSION,
69 | /**
70 | * If the array is empty, then S= 3. If the array is not empty,
71 | * then S = 3 + 2 × N + (P1 + P2 + ... + Pn), where N is the number of proofs in the array,
72 | * Pn is the size on N-th proof in bytes.
73 | * The maximum number of proofs in the array is 8. The maximum size of each proof is 64 bytes
74 | */
75 | @SerializedName("proofs") var proofs: MutableList? = null
76 | ) {
77 |
78 | private fun toBytes(): ByteArray {
79 | return toBytesV3()
80 | }
81 |
82 | private fun toBytesV2(): ByteArray {
83 | return try {
84 | val orderTypeByte: Byte = if (orderType == WavesConstants.BUY_ORDER_TYPE) {
85 | 0
86 | } else {
87 | 1
88 | }
89 | Bytes.concat(
90 | byteArrayOf(version),
91 | WavesCrypto.base58decode(senderPublicKey),
92 | WavesCrypto.base58decode(matcherPublicKey),
93 | assetPair.toBytes(),
94 | byteArrayOf(orderTypeByte),
95 | Longs.toByteArray(price),
96 | Longs.toByteArray(amount),
97 | Longs.toByteArray(timestamp),
98 | Longs.toByteArray(expiration),
99 | Longs.toByteArray(matcherFee)
100 | )
101 | } catch (e: Exception) {
102 | Log.e("CreateOrderRequest", "Couldn't create toBytes", e)
103 | ByteArray(0)
104 | }
105 | }
106 |
107 | private fun toBytesV3(): ByteArray {
108 | return try {
109 | version = 3
110 | Bytes.concat(
111 | toBytesV2(),
112 | SignUtil.arrayOption(matcherFeeAssetId)
113 | )
114 | } catch (e: Exception) {
115 | Log.e("CreateOrderRequest", "Couldn't create toBytesV3", e)
116 | ByteArray(0)
117 | }
118 | }
119 |
120 | fun sign(privateKey: ByteArray) {
121 | proofs = mutableListOf(
122 | WavesCrypto.base58encode(
123 | WavesCrypto.signBytesWithPrivateKey(toBytes(), WavesCrypto.base58encode(privateKey))
124 | )
125 | )
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/AliasTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.crypto.WavesCrypto
13 | import com.wavesplatform.sdk.utils.arrayWithSize
14 | import java.nio.charset.Charset
15 |
16 | /**
17 | * The Alias transaction creates short readable alias for address
18 | */
19 | class AliasTransaction(
20 | /**
21 | * Alias, short name for address in Waves blockchain.
22 | * Alias bytes must be in [4;30]
23 | * Alphabet: -.0123456789@_abcdefghijklmnopqrstuvwxyz
24 | */
25 | @SerializedName("alias") var alias: String = ""
26 | ) :
27 | BaseTransaction(CREATE_ALIAS) {
28 |
29 | override fun toBytes(): ByteArray {
30 | return try {
31 | Bytes.concat(
32 | byteArrayOf(type),
33 | byteArrayOf(version),
34 | WavesCrypto.base58decode(senderPublicKey),
35 | Bytes.concat(
36 | byteArrayOf(version),
37 | byteArrayOf(chainId),
38 | alias.toByteArray(
39 | Charset.forName("UTF-8")
40 | ).arrayWithSize()
41 | ).arrayWithSize(),
42 | Longs.toByteArray(fee),
43 | Longs.toByteArray(timestamp)
44 | )
45 | } catch (e: Exception) {
46 | Log.e("Sign", "Can't create bytes for sign in Alias Transaction", e)
47 | ByteArray(0)
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/BurnTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.crypto.WavesCrypto
13 |
14 | /**
15 | * The Burn transaction irreversible deletes amount of some asset
16 | * It's impossible to burn WAVES with the burn transaction.
17 | */
18 | class BurnTransaction(
19 | /**
20 | * Id of burnable asset in Waves blockchain, different for main and test net
21 | */
22 | @SerializedName("assetId") val assetId: String,
23 | /**
24 | * Amount of asset to burn in satoshi
25 | */
26 | @SerializedName("amount") var amount: Long
27 | ) : BaseTransaction(BURN) {
28 |
29 | override fun toBytes(): ByteArray {
30 | return try {
31 | Bytes.concat(
32 | byteArrayOf(type),
33 | byteArrayOf(version),
34 | byteArrayOf(chainId),
35 | WavesCrypto.base58decode(senderPublicKey),
36 | WavesCrypto.base58decode(assetId),
37 | Longs.toByteArray(amount),
38 | Longs.toByteArray(fee),
39 | Longs.toByteArray(timestamp)
40 | )
41 | } catch (e: Exception) {
42 | Log.e("Sign", "Can't create bytes for sign in Burn Transaction", e)
43 | ByteArray(0)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/LeaseCancelTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.crypto.WavesCrypto
13 |
14 | /**
15 | * The cancel leasing transaction reverse [LeaseTransaction].
16 | * Lease cancel transaction is used to to cancel
17 | * and discontinue the WAVES leasing process to a Waves node.
18 | */
19 | class LeaseCancelTransaction(
20 | /**
21 | * Id of Leasing Transaction to cancel
22 | */
23 | @SerializedName("leaseId") var leaseId: String = ""
24 | ) :
25 | BaseTransaction(CANCEL_LEASING) {
26 |
27 | override fun toBytes(): ByteArray {
28 | return try {
29 | Bytes.concat(
30 | byteArrayOf(type),
31 | byteArrayOf(version),
32 | byteArrayOf(chainId),
33 | WavesCrypto.base58decode(senderPublicKey),
34 | Longs.toByteArray(fee),
35 | Longs.toByteArray(timestamp),
36 | WavesCrypto.base58decode(leaseId)
37 | )
38 | } catch (e: Exception) {
39 | Log.e("Sign", "Can't create bytes for sign in Cancel Leasing Transaction", e)
40 | ByteArray(0)
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/LeaseTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.os.Parcelable
9 | import android.util.Log
10 | import com.google.common.primitives.Bytes
11 | import com.google.common.primitives.Longs
12 | import com.google.gson.annotations.SerializedName
13 | import com.wavesplatform.sdk.crypto.WavesCrypto
14 | import com.wavesplatform.sdk.utils.arrayWithSize
15 | import com.wavesplatform.sdk.utils.isAlias
16 | import com.wavesplatform.sdk.utils.parseAlias
17 | import kotlinx.android.parcel.Parcelize
18 | import java.nio.charset.Charset
19 |
20 | /**
21 | * The Leasing transaction leases amount of Waves to node operator.
22 | * it can be address or alias by Proof-of-Stake consensus. It will perform at non-node address.
23 | * You always can reverse the any leased amount by [LeaseCancelTransaction]
24 | */
25 | @Parcelize
26 | class LeaseTransaction(
27 | /**
28 | * Address or alias of Waves blockchain to lease
29 | */
30 | @SerializedName("recipient") var recipient: String,
31 | /**
32 | * Amount to lease of Waves in satoshi
33 | */
34 | @SerializedName("amount") var amount: Long
35 | ) :
36 | BaseTransaction(CREATE_LEASING), Parcelable {
37 |
38 | override fun toBytes(): ByteArray {
39 | return try {
40 | Bytes.concat(
41 | byteArrayOf(type),
42 | byteArrayOf(version),
43 | byteArrayOf(0.toByte()),
44 | WavesCrypto.base58decode(senderPublicKey),
45 | resolveRecipientBytes(recipient.isAlias()),
46 | Longs.toByteArray(amount),
47 | Longs.toByteArray(fee),
48 | Longs.toByteArray(timestamp)
49 | )
50 | } catch (e: Exception) {
51 | Log.e("Sign", "Can't create bytes for sign in Create Leasing Transaction", e)
52 | ByteArray(0)
53 | }
54 | }
55 |
56 | private fun resolveRecipientBytes(recipientIsAlias: Boolean): ByteArray? {
57 | return if (recipientIsAlias) {
58 | Bytes.concat(
59 | byteArrayOf(version),
60 | byteArrayOf(chainId),
61 | recipient.parseAlias().toByteArray(
62 | Charset.forName("UTF-8")
63 | ).arrayWithSize()
64 | )
65 | } else {
66 | WavesCrypto.base58decode(recipient)
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/MassTransferTransaction.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.node
2 |
3 | import android.os.Parcelable
4 | import android.util.Log
5 | import com.google.common.primitives.Bytes
6 | import com.google.common.primitives.Longs
7 | import com.google.common.primitives.Shorts
8 | import com.google.gson.annotations.SerializedName
9 | import com.wavesplatform.sdk.crypto.WavesCrypto
10 | import com.wavesplatform.sdk.model.request.node.TransferTransaction.Companion.MAX_ATTACHMENT_SIZE
11 | import com.wavesplatform.sdk.utils.SignUtil
12 | import com.wavesplatform.sdk.utils.SignUtil.attachmentBytes
13 | import kotlinx.android.parcel.Parcelize
14 |
15 | /**
16 | * The Mass-Transfer transaction sends a lot of transactions of asset for recipients set
17 | *
18 | * Transfer transaction is used to combine several ordinary transfer transactions
19 | * that share single sender and asset ID (it has a list of recipients,
20 | * and an amount to be transferred to each recipient).
21 | * The maximum number of recipients in a single transaction is 100.
22 | *
23 | * The transfers to self are allowed, as well as zero valued transfers.
24 | * In the recipients list, a recipient can occur several times, this is not considered an error.
25 | *
26 | * Fee depends of mass transactions count
27 | * 0.001 + 0.0005 × N, N is the number of transfers inside of a transaction
28 | */
29 | class MassTransferTransaction(
30 | /**
31 | * Id of transferable asset in Waves blockchain, different for main and test net
32 | */
33 | @SerializedName("assetId") var assetId: String?,
34 | /**
35 | * Additional info [0,[MAX_ATTACHMENT_SIZE]] bytes of string encoded in Base58
36 | */
37 | @SerializedName("attachment") var attachment: String,
38 | /**
39 | * Collection of recipients with amount each
40 | */
41 | @SerializedName("transfers") var transfers: List = mutableListOf()
42 | ) : BaseTransaction(MASS_TRANSFER) {
43 |
44 | /**
45 | * Total count of transfers, optional
46 | */
47 | @SerializedName("transferCount")
48 | var transferCount: Int = 0
49 | /**
50 | * Total amount of transfers, optional
51 | */
52 | @SerializedName("totalAmount")
53 | var totalAmount: Long? = null
54 |
55 | override fun sign(seed: String): String {
56 | version = 1
57 | signature = super.sign(seed)
58 | return signature ?: ""
59 | }
60 |
61 | override fun toBytes(): ByteArray {
62 |
63 | val assetIdArray = if (assetId.isNullOrEmpty()) {
64 | byteArrayOf(0)
65 | } else {
66 | SignUtil.arrayOption(assetId!!)
67 | }
68 |
69 | return try {
70 | Bytes.concat(
71 | byteArrayOf(type),
72 | byteArrayOf(version),
73 | WavesCrypto.base58decode(senderPublicKey),
74 | assetIdArray,
75 | transfersArray(),
76 | Longs.toByteArray(timestamp),
77 | Longs.toByteArray(fee),
78 | attachmentBytes(attachment)
79 | )
80 | } catch (e: Exception) {
81 | Log.e("Sign", "Can't create bytes for sign in Mass Transfer Transaction", e)
82 | ByteArray(0)
83 | }
84 | }
85 |
86 | private fun transfersArray(): ByteArray {
87 | var recipientAmountChainArray = byteArrayOf()
88 | for (transfer in transfers) {
89 | val recipient = SignUtil.recipientBytes(transfer.recipient, version, chainId)
90 | val amount = Longs.toByteArray(transfer.amount)
91 | recipientAmountChainArray = Bytes.concat(recipientAmountChainArray, recipient, amount)
92 | }
93 | val lengthBytes = Shorts.toByteArray(transfers.size.toShort())
94 | return Bytes.concat(lengthBytes, recipientAmountChainArray)
95 | }
96 |
97 | /**
98 | * The item of the Mass-transfer transaction
99 | */
100 | @Parcelize
101 | class Transfer(
102 | /**
103 | * Address or alias of Waves blockchain
104 | */
105 | @SerializedName("recipient") var recipient: String = "",
106 | /**
107 | * Amount of asset in satoshi
108 | */
109 | @SerializedName("amount") var amount: Long = 0L
110 | ) : Parcelable
111 | }
112 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/ReissueTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.common.primitives.Longs
11 | import com.google.gson.annotations.SerializedName
12 | import com.wavesplatform.sdk.crypto.WavesCrypto
13 |
14 | /**
15 | * The Reissue transaction is used to give the ability to reissue more tokens of an asset
16 | * by specifying the amount and the asset id. Only quantity and reissuable can be new values
17 | */
18 | class ReissueTransaction(
19 | /**
20 | * Id of your asset that should be changed
21 | */
22 | @SerializedName("assetId") val assetId: String,
23 | /**
24 | * Quantity defines the total tokens supply that your asset will contain
25 | */
26 | @SerializedName("quantity") val quantity: Long,
27 | /**
28 | * Reissuability allows for additional tokens creation that will be added
29 | * to the total token supply of asset.
30 | * A non-reissuable asset will be permanently limited to the total token supply
31 | * defined during the transaction.
32 | */
33 | @SerializedName("reissuable") val reissuable: Boolean
34 | ) : BaseTransaction(REISSUE) {
35 |
36 | init {
37 | this.fee = WAVES_REISSUE_MIN_FEE
38 | }
39 |
40 | override fun toBytes(): ByteArray {
41 | try {
42 | val reissuableBytes = if (reissuable) {
43 | byteArrayOf(1)
44 | } else {
45 | byteArrayOf(0)
46 | }
47 |
48 | return Bytes.concat(
49 | byteArrayOf(type),
50 | byteArrayOf(version),
51 | byteArrayOf(chainId),
52 | WavesCrypto.base58decode(senderPublicKey),
53 | WavesCrypto.base58decode(assetId),
54 | Longs.toByteArray(quantity),
55 | reissuableBytes,
56 | Longs.toByteArray(fee),
57 | Longs.toByteArray(timestamp)
58 | )
59 | } catch (e: Exception) {
60 | Log.e("Sign", "Can't create bytes for sign in Reissue Transaction", e)
61 | return ByteArray(0)
62 | }
63 | }
64 |
65 | companion object {
66 | const val WAVES_REISSUE_MIN_FEE = 100000000L
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/SetAssetScriptTransaction.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.node
2 |
3 | import android.util.Log
4 | import com.google.common.primitives.Bytes
5 | import com.google.common.primitives.Longs
6 | import com.google.gson.annotations.SerializedName
7 | import com.wavesplatform.sdk.crypto.WavesCrypto
8 | import com.wavesplatform.sdk.utils.scriptBytes
9 |
10 | /**
11 | * Set asset script transaction (set script to asset)
12 | *
13 | * You can only update script of asset, that was issued before by [IssueTransaction]
14 | *
15 | * An asset script is a script that is attached to an asset with a set asset script transaction.
16 | * An asset with the attached script is called a smart asset.
17 | * You can attach a script to an asset only during the creation of the asset.
18 | * Script can be developed with [Waves Ride IDE]({https://ide.wavesplatform.com/)
19 | *
20 | * Smart assets are unique virtual currency tokens that may represent a tangible real-world asset,
21 | * or a non-tangible ownership that can be purchased, sold, or exchanged as defined
22 | * by the rules of a script on the Waves blockchain network.
23 | *
24 | * Only the issuer of that asset can change the asset's script.
25 | */
26 | class SetAssetScriptTransaction(
27 | /**
28 | * Selected your asset Id for script
29 | */
30 | @SerializedName("assetId") var assetId: String,
31 | /**
32 | * Base64 binary string with Waves Ride script
33 | * You can use "base64:compiledScriptStringInBase64" and just "compiledScriptStringInBase64".
34 | * Can't be empty string
35 | * You can set asset script only on your asset
36 | */
37 | @SerializedName("script") var script: String
38 | ) : BaseTransaction(ASSET_SCRIPT) {
39 |
40 | override fun toBytes(): ByteArray {
41 | return try {
42 | Bytes.concat(
43 | byteArrayOf(type),
44 | byteArrayOf(version),
45 | byteArrayOf(chainId),
46 | WavesCrypto.base58decode(senderPublicKey),
47 | WavesCrypto.base58decode(assetId),
48 | Longs.toByteArray(fee),
49 | Longs.toByteArray(timestamp),
50 | scriptBytes(script)
51 | )
52 | } catch (e: Exception) {
53 | Log.e("Sign", "Can't create bytes for sign in Data Transaction", e)
54 | ByteArray(0)
55 | }
56 | }
57 |
58 | override fun sign(seed: String): String {
59 | version = 1
60 | signature = super.sign(seed)
61 | return signature ?: ""
62 | }
63 |
64 | companion object {
65 | const val WAVES_SET_ASSET_SCRIPT_MIN_FEE = 100000000L
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/SetScriptTransaction.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.node
2 |
3 | import android.util.Log
4 | import com.google.common.primitives.Bytes
5 | import com.google.common.primitives.Longs
6 | import com.google.gson.annotations.SerializedName
7 | import com.wavesplatform.sdk.crypto.WavesCrypto
8 | import com.wavesplatform.sdk.utils.scriptBytes
9 |
10 | /**
11 | * Script transactions (set script to account) allow you to extend the available functionality
12 | * of the standard Waves application. One of the uses of script transaction
13 | * is creating a multi-signature wallet. Script can be developed
14 | * with [Waves Ride IDE]({https://ide.wavesplatform.com/)
15 | *
16 | * An account with the attached script is called a smart account.
17 | *
18 | * You can also cancel the active script transaction. You must send transaction with null script.
19 | *
20 | * Before you start, please keep in mind.
21 | * We do not recommend you submit script transactions unless you are an experienced user.
22 | *
23 | * !!! Errors can lead to permanent loss of access to your account.
24 | *
25 | * Set script transaction is used to setup an smart account,
26 | * The account needs to issue Set script transaction which contains the predicate.
27 | * Upon success, every outgoing transaction will be validated not by the default mechanism
28 | * of signature validation, but according to the predicate logic.
29 | *
30 | * Account script can be changed or cleared if the script installed allows
31 | * the new set script transaction to process. The set script transaction can be changed
32 | * by another set script transaction call unless it’s prohibited by a previous set script.
33 | */
34 | class SetScriptTransaction(
35 | /**
36 | * Base64 binary string with Waves Ride script
37 | * Null for cancel script. Watch out about commissions on set and cancel script
38 | * You can use "base64:compiledScriptStringInBase64" and just "compiledScriptStringInBase64".
39 | * Can't be empty string
40 | */
41 | @SerializedName("script") var script: String? = null
42 | ) : BaseTransaction(ADDRESS_SCRIPT) {
43 |
44 | override fun toBytes(): ByteArray {
45 | return try {
46 | Bytes.concat(
47 | byteArrayOf(type),
48 | byteArrayOf(version),
49 | byteArrayOf(chainId),
50 | WavesCrypto.base58decode(senderPublicKey),
51 | scriptBytes(script),
52 | Longs.toByteArray(fee),
53 | Longs.toByteArray(timestamp)
54 | )
55 | } catch (e: Exception) {
56 | Log.e("Sign", "Can't create bytes for sign in SetScript Transaction", e)
57 | ByteArray(0)
58 | }
59 | }
60 |
61 | override fun sign(seed: String): String {
62 | version = 1
63 | signature = super.sign(seed)
64 | return signature ?: ""
65 | }
66 |
67 | companion object {
68 | const val WAVES_SET_SCRIPT_MIN_FEE = 1000000L
69 | const val WAVES_CANCEL_SET_SCRIPT_MIN_FEE = 1000000L
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/SponsorshipTransaction.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.request.node
2 |
3 | import android.util.Log
4 | import com.google.common.primitives.Bytes
5 | import com.google.common.primitives.Longs
6 | import com.google.gson.annotations.SerializedName
7 | import com.wavesplatform.sdk.crypto.WavesCrypto
8 |
9 | /**
10 | * Sponsorship transaction (or is Autonomous Assets)
11 | * moves Waves-fees for selected asset for all transfer transactions
12 | * to your account.
13 | *
14 | * Sponsorship transaction is used to set a transaction fee nominated in an asset.
15 | * However, node owners need to explicitly allow transaction fees in the asset
16 | * by manually editing node configuration file.
17 | * Otherwise, node won't be able to mine a block with these transactions.
18 | *
19 | * The sponsorship could be set for an asset. In this case miner will receive fee in waves
20 | * for the processing of transactions, the fee of which is nominated in sponsored asset.
21 | *
22 | * After this transaction is confirmed, it becomes possible to use this asset
23 | * as a fee (automatically for all miners). When transaction with fee in sponsored fee
24 | * asset appears any miner just puts it to forged block.
25 | * Instead of just transferring fee asset to miner's balance blockchain does a bit different thing:
26 | * It automatically moves fee asset to sponsor's (issuer's) account
27 | * and transfers standard transaction cost in WAVES from sponsor's to miner's accounts.
28 | * In fact two miners will receive these WAVES because of NG 40/60 fee distributions.
29 | *
30 | * Example:
31 | * I issue my own asset - Super Coin. I want others to use super coin as a fee.
32 | * I create SponsorshipTransaction(asset="Super Coin's id", sponsored=true, transactionFee=0.1).
33 | * Then I put 100 waves to my account. Now anyone can create Transfer transaction
34 | * with 0.1 super coin as a fee. Someone creates transaction with fee = 0.1 super coin,
35 | * as a result I get 0.1 super coin on my account, and miners get 0.001 waves from my account.
36 | * Since I have 100 waves, users can do 100000 transaction until
37 | * the deposit will be fully transferred to miners,
38 | * at this moment I will have 10000 super coins from fees.
39 | * When deposit is gone no new transactions with super coin fees can be made.
40 | *
41 | * Only the issuer of an asset can set up sponsorship.
42 | * The sponsorship is set by giving the rate at which fee in an asset is converted to Waves.
43 | *
44 | * For cancel send with minSponsoredAssetFee == 0
45 | */
46 | class SponsorshipTransaction(
47 | /**
48 | * Selected your asset Id for sponsorship
49 | */
50 | @SerializedName("assetId") var assetId: String,
51 | /**
52 | * Min sponsored asset fee. If "0" Sponsorship will be cancelled
53 | */
54 | @SerializedName("minSponsoredAssetFee") var minSponsoredAssetFee: Long?
55 | ) :
56 | BaseTransaction(SPONSORSHIP) {
57 |
58 | override fun toBytes(): ByteArray {
59 | return try {
60 | Bytes.concat(
61 | byteArrayOf(type),
62 | byteArrayOf(version),
63 | WavesCrypto.base58decode(senderPublicKey),
64 | WavesCrypto.base58decode(assetId),
65 | Longs.toByteArray(minSponsoredAssetFee ?: 0),
66 | Longs.toByteArray(fee),
67 | Longs.toByteArray(timestamp)
68 | )
69 | } catch (e: Exception) {
70 | Log.e("Sign", "Can't create bytes for sign in Sponsorship Transaction", e)
71 | ByteArray(0)
72 | }
73 | }
74 |
75 | override fun sign(seed: String): String {
76 | version = 1
77 | if (fee == 0L) {
78 | fee = 100400000L
79 | }
80 | signature = super.sign(seed)
81 | return signature ?: ""
82 | }
83 |
84 | companion object {
85 | const val WAVES_SPONSORSHIP_MIN_FEE = 100000000L
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/request/node/TransferTransaction.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.request.node
7 |
8 | import android.os.Parcel
9 | import android.os.Parcelable
10 | import android.util.Log
11 | import com.google.common.primitives.Bytes
12 | import com.google.common.primitives.Longs
13 | import com.google.gson.annotations.SerializedName
14 | import com.wavesplatform.sdk.crypto.WavesCrypto
15 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransaction
16 | import com.wavesplatform.sdk.utils.SignUtil
17 | import com.wavesplatform.sdk.utils.parseAlias
18 | import kotlinx.android.parcel.Parceler
19 | import kotlinx.android.parcel.Parcelize
20 |
21 | /**
22 | * Transfer transaction sends amount of asset on address.
23 | * It is used to transfer a specific amount of an asset (WAVES by default)
24 | * to the recipient (by address or alias).
25 | */
26 | @Parcelize
27 | open class TransferTransaction(
28 | /**
29 | * Id of transferable asset in Waves blockchain, different for main and test net
30 | */
31 | @SerializedName("assetId") var assetId: String = "",
32 | /**
33 | * Address or alias of Waves blockchain
34 | */
35 | @SerializedName("recipient") var recipient: String = "",
36 | /**
37 | * Amount of asset in satoshi
38 | */
39 | @SerializedName("amount") var amount: Long = 0,
40 | /**
41 | * Additional info [0,140] bytes of string encoded in Base58
42 | */
43 | @SerializedName("attachment") var attachment: String = "",
44 | /**
45 | * Asset id instead Waves for transaction commission withdrawal
46 | */
47 | @SerializedName("feeAssetId") var feeAssetId: String = ""
48 | ) :
49 | BaseTransaction(TRANSFER), Parcelable, KeeperTransaction {
50 |
51 | override fun toBytes(): ByteArray {
52 | return try {
53 | Bytes.concat(
54 | byteArrayOf(type),
55 | byteArrayOf(version),
56 | WavesCrypto.base58decode(senderPublicKey),
57 | SignUtil.arrayOption(assetId),
58 | SignUtil.arrayOption(feeAssetId),
59 | Longs.toByteArray(timestamp),
60 | Longs.toByteArray(amount),
61 | Longs.toByteArray(fee),
62 | SignUtil.recipientBytes(recipient.parseAlias(), version, chainId),
63 | SignUtil.attachmentBytes(attachment)
64 | )
65 | } catch (e: Exception) {
66 | Log.e("Sign", "Can't create bytes for sign in Transfer Transaction", e)
67 | ByteArray(0)
68 | }
69 | }
70 |
71 | override fun sign(seed: String): String {
72 | signature = super.sign(seed)
73 | return signature ?: ""
74 | }
75 |
76 | companion object : Parceler {
77 |
78 | override fun TransferTransaction.write(parcel: Parcel, flags: Int) {
79 | parcel.apply {
80 | writeString(assetId)
81 | writeString(recipient)
82 | writeLong(amount)
83 | writeString(attachment)
84 | writeString(feeAssetId)
85 | writeBaseToParcel(this)
86 | }
87 | }
88 |
89 | override fun create(parcel: Parcel): TransferTransaction {
90 | return TransferTransaction(
91 | parcel.readString().orEmpty(),
92 | parcel.readString().orEmpty(),
93 | parcel.readLong(),
94 | parcel.readString().orEmpty(),
95 | parcel.readString().orEmpty()
96 | )
97 | .apply {
98 | readBaseFromParcel(parcel)
99 | }
100 | }
101 |
102 | fun getAttachmentSize(attachment: String?): Int {
103 | if (attachment == null) {
104 | return 0
105 | }
106 | return try {
107 | attachment.toByteArray().size
108 | } catch (e: Exception) {
109 | e.printStackTrace()
110 | 0
111 | }
112 | }
113 |
114 | const val MAX_ATTACHMENT_SIZE = 140
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/ErrorResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response
7 |
8 | class ErrorResponse(var error: Int, var message: String)
9 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/AliasDataResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.response.node.transaction.AliasTransactionResponse
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | @Parcelize
9 | data class AliasDataResponse(
10 | @SerializedName("__type") var type: String = "alias",
11 | @SerializedName("data") var alias: AliasTransactionResponse = AliasTransactionResponse()
12 | ) : Parcelable
13 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/AliasesResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.data
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 |
12 | @Parcelize
13 | data class AliasesResponse(
14 | @SerializedName("__type") var type: String = "list",
15 | @SerializedName("data") var data: List = listOf()
16 | ) : Parcelable
17 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/AssetsInfoResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.data
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import com.wavesplatform.sdk.utils.WavesConstants
11 | import com.wavesplatform.sdk.utils.isWavesId
12 | import kotlinx.android.parcel.Parcelize
13 | import java.math.BigDecimal
14 | import java.util.Date
15 |
16 | data class AssetsInfoResponse(
17 | @SerializedName("__type") var type: String = "list",
18 | @SerializedName("data") var data: List = listOf()
19 | )
20 |
21 | data class AssetsInfoDataResponse(
22 | @SerializedName("__type") var type: String = "asset",
23 | @SerializedName("data") var assetInfo: AssetInfoResponse = AssetInfoResponse()
24 | )
25 |
26 | @Parcelize
27 | open class AssetInfoResponse(
28 | @SerializedName("ticker") var ticker: String? = "",
29 | @SerializedName("id") var id: String = "",
30 | @SerializedName("name") var name: String = "",
31 | @SerializedName("precision") var precision: Int = 0,
32 | @SerializedName("description") var description: String = "",
33 | @SerializedName("height") var height: Int = 0,
34 | @SerializedName("timestamp") var timestamp: Date = Date(),
35 | @SerializedName("sender") var sender: String = "",
36 | @SerializedName("quantity") var quantity: BigDecimal = BigDecimal.ZERO,
37 | @SerializedName("hasScript") var hasScript: Boolean = false,
38 | @SerializedName("minSponsoredFee") var minSponsoredFee: Long = 0,
39 | @SerializedName("reissuable") var reissuable: Boolean = false,
40 | var isSpam: Boolean = false
41 | ) : Parcelable {
42 | fun isSponsored(): Boolean {
43 | return minSponsoredFee > 0
44 | }
45 |
46 | fun getTokenTicker(): String {
47 | return when {
48 | id.isWavesId() -> WavesConstants.WAVES_ASSET_ID_FILLED
49 | ticker.isNullOrEmpty() -> name
50 | else -> ticker ?: name
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/CandlesResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.data
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 | import java.text.SimpleDateFormat
12 | import java.util.Locale
13 | import java.util.TimeZone
14 |
15 | @Parcelize
16 | data class CandlesResponse(
17 | @SerializedName("__type")
18 | var type: String = "list",
19 | @SerializedName("data")
20 | var data: List = mutableListOf()
21 | ) : Parcelable {
22 |
23 | @Parcelize
24 | data class Data(
25 | @SerializedName("__type")
26 | var type: String = "candle",
27 | @SerializedName("data")
28 | var data: CandleResponse
29 | ) : Parcelable {
30 |
31 | @Parcelize
32 | data class CandleResponse(
33 | @SerializedName("close")
34 | var close: Double? = 0.0,
35 | @SerializedName("high")
36 | var high: Double? = 0.0,
37 | @SerializedName("low")
38 | var low: Double? = 0.0,
39 | @SerializedName("open")
40 | var openValue: Double? = 0.0,
41 | @SerializedName("time")
42 | var time: String = "",
43 | @SerializedName("txsCount")
44 | var txsCount: Int? = 0,
45 | @SerializedName("volume")
46 | var volume: Double? = 0.0
47 | ) : Parcelable {
48 |
49 | private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.getDefault())
50 |
51 | fun getTimeInMillis(): Long {
52 | dateFormat.timeZone = TimeZone.getTimeZone("UTC")
53 | val date = dateFormat.parse(time)
54 | dateFormat.timeZone = TimeZone.getDefault()
55 | return dateFormat.parse(dateFormat.format(date)).time
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/DataServiceMassTransferTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import com.wavesplatform.sdk.WavesSdk
5 | import com.wavesplatform.sdk.utils.WavesConstants
6 |
7 | data class DataServiceMassTransferTransactionResponse(
8 | @SerializedName("__type") val type: String,
9 | @SerializedName("isLastPage") val isLastPage: Boolean?,
10 | @SerializedName("lastCursor") val lastCursor: String?,
11 | @SerializedName("data") val data: List
12 | ) {
13 | data class Data(
14 | @SerializedName("__type") val type: String,
15 | @SerializedName("data") val transaction: Transaction
16 | )
17 |
18 | data class Transaction(
19 | @SerializedName("assetId") val assetId: String?,
20 | @SerializedName("attachment") val attachment: String,
21 | @SerializedName("transfers") val transfers: List,
22 | @SerializedName("type") val type: Byte,
23 | @SerializedName("id") val id: String? = null,
24 | @SerializedName("sender") val sender: String = "",
25 | @SerializedName("senderPublicKey") val senderPublicKey: String = "",
26 | @SerializedName("timestamp") val timestamp: String,
27 | @SerializedName("fee") val fee: Number = WavesConstants.WAVES_MIN_FEE,
28 | @SerializedName("chainId") val chainId: Byte? = WavesSdk.getEnvironment().chainId,
29 | @SerializedName("version") val version: Byte = 2,
30 | @SerializedName("proofs") val proofs: MutableList = mutableListOf(),
31 | @SerializedName("signature") val signature: String = "",
32 | @SerializedName("height") val height: Long? = null
33 | )
34 |
35 | data class Transfer(
36 | @SerializedName("recipient") val recipient: String = "",
37 | @SerializedName("amount") val amount: Double = 0.0
38 | )
39 | }
40 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/LastTradesResponseDataList.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.data
7 |
8 | import com.google.gson.annotations.SerializedName
9 | import com.wavesplatform.sdk.model.response.data.transaction.BaseDataListTransactionsResponse
10 |
11 | class LastTradesResponseDataList : BaseDataListTransactionsResponse() {
12 |
13 | data class ExchangeTransactionResponse(
14 | @SerializedName("amount")
15 | var amount: Double = 0.0,
16 | @SerializedName("buyMatcherFee")
17 | var buyMatcherFee: Double = 0.0,
18 | @SerializedName("fee")
19 | var fee: Double = 0.0,
20 | @SerializedName("height")
21 | var height: Int = 0,
22 | @SerializedName("id")
23 | var id: String = "",
24 | @SerializedName("order1")
25 | var order1: ExchangeOrderResponse = ExchangeOrderResponse(),
26 | @SerializedName("order2")
27 | var order2: ExchangeOrderResponse = ExchangeOrderResponse(),
28 | @SerializedName("price")
29 | var price: Double = 0.0,
30 | @SerializedName("sellMatcherFee")
31 | var sellMatcherFee: Double = 0.0,
32 | @SerializedName("sender")
33 | var sender: String = "",
34 | @SerializedName("senderPublicKey")
35 | var senderPublicKey: String = "",
36 | @SerializedName("signature")
37 | var signature: String = "",
38 | @SerializedName("timestamp")
39 | var timestamp: String = "",
40 | @SerializedName("type")
41 | var type: Int = 0
42 | ) {
43 | data class ExchangeOrderResponse(
44 | @SerializedName("amount")
45 | var amount: Double = 0.0,
46 | @SerializedName("assetPair")
47 | var assetPair: AssetPairResponse = AssetPairResponse(),
48 | @SerializedName("expiration")
49 | var expiration: String = "",
50 | @SerializedName("id")
51 | var id: String = "",
52 | @SerializedName("matcherFee")
53 | var matcherFee: Double = 0.0,
54 | @SerializedName("matcherPublicKey")
55 | var matcherPublicKey: String = "",
56 | @SerializedName("orderType")
57 | var orderType: String = "",
58 | @SerializedName("price")
59 | var price: Double = 0.0,
60 | @SerializedName("sender")
61 | var sender: String = "",
62 | @SerializedName("senderPublicKey")
63 | var senderPublicKey: String = "",
64 | @SerializedName("signature")
65 | var signature: String = "",
66 | @SerializedName("timestamp")
67 | var timestamp: String = ""
68 | ) {
69 |
70 | data class AssetPairResponse(
71 | @SerializedName("amountAsset")
72 | var amountAsset: String = "",
73 | @SerializedName("priceAsset")
74 | var priceAsset: String = ""
75 | )
76 | }
77 |
78 | fun getMyOrder(): ExchangeOrderResponse {
79 | return if (order1.timestamp > order2.timestamp) order1
80 | else order2
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/PairResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.data
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 | import java.math.BigDecimal
12 |
13 | @Parcelize
14 | data class PairResponse(
15 | @SerializedName("__type") var type: String = "",
16 | @SerializedName("data") var data: DataResponse = DataResponse()
17 | ) : Parcelable {
18 |
19 | @Parcelize
20 | data class DataResponse(
21 | @SerializedName("firstPrice") var firstPrice: BigDecimal = BigDecimal(0),
22 | @SerializedName("lastPrice") var lastPrice: BigDecimal = BigDecimal(0),
23 | @SerializedName("volume") var volume: BigDecimal = BigDecimal(0),
24 | @SerializedName("volumeWaves") var volumeWaves: BigDecimal? = BigDecimal(0)
25 | ) : Parcelable
26 | }
27 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/PairsRatesResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class PairsRatesResponse(
6 | @SerializedName("__type") val type: String,
7 | @SerializedName("data") val data: List
8 | )
9 |
10 | data class Data(
11 | @SerializedName("__type") val type: String,
12 | @SerializedName("data") val rate: Rate,
13 | @SerializedName("amountAsset") val amountAsset: String,
14 | @SerializedName("priceAsset") val priceAsset: String
15 | )
16 |
17 | data class Rate(@SerializedName("rate") val price: Double)
18 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/SearchPairResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import kotlinx.android.parcel.Parcelize
6 | import java.math.BigDecimal
7 |
8 | /**
9 | * If Search it returns the list op DEX pairs with amountAsset and priceAsset
10 | * If it Request with special pairs order, it's return order list same length
11 | * with data if pair exist and null if not
12 | */
13 | @Parcelize
14 | data class SearchPairResponse(
15 | @SerializedName("__type") var type: String = "list",
16 | @SerializedName("data") var data: List = mutableListOf()
17 | ) : Parcelable {
18 |
19 | @Parcelize
20 | data class Pair(
21 | @SerializedName("__type") var type: String = "pair",
22 | @SerializedName("data") var data: Data? = null,
23 | @SerializedName("amountAsset") var amountAsset: String?,
24 | @SerializedName("priceAsset") var priceAsset: String?
25 | ) : Parcelable {
26 |
27 | @Parcelize
28 | data class Data(
29 | @SerializedName("firstPrice") var firstPrice: BigDecimal = BigDecimal(0),
30 | @SerializedName("lastPrice") var lastPrice: BigDecimal = BigDecimal(0),
31 | @SerializedName("low") var low: BigDecimal = BigDecimal(0),
32 | @SerializedName("high") var high: BigDecimal = BigDecimal(0),
33 | @SerializedName("weightedAveragePrice") var weightedAveragePrice: BigDecimal = BigDecimal(0),
34 | @SerializedName("volume") var volume: BigDecimal = BigDecimal(0),
35 | @SerializedName("quoteVolume") var quoteVolume: BigDecimal? = BigDecimal(0),
36 | @SerializedName("volumeWaves") var volumeWaves: BigDecimal? = BigDecimal(0),
37 | @SerializedName("txsCount") var txsCount: Long? = null
38 | ) : Parcelable
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/transaction/BaseDataListTransactionsResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | open class BaseDataListTransactionsResponse constructor(
6 | @SerializedName("__type")
7 | var type: String = "",
8 | @SerializedName("data")
9 | var data: List> = listOf(),
10 | @SerializedName("lastCursor")
11 | var lastCursor: String = ""
12 | ) {
13 |
14 | data class DataResponse(
15 | @SerializedName("__type")
16 | var type: String = "",
17 | @SerializedName("data")
18 | var transaction: T
19 | )
20 | }
21 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/transaction/BaseDataTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data.transaction
2 |
3 | import android.os.Parcel
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.WavesSdk
6 | import com.wavesplatform.sdk.keeper.interfaces.BaseTransactionParcelable
7 |
8 | abstract class BaseDataTransactionResponse(
9 | /**
10 | * ID of the transaction type. Correct values in [1; 16]
11 | * see also Companion Object of BaseTransaction
12 | */
13 | @SerializedName("type") val type: Byte,
14 |
15 | /**
16 | * Hash of all transaction data
17 | */
18 | @SerializedName("id")
19 | var id: String? = null,
20 |
21 | /**
22 | * Sender address
23 | */
24 | @SerializedName("sender")
25 | var sender: String = "",
26 |
27 | /**
28 | * Account public key of the sender
29 | */
30 | @SerializedName("senderPublicKey")
31 | var senderPublicKey: String = "",
32 |
33 | /**
34 | * Unix time of sending of transaction to blockchain
35 | */
36 | @SerializedName("timestamp")
37 | var timestamp: String = "",
38 |
39 | /**
40 | * A transaction fee is a fee that an account owner pays to send a transaction.
41 | * Transaction fee in WAVELET
42 | */
43 | @SerializedName("fee")
44 | var fee: Double = 0.0,
45 |
46 | /**
47 | * Determines the network where the transaction will be published to.
48 | * [WavesCrypto.TEST_NET_CHAIN_ID] for test network,
49 | * [WavesCrypto.MAIN_NET_CHAIN_ID] for main network
50 | */
51 | @SerializedName("chainId")
52 | val chainId: Byte? = WavesSdk.getEnvironment().chainId,
53 |
54 | /**
55 | * Version number of the data structure of the transaction.
56 | * The value has to be equal to 2
57 | */
58 | @SerializedName("version")
59 | var version: Byte = 2,
60 |
61 | /**
62 | * Transaction signature fo v2
63 | * If the array is empty, then S= 3. If the array is not empty,
64 | * then S = 3 + 2 × N + (P1 + P2 + ... + Pn), where N is the number of proofs in the array,
65 | * Pn is the size on N-th proof in bytes.
66 | * The maximum number of proofs in the array is 8. The maximum size of each proof is 64 bytes
67 | */
68 | @SerializedName("proofs")
69 | val proofs: MutableList = mutableListOf(),
70 |
71 | /**
72 | * Transaction signature fo v1
73 | */
74 | @SerializedName("signature")
75 | var signature: String = "",
76 |
77 | /**
78 | * Transaction blockchain height
79 | */
80 | @SerializedName("height")
81 | var height: Long? = null
82 | ) : BaseTransactionParcelable {
83 |
84 | override fun writeBaseToParcel(parcel: Parcel) {
85 | parcel.apply {
86 | writeString(id)
87 | writeString(sender)
88 | writeString(senderPublicKey)
89 | writeString(timestamp)
90 | writeDouble(fee)
91 | writeByte(version)
92 | writeStringList(proofs)
93 | writeString(signature)
94 | writeLong(height ?: 0)
95 | }
96 | }
97 |
98 | override fun readBaseFromParcel(parcel: Parcel) {
99 | id = parcel.readString()
100 | sender = parcel.readString().orEmpty()
101 | senderPublicKey = parcel.readString().orEmpty()
102 | timestamp = parcel.readString().orEmpty()
103 | fee = parcel.readDouble()
104 | // chainId = parcel.readByte()
105 | version = parcel.readByte()
106 | parcel.readStringList(proofs)
107 | signature = parcel.readString().orEmpty()
108 | height = parcel.readLong()
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/transaction/DataMassTransferTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.MassTransferTransaction]
10 | */
11 | @Parcelize
12 | class DataMassTransferTransactionResponse(
13 | @SerializedName("assetId")
14 | var assetId: String?,
15 | @SerializedName("attachment")
16 | var attachment: String,
17 | @SerializedName("transfers")
18 | var transfers: MutableList
19 | ) :
20 | BaseDataTransactionResponse(type = BaseTransaction.MASS_TRANSFER), Parcelable {
21 | /**
22 | * The item of the Mass-transfer transaction
23 | */
24 | @Parcelize
25 | class Transfer(
26 | /**
27 | * Address or alias of Waves blockchain
28 | */
29 | @SerializedName("recipient") var recipient: String = "",
30 | @SerializedName("amount") var amount: Double = 0.0
31 | ) : Parcelable
32 | }
33 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/data/transaction/DataMassTransferTransactionResponseWrapperList.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.data.transaction
2 |
3 | class DataMassTransferTransactionResponseWrapperList : BaseDataListTransactionsResponse()
4 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/local/ServersConfigurationResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.local
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class ServersConfigurationResponse(
6 | @SerializedName("name") var name: String = "",
7 | @SerializedName("servers") var servers: Servers = Servers(),
8 | @SerializedName("scheme") var scheme: String = ""
9 | ) {
10 |
11 | data class Servers(
12 | @SerializedName("nodeUrl") var nodeUrl: String = "",
13 | @SerializedName("dataUrl") var dataUrl: String = "",
14 | @SerializedName("matcherUrl") var matcherUrl: String = ""
15 | )
16 | }
17 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/AssetPairOrderResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.matcher
7 |
8 | import com.google.gson.annotations.SerializedName
9 | import com.wavesplatform.sdk.utils.MoneyUtil
10 | import com.wavesplatform.sdk.utils.stripZeros
11 | import java.math.BigInteger
12 |
13 | class AssetPairOrderResponse {
14 |
15 | @SerializedName("id")
16 | var id: String = ""
17 | @SerializedName("type")
18 | var type: String = ""
19 | @SerializedName("orderType")
20 | var orderType: String = ""
21 | @SerializedName("amount")
22 | var amount: Long = 0
23 | @SerializedName("price")
24 | var price: Long = 0
25 | @SerializedName("timestamp")
26 | var timestamp: Long = 0
27 | @SerializedName("filled")
28 | var filled: Long = 0
29 | @SerializedName("status")
30 | var status: String = ""
31 | @SerializedName("assetPair")
32 | var assetPair: AssetPairResponse? = null
33 | @SerializedName("sectionTimestamp")
34 | var sectionTimestamp: Long = 0
35 | @SerializedName("fee")
36 | var fee: Long? = null
37 | @SerializedName("feeAsset")
38 | var feeAsset: String? = null
39 |
40 | class AssetPairResponse {
41 | @SerializedName("amountAsset")
42 | var amountAsset: String = ""
43 | @SerializedName("priceAsset")
44 | var priceAsset: String = ""
45 | }
46 |
47 | fun getScaledPrice(amountAssetDecimals: Int?, priceAssetDecimals: Int?): String {
48 | return MoneyUtil.getScaledPrice(
49 | price,
50 | amountAssetDecimals ?: 8,
51 | priceAssetDecimals ?: 8
52 | ).stripZeros()
53 | }
54 |
55 | fun getScaledTotal(priceAssetDecimals: Int?): String {
56 | return MoneyUtil.getTextStripZeros(
57 | BigInteger.valueOf(amount)
58 | .multiply(BigInteger.valueOf(price))
59 | .divide(BigInteger.valueOf(100000000)).toLong(),
60 | priceAssetDecimals ?: 8
61 | ).stripZeros()
62 | }
63 |
64 | fun getScaledAmount(amountAssetDecimals: Int?): String {
65 | return MoneyUtil.getScaledText(amount, amountAssetDecimals ?: 8).stripZeros()
66 | }
67 |
68 | companion object {
69 | const val API_STATUS_CANCELLED = "Cancelled"
70 | const val API_STATUS_ACCEPTED = "Accepted"
71 | const val API_STATUS_PARTIALLY_FILLED = "PartiallyFilled"
72 | const val API_STATUS_FILLED = "Filled"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/CreateOrderResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.matcher
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | /**
6 | * Success:
7 | * {
8 | * "message": {
9 | * "success": true,
10 | * "message": {
11 | * "version": 3,
12 | * "id": "8vLJDRETEkY6G6oDSDJjucMqzSXjNrcunH4LzQZBeMTo",
13 | * "sender": "3PNaua1fMrQm4TArqeTuakmY1u985CgMRk6",
14 | * "senderPublicKey": "B3f8VFh6T2NGT26U7rHk2grAxn5zi9iLkg4V9uxG6C8q",
15 | * "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
16 | * "assetPair": {
17 | * "amountAsset": "9AT2kEi8C4AYxV1qKxtQTVpD5i54jCPvaNNRP6VzRtYZ",
18 | * "priceAsset": "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu"
19 | * },
20 | * "orderType": "buy",
21 | * "amount": 7300,
22 | * "price": 13700,
23 | * "timestamp": 1611934060218,
24 | * "expiration": 1614439660218,
25 | * "matcherFee": 300000,
26 | * "matcherFeeAssetId": null,
27 | * "signature": "3kHrjYjuHrBTk25UvEu85nCqLsxXjEn9r1nqxQfbATLCJDiNLdugY1WU5JYMNn6wsJgpLJY4qYViRygbZQsCiMfB",
28 | * "proofs": [
29 | * "3kHrjYjuHrBTk25UvEu85nCqLsxXjEn9r1nqxQfbATLCJDiNLdugY1WU5JYMNn6wsJgpLJY4qYViRygbZQsCiMfB"
30 | * ]
31 | * },
32 | * "status": "OrderAccepted"
33 | * }
34 | *
35 | * Error:
36 | * {
37 | * "error": 9440512,
38 | * "message": "The signature of order is invalid...",
39 | * "template": "The signature of order {{id}} is invalid: {{details}}",
40 | * "params": {
41 | * "id": "EFE6uzy8t9JQtvjHnEXpPd3DbC8LpDLYkYFhwozhayDA",
42 | * "details": The signature of order is invalid..."
43 | * },
44 | * "status": "OrderRejected",
45 | * "success": false
46 | * }
47 | *
48 | */
49 | data class CreateOrderResponse(
50 | @SerializedName("status")
51 | var status: String? = null,
52 | @SerializedName("success")
53 | var success: Boolean? = null
54 | ) {
55 |
56 | companion object {
57 | const val STATUS_ORDER_ACCEPTED = "OrderAccepted"
58 | const val STATUS_ORDER_REJECTED = "OrderRejected"
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/MarketResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.matcher
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 |
12 | @Parcelize
13 | open class MarketResponse(
14 | @SerializedName("id") var id: String? = "",
15 | @SerializedName("amountAsset") var amountAsset: String = "",
16 | @SerializedName("amountAssetName") var amountAssetName: String = "",
17 | @SerializedName("amountAssetShortName") var amountAssetShortName: String? = "",
18 | @SerializedName("amountAssetLongName") var amountAssetLongName: String? = "",
19 | @SerializedName("amountAssetDecimals") var amountAssetDecimals: Int = 0,
20 | @SerializedName("amountAssetInfo") var amountAssetInfo: AmountAssetInfoResponse = AmountAssetInfoResponse(),
21 | @SerializedName("priceAsset") var priceAsset: String = "",
22 | @SerializedName("priceAssetName") var priceAssetName: String = "",
23 | @SerializedName("priceAssetShortName") var priceAssetShortName: String? = "",
24 | @SerializedName("priceAssetLongName") var priceAssetLongName: String? = "",
25 | @SerializedName("priceAssetInfo") var priceAssetInfo: PriceAssetInfoResponse = PriceAssetInfoResponse(),
26 | @SerializedName("priceAssetDecimals") var priceAssetDecimals: Int = 0,
27 | @SerializedName("created") var created: Long = 0,
28 | @SerializedName("checked") var checked: Boolean = false,
29 | @SerializedName("popular") var popular: Boolean = false,
30 | @SerializedName("position") var position: Int = -1,
31 | @SerializedName("currentTimeFrame") var currentTimeFrame: Int? = null
32 | ) : Parcelable
33 |
34 | @Parcelize
35 | data class AmountAssetInfoResponse(
36 | @SerializedName("decimals") var decimals: Int = 0
37 | ) : Parcelable
38 |
39 | @Parcelize
40 | data class PriceAssetInfoResponse(
41 | @SerializedName("decimals") var decimals: Int = 0
42 | ) : Parcelable
43 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/MarketsResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.matcher
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | data class MarketsResponse(
11 | @SerializedName("matcherPublicKey") var matcherPublicKey: String = "",
12 | @SerializedName("markets") var markets: List = listOf()
13 | )
14 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/MatcherSettingsResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.matcher
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import com.wavesplatform.sdk.utils.WavesConstants
5 |
6 | class MatcherSettingsResponse(
7 | @SerializedName("priceAssets") var priceAssets: List = listOf(),
8 | @SerializedName("orderFee") var orderFee: MutableMap = hashMapOf()
9 | ) {
10 |
11 | class Fee(
12 | @SerializedName("baseFee") var baseFee: Long = WavesConstants.WAVES_ORDER_MIN_FEE,
13 | @SerializedName("rates") var rates: MutableMap = hashMapOf()
14 | )
15 |
16 | companion object {
17 | const val DYNAMIC = "dynamic"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/matcher/OrderBookResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.matcher
7 |
8 | import android.util.Log
9 | import com.google.common.primitives.Bytes
10 | import com.google.gson.annotations.SerializedName
11 | import com.wavesplatform.sdk.utils.MoneyUtil
12 | import com.wavesplatform.sdk.utils.SignUtil
13 | import com.wavesplatform.sdk.utils.stripZeros
14 | import java.math.BigInteger
15 |
16 | class OrderBookResponse(
17 | @SerializedName("timestamp") var timestamp: Long = 0,
18 | @SerializedName("pair") var pair: PairResponse = PairResponse(),
19 | @SerializedName("bids") var bids: List = listOf(),
20 | @SerializedName("asks") var asks: List = listOf()
21 | ) {
22 |
23 | class PairResponse(
24 | @SerializedName("amountAsset") var amountAsset: String = "",
25 | @SerializedName("priceAsset") var priceAsset: String = ""
26 | ) {
27 | fun toBytes(): ByteArray {
28 | return try {
29 | Bytes.concat(
30 | SignUtil.arrayOption(amountAsset),
31 | SignUtil.arrayOption(priceAsset)
32 | )
33 | } catch (e: Exception) {
34 | Log.e("Wallet", "Couldn't create bytes for AssetPairResponse: ", e)
35 | ByteArray(0)
36 | }
37 | }
38 | }
39 |
40 | open class AskResponse(
41 | @SerializedName("amount") var amount: Long = 0,
42 | @SerializedName("price") var price: Long = 0,
43 | @SerializedName("sum") var sum: Long = 0
44 | ) {
45 |
46 | val total: Long
47 | get() {
48 | return BigInteger.valueOf(amount)
49 | .multiply(BigInteger.valueOf(price))
50 | .divide(BigInteger.valueOf(100000000)).toLong()
51 | }
52 |
53 | fun getScaledSum(priceAssetDecimals: Int?): String {
54 | return MoneyUtil.getTextStripZeros(sum, priceAssetDecimals ?: 8).stripZeros()
55 | }
56 | }
57 |
58 | open class BidResponse(
59 | @SerializedName("amount") var amount: Long = 0,
60 | @SerializedName("price") var price: Long = 0,
61 | @SerializedName("sum") var sum: Long = 0
62 | ) {
63 |
64 | val total: Long
65 | get() {
66 | return BigInteger.valueOf(amount)
67 | .multiply(BigInteger.valueOf(price))
68 | .divide(BigInteger.valueOf(100000000)).toLong()
69 | }
70 |
71 | fun getScaledSum(priceAssetDecimals: Int?): String {
72 | return MoneyUtil.getTextStripZeros(sum, priceAssetDecimals ?: 8).stripZeros()
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/AddressAssetBalanceResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | data class AddressAssetBalanceResponse(
11 | @SerializedName("address") var address: String = "",
12 | @SerializedName("assetId") var assetId: String = "",
13 | @SerializedName("balance") var balance: Long = 0L
14 | )
15 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/AssetBalanceResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import com.wavesplatform.sdk.utils.MoneyUtil
11 | import kotlinx.android.parcel.Parcelize
12 | import java.math.BigDecimal
13 |
14 | open class AssetBalancesResponse(
15 | @SerializedName("address") var address: String? = null,
16 | @SerializedName("balances") var balances: List = ArrayList()
17 | )
18 |
19 | @Parcelize
20 | open class AssetBalanceResponse(
21 | @SerializedName("assetId") var assetId: String = "",
22 | @SerializedName("balance") var balance: Long? = 0,
23 | @SerializedName("leasedBalance") var leasedBalance: Long? = 0,
24 | @SerializedName("inOrderBalance") var inOrderBalance: Long? = 0,
25 | @SerializedName("reissuable") var reissuable: Boolean? = false,
26 | @SerializedName("minSponsoredAssetFee") var minSponsoredAssetFee: Long? = 0,
27 | @SerializedName("sponsorBalance") var sponsorBalance: Long? = 0,
28 | @SerializedName("quantity") var quantity: BigDecimal? = BigDecimal.ZERO,
29 | @SerializedName("issueTransaction") var issueTransaction: IssueTransactionResponse? = IssueTransactionResponse(id = assetId),
30 | var isHidden: Boolean = false,
31 | var position: Int = -1,
32 | var configureVisibleState: Boolean = false,
33 | var isChecked: Boolean = false,
34 | var isFiatMoney: Boolean = false,
35 | var isFavorite: Boolean = false,
36 | var isGateway: Boolean = false,
37 | var isSpam: Boolean = false
38 | ) : Parcelable {
39 |
40 | fun isSponsored(): Boolean {
41 | return minSponsoredAssetFee ?: 0 > 0
42 | }
43 |
44 | fun isScripted(): Boolean {
45 | return !issueTransaction?.script.isNullOrEmpty()
46 | }
47 |
48 | fun isMyWavesToken(address: String): Boolean {
49 | return issueTransaction?.sender == address
50 | }
51 |
52 | fun getDecimals(): Int {
53 | return if (issueTransaction != null) {
54 | issueTransaction!!.decimals ?: 8
55 | } else {
56 | 8
57 | }
58 | }
59 |
60 | fun getDescription(): String {
61 | return if (issueTransaction == null) {
62 | ""
63 | } else {
64 | issueTransaction!!.description ?: ""
65 | }
66 | }
67 |
68 | fun getDisplayTotalBalance(): String {
69 | return MoneyUtil.getScaledText(balance, this)
70 | }
71 |
72 | fun getDisplayInOrderBalance(): String {
73 | return MoneyUtil.getScaledText(inOrderBalance, this)
74 | }
75 |
76 | fun getDisplayLeasedBalance(): String {
77 | return MoneyUtil.getScaledText(leasedBalance, this)
78 | }
79 |
80 | fun getDisplayAvailableBalance(): String {
81 | return MoneyUtil.getScaledText(getAvailableBalance(), this)
82 | }
83 |
84 | fun getAvailableBalance(): Long {
85 | val availableBalance = balance
86 | ?.minus(inOrderBalance ?: 0)
87 | ?.minus(leasedBalance ?: 0) ?: 0L
88 | return if (availableBalance < 0) {
89 | 0L
90 | } else {
91 | availableBalance
92 | }
93 | }
94 |
95 | fun getSponsorBalance(): Long {
96 | return sponsorBalance ?: 0
97 | }
98 |
99 | fun isAssetId(assetId: String): Boolean {
100 | return assetId == this.assetId
101 | }
102 |
103 | fun getName(): String {
104 | return issueTransaction?.name ?: ""
105 | }
106 |
107 | fun getDisplayBalanceWithUnit(): String {
108 | return getDisplayTotalBalance() + " " + getName()
109 | }
110 |
111 | fun isWaves(): Boolean {
112 | return assetId.isNullOrEmpty()
113 | }
114 | }
115 |
116 | @Parcelize
117 | open class IssueTransactionResponse(
118 | @SerializedName("type") var type: Int? = 0,
119 | @SerializedName("id") var id: String? = "",
120 | @SerializedName("sender") var sender: String? = "",
121 | @SerializedName("senderPublicKey") var senderPublicKey: String? = "",
122 | @SerializedName("fee") var fee: Int? = 0,
123 | @SerializedName("timestamp") var timestamp: Long? = 0,
124 | @SerializedName("signature") var signature: String? = "",
125 | @SerializedName("version") var version: Int? = 0,
126 | @SerializedName("assetId") var assetId: String? = "",
127 | @SerializedName("name") var name: String? = "",
128 | @SerializedName("quantity") var quantity: BigDecimal? = BigDecimal.ZERO,
129 | @SerializedName("reissuable") var reissuable: Boolean? = false,
130 | @SerializedName("decimals") var decimals: Int? = 0,
131 | @SerializedName("description") var description: String? = "",
132 | @SerializedName("script") var script: String? = ""
133 | ) : Parcelable
134 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/AssetsDetailsResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 | import java.math.BigDecimal
12 |
13 | @Parcelize
14 | data class AssetsDetailsResponse(
15 | @SerializedName("assetId") var assetId: String = "",
16 | @SerializedName("issueHeight") var issueHeight: Long = 0L,
17 | @SerializedName("issueTimestamp") var issueTimestamp: Long = 0L,
18 | @SerializedName("issuer") var issuer: String = "",
19 | @SerializedName("name") var name: String = "",
20 | @SerializedName("description") var description: String = "",
21 | @SerializedName("decimals") var decimals: Int = 8,
22 | @SerializedName("reissuable") var reissuable: Boolean? = null,
23 | @SerializedName("quantity") var quantity: BigDecimal = BigDecimal.ZERO,
24 | @SerializedName("scripted") var scripted: Boolean = false,
25 | @SerializedName("minSponsoredAssetFee") var minSponsoredAssetFee: Long = 0L
26 | ) : Parcelable
27 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/BlockChainData.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 4/2/2020
3 | * Copyright © 2020 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | data class BlockChainData(
11 | @SerializedName("key")
12 | var key: String,
13 | @SerializedName("type")
14 | var type: String,
15 | @SerializedName("value")
16 | var value: Long
17 | )
18 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/HeightResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | data class HeightResponse(@SerializedName("height") var height: Int = 0)
11 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/ScriptInfoResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 |
12 | @Parcelize
13 | data class ScriptInfoResponse(
14 | @SerializedName("address") var address: String = "",
15 | @SerializedName("complexity") var complexity: Long = 0L,
16 | @SerializedName("extraFee") var extraFee: Long = 0L
17 | ) : Parcelable
18 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/UtilsTimeResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import com.google.gson.annotations.SerializedName
9 |
10 | data class UtilsTimeResponse(
11 | @SerializedName("system")
12 | var system: Long = 0,
13 | @SerializedName("NTP")
14 | var ntp: Long = 0
15 | )
16 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/WavesBalanceResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.model.response.node
7 |
8 | import android.os.Parcelable
9 | import com.google.gson.annotations.SerializedName
10 | import kotlinx.android.parcel.Parcelize
11 |
12 | @Parcelize
13 | class WavesBalanceResponse(
14 | @SerializedName("address") var address: String? = null,
15 | @SerializedName("balance") var balance: Long = 0
16 | ) : Parcelable
17 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/AliasTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.AliasTransaction]
10 | */
11 | @Parcelize
12 | class AliasTransactionResponse(
13 | @SerializedName("alias")
14 | var alias: String = "",
15 | @SerializedName("address")
16 | var address: String = "",
17 | var own: Boolean = false
18 | ) :
19 | BaseTransactionResponse(type = BaseTransaction.CREATE_ALIAS), Parcelable
20 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/BaseTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcel
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.WavesSdk
6 | import com.wavesplatform.sdk.keeper.interfaces.BaseTransactionParcelable
7 | import com.wavesplatform.sdk.utils.WavesConstants
8 |
9 | abstract class BaseTransactionResponse(
10 | /**
11 | * ID of the transaction type. Correct values in [1; 16]
12 | * see also Companion Object of BaseTransaction
13 | */
14 | @SerializedName("type") val type: Byte,
15 |
16 | /**
17 | * Hash of all transaction data
18 | */
19 | @SerializedName("id")
20 | var id: String? = null,
21 |
22 | /**
23 | * Sender address
24 | */
25 | @SerializedName("sender")
26 | var sender: String = "",
27 |
28 | /**
29 | * Account public key of the sender
30 | */
31 | @SerializedName("senderPublicKey")
32 | var senderPublicKey: String = "",
33 |
34 | /**
35 | * Unix time of sending of transaction to blockchain
36 | */
37 | @SerializedName("timestamp")
38 | var timestamp: Long = 0L,
39 |
40 | /**
41 | * A transaction fee is a fee that an account owner pays to send a transaction.
42 | * Transaction fee in WAVELET
43 | */
44 | @SerializedName("fee")
45 | var fee: Long = WavesConstants.WAVES_MIN_FEE,
46 |
47 | /**
48 | * Determines the network where the transaction will be published to.
49 | * [WavesCrypto.TEST_NET_CHAIN_ID] for test network,
50 | * [WavesCrypto.MAIN_NET_CHAIN_ID] for main network
51 | */
52 | @SerializedName("chainId")
53 | val chainId: Byte? = WavesSdk.getEnvironment().chainId,
54 |
55 | /**
56 | * Version number of the data structure of the transaction.
57 | * The value has to be equal to 2
58 | */
59 | @SerializedName("version")
60 | var version: Byte = 2,
61 |
62 | /**
63 | * Transaction signature fo v2
64 | * If the array is empty, then S= 3. If the array is not empty,
65 | * then S = 3 + 2 × N + (P1 + P2 + ... + Pn), where N is the number of proofs in the array,
66 | * Pn is the size on N-th proof in bytes.
67 | * The maximum number of proofs in the array is 8. The maximum size of each proof is 64 bytes
68 | */
69 | @SerializedName("proofs")
70 | val proofs: MutableList = mutableListOf(),
71 |
72 | /**
73 | * Transaction signature fo v1
74 | */
75 | @SerializedName("signature")
76 | var signature: String = "",
77 |
78 | /**
79 | * Transaction blockchain height
80 | */
81 | @SerializedName("height")
82 | var height: Long? = null
83 | ) : BaseTransactionParcelable {
84 |
85 | override fun writeBaseToParcel(parcel: Parcel) {
86 | parcel.apply {
87 | writeString(id)
88 | writeString(sender)
89 | writeString(senderPublicKey)
90 | writeLong(timestamp)
91 | writeLong(fee)
92 | writeByte(version)
93 | writeStringList(proofs)
94 | writeString(signature)
95 | writeLong(height ?: 0)
96 | }
97 | }
98 |
99 | override fun readBaseFromParcel(parcel: Parcel) {
100 | id = parcel.readString()
101 | sender = parcel.readString().orEmpty()
102 | senderPublicKey = parcel.readString().orEmpty()
103 | timestamp = parcel.readLong()
104 | fee = parcel.readLong()
105 | // chainId = parcel.readByte()
106 | version = parcel.readByte()
107 | parcel.readStringList(proofs)
108 | signature = parcel.readString().orEmpty()
109 | height = parcel.readLong()
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/BurnTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.BurnTransaction]
10 | */
11 | @Parcelize
12 | class BurnTransactionResponse(
13 | @SerializedName("assetId")
14 | val assetId: String = "",
15 | @SerializedName("amount")
16 | var amount: Long = 0
17 | ) :
18 | BaseTransactionResponse(type = BaseTransaction.BURN), Parcelable
19 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/DataTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcel
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransactionResponse
6 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
7 | import com.wavesplatform.sdk.model.request.node.DataTransaction
8 | import kotlinx.android.parcel.Parceler
9 | import kotlinx.android.parcel.Parcelize
10 |
11 | /**
12 | * See [com.wavesplatform.sdk.model.request.node.DataTransaction]
13 | */
14 | @Parcelize
15 | class DataTransactionResponse(
16 | @SerializedName("data")
17 | var data: List? = null
18 | ) :
19 | BaseTransactionResponse(type = BaseTransaction.DATA), KeeperTransactionResponse {
20 |
21 | companion object : Parceler {
22 |
23 | override fun DataTransactionResponse.write(parcel: Parcel, flags: Int) {
24 | parcel.apply {
25 | writeTypedList(data)
26 | writeBaseToParcel(this)
27 | }
28 | }
29 |
30 | override fun create(parcel: Parcel): DataTransactionResponse {
31 | return DataTransactionResponse(
32 | mutableListOf().apply {
33 | parcel.readTypedList(this, DataTransaction.Data.CREATOR)
34 | }
35 | )
36 | .apply {
37 | readBaseFromParcel(parcel)
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/ExchangeTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import com.wavesplatform.sdk.model.request.node.ExchangeTransaction
7 | import kotlinx.android.parcel.Parcelize
8 |
9 | /**
10 | * See [com.wavesplatform.sdk.model.request.node.ExchangeTransaction]
11 | */
12 | @Parcelize
13 | internal class ExchangeTransactionResponse(
14 | @SerializedName("order1")
15 | var order1: ExchangeTransaction.Order,
16 | @SerializedName("order2")
17 | var order2: ExchangeTransaction.Order,
18 | @SerializedName("price")
19 | var price: Long,
20 | @SerializedName("amount")
21 | var amount: Long,
22 | @SerializedName("buyMatcherFee")
23 | var buyMatcherFee: Long,
24 | @SerializedName("sellMatcherFee")
25 | var sellMatcherFee: Long
26 | ) :
27 | BaseTransactionResponse(type = BaseTransaction.EXCHANGE), Parcelable
28 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/InvokeScriptTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcel
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransactionResponse
6 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
7 | import com.wavesplatform.sdk.model.request.node.InvokeScriptTransaction
8 | import kotlinx.android.parcel.Parceler
9 | import kotlinx.android.parcel.Parcelize
10 |
11 | /**
12 | * See [com.wavesplatform.sdk.model.request.node.InvokeScriptTransaction]
13 | */
14 | @Parcelize
15 | class InvokeScriptTransactionResponse(
16 | @SerializedName("feeAssetId")
17 | var feeAssetId: String?,
18 | @SerializedName("dApp")
19 | var dApp: String,
20 | @SerializedName("call")
21 | var call: InvokeScriptTransaction.Call?,
22 | @SerializedName("payment") var payment: List = mutableListOf()
23 | ) : BaseTransactionResponse(type = BaseTransaction.SCRIPT_INVOCATION), KeeperTransactionResponse {
24 |
25 | companion object : Parceler {
26 |
27 | override fun InvokeScriptTransactionResponse.write(parcel: Parcel, flags: Int) {
28 | parcel.apply {
29 | writeString(feeAssetId)
30 | writeString(dApp)
31 | writeParcelable(call, flags)
32 | writeTypedList(payment)
33 | writeBaseToParcel(this)
34 | }
35 | }
36 |
37 | override fun create(parcel: Parcel): InvokeScriptTransactionResponse {
38 | return InvokeScriptTransactionResponse(
39 | parcel.readString().orEmpty(),
40 | parcel.readString().orEmpty(),
41 | parcel.readParcelable(InvokeScriptTransaction.Call::class.java.classLoader),
42 | parcel.createTypedArrayList(InvokeScriptTransaction.Payment.CREATOR).orEmpty()
43 | )
44 | .apply {
45 | readBaseFromParcel(parcel)
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/IssueTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.IssueTransaction]
10 | */
11 | @Parcelize
12 | class IssueTransactionResponse(
13 | @SerializedName("assetId")
14 | var assetId: String,
15 | @SerializedName("name")
16 | var name: String,
17 | @SerializedName("quantity")
18 | var quantity: Long,
19 | @SerializedName("reissuable")
20 | var reissuable: Boolean,
21 | @SerializedName("decimals")
22 | var decimals: Int,
23 | @SerializedName("description")
24 | var description: String,
25 | @SerializedName("script")
26 | var script: String?
27 | ) :
28 | BaseTransactionResponse(type = BaseTransaction.ISSUE), Parcelable
29 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/LeaseCancelTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.LeaseCancelTransaction]
10 | */
11 | @Parcelize
12 | class LeaseCancelTransactionResponse(
13 | @SerializedName("leaseId")
14 | var leaseId: String = ""
15 | ) : BaseTransactionResponse(type = BaseTransaction.CANCEL_LEASING), Parcelable
16 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/LeaseTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.LeaseTransaction]
10 | */
11 | @Parcelize
12 | class LeaseTransactionResponse(
13 | @SerializedName("assetId")
14 | var assetId: String = "",
15 | @SerializedName("recipient")
16 | var recipient: String = "",
17 | @SerializedName("amount")
18 | var amount: Long = 0L,
19 | @SerializedName("attachment")
20 | var attachment: String = "",
21 | @SerializedName("feeAssetId")
22 | var feeAssetId: String = ""
23 | ) :
24 | BaseTransactionResponse(type = BaseTransaction.CREATE_LEASING), Parcelable
25 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/MassTransferTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import com.wavesplatform.sdk.model.request.node.MassTransferTransaction.Transfer
7 | import kotlinx.android.parcel.Parcelize
8 |
9 | /**
10 | * See [com.wavesplatform.sdk.model.request.node.MassTransferTransaction]
11 | */
12 | @Parcelize
13 | class MassTransferTransactionResponse(
14 | @SerializedName("assetId")
15 | var assetId: String?,
16 | @SerializedName("attachment")
17 | var attachment: String,
18 | @SerializedName("transferCount")
19 | var transferCount: Int,
20 | @SerializedName("totalAmount")
21 | var totalAmount: Long,
22 | @SerializedName("transfers")
23 | var transfers: Array
24 | ) :
25 | BaseTransactionResponse(type = BaseTransaction.MASS_TRANSFER), Parcelable
26 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/ReissueTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.ReissueTransaction]
10 | */
11 | @Parcelize
12 | class ReissueTransactionResponse(
13 | @SerializedName("assetId")
14 | var assetId: String,
15 | @SerializedName("quantity")
16 | var quantity: Long,
17 | @SerializedName("reissuable")
18 | var reissuable: Boolean
19 | ) :
20 | BaseTransactionResponse(type = BaseTransaction.REISSUE), Parcelable
21 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/SetAssetScriptTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.SetAssetScriptTransaction]
10 | */
11 | @Parcelize
12 | class SetAssetScriptTransactionResponse(
13 | @SerializedName("assetId")
14 | val assetId: String = "",
15 | @SerializedName("script")
16 | val script: String = ""
17 | ) :
18 | BaseTransactionResponse(type = BaseTransaction.ASSET_SCRIPT), Parcelable
19 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/SetScriptTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.SetScriptTransaction]
10 | */
11 | @Parcelize
12 | class SetScriptTransactionResponse(
13 | @SerializedName("script")
14 | var script: String?
15 | ) :
16 | BaseTransactionResponse(type = BaseTransaction.ADDRESS_SCRIPT), Parcelable
17 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/SponsorshipTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcelable
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
6 | import kotlinx.android.parcel.Parcelize
7 |
8 | /**
9 | * See [com.wavesplatform.sdk.model.request.node.SponsorshipTransaction]
10 | */
11 | @Parcelize
12 | class SponsorshipTransactionResponse(
13 | var assetId: String,
14 | @SerializedName("minSponsoredAssetFee")
15 | var minSponsoredAssetFee: Long
16 | ) :
17 | BaseTransactionResponse(type = BaseTransaction.SPONSORSHIP), Parcelable
18 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/model/response/node/transaction/TransferTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.model.response.node.transaction
2 |
3 | import android.os.Parcel
4 | import com.google.gson.annotations.SerializedName
5 | import com.wavesplatform.sdk.keeper.interfaces.KeeperTransactionResponse
6 | import com.wavesplatform.sdk.model.request.node.BaseTransaction
7 | import kotlinx.android.parcel.Parceler
8 | import kotlinx.android.parcel.Parcelize
9 |
10 | /**
11 | * See [com.wavesplatform.sdk.model.request.node.TransferTransaction]
12 | */
13 | @Parcelize
14 | class TransferTransactionResponse(
15 | @SerializedName("assetId")
16 | var assetId: String? = "",
17 | @SerializedName("recipient")
18 | var recipient: String = "",
19 | @SerializedName("amount")
20 | var amount: Long = 0L,
21 | @SerializedName("attachment")
22 | var attachment: String? = "",
23 | @SerializedName("feeAssetId")
24 | var feeAssetId: String? = ""
25 | ) :
26 | BaseTransactionResponse(type = BaseTransaction.TRANSFER), KeeperTransactionResponse {
27 |
28 | companion object : Parceler {
29 |
30 | override fun TransferTransactionResponse.write(parcel: Parcel, flags: Int) {
31 | parcel.apply {
32 | writeString(assetId)
33 | writeString(recipient)
34 | writeLong(amount)
35 | writeString(attachment)
36 | writeString(feeAssetId)
37 | writeBaseToParcel(this)
38 | }
39 | }
40 |
41 | override fun create(parcel: Parcel): TransferTransactionResponse {
42 | return TransferTransactionResponse(
43 | parcel.readString().orEmpty(),
44 | parcel.readString().orEmpty(),
45 | parcel.readLong(),
46 | parcel.readString().orEmpty(),
47 | parcel.readString().orEmpty()
48 | )
49 | .apply {
50 | readBaseFromParcel(parcel)
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/net/CallAdapterFactory.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.net
2 |
3 | import io.reactivex.Completable
4 | import io.reactivex.Maybe
5 | import io.reactivex.Observable
6 | import io.reactivex.Single
7 | import retrofit2.Call
8 | import retrofit2.CallAdapter
9 | import retrofit2.HttpException
10 | import retrofit2.Retrofit
11 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
12 | import java.io.IOException
13 | import java.lang.reflect.Type
14 | import java.net.ConnectException
15 | import java.net.SocketTimeoutException
16 | import java.net.UnknownHostException
17 | import java.util.concurrent.TimeoutException
18 |
19 | internal class CallAdapterFactory(private val errorListener: OnErrorListener? = null) : CallAdapter.Factory() {
20 |
21 | private val original: RxJava2CallAdapterFactory = RxJava2CallAdapterFactory.create()
22 |
23 | /**
24 | * Returns an [RxCallAdapterWrapper] instance
25 | */
26 | override fun get(
27 | returnType: Type,
28 | annotations: Array,
29 | retrofit: Retrofit
30 | ): CallAdapter<*, *>? {
31 | val originalCallAdapter = original.get(returnType, annotations, retrofit) ?: return null
32 | return RxCallAdapterWrapper(
33 | retrofit,
34 | originalCallAdapter
35 | as CallAdapter,
36 | returnType
37 | )
38 | }
39 |
40 | inner class RxCallAdapterWrapper(
41 | private val retrofit: Retrofit,
42 | private val wrapped: CallAdapter,
43 | private val returnType: Type
44 | ) : CallAdapter {
45 |
46 | override fun responseType(): Type {
47 | return wrapped.responseType()
48 | }
49 |
50 | override fun adapt(call: Call): Any {
51 | return convert(wrapped.adapt(call))
52 | }
53 |
54 | private fun handleErrorToShow(throwable: Throwable): NetworkException {
55 | val retrofitException = asRetrofitException(throwable)
56 | errorListener?.onError(retrofitException)
57 | return retrofitException
58 | }
59 |
60 | private fun convert(o: Any): Any {
61 | return when (o) {
62 | is Observable<*> -> o.onErrorResumeNext { throwable: Throwable -> Observable.error(handleErrorToShow(throwable)) }
63 | is Single<*> -> o.onErrorResumeNext { Single.error(handleErrorToShow(it)) }
64 | is Completable -> o.onErrorResumeNext { Completable.error(handleErrorToShow(it)) }
65 | is Maybe<*> -> o.onErrorResumeNext { throwable: Throwable -> Maybe.error(handleErrorToShow(throwable)) }
66 | else -> o
67 | }
68 | }
69 |
70 | private fun asRetrofitException(throwable: Throwable): NetworkException {
71 |
72 | // Non-200 http error
73 | if (throwable is HttpException) {
74 | val response = throwable.response()
75 | if (response != null) {
76 | return NetworkException.httpError(
77 | response.raw().request()
78 | .url().toString(),
79 | response, retrofit
80 | )
81 | }
82 | }
83 |
84 | if (throwable is TimeoutException ||
85 | throwable is ConnectException ||
86 | throwable is SocketTimeoutException ||
87 | throwable is UnknownHostException
88 | ) {
89 | return NetworkException.networkError(IOException(throwable.message, throwable))
90 | }
91 |
92 | return NetworkException.unexpectedError(throwable)
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/net/NetworkException.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.net
7 |
8 | import retrofit2.Response
9 | import retrofit2.Retrofit
10 | import java.io.IOException
11 |
12 | class NetworkException internal constructor(
13 | message: String?,
14 | /**
15 | * The request URL which produced the error.
16 | */
17 | val url: String?,
18 | /**
19 | * Response object containing status code, headers, body, etc.
20 | */
21 | val response: Response<*>?,
22 | /**
23 | * The event kind which triggered this error.
24 | */
25 | val kind: Kind,
26 | exception: Throwable?,
27 | /**
28 | * The Retrofit this request was executed on
29 | */
30 | private val retrofit: Retrofit?
31 | ) : RuntimeException(message, exception) {
32 |
33 | /**
34 | * Identifies the event kind which triggered a [NetworkException].
35 | */
36 | enum class Kind {
37 | /**
38 | * An [IOException] occurred while communicating to the server.
39 | */
40 | NETWORK,
41 | /**
42 | * A non-200 HTTP status code was received from the server.
43 | */
44 | HTTP,
45 | /**
46 | * An internal error occurred while attempting to execute a request. It is best practice to
47 | * re-throw this exception so your application crashes.
48 | */
49 | UNEXPECTED
50 | }
51 |
52 | /**
53 | * HTTP response body converted to specified `type`. `null` if there is no
54 | * response.
55 | *
56 | * @throws IOException if unable to convert the body to the specified `type`.
57 | * *
58 | * * public void onError(Throwable throwable) {
59 | * NetworkException error = (NetworkException) throwable;
60 | * LoginErrorResponse response = error.getBodyAs(LoginErrorResponse.class);
61 | * //...
62 | * }
63 | */
64 | fun getErrorBodyAs(type: Class): T? {
65 | if (response?.errorBody() == null) {
66 | return null
67 | }
68 | val converter = retrofit?.responseBodyConverter(type, arrayOfNulls(0))
69 | return converter?.convert(response.errorBody())
70 | }
71 |
72 | companion object {
73 |
74 | fun httpError(url: String, response: Response<*>, retrofit: Retrofit?): NetworkException {
75 | val message = response.code().toString() + " " + response.message()
76 | return NetworkException(message, url, response, Kind.HTTP, null, retrofit)
77 | }
78 |
79 | fun networkError(exception: IOException): NetworkException {
80 | return NetworkException(exception.message, null, null, Kind.NETWORK, exception, null)
81 | }
82 |
83 | fun unexpectedError(exception: Throwable): NetworkException {
84 | return NetworkException(exception.message, null, null, Kind.UNEXPECTED, exception, null)
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/net/OnErrorListener.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.net
2 |
3 | interface OnErrorListener {
4 | fun onError(exception: NetworkException)
5 | }
6 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/ActivityExtentions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.utils
7 |
8 | import android.content.Intent
9 | import com.wavesplatform.sdk.utils.inline.InlineActivityResult
10 | import com.wavesplatform.sdk.utils.inline.OnActivityResult
11 |
12 | fun androidx.fragment.app.FragmentActivity.startActivityForResult(
13 | intent: Intent,
14 | requestCode: Int = 196,
15 | onActivityResult: OnActivityResult
16 | ) = InlineActivityResult
17 | .getInstance()
18 | .start(
19 | fragmentManager = supportFragmentManager,
20 | intent = intent,
21 | requestCode = requestCode,
22 | onActivityResult = onActivityResult
23 | )
24 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/AddressExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import com.wavesplatform.sdk.WavesSdk
4 | import com.wavesplatform.sdk.crypto.WavesCrypto
5 | import java.util.Arrays
6 |
7 | const val WAVES_PREFIX = "waves://"
8 |
9 | fun String?.isValidWavesAddress(): Boolean {
10 | if (this.isNullOrEmpty()) return false
11 | return try {
12 | val bytes = WavesCrypto.base58decode(this)
13 | if (bytes.size == WavesCrypto.ADDRESS_LENGTH &&
14 | bytes[0] == WavesCrypto.ADDRESS_VERSION &&
15 | bytes[1] == WavesSdk.getEnvironment().chainId
16 | ) {
17 | val checkSum = Arrays.copyOfRange(
18 | bytes,
19 | bytes.size - WavesCrypto.CHECK_SUM_LENGTH, bytes.size
20 | )
21 | val checkSumGenerated = WavesCrypto.calcCheckSum(
22 | bytes.copyOf(bytes.size - WavesCrypto.CHECK_SUM_LENGTH)
23 | )
24 | Arrays.equals(checkSum, checkSumGenerated)
25 | } else {
26 | false
27 | }
28 | } catch (e: Exception) {
29 | false
30 | }
31 | }
32 |
33 | fun String.isAlias(): Boolean {
34 | return this.contains("alias")
35 | }
36 |
37 | fun String.makeAsAlias(): String {
38 | val prefix = "alias:${WavesSdk.getEnvironment().chainId.toChar()}:"
39 | return if (this.startsWith(prefix)) {
40 | this
41 | } else {
42 | prefix + this
43 | }
44 | }
45 |
46 | fun String.parseAlias(): String {
47 | return this.substringAfterLast(":")
48 | }
49 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/Environment.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import android.content.Context
4 | import com.google.gson.Gson
5 | import com.google.gson.annotations.SerializedName
6 | import com.wavesplatform.sdk.crypto.WavesCrypto
7 | import com.wavesplatform.sdk.model.response.local.ServersConfigurationResponse
8 |
9 | /**
10 | * Settings for work of SDK with nodes and other Waves net-services.
11 | * It contains urls and time correction
12 | */
13 | class Environment(
14 | @SerializedName("server") var server: Server,
15 | @SerializedName("timestampServerDiff") var timestampServerDiff: Long
16 | ) {
17 |
18 | @SerializedName("nodeUrl")
19 | var nodeUrl: String = ""
20 | @SerializedName("dataUrl")
21 | var dataUrl: String = ""
22 | @SerializedName("matcherUrl")
23 | var matcherUrl: String = ""
24 | @SerializedName("scheme")
25 | var chainId: Byte = WavesCrypto.MAIN_NET_CHAIN_ID
26 |
27 | fun init(context: Context) {
28 | val gson = Gson()
29 | val configurationResponse =
30 | when (server) {
31 | Server.MainNet -> {
32 | gson.fromJson(
33 | context.loadJsonFromAsset(WavesConstants.Environments.FILENAME_MAIN_NET),
34 | ServersConfigurationResponse::class.java
35 | )
36 | }
37 | Server.TestNet -> {
38 | gson.fromJson(
39 | context.loadJsonFromAsset(WavesConstants.Environments.FILENAME_TEST_NET),
40 | ServersConfigurationResponse::class.java
41 | )
42 | }
43 | Server.StageNet -> {
44 | gson.fromJson(
45 | context.loadJsonFromAsset(WavesConstants.Environments.FILENAME_STAGE_NET),
46 | ServersConfigurationResponse::class.java
47 | )
48 | }
49 | is Server.Custom -> {
50 | val serverCustom = server as Server.Custom
51 | ServersConfigurationResponse(
52 | "Custom",
53 | ServersConfigurationResponse.Servers(
54 | nodeUrl = serverCustom.node,
55 | dataUrl = serverCustom.data,
56 | matcherUrl = serverCustom.matcher
57 | ),
58 | String(byteArrayOf(serverCustom.scheme))
59 | )
60 | }
61 | }
62 | this.chainId = configurationResponse.scheme.first().toByte()
63 | this.dataUrl = configurationResponse.servers.dataUrl
64 | this.nodeUrl = configurationResponse.servers.nodeUrl
65 | this.matcherUrl = configurationResponse.servers.matcherUrl
66 | }
67 |
68 | fun getTime(): Long {
69 | return System.currentTimeMillis() + timestampServerDiff
70 | }
71 |
72 | companion object {
73 | val DEFAULT = Environment(server = Server.MainNet, timestampServerDiff = 0L)
74 | val MAIN_NET = DEFAULT
75 | val TEST_NET = Environment(server = Server.TestNet, timestampServerDiff = 0L)
76 | val STAGE_NET = Environment(server = Server.StageNet, timestampServerDiff = 0L)
77 | }
78 |
79 | sealed class Server {
80 | object MainNet : Server()
81 | object TestNet : Server()
82 | object StageNet : Server()
83 | class Custom(val node: String, val matcher: String, val data: String, val scheme: Byte) :
84 | Server()
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/KeeperExtentions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 23/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.utils
7 |
8 | import android.content.Context
9 | import android.content.Intent
10 | import android.content.pm.PackageManager
11 |
12 | fun Context.isAppInstalled(packageName: String): Boolean {
13 | return try {
14 | packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
15 | true
16 | } catch (e: Throwable) {
17 | false
18 | }
19 | }
20 |
21 | fun Context.isIntentAvailable(action: String) =
22 | packageManager?.queryIntentActivities(Intent(action), PackageManager.MATCH_DEFAULT_ONLY)?.any() ?: false
23 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/RootUtil.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import android.os.Build
4 | import com.wavesplatform.sdk.BuildConfig
5 | import java.io.BufferedReader
6 | import java.io.File
7 | import java.io.InputStreamReader
8 |
9 | object RootUtil {
10 |
11 | val isDeviceRooted: Boolean
12 | get() = !BuildConfig.DEBUG && (buildTags() || checkPaths() || checkSuperUser() || isEmulator)
13 |
14 | private val isEmulator: Boolean
15 | get() = (
16 | Build.FINGERPRINT.startsWith("generic") ||
17 | Build.FINGERPRINT.startsWith("unknown") ||
18 | Build.MODEL.contains("google_sdk") ||
19 | Build.MODEL.contains("Emulator") ||
20 | Build.MODEL.contains("Android SDK built for x86") ||
21 | Build.MANUFACTURER.contains("Genymotion") ||
22 | Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic") ||
23 | "google_sdk" == Build.PRODUCT
24 | )
25 |
26 | private fun buildTags(): Boolean {
27 | val buildTags = Build.TAGS
28 | return buildTags != null && buildTags.contains("test-keys")
29 | }
30 |
31 | private fun checkPaths(): Boolean {
32 | val paths = arrayOf("/data/local/su", "/data/local/xbin/su", "/data/local/bin/su", "/sbin/su", "/system/app/Superuser.apk", "/system/bin/failsafe/su", "/system/bin/su", "/system/sd/xbin/su", "/system/xbin/su")
33 |
34 | for (path in paths) {
35 | if (File(path).exists()) {
36 | return true
37 | }
38 | }
39 | return false
40 | }
41 |
42 | private fun checkSuperUser(): Boolean {
43 | var process: Process? = null
44 | return try {
45 | process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
46 | val `in` = BufferedReader(InputStreamReader(process!!.inputStream))
47 | `in`.readLine() != null
48 | } catch (t: Throwable) {
49 | false
50 | } finally {
51 | process?.destroy()
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/RxUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.utils
7 |
8 | import io.reactivex.CompletableTransformer
9 | import io.reactivex.FlowableTransformer
10 | import io.reactivex.ObservableTransformer
11 | import io.reactivex.SingleTransformer
12 | import io.reactivex.android.schedulers.AndroidSchedulers
13 | import io.reactivex.disposables.Disposable
14 | import io.reactivex.schedulers.Schedulers
15 |
16 | object RxUtil {
17 |
18 | fun unsubscribe(subscription: Disposable?) {
19 | if (subscription != null && !subscription.isDisposed) {
20 | subscription.dispose()
21 | }
22 | }
23 |
24 | fun applyObservableDefaultSchedulers(): ObservableTransformer { // compose
25 | return ObservableTransformer { observable ->
26 | observable.subscribeOn(Schedulers.io())
27 | .observeOn(AndroidSchedulers.mainThread())
28 | }
29 | }
30 |
31 | fun applySingleDefaultSchedulers(): SingleTransformer { // compose
32 | return SingleTransformer { observable ->
33 | observable.subscribeOn(Schedulers.io())
34 | .observeOn(AndroidSchedulers.mainThread())
35 | }
36 | }
37 |
38 | fun applyFlowableDefaultSchedulers(): FlowableTransformer { // compose
39 | return FlowableTransformer { observable ->
40 | observable.subscribeOn(Schedulers.io())
41 | .observeOn(AndroidSchedulers.mainThread())
42 | }
43 | }
44 |
45 | fun applySchedulersToCompletable(): CompletableTransformer {
46 | return CompletableTransformer { observable ->
47 | observable.subscribeOn(Schedulers.io())
48 | .observeOn(AndroidSchedulers.mainThread())
49 | }
50 | }
51 |
52 | fun applySchedulersToObservable(): ObservableTransformer {
53 | return ObservableTransformer { observable ->
54 | observable.subscribeOn(Schedulers.io())
55 | .observeOn(AndroidSchedulers.mainThread())
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/SignUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 1/4/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.utils
7 |
8 | import com.google.common.primitives.Bytes
9 | import com.google.common.primitives.Shorts
10 | import com.wavesplatform.sdk.crypto.WavesCrypto
11 |
12 | object SignUtil {
13 |
14 | private val CHARSET = charset("UTF-8")
15 |
16 | fun textToBase58(attachmentPlainText: String?): String {
17 | return WavesCrypto.base58encode((attachmentPlainText ?: "").toByteArray(CHARSET))
18 | }
19 |
20 | fun textFromBase58(base58Text: String): String {
21 | return WavesCrypto.base58decode(base58Text).toString(CHARSET)
22 | }
23 |
24 | fun arrayWithSize(s: String?): ByteArray {
25 | return if (s != null && s.isNotEmpty()) {
26 | val b = WavesCrypto.base58decode(s)
27 | Bytes.concat(Shorts.toByteArray(b.size.toShort()), b)
28 | } else {
29 | Shorts.toByteArray(0.toShort())
30 | }
31 | }
32 |
33 | fun arrayOption(o: String?): ByteArray {
34 | return if (o.isNullOrEmpty())
35 | byteArrayOf(0)
36 | else
37 | Bytes.concat(byteArrayOf(1), WavesCrypto.base58decode(o))
38 | }
39 |
40 | fun attachmentBytes(base58Attachment: String): ByteArray {
41 | return if (base58Attachment.isEmpty()) {
42 | byteArrayOf(0, 0)
43 | } else {
44 | textFromBase58(base58Attachment).toByteArray(CHARSET).arrayWithSize()
45 | }
46 | }
47 |
48 | fun recipientBytes(recipient: String, version: Byte, chainId: Byte): ByteArray {
49 | return if (recipient.length <= 30) {
50 | Bytes.concat(
51 | byteArrayOf(version),
52 | byteArrayOf(chainId),
53 | recipient.parseAlias()
54 | .toByteArray(CHARSET)
55 | .arrayWithSize()
56 | )
57 | } else {
58 | WavesCrypto.base58decode(recipient)
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/ThrowableExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import com.wavesplatform.sdk.net.NetworkException
4 | import retrofit2.HttpException
5 | import java.io.IOException
6 | import java.net.ConnectException
7 | import java.net.SocketTimeoutException
8 | import java.net.UnknownHostException
9 | import java.util.concurrent.TimeoutException
10 |
11 | fun Throwable.asRetrofitException(): NetworkException {
12 |
13 | // Non-200 http error
14 | if (this is HttpException) {
15 | val response = this.response()
16 | if (response != null) {
17 | return NetworkException.httpError(
18 | response.raw().request()
19 | .url().toString(),
20 | response, null
21 | )
22 | }
23 | }
24 |
25 | if (this is TimeoutException ||
26 | this is ConnectException ||
27 | this is SocketTimeoutException ||
28 | this is UnknownHostException
29 | ) {
30 | return NetworkException.networkError(IOException(message, this))
31 | }
32 |
33 | return NetworkException.unexpectedError(this)
34 | }
35 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/WavesConstants.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import com.wavesplatform.sdk.model.response.data.AssetInfoResponse
4 | import java.math.BigDecimal
5 |
6 | object WavesConstants {
7 |
8 | object Environments {
9 | const val FILENAME_MAIN_NET = "environment_mainnet.json"
10 | const val FILENAME_TEST_NET = "environment_testnet.json"
11 | const val FILENAME_STAGE_NET = "environment_stagenet.json"
12 | }
13 |
14 | const val VERSION: Byte = 2
15 | const val WAVES_ASSET_ID_EMPTY = ""
16 | const val WAVES_ASSET_ID_FILLED = "WAVES"
17 | const val SELL_ORDER_TYPE = "sell"
18 | const val BUY_ORDER_TYPE = "buy"
19 | const val CUSTOM_FEE_ASSET_NAME = "Waves"
20 | const val WAVES_MIN_FEE = 100000L
21 | const val WAVES_ORDER_MIN_FEE = 300000L
22 | const val WAVES_INVOKE_MIN_FEE = 500000L
23 | const val MIN_WAVES_SPONSORED_BALANCE = 1.005
24 |
25 | val WAVES_ASSET_INFO = AssetInfoResponse(
26 | id = WAVES_ASSET_ID_EMPTY,
27 | precision = 8,
28 | name = "WAVES",
29 | quantity = BigDecimal.valueOf(10000000000000000L)
30 | )
31 | }
32 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/_NumberExt.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.utils
2 |
3 | import java.math.BigDecimal
4 | import java.math.RoundingMode
5 |
6 | fun BigDecimal.unscaledLong(decimals: Int): Long {
7 | return setScale(decimals, RoundingMode.HALF_EVEN).unscaledValue().toLong()
8 | }
9 |
10 | fun BigDecimal.unscaledLong(priceDecimals: Int, amountDecimals: Int): Long {
11 | return setScale(8 + priceDecimals - amountDecimals, RoundingMode.HALF_EVEN)
12 | .unscaledValue().toLong()
13 | }
14 |
15 | fun BigDecimal?.toDoubleOrZero(): Double = this?.toDouble() ?: 0.0
16 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/inline/ActivityResult.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 | package com.wavesplatform.sdk.utils.inline
6 |
7 | import android.app.Activity.RESULT_OK
8 | import android.content.Intent
9 |
10 | typealias OnActivityResult = (success: Boolean, data: Intent) -> Unit
11 |
12 | data class ActivityResult(
13 | private var onActivityResult: OnActivityResult?,
14 | private var fragmentManager: androidx.fragment.app.FragmentManager?
15 | ) {
16 | private fun removeFragment(requestCode: Int) {
17 | val tag = InlineActivityResult.getTag(requestCode)
18 | val fragment = fragmentManager?.findFragmentByTag(tag) ?: return
19 | fragmentManager
20 | ?.beginTransaction()
21 | ?.apply { remove(fragment) }
22 | ?.commit()
23 | fragmentManager = null
24 | }
25 |
26 | fun deliverResult(requestCode: Int, resultCode: Int, data: Intent) {
27 | onActivityResult?.invoke(resultCode == RESULT_OK, data)
28 | onActivityResult = null
29 | removeFragment(requestCode)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/inline/ActivityResultFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 | package com.wavesplatform.sdk.utils.inline
6 |
7 | import android.content.Context
8 | import android.content.Intent
9 | import android.os.Bundle
10 | import androidx.fragment.app.Fragment
11 |
12 | class ActivityResultFragment : Fragment() {
13 |
14 | private val ERR_MSG_INTENT = "Intent args must be provided"
15 | private val ERR_MSG_REQUEST_CODE = "Non-zero request code args must be provided"
16 | private val ERR_MSG_STARTED = "Started args must be provided"
17 |
18 | private var started: Boolean = false
19 | get() {
20 | return arguments?.getBoolean(KEY_STARTED)
21 | ?: throw IllegalStateException(ERR_MSG_STARTED)
22 | }
23 | set(value) {
24 | field = value
25 | arguments?.putBoolean(KEY_STARTED, value) ?: throw IllegalStateException(ERR_MSG_INTENT)
26 | }
27 |
28 | override fun onAttach(context: Context) {
29 | super.onAttach(context)
30 | if (!started) {
31 | startActivityForResult(launchIntent(), requestCode())
32 | started = true
33 | }
34 | }
35 |
36 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
37 | super.onActivityResult(requestCode, resultCode, data)
38 | if (requestCode == requestCode()) {
39 | InlineActivityResult
40 | .getInstance()
41 | .stopWithResult(
42 | requestCode = requestCode, resultCode = resultCode,
43 | data = data
44 | ?: Intent()
45 | )
46 | }
47 | }
48 |
49 | private fun launchIntent(): Intent {
50 | return arguments?.getParcelable(KEY_INTENT) ?: throw IllegalStateException(ERR_MSG_INTENT)
51 | }
52 |
53 | private fun requestCode(): Int {
54 | return arguments?.getInt(KEY_REQUEST_CODE, 0)
55 | ?.takeIf { it != 0 }
56 | ?: throw IllegalStateException(ERR_MSG_REQUEST_CODE)
57 | }
58 |
59 | companion object {
60 | fun newInstance(launchIntent: Intent, requestCode: Int): ActivityResultFragment {
61 | return ActivityResultFragment()
62 | .apply {
63 | arguments = Bundle().apply {
64 | putParcelable(KEY_INTENT, launchIntent)
65 | putInt(KEY_REQUEST_CODE, requestCode)
66 | }
67 | }
68 | }
69 |
70 | private const val KEY_INTENT = "key_intent"
71 | private const val KEY_REQUEST_CODE = "key_request_code"
72 | private const val KEY_STARTED = "key_started"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/java/com/wavesplatform/sdk/utils/inline/InlineActivityResult.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Eduard Zaydel on 27/8/2019
3 | * Copyright © 2019 Waves Platform. All rights reserved.
4 | */
5 |
6 | package com.wavesplatform.sdk.utils.inline
7 |
8 | import android.content.Intent
9 |
10 | class InlineActivityResult {
11 | private var pending: MutableMap = mutableMapOf()
12 |
13 | fun start(
14 | fragmentManager: androidx.fragment.app.FragmentManager,
15 | intent: Intent,
16 | requestCode: Int,
17 | onActivityResult: OnActivityResult
18 | ) {
19 | check(!pending.containsKey(requestCode)) {
20 | "There is already a pending request for requestCode $requestCode."
21 | }
22 |
23 | pending[requestCode] = ActivityResult(onActivityResult = onActivityResult, fragmentManager = fragmentManager)
24 | val fragment = ActivityResultFragment.newInstance(launchIntent = intent, requestCode = requestCode)
25 |
26 | fragmentManager
27 | .beginTransaction()
28 | .apply { add(fragment, getTag(requestCode)) }
29 | .commit()
30 | }
31 |
32 | fun stopWithResult(requestCode: Int, resultCode: Int, data: Intent) {
33 | val pendingRequest = pending[requestCode]
34 | ?: throw IllegalStateException("There's no pending request for requestCode $requestCode.")
35 |
36 | pendingRequest.deliverResult(requestCode = requestCode, resultCode = resultCode, data = data)
37 | pending.remove(requestCode)
38 | }
39 |
40 | companion object {
41 | private var instanceCreator: (() -> InlineActivityResult)? = null
42 |
43 | fun getInstance(): InlineActivityResult {
44 | val defaultCreator = {
45 | instance ?: InlineActivityResult().also { instance = it }
46 | }
47 | return instanceCreator?.invoke() ?: defaultCreator()
48 | }
49 |
50 | fun getTag(requestCode: Int): String = "${TAG_FRAGMENT_PREFIX}_$requestCode"
51 |
52 | private const val TAG_FRAGMENT_PREFIX = "tag_inline_activity_result_"
53 | private var instance: InlineActivityResult? = null
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/wavesplatform/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WavesPlatform App
3 |
4 |
--------------------------------------------------------------------------------
/wavesplatform/src/test/java/com/wavesplatform/sdk/crypto/WavesCryptoTest.kt:
--------------------------------------------------------------------------------
1 | package com.wavesplatform.sdk.crypto
2 |
3 | import org.junit.Assert
4 | import org.junit.Test
5 | import org.junit.runner.RunWith
6 | import org.robolectric.RobolectricTestRunner
7 |
8 | @RunWith(RobolectricTestRunner::class)
9 | class WavesCryptoTest {
10 |
11 | @Test
12 | fun addressBySeed() {
13 | Assert.assertEquals(ADDRESS, WavesCrypto.addressBySeed(SEED, TEST_NET_CHAIN_ID))
14 | }
15 |
16 | @Test
17 | fun publicKey() {
18 | Assert.assertEquals(WavesCrypto.publicKey(SEED), PUBLIC_KEY)
19 | }
20 |
21 | @Test
22 | fun privateKey() {
23 | Assert.assertEquals(WavesCrypto.privateKey(SEED), PRIVATE_KEY)
24 | }
25 |
26 | @Test
27 | fun keyPair() {
28 | val keyPair = WavesCrypto.keyPair(SEED)
29 | Assert.assertEquals(WavesCrypto.publicKey(SEED), keyPair.publicKey)
30 | Assert.assertEquals(WavesCrypto.privateKey(SEED), keyPair.privateKey)
31 | }
32 |
33 | @Test
34 | fun addressByPublicKey() {
35 | Assert.assertEquals(ADDRESS, WavesCrypto.addressByPublicKey(PUBLIC_KEY, TEST_NET_CHAIN_ID))
36 | }
37 |
38 | @Test
39 | fun randomSeed() {
40 | val randomSeed = WavesCrypto.randomSeed()
41 | Assert.assertEquals(randomSeed.matches("[a-zA-Z ]+".toRegex()), true)
42 | Assert.assertEquals(randomSeed.length > 25, true)
43 | val words = randomSeed.split(" ")
44 | Assert.assertEquals(words.size, 15)
45 | }
46 |
47 | @Test
48 | fun verifySignature() {
49 | Assert.assertEquals(
50 | WavesCrypto.verifySignature(
51 | PUBLIC_KEY,
52 | RANDOM_BYTES,
53 | WavesCrypto.signBytesWithPrivateKey(RANDOM_BYTES, PRIVATE_KEY)
54 | ),
55 | true
56 | )
57 |
58 | Assert.assertEquals(
59 | WavesCrypto.verifySignature(
60 | PUBLIC_KEY,
61 | RANDOM_BYTES,
62 | WavesCrypto.signBytesWithSeed(RANDOM_BYTES, SEED)
63 | ),
64 | true
65 | )
66 | }
67 |
68 | @Test
69 | fun verifyPublicKey() {
70 | Assert.assertEquals(WavesCrypto.verifyPublicKey(PUBLIC_KEY), true)
71 | }
72 |
73 | @Test
74 | fun verifyAddress() {
75 | Assert.assertEquals(WavesCrypto.verifyAddress(ADDRESS, TEST_NET_CHAIN_ID, PUBLIC_KEY), true)
76 | }
77 |
78 | @Test
79 | fun base58() {
80 | Assert.assertEquals(
81 | WavesCrypto.base58decode(WavesCrypto.base58encode(RANDOM_BYTES)).contentEquals(RANDOM_BYTES),
82 | true
83 | )
84 | Assert.assertEquals(WavesCrypto.base58encode(WavesCrypto.base58decode(ADDRESS)), ADDRESS)
85 | }
86 |
87 | @Test
88 | fun base64() {
89 | Assert.assertTrue(WavesCrypto.base64decode(WavesCrypto.base64encode(RANDOM_BYTES)).contentEquals(RANDOM_BYTES))
90 | Assert.assertEquals(RANDOM_STRING_IN_BASE64, WavesCrypto.base64encode(RANDOM_STRING.toByteArray()))
91 | }
92 |
93 | @Test
94 | fun aesEncryptDecrypt() {
95 | val cipherText = AESUtil.encrypt("Hello!", "11111111")
96 | val clearText = AESUtil.decrypt(cipherText, "11111111")
97 | Assert.assertEquals(clearText, "Hello!")
98 | }
99 |
100 | companion object {
101 | const val SEED =
102 | "chronic comic else cool seat filter amount banner bottom spice cup figure exact elephant copper"
103 | const val ADDRESS = "3MxZem69rYm4osMoUo5KLKq89nYoMMhi29e"
104 | const val PUBLIC_KEY = "HPoP3v8pj1yRJZdvXzibGV1RoCbuEzRnxAxJ24a81hFJ"
105 | const val PRIVATE_KEY = "4HimGuCggEJ7m19aGMGLBVsqyaSnsk1zsjLWiFimQM3Q"
106 | const val TEST_NET_CHAIN_ID = WavesCrypto.TEST_NET_CHAIN_ID.toString()
107 | val RANDOM_BYTES = byteArrayOf(56, 127, 57, -24, 0, 77, 33, -14, 14, 69, 55, 5, 110, -1, 12)
108 | val RANDOM_STRING = "slll000OOOjdgnlfsjdgnsqwertyulslkdmzxcvbnm"
109 | val RANDOM_STRING_IN_BASE64 = "c2xsbDAwME9PT2pkZ25sZnNqZGduc3F3ZXJ0eXVsc2xrZG16eGN2Ym5t\n"
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/wavesplatform/src/test/resources/robolectric.properties:
--------------------------------------------------------------------------------
1 | sdk=28
2 |
--------------------------------------------------------------------------------