-
Notifications
You must be signed in to change notification settings - Fork 1
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
Vik #2
Open
SvineruS
wants to merge
14
commits into
master
Choose a base branch
from
vik
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Vik #2
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7d0ac67
redesigned schema for mongoose, graphql (due to new collection "token…
kiwvic 07e57cf
apollo instead of express
kiwvic 26f4134
redesign fake tokens gen
kiwvic 6fc7e57
add pagination
kiwvic 978fad7
lil pagination fix
kiwvic e3430c9
swap to another cursor pagination lib
kiwvic 66b65e1
little fix
kiwvic 51a0d1e
add getTokens
kiwvic c9f0f36
add EventType
kiwvic 9483b90
gen_fake_tokens little changes
kiwvic 5266961
0x000... to ethers.constants.AddressZero
kiwvic 3f0a86d
add uploadFile (def only), apollo-server-express
kiwvic 28816c2
add uploadFile, apollo-server-express
kiwvic 6004338
add getSpecificToken
kiwvic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,32 +1,12 @@ | ||
import { Marketplace } from "../marketplace"; | ||
import express from 'express' | ||
import bodyParser from 'body-parser' | ||
import { OrderFront } from "../types/common"; | ||
import { graphqlHTTP } from "express-graphql"; | ||
import { schema } from "./schema"; | ||
import { ApolloServer} from "apollo-server"; | ||
|
||
|
||
export async function start(marketplace: Marketplace) { | ||
|
||
const app = express() | ||
const jsonParser = bodyParser.json() | ||
|
||
app.use( | ||
"/graphql", | ||
graphqlHTTP({ | ||
schema: schema(marketplace), | ||
graphiql: true, | ||
})); | ||
|
||
app.post('/orders', jsonParser, async (req: any, res: any) => res.json(await marketplace.createOrder(OrderFront.fromJson(req.body)))); | ||
app.get('/orders', async (req: any, res: any) => res.json(await marketplace.getOrders())); | ||
app.get('/orders/:orderId', async (req: any, res: any) => res.json(await marketplace.getOrder(req.params.orderId))); | ||
app.get('/tokens', async (req: any, res: any) => res.json(await marketplace.getTokens())); | ||
app.post('/asset/create', async (req: any, res: any) => res.set('Status Code', 202)); | ||
|
||
|
||
console.log("starting") | ||
app.listen(8080); | ||
|
||
const server = new ApolloServer({ schema: schema(marketplace) }) | ||
server.listen({port: 8080}).then( | ||
() => { console.log("ready at 8080") } | ||
).catch((err) => {console.log(err)}); | ||
} | ||
|
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
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 |
---|---|---|
@@ -1,32 +1,42 @@ | ||
import {TokensCollection} from "../../lib/types/mongo"; | ||
import {TokensCollection, Tokens} from "../lib/types/mongo"; | ||
import {ethers} from "ethers"; | ||
import {zero} from "./utils"; | ||
import {TokenType} from "../../lib/types/common"; | ||
import {zero} from "../test/utils/utils"; | ||
import {TokenType} from "../lib/types/common"; | ||
import amongus from "mongoose"; | ||
|
||
amongus.connect('mongodb://root:example@localhost:27017/admin'); | ||
|
||
randomCollection() | ||
|
||
generateFakeData(); | ||
|
||
function randomCollection() { | ||
const tokens = []; | ||
for (let i=0; i<10; i++) | ||
tokens.push(randomToken()) | ||
|
||
function generateFakeData() { | ||
let collectionObjId; | ||
new TokensCollection({ | ||
contractAddress: randomAddress(), | ||
tokenType: randomChoice([TokenType.ERC1155, TokenType.ERC721]), | ||
owner: randomAddress(), | ||
tokens: [] | ||
}).save().then((r:any) => console.log(r)); | ||
}).save().then((r:any) => { | ||
collectionObjId = r._id | ||
const tokens = []; | ||
for (let i=0; i<5; i++) | ||
tokens.push(randomToken(collectionObjId)); | ||
console.log(collectionObjId); | ||
|
||
tokens.forEach(value => { | ||
new Tokens(value).save().then((r:any) => {}); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
function randomToken() { | ||
function randomToken(collectionObjId: any) { | ||
const tokenId = randomFrom0To(1000).toString(); | ||
const quantity = randomFrom0To(100) | ||
const addr = randomAddress() | ||
const quantity = randomFrom0To(100); | ||
const addr = randomAddress(); | ||
|
||
return { | ||
collectionObjectId: collectionObjId, | ||
tokenId: tokenId, | ||
metadata_uri: `http://localhost/${tokenId}`, | ||
metadata: | ||
|
@@ -55,11 +65,15 @@ function randomToken() { | |
} | ||
} | ||
|
||
function toHex(d: any) { | ||
return ("0"+(Number(d).toString(16))).slice(-2).toUpperCase() | ||
} | ||
function randomAddress() { | ||
return "0x" + ethers.utils.keccak256(randomFrom0To(100000).toString()).toString().slice(0, 40) | ||
let st = `0x${toHex(randomFrom0To(100000))}`; | ||
return ethers.utils.keccak256(st).toString().slice(0, 40) | ||
} | ||
function randomHash() { | ||
return "0x" + ethers.utils.keccak256(randomFrom0To(100000).toString()).toString().slice(0, 64) | ||
return ethers.utils.keccak256(`0x${toHex(randomFrom0To(100000))}`).toString().slice(0, 64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
function randomChoice(items: any[]) { | ||
return items[randomFrom0To(items.length)]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// noinspection