Skip to content

Commit 4ce4532

Browse files
authored
Feature/client v 1 5 2 (#13)
* Added ErrorCode type * Extended network config with reconnect_timeout and endpoints * Implemented tests for endpoints * Version bump
1 parent 60b020c commit 4ce4532

File tree

9 files changed

+181
-35
lines changed

9 files changed

+181
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Release Notes
22
All notable changes to this project will be documented in this file.
33

4+
## 1.5.2 Jan 14, 2021
5+
6+
### Featured
7+
- Support for TON-Client (1.5.2 Dec 30, 2020)
8+
49
## 1.4.0 Jan 12, 2021
510

611
### Featured

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Instead, a thin C wrapper is implemented. The wrapper translates Java calls into
1919

2020
## Compatibility
2121

22-
The current version is compatible with Freeton client v1.4.0, JDK 1.8+ and Scala 2.12.
22+
The current version is compatible with Freeton client v1.5.2, JDK 1.8+ and Scala 2.12.
2323

2424
We use CI on Linux Focal Fossa and MacOs X hosts to run our tests.
2525

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "freeton-sdk-client-scala-binding"
22

3-
version := "1.4.0-M1"
3+
version := "1.5.2-M1"
44

55
organization := "com.dancingcode"
66

src/main/scala/ton/sdk/client/binding/Api.scala

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,9 @@ object Api {
4141

4242
type DebotHandle = Int
4343

44+
4445
/**
45-
* @param code
46-
* -1 -> JsonApiParsingError
47-
*
48-
* 1 -> NotImplemented
49-
* 2 -> InvalidHex
50-
* 3 -> InvalidBase64
51-
* 4 -> InvalidAddress
52-
* 5 -> CallbackParamsCantBeConvertedToJson
53-
* 6 -> WebsocketConnectError
54-
* 7 -> WebsocketReceiveError
55-
* 8 -> WebsocketSendError
56-
* 9 -> HttpClientCreateError
57-
* 10 -> HttpRequestCreateError
58-
* 11 -> HttpRequestSendError
59-
* 12 -> HttpRequestParseError
60-
* 13 -> CallbackNotRegistered
61-
* 14 -> NetModuleNotInit
62-
* 15 -> InvalidConfig
63-
* 16 -> CannotCreateRuntime
64-
* 17 -> InvalidContextHandle
65-
* 18 -> CannotSerializeResult
66-
* 19 -> CannotSerializeError
67-
* 20 -> CannotConvertJsValueToJson
68-
* 21 -> CannotReceiveSpawnedResult
69-
* 22 -> SetTimerError
70-
* 23 -> InvalidParams
71-
* 24 -> ContractsAddressConversionFailed
72-
* 25 -> UnknownFunction
73-
*
46+
* @param code the client error code
7447
* @param message the error message
7548
* @param data the underlying data
7649
*/
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package ton.sdk.client.binding
2+
3+
final case class ClientErrorCode(code: Long)
4+
5+
object ClientErrors {
6+
val JsonApiParsingError = ClientErrorCode(-1L)
7+
val NotImplemented = ClientErrorCode(1)
8+
val InvalidHex = ClientErrorCode(2)
9+
val InvalidBase64 = ClientErrorCode(3)
10+
val InvalidAddress = ClientErrorCode(4)
11+
val CallbackParamsCantBeConvertedToJson = ClientErrorCode(5)
12+
val WebsocketConnectError = ClientErrorCode(6)
13+
val WebsocketReceiveError = ClientErrorCode(7)
14+
val WebsocketSendError = ClientErrorCode(8)
15+
val HttpClientCreateError = ClientErrorCode(9)
16+
val HttpRequestCreateError = ClientErrorCode(10)
17+
val HttpRequestSendError = ClientErrorCode(11)
18+
val HttpRequestParseError = ClientErrorCode(12)
19+
val CallbackNotRegistered = ClientErrorCode(13)
20+
val NetModuleNotInit = ClientErrorCode(14)
21+
val InvalidConfig = ClientErrorCode(15)
22+
val CannotCreateRuntime = ClientErrorCode(16)
23+
val InvalidContextHandle = ClientErrorCode(17)
24+
val CannotSerializeResult = ClientErrorCode(18)
25+
val CannotSerializeError = ClientErrorCode(19)
26+
val CannotConvertJsValueToJson = ClientErrorCode(20)
27+
val CannotReceiveSpawnedResult = ClientErrorCode(21)
28+
val SetTimerError = ClientErrorCode(22)
29+
val InvalidParams = ClientErrorCode(23)
30+
val ContractsAddressConversionFailed = ClientErrorCode(24)
31+
val UnknownFunction = ClientErrorCode(25)
32+
val AppRequestError = ClientErrorCode(26)
33+
val NoSuchRequest = ClientErrorCode(27)
34+
val CanNotSendRequestResult = ClientErrorCode(28)
35+
val CanNotReceiveRequestResult = ClientErrorCode(29)
36+
val CanNotParseRequestResult = ClientErrorCode(30)
37+
val UnexpectedCallbackResponse = ClientErrorCode(31)
38+
val CanNotParseNumber = ClientErrorCode(32)
39+
val InternalError = ClientErrorCode(33)
40+
}
41+
42+
object AbiErrors {
43+
val RequiredAddressMissingForEncodeMessage = ClientErrorCode(301)
44+
val RequiredCallSetMissingForEncodeMessage = ClientErrorCode(302)
45+
val InvalidJson = ClientErrorCode(303)
46+
val InvalidMessage = ClientErrorCode(304)
47+
val EncodeDeployMessageFailed = ClientErrorCode(305)
48+
val EncodeRunMessageFailed = ClientErrorCode(306)
49+
val AttachSignatureFailed = ClientErrorCode(307)
50+
val InvalidTvcImage = ClientErrorCode(308)
51+
val RequiredPublicKeyMissingForFunctionHeader = ClientErrorCode(309)
52+
val InvalidSigner = ClientErrorCode(310)
53+
val InvalidAbi = ClientErrorCode(311)
54+
}
55+
56+
object BocErrors {
57+
val InvalidBoc = ClientErrorCode(201)
58+
val SerializationError = ClientErrorCode(202)
59+
val InappropriateBlock = ClientErrorCode(203)
60+
val MissingSourceBoc = ClientErrorCode(204)
61+
}
62+
63+
object CryptoErrors {
64+
val InvalidPublicKey = ClientErrorCode(100)
65+
val InvalidSecretKey = ClientErrorCode(101)
66+
val InvalidKey = ClientErrorCode(102)
67+
val InvalidFactorizeChallenge = ClientErrorCode(106)
68+
val InvalidBigInt = ClientErrorCode(107)
69+
val ScryptFailed = ClientErrorCode(108)
70+
val InvalidKeySize = ClientErrorCode(109)
71+
val NaclSecretBoxFailed = ClientErrorCode(110)
72+
val NaclBoxFailed = ClientErrorCode(111)
73+
val NaclSignFailed = ClientErrorCode(112)
74+
val Bip39InvalidEntropy = ClientErrorCode(113)
75+
val Bip39InvalidPhrase = ClientErrorCode(114)
76+
val Bip32InvalidKey = ClientErrorCode(115)
77+
val Bip32InvalidDerivePath = ClientErrorCode(116)
78+
val Bip39InvalidDictionary = ClientErrorCode(117)
79+
val Bip39InvalidWordCount = ClientErrorCode(118)
80+
val MnemonicGenerationFailed = ClientErrorCode(119)
81+
val MnemonicFromEntropyFailed = ClientErrorCode(120)
82+
val SigningBoxNotRegistered = ClientErrorCode(121)
83+
}
84+
85+
object DebotErrors {
86+
val DebotStartFailed = ClientErrorCode(801)
87+
val DebotFetchFailed = ClientErrorCode(802)
88+
val DebotExecutionFailed = ClientErrorCode(803)
89+
val DebotInvalidHandle = ClientErrorCode(804)
90+
}
91+
92+
object NetErrors {
93+
val QueryFailed = ClientErrorCode(601L)
94+
val SubscribeFailed = ClientErrorCode(602L)
95+
val WaitForFailed = ClientErrorCode(603L)
96+
val GetSubscriptionResultFailed = ClientErrorCode(604L)
97+
val InvalidServerResponse = ClientErrorCode(605L)
98+
val ClockOutOfSync = ClientErrorCode(606L)
99+
val WaitForTimeout = ClientErrorCode(607L)
100+
val GraphqlError = ClientErrorCode(608L)
101+
val NetworkModuleSuspended = ClientErrorCode(609L)
102+
val WebsocketDisconnected = ClientErrorCode(610L)
103+
val NotSupported = ClientErrorCode(611L)
104+
val NoEndpointsProvided = ClientErrorCode(612L)
105+
}
106+
107+
object ProcessingErrors {
108+
val MessageAlreadyExpired = ClientErrorCode(501)
109+
val MessageHasNotDestinationAddress = ClientErrorCode(502)
110+
val CanNotBuildMessageCell = ClientErrorCode(503)
111+
val FetchBlockFailed = ClientErrorCode(504)
112+
val SendMessageFailed = ClientErrorCode(505)
113+
val InvalidMessageBoc = ClientErrorCode(506)
114+
val MessageExpired = ClientErrorCode(507)
115+
val TransactionWaitTimeout = ClientErrorCode(508)
116+
val InvalidBlockReceived = ClientErrorCode(509)
117+
val CanNotCheckBlockShard = ClientErrorCode(510)
118+
val BlockNotFound = ClientErrorCode(511)
119+
val InvalidData = ClientErrorCode(512)
120+
val ExternalSignerMustNotBeUsed = ClientErrorCode(513)
121+
}
122+
123+
object TvmErrors {
124+
val CanNotReadTransaction = ClientErrorCode(401)
125+
val CanNotReadBlockchainConfig = ClientErrorCode(402)
126+
val TransactionAborted = ClientErrorCode(403)
127+
val InternalError = ClientErrorCode(404)
128+
val ActionPhaseFailed = ClientErrorCode(405)
129+
val AccountCodeMissing = ClientErrorCode(406)
130+
val LowBalance = ClientErrorCode(407)
131+
val AccountFrozenOrDeleted = ClientErrorCode(408)
132+
val AccountMissing = ClientErrorCode(409)
133+
val UnknownExecutionError = ClientErrorCode(410)
134+
val InvalidInputStack = ClientErrorCode(411)
135+
val InvalidAccountBoc = ClientErrorCode(412)
136+
val InvalidMessageType = ClientErrorCode(413)
137+
val ContractExecutionError = ClientErrorCode(414)
138+
}

src/main/scala/ton/sdk/client/binding/model.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import ton.sdk.client.modules.Processing
1313
*/
1414
final case class NetworkConfig(
1515
server_address: String,
16+
endpoints: Seq[String],
1617
network_retries_count: Option[Int] = None,
1718
message_retries_count: Option[Int] = None,
1819
message_processing_timeout: Option[Int] = None,
1920
wait_for_timeout: Option[Int] = None,
2021
out_of_sync_threshold: Option[BigInt] = None,
22+
reconnect_timeout: Option[Int] = None,
2123
access_key: Option[String] = None
2224
)
2325

@@ -36,7 +38,7 @@ final case class ClientConfig(network: Option[NetworkConfig] = None, crypto: Opt
3638
* Collection of known networks.
3739
*/
3840
object ClientConfig {
39-
def fromServer(server: String): ClientConfig = ClientConfig(Option(NetworkConfig(server)))
41+
def fromServer(server: String): ClientConfig = ClientConfig(Option(NetworkConfig(server, Seq(server))))
4042
val MAIN_NET = fromServer("main.ton.dev")
4143
val DEV_NET = fromServer("net.ton.dev")
4244
val TEST_NET = fromServer("testnet.ton.dev")

src/main/scala/ton/sdk/client/modules/Net.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ object Net {
1818

1919
private val module = "net"
2020

21+
final case class EndpointsSet(endpoints: Seq[String])
22+
2123
object Request {
2224
final case class Unsubscribe(handle: Long)
2325
final case class Query(query: String, variables: Option[Json])
2426
final case class QueryCollection(collection: String, result: String, filter: Option[Json] = None, order: Option[Seq[OrderBy]] = None, limit: Option[Long] = None)
2527
final case class WaitForCollection(collection: String, result: String, filter: Option[Json] = None, timeout: Option[Long] = None)
2628
final case class SubscribeCollection(collection: String, result: String, filter: Option[Json] = None)
2729
final case class FindLastShardBlock(address: String)
30+
case object FetchEndpoints
31+
final case class SetEndpoints(endpoints: Seq[String])
32+
2833
case object Suspend
2934
case object Resume
3035
}
@@ -45,4 +50,7 @@ object Net {
4550
implicit val suspend = new SdkCall[Request.Suspend.type, Json] { override val function: String = s"$module.suspend" }
4651
implicit val resume = new SdkCall[Request.Resume.type, Json] { override val function: String = s"$module.resume" }
4752
implicit val find_last_shard_block = new SdkCall[Request.FindLastShardBlock, Result.LastShardBlock] { override val function: String = s"$module.find_last_shard_block" }
53+
implicit val fetch_endpoints = new SdkCall[Request.FetchEndpoints.type, EndpointsSet] { override val function: String = s"$module.fetch_endpoints" }
54+
implicit val set_endpoints = new SdkCall[Request.SetEndpoints, Unit] { override val function: String = s"$module.set_endpoints" }
55+
4856
}

src/test/scala/ton/sdk/client/binding/ApiSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.circe.Json
44
import org.scalatest.flatspec.AsyncFlatSpec
55
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
66
import ton.sdk.client.binding.Api._
7+
import ton.sdk.client.binding.ClientErrors.HttpRequestCreateError
78

89
class ApiSpec extends AsyncFlatSpec {
910

@@ -17,7 +18,7 @@ class ApiSpec extends AsyncFlatSpec {
1718

1819
"testing string representation" should "further improve coverage" in {
1920
val data = Json.fromString("This can only happen if client returns malformed json")
20-
val error = new SdkClientError(10, "Uh-Oh", data)
21+
val error = new SdkClientError(HttpRequestCreateError.code, "Uh-Oh", data)
2122
val str = new SdkError[Unit](error).toString
2223
str shouldEqual "ton.sdk.client.binding.Api$SdkClientError: Uh-Oh"
2324
}

src/test/scala/ton/sdk/client/modules/netSpec.scala

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ abstract class NetSpec[T[_]] extends AsyncFlatSpec with SdkAssertions[T] {
157157
}
158158

159159
it should "query" in {
160-
val variables = Option(Map("time" -> (System.currentTimeMillis/1000)).asJson)
160+
val variables = Option(Map("time" -> (System.currentTimeMillis / 1000)).asJson)
161161
val query = "query($time: Float){messages(filter:{created_at:{ge:$time}}limit:5){id}}"
162162
val result = devNet { implicit ctx =>
163163
call(Request.Query(query, variables))
@@ -166,7 +166,7 @@ abstract class NetSpec[T[_]] extends AsyncFlatSpec with SdkAssertions[T] {
166166
}
167167

168168
it should "not query" in {
169-
val variables = Option(Map("time" -> (System.currentTimeMillis/1000 - 60)).asJson)
169+
val variables = Option(Map("time" -> (System.currentTimeMillis / 1000 - 60)).asJson)
170170
val query = "query($time: Float){(filter:{created_at:{ge:$time}}limit:5){id}}"
171171
val result = devNet { implicit ctx =>
172172
call(Request.Query(query, variables))
@@ -187,4 +187,23 @@ abstract class NetSpec[T[_]] extends AsyncFlatSpec with SdkAssertions[T] {
187187
}
188188
assertSdkError(result)("Invalid address [fatal error]: baker street, london 221b")
189189
}
190+
191+
it should "fetch_endpoints" in {
192+
val network = ClientConfig.DEV_NET.network.map(cfg => cfg.copy(endpoints = Seq("cinet.tonlabs.io", "cinet2.tonlabs.io")))
193+
val config = ClientConfig.DEV_NET.copy(network = network)
194+
val result = ef.managed(config) { implicit ctx =>
195+
call(Request.FetchEndpoints)
196+
}
197+
assertExpression(result) { r =>
198+
println(r); r.endpoints.nonEmpty
199+
}
200+
}
201+
202+
it should "set_endpoints" in {
203+
val result = devNet { implicit ctx =>
204+
call(Request.SetEndpoints(Seq("localhost")))
205+
}
206+
assertExpression(result)(_ == (()))
207+
}
208+
190209
}

0 commit comments

Comments
 (0)