Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
graphql request endpoint mutations type and data code added
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Nov 2, 2021
1 parent 6fd768a commit 82d3170
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 56 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ token0=51254d70d183f4b1e59ee5d5b0c76d3c3a81d0366278beecc05b546d49a9835c
token1=96b0431770a34f5b651a43c830f3c8537e7c44f2cb8191d7efbcca2379785cda
pair=11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
NODE_ADDRESS=http://159.65.118.250:7777/rpc
EVENT_STREAM_ADDRESS=http://159.65.118.250:9999/events/main
Expand Down
11 changes: 6 additions & 5 deletions JsClients/FACTORY/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
TOKEN0_CONTRACT,
TOKEN1_CONTRACT,
PAIR_CONTRACT,
GRAPHQL
} = process.env;

const KEYS = Keys.Ed25519.parseKeyFiles(
Expand All @@ -48,8 +49,7 @@ const test = async () => {
async (eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Deployhash: ", deploy.deployHash);
const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Timestamp: ", timestamp);
console.log("... Block hash: ", block_hash);

Expand All @@ -62,15 +62,16 @@ const test = async () => {
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);
console.log(newData[5][0].data + " = " + newData[5][1].data);


request('http://localhost:3000/graphql',
request(GRAPHQL!,
`mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: Int!, $blockHash: String!){
handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) {
id
result
}
}`,
{token0:'51254d70d183f4b1e59ee5d5b0c76d3c3a81d0366278beecc05b546d49a9835c', token1: '96b0431770a34f5b651a43c830f3c8537e7c44f2cb8191d7efbcca2379785cda', pair: '11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', all_pairs_length: 5, timeStamp:1000, blockHash:'0000000000000000000000000000000000000000000000000000000000000000'})
{token0:newData[2][1].data, token1: newData[3][1].data, pair: newData[4][1].data, all_pairs_length: newData[5][1].data, timeStamp:timestamp, blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));

Expand Down
2 changes: 1 addition & 1 deletion JsClients/FACTORY/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getDeploy = async (NODE_URL: string, deployHash: string) => {
if (raw.execution_results.length !== 0) {
// @ts-ignore
if (raw.execution_results[0].result.Success) {
return [deploy.header.timestamp,deploy.header.gasPrice,raw.execution_results[0].block_hash];
return [deploy.header.timestamp,raw.execution_results[0].block_hash];
} else {
// @ts-ignore
throw Error("Contract execution: " + raw.execution_results[0].result.Failure.error_message);
Expand Down
94 changes: 76 additions & 18 deletions JsClients/PAIR/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const {
FACTORY_CONTRACT,
TOKEN0_CONTRACT,
TOKEN1_CONTRACT,
PAIR_CONTRACT_NAME
PAIR_CONTRACT_NAME,
GRAPHQL
} = process.env;

// const TOKEN_META = new Map(parseTokenMeta(process.env.TOKEN_META!));
Expand Down Expand Up @@ -66,34 +67,91 @@ const test = async () => {
async (eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Deployhash: ", deploy.deployHash);
console.log("... Timestamp: ", timestamp);
//console.log("... GasPrice: ", gasPrice);
console.log("... Block hash: ", block_hash);

let newData = JSON.parse(JSON.stringify(result.value()));

let newData = JSON.parse(JSON.stringify(result.value()));

console.log(eventName+ " Event result: ");
console.log(newData[0][0].data + " = " + newData[0][1].data);
console.log(newData[1][0].data + " = " + newData[1][1].data);
console.log(newData[2][0].data + " = " + newData[2][1].data);
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);
console.log(newData[5][0].data + " = " + newData[5][1].data);

// if(eventName=="transfer")
// {
// request('http://localhost:3000/graphql', `mutation handleTransfer($from: String!, $to: String!, $value: Int!, $pair: String!) {
// createUser(email: $email, password: $password) {
// id
// email
// }
// }`, {email: 'john.doe@mail.com', password: 'Pa$$w0rd'})
// .then(data => console.info(data))
// .catch(error => console.error(error));

// }
console.log(newData[6][0].data + " = " + newData[6][1].data);
console.log(newData[7][0].data + " = " + newData[7][1].data);
console.log(newData[8][0].data + " = " + newData[8][1].data);
console.log(newData[9][0].data + " = " + newData[9][1].data);

if(eventName=="transfer")
{
request(GRAPHQL!,
`mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){
handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
}`,
{from:newData[2][1].data, to: newData[3][1].data, value: newData[4][1].data, pairAddress: newData[5][1].data, deployHash:deploy.deployHash,timeStamp:timestamp, blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}
else if (eventName=="mint")
{
request(GRAPHQL!,
`mutation handleMint( $amount0: String!, $amount1: String!, $sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){
handleMint( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
}`,
{amount0:newData[3][1].data, amount1: newData[4][1].data, sender: newData[2][1].data,logIndex:0, pairAddress: newData[5][1].data, deployHash:deploy.deployHash,timeStamp:timestamp, blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}
else if (eventName=="burn")
{
request(GRAPHQL!,
`mutation handleBurn( $amount0: String!, $amount1: String!, $sender: String!,$logIndex: Int!,$to: String!, $pairAddress: String!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){
handleBurn( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, to:$to, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
}`,
{amount0:newData[3][1].data, amount1: newData[4][1].data, sender: newData[2][1].data,logIndex:0, to:newData[5][1].data,pairAddress: newData[6][1].data, deployHash:deploy.deployHash,timeStamp:timestamp, blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}
else if (eventName=="sync")
{
request(GRAPHQL!,
`mutation handleSync( $reserve0: String!, $reserve1: String!, $pairAddress: String!){
handleSync( reserve0: $reserve0, reserve1: $reserve1, pairAddress: $pairAddress) {
result
}
}`,
{reserve0:newData[2][1].data, reserve1: newData[3][1].data, pairAddress: newData[4][1].data})
.then(data => console.log(data))
.catch(error => console.error(error));
}
else if (eventName=="swap")
{
request(GRAPHQL!,
`mutation handleSwap( $amount0In: String!, $amount1In: String!, $amount0Out: String!, $amount1Out: String!, $to: String!,$from: String!,$sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){
handleSwap( amount0In: $amount0In, amount1In: $amount1In, amount0Out: $amount0Out, amount1Out: $amount1Out, to:$to, from:$from,sender: $sender,logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
}`,
{amount0In:newData[3][1].data, amount1In: newData[4][1].data,amount0Out:newData[5][1].data, amount1Out: newData[6][1].data,to:newData[7][1].data,from:newData[8][1].data, sender: newData[2][1].data,logIndex:0,pairAddress: newData[9][1].data, deployHash:deploy.deployHash,timeStamp:timestamp, blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}


} else {
console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
Expand Down
2 changes: 1 addition & 1 deletion JsClients/PAIR/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getDeploy = async (NODE_URL: string, deployHash: string) => {
if (raw.execution_results.length !== 0) {
// @ts-ignore
if (raw.execution_results[0].result.Success) {
return [deploy.header.timestamp,deploy.header.gasPrice,raw.execution_results[0].block_hash];
return [deploy.header.timestamp,raw.execution_results[0].block_hash];
} else {
// @ts-ignore
throw Error("Contract execution: " + raw.execution_results[0].result.Failure.error_message);
Expand Down
Loading

0 comments on commit 82d3170

Please sign in to comment.