Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mit hackathon #46

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project/boot/
*.log
*.loaded
*.pid
nohup.out
##
## emacs & ensime
##
Expand Down
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,72 @@ sbt clean compile run
./scripts/rsong-int-tests.py localhost:9000
```

## Music Search

sampleSearch payload:
```aidl
{
"albumTitle":"Tiny Human",
"songTitle": "Tiny Human",
"artist": "ilan & kayvan rock"
}
```
Sample Response payload
```aidl
{
"song": {
"id": "Tiny Human",
"title": "Tiny Human",
"name": "Tiny Human",
"audio": [
{
"effect": "3D",
"uri": "/v1/song/music/Tiny_Human_Immersive.izr",
"duration_ms": 1000
},
{
"effect": "Stereo",
"uri": "/v1/song/music/Tiny_Human_Stereo.izr",
"duration_ms": 1000
}
],
"language": "EN"
},
"artists": [
{
"id": "Imogen-Heap",
"title": "Imogen Heap",
"name": "Imogen Heap"
}
],
"artwork": [
{
"id": "Tiny Human",
"uri": "/v1/art/Tiny Human.jpg"
}
],
"album": {
"id": "album-id-Tiny_Human",
"title": "Tiny Human",
"name": "Tiny Human",
"artworks": [
{
"id": "Tiny Human",
"uri": "/v1/art/Tiny Human.jpg"
}
],
"duration_ms": 10000,
"artists": [
{
"id": "Imogen-Heap",
"title": "Imogen Heap",
"name": "Imogen Heap"
}
],
"uri": "/v1/art/Tiny Human.jpg"
}
}
```

## url Inventory
```
Expand Down
Binary file removed lib/casper_2.12.jar
Binary file not shown.
Binary file modified lib/comm_2.12.jar
Binary file not shown.
Binary file modified lib/crypto_2.12.jar
Binary file not shown.
Binary file modified lib/models_2.12.jar
Binary file not shown.
Binary file modified lib/rholang_2.12.jar
Binary file not shown.
Binary file removed lib/rspace_2.12.jar
Binary file not shown.
Binary file modified lib/shared_2.12.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions scripts/mit-hack-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl --header "Content-Type: application/json" \
--request POST \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a search should use GET.

--data '{"id": "Tiny Human", "albumTitle":"Tiny Human", "songTitle": "Tiny Human", "artist": "artist-name-1"}' \
http://localhost:9000/v1/music
2 changes: 1 addition & 1 deletion scripts/rsong-int-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _curl(name):
return


for name in ['Broke', 'Euphoria', 'Tiny_Human']:
for name in ['Broke', 'Euphoria', 'Tiny_Human']:
_curl(name)


15 changes: 9 additions & 6 deletions scripts/startValidator.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash
## usage ./startValidator.sh

rnode run -s \
DIR=~/dev/workspaces/workspace-rchain/rchain/node/target/universal/rnode-0.7.1
EX=$DIR/bin/rnode
$EX run -s \
--map-size 2048576000 \
--casper-block-store-size 2048576000 \
--required-sigs 0 \
--map_size 2048576000 \
--thread-pool-size 5 ##\
## --validator-private-key \
## ae131c0502a2ddf9a23d3f893cd842f122fa29b5530cb2967410ea3c45e7c566
--thread-pool-size 5 \
--bonds-file ~/.rnode/genesis/bonds.txt \
--validator-private-key \
793fbe701f0292743629484ca9f2d73d7cfb8ccdd186f536768fefd997b08074
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coop {
coop {
rchain {
rsong {
rsongdata.concat.size=1024
Expand Down
13 changes: 13 additions & 0 deletions src/main/scala/coop/rchain/api/SongApi.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package coop.rchain.api

import cats.effect._
import cats.effect.IO

import com.typesafe.scalalogging.Logger
import coop.rchain.domain.RSongModel.SearchModel
import org.http4s.circe._
import coop.rchain.protocol.Protocol._
import coop.rchain.repo._
import org.http4s._
import org.http4s.dsl.Http4sDsl
import io.circe.generic.auto._
import io.circe.syntax._
import io.circe._
import io.circe.parser._
import io.circe.generic.auto._
import coop.rchain.domain._
import coop.rchain.service.moc.MocSongMetadata
import coop.rchain.service.moc.MocSongMetadata.mocSongs
Expand Down Expand Up @@ -55,6 +61,13 @@ class SongApi[F[_] : Sync](proxy: RholangProxy) extends Http4sDsl[F] {
}
)

case req @ POST -> Root / music =>
req.decode[String] { data =>
val searchId = parse(data).toOption.get.as[SearchModel].toOption.get.id
Ok(SearchMusic.search(searchId).toOption.get.asJson)
}


case GET -> Root / "art" / id ⇒
getMemoizedAsset(id)(proxy).fold(
l => {
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/coop/rchain/domain/ErrorCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object ErrorCode extends Enumeration {
nameNotFound,
unregisteredUser,
cacheLayer,
jsonError,
unknown = Value
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/coop/rchain/domain/RSongModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ object RSongModel {
metadata: RSongMetadata,
uri: String
)
case class SearchModel (
id: String,
albumTitle: String,
songTitle: String,
artist: String
)

}
4 changes: 3 additions & 1 deletion src/main/scala/coop/rchain/protocol/ParToDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ object ParOps {
println(e)
log.error(s"String2Par failed with Exception: ${e}")
Left(Err(ErrorCode.nameToPar, e.getMessage, None))
case Success(r) => Right(r)
case Success(r) =>
log.info(s"rTerm: ${rTerm} Par: ${r}")
Right(r)
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/coop/rchain/repo/RholangProxy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class RholangProxy(channel: ManagedChannel) {
DeployData()
.withTerm(contract)
.withTimestamp(System.currentTimeMillis())
.withPhloLimit(coop.rchain.casper.protocol.PhloLimit(0))
.withPhloPrice(coop.rchain.casper.protocol.PhloPrice(0))
.withPhloLimit((Long.MaxValue))
.withPhloPrice((1L))
.withNonce(0)
.withFrom("0x1")
)
Expand Down Expand Up @@ -77,15 +77,15 @@ class RholangProxy(channel: ManagedChannel) {

import coop.rchain.protocol.ParOps._
def dataAtName(
rholangName: String): Either[Err, ListeningNameDataResponse] = {
rholangName: String): Either[Err, ListeningNameDataResponse] = {
log.debug(s"dataAtName received name $rholangName")
rholangName.asPar.flatMap(p => dataAtName(p))
}

import coop.rchain.protocol.ParOps._
private def dataAtName(par: Par): Either[Err, ListeningNameDataResponse] = {
log.debug(s"dataAtName received par ${PrettyPrinter().buildString(par)}")
val res = grpc.listenForDataAtName(par)
val res = grpc.listenForDataAtName(DataAtNameQuery(Int.MaxValue,Some(par)))
res.status match {
case "Success" =>
log.debug(s"dataAtName returned payload size: ${res.length}")
Expand All @@ -95,5 +95,4 @@ class RholangProxy(channel: ManagedChannel) {
Left(Err(ErrorCode.nameNotFound, s"${res}", None))
}
}

}
31 changes: 31 additions & 0 deletions src/main/scala/coop/rchain/repo/SearchMusic.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package coop.rchain.repo

import coop.rchain.domain.RSongModel.{RSongModel, SearchModel}
import coop.rchain.service.moc.MocSongMetadata
import io.circe.Json
import coop.rchain.domain._
import io.circe._
import io.circe.generic.auto._
import io.circe.parser._
import io.circe.syntax._
import org.http4s.Request

object SearchMusic {

def search(id: String) = MocSongMetadata.getMetadata(id)
def searchJson(payload: Json) = {

val searchModel : Either[Err, SearchModel] =
payload.as[RSongModel] match {
case d: DecodingFailure =>Left(
Err(ErrorCode.jsonError, d.message, None) )
case s: SearchModel => Right(s)
}
searchModel.map(x => MocSongMetadata.getMetadata(x.id))


}

def searchRequest[F] =
search("Tiny Human")
}
3 changes: 2 additions & 1 deletion src/main/scala/coop/rchain/repo/SongRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ object SongRepo {
songId <- findByName(proxy, assetName)
songIdOut = s"${songId}-${SONG_OUT}"
retrieveSongArgs = s"""("$songId".hexToBytes(), "$songIdOut")"""
termToRetrieveSong = s"""@["Immersion", "retrieveSong"]!$retrieveSongArgs"""
termToRetrieveSong =
s"""@["Immersion", "retrieveSong"]!$retrieveSongArgs"""
_ <- proxy.deployAndPropose(termToRetrieveSong)
songData <- findByName(proxy, songIdOut)
binarySongData = Base16.decode(songData)
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/coop/rchain/utils/HexUtilsSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package coop.rchain.utils

import coop.rchain.models.Expr.ExprInstance.GString
import coop.rchain.models.Par
import org.specs2._

class HexUtilsSpec extends Specification {
Expand All @@ -15,4 +17,7 @@ class HexUtilsSpec extends Specification {
bytes2hex(hex2bytes(data), Option("-")) === data
}

def a = {
val p = Par(exprs = GString(""))
}
}
4 changes: 2 additions & 2 deletions src/universal/conf/application.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Setting -X directly (-J is stripped)
# -J-X
-J-Xms3g
-J-Xmx11g
-J-Xms1g
-J-Xmx3g