-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f621fc
commit e2aa466
Showing
25 changed files
with
1,481 additions
and
559 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { getContractId } from '@/utils/contracts' | ||
import { AppError, getErrorMessage, handleError } from '@/utils/errors' | ||
import { getNFTContract } from '@/utils/tokens' | ||
|
||
/** | ||
* @swagger | ||
* /v1/nft/{contract_id}/{token_id}/approve: | ||
* get: | ||
* tags: [Non Fungible Tokens] | ||
* description: Approves a user for a token, returning the operation. | ||
* summary: Approves a user for a token, returning the operation. | ||
* parameters: | ||
* - name: contract_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: Koinos address of the contract | ||
* required: true | ||
* example: "@koinos.fun" | ||
* - name: token_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The token ID | ||
* required: true | ||
* example: "0x35303437" | ||
* - name: operator | ||
* in: query | ||
* schema: | ||
* type: string | ||
* description: Koinos address of the account operating the token | ||
* required: true | ||
* example: 1EnaBDVTA5hqXokC2dDzt2JT5eHv1y7ff1 | ||
* - name: approve | ||
* in: query | ||
* schema: | ||
* type: boolean | ||
* description: Whether to approve the operator or not. | ||
* required: false | ||
* example: true | ||
* - name: memo | ||
* in: query | ||
* schema: | ||
* type: string | ||
* description: Optional memo | ||
* required: false | ||
* responses: | ||
* 200: | ||
* description: Operation | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* call_contract: | ||
* type: object | ||
* properties: | ||
* contract_id: | ||
* type: string | ||
* entry_point: | ||
* type: integer | ||
* args: | ||
* type: string | ||
* example: | ||
* call_contract: | ||
* contract_id: 1EnaBDVTA5hqXokC2dDzt2JT5eHv1y7ff1 | ||
* entry_point: 1960973952 | ||
* args: "ChkAY8ED6InNJ-LSQhg38spEhfSAWi8UN6HnEhkAlzgMKVPolWBD5lWUM7yqKcudeRB3V_SkGgQ1MDQ3" | ||
*/ | ||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { contract_id: string, token_id: string } } | ||
) { | ||
try { | ||
const contract_id = await getContractId(params.contract_id) | ||
const contract = await getNFTContract(contract_id) | ||
|
||
const { searchParams } = new URL(request.url) | ||
const operator = searchParams.get('operator') | ||
const approved = searchParams.get('approved') | ||
const memo = searchParams.get('memo') | ||
|
||
try { | ||
const { result: ownerRes } = await contract.functions.owner_of({ | ||
token_id: params.token_id | ||
}); | ||
|
||
return Response.json(await contract.encodeOperation({ | ||
name: 'approve', | ||
args: { | ||
owner: ownerRes?.value, | ||
operator: operator, | ||
token_id: params.token_id, | ||
approved: approved ? approved == 'true' : undefined, | ||
memo | ||
} | ||
})); | ||
} catch (error) { | ||
throw new AppError(getErrorMessage(error as Error)) | ||
} | ||
} catch (error) { | ||
return handleError(error as Error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { getContractId } from '@/utils/contracts' | ||
import { AppError, getErrorMessage, handleError } from '@/utils/errors' | ||
import { getNFTContract } from '@/utils/tokens' | ||
|
||
/** | ||
* @swagger | ||
* /v1/nft/{contract_id}/{token_id}/approved: | ||
* get: | ||
* tags: [Non Fungible Tokens] | ||
* description: Returns the approved operators for the token | ||
* summary: Returns the approved operators for the token. | ||
* parameters: | ||
* - name: contract_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The Koinos address of the NFT contract. | ||
* required: true | ||
* example: "@koinos.fun" | ||
* - name: token_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The token ID | ||
* required: true | ||
* example: 0x3937 | ||
* - name: start | ||
* in: query | ||
* schema: | ||
* type: string | ||
* example: "\"0x00\"" | ||
* description: Token ID to start with | ||
* required: true | ||
* - name: limit | ||
* in: query | ||
* schema: | ||
* type: integer | ||
* example: 5 | ||
* description: Number of tokens to return | ||
* required: true | ||
* - name: descending | ||
* in: query | ||
* schema: | ||
* type: boolean | ||
* example: | ||
* description: "Flag to return tokens in descending order (default: false)" | ||
* required: false | ||
* responses: | ||
* 200: | ||
* description: The operator's approval status for the token | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* value: | ||
* type: array | ||
* items: | ||
* type: string | ||
* example: | ||
* value: [] | ||
*/ | ||
|
||
export async function GET(request: Request, { params }: { params: { contract_id: string, token_id: string } }) { | ||
try { | ||
const contract_id = await getContractId(params.contract_id) | ||
|
||
const contract = getNFTContract(contract_id) | ||
|
||
const { searchParams } = new URL(request.url) | ||
const start = searchParams.get('start') | ||
const limit = searchParams.get('limit') | ||
const descending = searchParams.get('descending') | ||
|
||
try { | ||
const { result: approvedRes } = await contract.functions.get_approved({ | ||
token_id: params.token_id, | ||
start, | ||
limit, | ||
descending: descending ? descending == 'true' : undefined | ||
}) | ||
|
||
if (approvedRes?.values) { | ||
return Response.json({value: approvedRes?.values}) | ||
} | ||
|
||
if (approvedRes?.value){ | ||
return Response.json({value: [approvedRes?.value]}) | ||
} | ||
|
||
return Response.json({value: []}) | ||
} catch (error) { | ||
throw new AppError(getErrorMessage(error as Error)) | ||
} | ||
} catch (error) { | ||
return handleError(error as Error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { getContractId } from '@/utils/contracts' | ||
import { AppError, getErrorMessage, handleError } from '@/utils/errors' | ||
import { getNFTContract } from '@/utils/tokens' | ||
|
||
/** | ||
* @swagger | ||
* /v1/nft/{contract_id}/{token_id}/burn: | ||
* get: | ||
* tags: [Non Fungible Tokens] | ||
* description: Burns the token, returning the operation. | ||
* summary: Burns the token, returning the operation. | ||
* parameters: | ||
* - name: contract_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: Koinos address of the contract | ||
* required: true | ||
* example: "@koinos.fun" | ||
* - name: token_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The token ID | ||
* required: true | ||
* example: "0x3937" | ||
* - name: memo | ||
* in: query | ||
* schema: | ||
* type: string | ||
* description: Optional memo | ||
* required: false | ||
* responses: | ||
* 200: | ||
* description: Operation | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* call_contract: | ||
* type: object | ||
* properties: | ||
* contract_id: | ||
* type: string | ||
* entry_point: | ||
* type: integer | ||
* args: | ||
* type: string | ||
* example: | ||
* call_contract: | ||
* contract_id: 1EnaBDVTA5hqXokC2dDzt2JT5eHv1y7ff1 | ||
* entry_point: 2241834181 | ||
* args: "CgI5Nw==" | ||
*/ | ||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { contract_id: string; token_id: string } } | ||
) { | ||
try { | ||
const contract_id = await getContractId(params.contract_id) | ||
const contract = await getNFTContract(contract_id) | ||
|
||
const { searchParams } = new URL(request.url) | ||
const memo = searchParams.get('owner') | ||
|
||
try { | ||
return Response.json(await contract.encodeOperation({ | ||
name: 'burn', | ||
args: { | ||
token_id: params.token_id, | ||
memo | ||
} | ||
})) | ||
} catch (error) { | ||
throw new AppError(getErrorMessage(error as Error)) | ||
} | ||
} catch (error) { | ||
return handleError(error as Error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getContractId } from '@/utils/contracts' | ||
import { AppError, getErrorMessage, handleError } from '@/utils/errors' | ||
import { getNFTContract } from '@/utils/tokens' | ||
|
||
/** | ||
* @swagger | ||
* /v1/nft/{contract_id}/{token_id}/metadata: | ||
* get: | ||
* tags: [Non Fungible Tokens] | ||
* description: Returns the metadata of the token. | ||
* summary: Returns the metadata of the token. | ||
* parameters: | ||
* - name: contract_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The Koinos address of the NFT contract. | ||
* required: true | ||
* example: "@koinos.fun" | ||
* - name: token_id | ||
* in: path | ||
* schema: | ||
* type: string | ||
* description: The token ID | ||
* required: true | ||
* example: "0x35303437" | ||
* responses: | ||
* 200: | ||
* description: The metadata of the token | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* value: | ||
* type: string | ||
* example: | ||
* value: false | ||
*/ | ||
|
||
export async function GET(request: Request, { params }: { params: { contract_id: string, token_id: string } }) { | ||
try { | ||
const contract_id = await getContractId(params.contract_id) | ||
const contract = getNFTContract(contract_id) | ||
|
||
try { | ||
const { result } = await contract.functions.metadata_of({ | ||
token_id: params.token_id | ||
}); | ||
|
||
return result?.value ? | ||
Response.json(JSON.parse(result?.value)) : | ||
Response.json({}); | ||
} catch (error) { | ||
throw new AppError(getErrorMessage(error as Error)) | ||
} | ||
} catch (error) { | ||
return handleError(error as Error) | ||
} | ||
} |
Oops, something went wrong.