Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Merge 2c3620d into 00794b6
Browse files Browse the repository at this point in the history
  • Loading branch information
catena2w committed Jan 8, 2018
2 parents 00794b6 + 2c3620d commit 9fee015
Show file tree
Hide file tree
Showing 84 changed files with 818 additions and 31,791 deletions.
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ val circeVersion = "0.8.0"

val networkDependencies = Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.+",
"com.typesafe.akka" % "akka-stream_2.12" % "2.4.+",
"org.bitlet" % "weupnp" % "0.1.+",
"commons-net" % "commons-net" % "3.+"
)
Expand All @@ -49,9 +50,8 @@ val apiDependencies = Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.swagger" %% "swagger-scala-module" % "1.0.3",
"com.github.swagger-akka-http" %% "swagger-akka-http" % "0.10.0",
"com.typesafe.akka" %% "akka-http" % "10.+"
"com.typesafe.akka" %% "akka-http" % "10.+",
"de.heikoseeberger" %% "akka-http-circe" % "1.18.0"
)

val loggingDependencies = Seq(
Expand All @@ -61,6 +61,7 @@ val loggingDependencies = Seq(

val testingDependencies = Seq(
"com.typesafe.akka" %% "akka-testkit" % "2.5.3" % "test",
"com.typesafe.akka" %% "akka-http-testkit" % "10.+" % "test",
"org.scalactic" %% "scalactic" % "3.0.3" % "test",
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.+",
Expand Down
251 changes: 251 additions & 0 deletions examples/src/main/resources/api/testApi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
openapi: "3.0.0"

info:
version: "0.1"
title: Scorex Node API example
description: API docs for example Scorex project.
contact:
name: Scorex framework Team
email: kushi@protonmail.com
url: https://github.com/scorexfoundation/scorex
license:
name: CC0 1.0 Universal
url: https://raw.githubusercontent.com/ScorexFoundation/Scorex/master/COPYING

components:
schemas:
# Objects
ModifierId:
description: Base58-encoded 32 byte modifier id
type: object
required:
- modifierId
properties:
modifierId:
type: string
example: D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4

Digest32:
description: Base58-encoded 32 byte digest
type: object
required:
- digest
properties:
digest:
type: string
example: FjX5cPuwMc2ocDLPWzt6jq29BXjvU6d5w5XURDJ6dmoM
Peer:
type: object
required:
- address
properties:
address:
type: string
example: 127.0.0.1:5673
name:
type: string
example: mynode
nonce:
type: integer
# int32
format: int64
example: 123456
lastSeen:
type: integer
# int32
format: int64
example: 123456


paths:

/nodeView/openSurface:
get:
summary: Get history open surface
operationId: getOpenSurface
tags:
- nodeView
responses:
200:
description: Array of modifier ids
content:
application/json:
schema:
type: array
example: ["D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4"]
items:
type: string
example: D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4

/nodeView/persistentModifier/{modifierId}:
get:
summary: Get history open surface
operationId: getPersistentModifierById
tags:
- nodeView
parameters:
- in: path
name: modifierId
required: true
description: ID of a requested modifier
schema:
type: string
responses:
200:
description: Node view modifier
content:
application/json:
schema:
type: object
required:
- id

/nodeView/pool:
get:
summary: Get memory pool
operationId: getPool
tags:
- nodeView
responses:
200:
description: Memory pool
content:
application/json:
schema:
type: object
required:
- size
- transactions

/peers/all:
get:
summary: Get all known peers
operationId: getAllPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/peers/connected:
get:
summary: Get current connected peers
operationId: getConnectedPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/peers/connect:
post:
summary: Add address to peers list
operationId: connectToPeer
tags:
- peers
requestBody:
required: true
content:
application/json:
schema:
type: string
example: 127.0.0.1:5673
responses:
200:
description: Attempt to connect to the peer
default:
description: Error
content:
application/json:
schema:
type: string
enum:
- invalid.peer.address
- invalid.json

/peers/blacklisted:
get:
summary: Get blacklisted peers
operationId: getBlacklistedPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/utils/seed:
get:
summary: Get random seed with 32 bytes size
operationId: getRandomSeed
tags:
- utils
responses:
200:
description: Base58-encoded 32 byte seed
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV

/utils/seed/{length}:
get:
summary: Generate random seed of specified length in bytes
operationId: getRandomSeedWithLength
tags:
- utils
parameters:
- in: path
name: length
required: true
description: seed length in bytes
schema:
type: string
responses:
200:
description: Base58-encoded N byte seed
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV

/utils/hash/blake2b:
post:
summary: Return Blake2b hash of specified message
operationId: hashBlake2b
tags:
- utils
requestBody:
required: true
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV
responses:
200:
description: Base58-encoded 32 byte hash
content:
text/plain:
schema:
type: string
example: 6QLZkR1RdHvF7gUw7oms1XdQM6kc9kxpmyHRADN5x7uQ
3 changes: 2 additions & 1 deletion examples/src/main/scala/examples/curvepos/SimpleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SimpleApp(val settingsFilename: String) extends Application {
actorSystem.actorOf(Props(new NodeViewSynchronizer[P, TX, SimpleSyncInfo, SimpleSyncInfoMessageSpec.type, PMOD, SimpleBlockchain, SimpleMemPool]
(networkController, nodeViewHolderRef, localInterface, SimpleSyncInfoMessageSpec, settings.network)))

override val apiTypes: Set[Class[_]] = Set(classOf[UtilsApiRoute], classOf[NodeViewApiRoute[P, TX]])
override val swaggerConfig = ""

override val apiRoutes: Seq[ApiRoute] = Seq(UtilsApiRoute(settings.restApi),
NodeViewApiRoute[P, TX](settings.restApi, nodeViewHolderRef))
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/scala/examples/hybrid/HybridApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import scorex.core.settings.ScorexSettings
import scorex.core.transaction.box.proposition.PublicKey25519Proposition

import scala.concurrent.duration._
import scala.io.Source
import scala.language.postfixOps

class HybridApp(val settingsFilename: String) extends Application {
Expand Down Expand Up @@ -43,8 +44,7 @@ class HybridApp(val settingsFilename: String) extends Application {
PeersApiRoute(peerManagerRef, networkController, settings.restApi)
)

override val apiTypes: Set[Class[_]] = Set(classOf[UtilsApiRoute], classOf[DebugApiRoute], classOf[WalletApiRoute],
classOf[NodeViewApiRoute[P, TX]], classOf[PeersApiRoute], classOf[StatsApiRoute])
override val swaggerConfig: String = Source.fromResource("api/testApi.yaml").getLines.mkString("\n")

val miner = actorSystem.actorOf(Props(new PowMiner(nodeViewHolderRef, hybridSettings.mining)))
val forger = actorSystem.actorOf(Props(new PosForger(hybridSettings, nodeViewHolderRef)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import examples.commons.SimpleBoxTransactionMemPool
Expand All @@ -10,10 +8,9 @@ import examples.hybrid.history.HybridHistory
import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.ModifierId
import scorex.core.api.http.{ApiRouteWithFullView, SuccessApiResponse}
import scorex.core.settings.{RESTApiSettings, ScorexSettings}
import scorex.core.settings.RESTApiSettings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -43,7 +40,7 @@ case class DebugApiRoute(override val settings: RESTApiSettings, nodeViewHolderR
def infoRoute: Route = path("info") {
getJsonRoute {
viewAsync().map { view =>
SuccessApiResponse( Map(
SuccessApiResponse(Map(
"height" -> view.history.height.toString.asJson,
"bestPoS" -> Base58.encode(view.history.bestPosId).asJson,
"bestPoW" -> Base58.encode(view.history.bestPowId).asJson,
Expand All @@ -58,14 +55,17 @@ case class DebugApiRoute(override val settings: RESTApiSettings, nodeViewHolderR
getJsonRoute {
viewAsync().map { view =>
val pubkeys = view.vault.publicKeys

def isMyPosBlock(b: HybridBlock): Boolean = b match {
case pos: PosBlock => pubkeys.exists(_.pubKeyBytes sameElements pos.generatorBox.proposition.pubKeyBytes)
case _ => false
}

def isMyPowBlock(b: HybridBlock): Boolean = b match {
case pow: PowBlock => pubkeys.exists(_.pubKeyBytes sameElements pow.generatorProposition.pubKeyBytes)
case _ => false
}

val posCount = view.history.count(isMyPosBlock)
val powCount = view.history.count(isMyPowBlock)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import examples.commons.SimpleBoxTransactionMemPool
Expand All @@ -10,16 +8,14 @@ import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.Json
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.ModifierId
import scorex.core.api.http.{ApiRouteWithFullView, ApiTry, SuccessApiResponse}
import scorex.core.settings.{RESTApiSettings, ScorexSettings}
import scorex.core.settings.RESTApiSettings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Try


case class StatsApiRoute(override val settings: RESTApiSettings, nodeViewHolderRef: ActorRef)
(implicit val context: ActorRefFactory)
extends ApiRouteWithFullView[HybridHistory, HBoxStoredState, HWallet, SimpleBoxTransactionMemPool] {
Expand Down
Loading

0 comments on commit 9fee015

Please sign in to comment.