fix: peer config to object (#574)

This commit is contained in:
Dima 2022-10-12 15:43:22 +03:00 committed by GitHub
parent 2ad5682718
commit 4108de209d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -209,13 +209,18 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "off"
@JSExportAll
case class Debug(printParticleId: js.UndefOr[Boolean], marineLogLevel: js.UndefOr[LogLevel])
@JSExportAll
case class PeerConfig(
connectTo: String,
defaultTtlMs: js.UndefOr[Int],
KeyPair: KeyPair,
debug: js.UndefOr[Debug]
)
) {
def createObj(): js.Object = {
val d: js.Any = defaultTtlMs.asInstanceOf[js.Any]
val deb: js.Any = debug.asInstanceOf[js.Any]
js.Dynamic.literal(connectTo = connectTo, defaultTtlMs = d, KeyPair = KeyPair, debug = deb)
}
}
trait AstStatus extends js.Object {
def success: Boolean
@ -268,7 +273,7 @@ object FluenceUtils {
@js.native
@JSImport("@fluencelabs/fluence", "Fluence")
object Fluence extends js.Object {
def start(config: js.UndefOr[PeerConfig]): js.Promise[js.Any] = js.native
def start(config: js.UndefOr[js.Object]): js.Promise[js.Any] = js.native
def stop(): js.Promise[js.Any] = js.native
def getPeer(): FluencePeer = js.native
def getStatus(): PeerStatus = js.native
@ -288,7 +293,8 @@ object KeyPairOp {
js.Dynamic.literal(
peerId = kp.Libp2pPeerId.toB58String(),
secretKey = encoder.encodeToString(kp.toEd25519PrivateKey().toArray.map(s => s.toByte)),
publicKey = encoder.encodeToString(kp.Libp2pPeerId.pubKey.marshal().toArray.map(s => s.toByte))
publicKey =
encoder.encodeToString(kp.Libp2pPeerId.pubKey.marshal().toArray.map(s => s.toByte))
)
}
}

View File

@ -56,13 +56,14 @@ object FuncCaller {
logLevel: js.UndefOr[aqua.js.LogLevel] = LogLevelTransformer.logLevelToAvm(
config.common.logLevel.aquavm
)
pc = PeerConfig(
config.common.multiaddr,
config.common.timeout.toMillis.toInt : js.UndefOr[Int],
keyPair,
Debug(printParticleId = config.common.flags.verbose, marineLogLevel = logLevel)
)
peerConfig = Some(
PeerConfig(
config.common.multiaddr,
config.common.timeout.toMillis.toInt : js.UndefOr[Int],
keyPair,
Debug(printParticleId = config.common.flags.verbose, marineLogLevel = logLevel)
)
pc.createObj()
).orUndefined
_ <- Fluence.start(peerConfig).toFuture
_ =