@attocash/commons-worker-remote
v6.7.1-patch.1
Published
Remote HTTP proof-of-work worker client for Atto applications.
Maintainers
Readme
commons-worker-remote
Remote HTTP worker implementation of AttoWorker. Useful to offload PoW to a separate service.
Highlights:
AttoWorker.remote(url, timeout, headerProvider)convenience, with a 5 minute default timeoutAttoWorkerAsyncBuilder.timeout(...)for async worker clients- Same
AttoWorkerAPI as CPU/OpenCL:work(block)andwork(network, timestamp, target) - Low-level request API via
AttoWorkerOperations.Request
Installation
Gradle:
implementation("cash.atto:commons-worker-remote:<version>")NPM:
npm install @attocash/commons-core @attocash/commons-worker @attocash/commons-worker-remoteQuick start
// Optional headers (JWT/API keys)
suspend fun headers(): Map<String, String> = mapOf("Authorization" to "Bearer <jwt>")
val worker = AttoWorker.remote("http://localhost:8085", headerProvider = ::headers)
// Optional timeout override
val workerWithTimeout = AttoWorker.remote("http://localhost:8085", 10.minutes, ::headers)
val asyncWorker =
AttoWorkerAsyncBuilder("http://localhost:8085")
.timeout(10.minutes)
.build()
// Compute work for a block
val work = worker.work(block)Low-level API
val request = AttoWorkerOperations.Request(
network = block.network,
timestamp = block.timestamp,
target = block.getTarget().value.toHex(),
)
val response = (worker as AttoWorkerOperations).work(request)
val work = response.workImplementation details: see AttoWorkerRemote.kt. The client uses Ktor and posts to /works with JSON, expecting a
JSON response.
