Skip to content

Commit

Permalink
Merge pull request #124 from walt-id/feat/Algorand-support
Browse files Browse the repository at this point in the history
Feat/algorand support
  • Loading branch information
SuperBatata authored Jul 21, 2023
2 parents b92dcc2 + f87d83c commit b26101a
Show file tree
Hide file tree
Showing 16 changed files with 519 additions and 11 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ dependencies {
// unique
implementation ("network.unique:unique-sdk-jvm:0.0.1")

// algorand
implementation ("com.algorand:algosdk:2.2.0")

// expediagroup graphql
implementation("com.expediagroup:graphql-kotlin-spring-client:6.4.0")
implementation("com.expediagroup", "graphql-kotlin-client-serialization", "6.4.0")
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
5 changes: 2 additions & 3 deletions js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import {NearRoutes} from './near/near.routes.config';
import {FlowRoutes} from './Flow/flow.routes.config';
import {PolkadotRoutes} from './polkadot/polkadot.routes.config';


import debug from 'debug';

const app: express.Application = express();
const server: http.Server = http.createServer(app);
const port = 3000;
const port = 4000;
const routes: Array<CommonRoutesConfig> = [];
const debugLog: debug.IDebugger = debug('app');

Expand Down Expand Up @@ -57,4 +56,4 @@ server.listen(port, () => {
routes.forEach((route: CommonRoutesConfig) => {
debugLog(`Routes configured for ${route.getName()}`);
});
});
});
3 changes: 2 additions & 1 deletion js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"winston": "^3.8.2"
},
"devDependencies": {
"@types/bn.js": "^5.1.1",
"@types/cors": "^2.8.12",
"@types/debug": "^4.1.7",
"@types/express": "^4.17.14",
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main/kotlin/id/walt/nftkit/App.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package id.walt.nftkit


import id.walt.nftkit.rest.NftKitApi


fun main() {
println("\n\n\n")

/* /////////// */
/* /////////// */
/* /////////// */

NftKitApi.start()


Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/id/walt/nftkit/Values.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ object Values {
const val POLKADOT_UNIQUE_EXPLORER = "https://unique.subscan.io/"
const val POLKADOT_OPAL_EXPLORER = "https://uniquescan.io/OPAL/"


//algorand values
const val ALGORAND_INDEXER_TESTNET= "https://testnet-algorand.api.purestake.io/idx2";
const val ALGORAND_INDEXER_MAINNET= "https://mainnet-algorand.api.purestake.io/idx2";

const val ALGORAND_ALGOD_TESTNET = "https://testnet-algorand.api.purestake.io/ps2";
const val ALGORAND_ALGOD_MAINNET = "https://mainnet-algorand.api.purestake.io/ps2";



const val ALGORAND_MAINNET_EXPLORER = "https://algoexplorer.io/"
const val ALGORAND_TESTNET_EXPLORER = "https://testnet.algoexplorer.io/"

}
125 changes: 125 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/AlgorandNftController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package id.walt.nftkit.rest

import cc.vileda.openapi.dsl.schema

import id.walt.nftkit.services.*
import id.walt.nftkit.tokenownersquery.TokenOwnersDataResponse
import id.walt.nftkit.utilis.Common
import io.javalin.http.Context
import io.javalin.plugin.openapi.dsl.document
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json



object AlgorandNftController{

private const val TAG = "Algorand Blockchain: Non-fungible tokens(NFTs)"
fun accountCreation(ctx : Context){
val result = AlgorandNftService.createAccount()
ctx.json(result)
}

fun accountCreationDocs() = document().operation {
it.summary("Create Algorand Account").operationId("CreateAlgorandAccount").addTagsItem("Algorand Blockchain: Non-fungible tokens(NFTs)")
}.json<AlgorandAccount>(200.toString()) {
it.description("Algorand Account")
}


fun assetCreation(ctx : Context){
val result = AlgorandNftService.createAssetArc3(ctx.pathParam("assetName"), ctx.pathParam("assetUnitName"), ctx.pathParam("url"))
ctx.json(result)
}

fun assetCreationDocs() = document().operation {
it.summary("Create Algorand Asset").operationId("CreateAlgorandAsset").addTagsItem("Algorand Blockchain: Non-fungible tokens(NFTs)")
}.json<AlgodResponse>(200.toString()) {
it.description("Algorand Asset")
}





fun fetchToken(ctx: Context){
val chain =ctx.pathParam("chain")
val asset = ctx.pathParam("assetId")
val response = AlgorandNftService.getToken(
asset.toLong(),
Common.getAlgorandChain(chain.uppercase())
)
ctx.json(response)
}
fun fetchTokenDocs()= document().operation {
it.summary("Fetching Token")
.operationId("fetchToken")
.addTagsItem(TAG)}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("assetId"){}
.json<AlgorandToken>("200"){
it.description("Fetched token")
}

///////////////////////////////////////////////////////////////////////////

fun fetchAssetMetadata(ctx: Context){
val chain =ctx.pathParam("chain")
val asset = ctx.pathParam("assetId")
val response = AlgorandNftService.getAssetMeatadata(
asset.toLong(),
Common.getAlgorandChain(chain.uppercase())
)
ctx.json(response)
}
fun fetchAssetMetadataDocs()= document().operation {
it.summary("Fetching token parametrs ")
.operationId("fetchAlgornadAssets")
.addTagsItem(TAG)}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("assetId"){}
.json<Asset>("200"){
it.description("Fetched token parameteres")
}

///////////////////////////////////////////////////////////////////////////

fun fetchAccountAssets(ctx: Context){
val chain = ctx.pathParam("chain")
val address = ctx.pathParam("address")
val response = AlgorandNftService.getAccountAssets(address, Common.getAlgorandChain(chain.uppercase()))
ctx.json(response)
}
fun fetchAccountAssetsDocs()= document().operation {
it.summary("Fetching account tokens ")
.operationId("fetchAccountAssets")
.addTagsItem(TAG)}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("address"){}
.json<AssetHoldingsResponse>("200"){
it.description("Fetched Tokens")
}

///////////////////////////////////////////////////////////////////////////

fun fetchNftMetadata(ctx: Context){
val chain =ctx.pathParam("chain")
val asset = ctx.pathParam("assetId")
val result = AlgorandNftService.getNftMetadata(asset.toLong(), Common.getAlgorandChain(chain.uppercase()) )
ctx.result(Json.encodeToString(result))

}
fun fetchNftMetadataDocs()= document().operation {
it.summary("Fetching NFT metadata ")
.operationId("fetchAlgornadNfts")
.addTagsItem(TAG)}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("assetId"){}
.json<AlgoNftMetadata>("200"){
it.description("Fetched NFT metadata")
}
}
28 changes: 28 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/NftKitApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,34 @@ object NftKitApi {

)
}

path("Algorand"){

post("account/create/",
documented(AlgorandNftController.accountCreationDocs(), AlgorandNftController::accountCreation)
)
post("asset/create/{assetName}/{assetUnitName}/{url}/",
documented(AlgorandNftController.assetCreationDocs(), AlgorandNftController::assetCreation)
)

get(
"chain/{chain}/asset/{assetId}",
documented(AlgorandNftController.fetchTokenDocs(), AlgorandNftController::fetchToken)
)
get(
"chain/{chain}/asset/{assetId}/params",
documented(AlgorandNftController.fetchAssetMetadataDocs(), AlgorandNftController::fetchAssetMetadata)
)
get(
"chain/{chain}/asset/{assetId}/metadata",
documented(AlgorandNftController.fetchNftMetadataDocs(), AlgorandNftController::fetchNftMetadata)
)
get(
"chain/{chain}/assets/account/{address}/",
documented(AlgorandNftController.fetchAccountAssetsDocs(), AlgorandNftController::fetchAccountAssets)
)

}
}
path("nft/verifier") {
get(
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/id/walt/nftkit/rest/TezosNftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ object TezosNftController {
val chain = ctx.pathParam("chain")
val contractAddress = ctx.pathParam("contractAddress")
val tokenId = ctx.pathParam("tokenId")
val result =
TezosNftService.getNftTezosMetadata(Common.getTezosChain(chain.uppercase()), contractAddress, tokenId)
val result = TezosNftService.getNftTezosMetadata(Common.getTezosChain(chain.uppercase()), contractAddress, tokenId)
result?.let {
ctx.json(
it
Expand Down Expand Up @@ -140,4 +139,4 @@ object TezosNftController {
}


}
}
Loading

0 comments on commit b26101a

Please sign in to comment.