toknapp / arweave4s Goto Github PK
View Code? Open in Web Editor NEWLight, modular, functional http-client for the Arweave blockchain
Home Page: https://upvest.co
License: Other
Light, modular, functional http-client for the Arweave blockchain
Home Page: https://upvest.co
License: Other
maybe builderpattern?
fyi @rootmos
Fyi @rootmos
I am trying to use the API from Kotlin code. As seen below, I am successful in retrieving the current block from the API. However, trying the price api fails to parse and yields.
class scala.Some cannot be cast to class scala.util.Either (scala.Some and scala.util.Either are in unnamed module of loader 'app')
java.lang.ClassCastException: class scala.Some cannot be cast to class scala.util.Either (scala.Some and scala.util.Either are in unnamed module of loader 'app')
(Coroutine boundary)
at io.test.ArweaveTest$test tx submit$1.invokeSuspend(ArweaveTest.kt:88)
Caused by: java.lang.ClassCastException: class scala.Some cannot be cast to class scala.util.Either (scala.Some and scala.util.Either are in unnamed module of loader 'app')
at co.upvest.arweave4s.api.package$FutureInstances$$anon$7.$anonfun$apply$3(package.scala:136)
at scala.util.Success.$anonfun$map$1(Try.scala:255)
at scala.util.Success.map(Try.scala:213)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Here is the test code I am using along with the succeeding current block test function and the failing price function. I've confirmed through tracing the data on the wire that I'm receiving 199333924
, but it then fails to be put into the Winston object.
package io.test
import co.upvest.arweave4s.adt.Block
import co.upvest.arweave4s.adt.Data
import co.upvest.arweave4s.adt.Winston
import com.google.common.truth.Truth.assertThat
import com.softwaremill.sttp.HttpURLConnectionBackend
import com.softwaremill.sttp.SttpBackendOptions
import com.softwaremill.sttp.Uri
import com.softwaremill.sttp.asynchttpclient.future.AsyncHttpClientFutureBackend
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import scala.compat.java8.FutureConverters.toJava
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.io.Source
import scala.runtime.BoxedUnit
import java.util.concurrent.Executors
import co.upvest.arweave4s.adt.`Wallet$`.`MODULE$` as Wallet
import co.upvest.arweave4s.api.`block$`.`MODULE$` as blockApi
import co.upvest.arweave4s.api.`package`.`Config$`.`MODULE$` as Config
import co.upvest.arweave4s.api.`package`.`future$`.`MODULE$` as future
import co.upvest.arweave4s.api.`package`.`id$`.`MODULE$` as idApi
import co.upvest.arweave4s.api.`price$`.`MODULE$` as priceApi
class ArweaveTest {
private val executorService = Executors.newScheduledThreadPool(5)
private val executionContext = ExecutionContext.fromExecutorService(executorService)
private val backend = AsyncHttpClientFutureBackend.apply(SttpBackendOptions.Default(), executionContext)
private val config = Config.apply(
Uri.apply("https", "arweave.net"),
backend
)
@Test
fun `test Arweave current block`() = runBlocking {
@Suppress("UNCHECKED_CAST")
val blockFuture = blockApi.current(config, future.futureJsonHandler(executionContext)) as Future<Block>
val block = toJava(blockFuture).await()
println(block)
}
@Test
fun `test price`() = runBlocking {
val pirateIpsum = """
Schooner ho run a rig yard run a shot across the bow trysail tack careen piracy measured fer yer chains.
Reef rope's end nipperkin gangplank sutler aye lad measured fer yer chains handsomely Privateer.
Fire ship rutters piracy gally keel swing the lead chandler jib Shiver me timbers gun.
Pillage haul wind grapple Gold Road gangplank fathom gun Privateer keel bilge water.
Deadlights barkadeer dead men tell no tales loot pink hulk ballast Spanish Main boatswain black jack.
""".trimIndent()
// Data to persist on the blockchain.
val testData = Data(pirateIpsum.toByteArray())
@Suppress("UNCHECKED_CAST")
val priceFuture: Future<Winston> =
priceApi.dataTransaction(testData, config, future.futureJsonHandler(executionContext)) as Future<Winston>
val price: Winston = toJava(priceFuture).await()
assertThat(price.amount().toString()).isEqualTo("199333924")
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.