-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from KowalewskiPawel/add-ver-0.4
Ver. 0.4; Add tx write execution result
- Loading branch information
Showing
3 changed files
with
73 additions
and
41 deletions.
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
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,52 +1,61 @@ | ||
import { randomUUID } from "crypto"; | ||
import { Request, Response } from "express"; | ||
import { readContractCall, writeContractCall } from "../contractAPI/contractCall"; | ||
import { | ||
readContractCall, | ||
writeContractCall, | ||
} from "../contractAPI/contractCall"; | ||
import { getTransactionUrl } from "../utils/fs"; | ||
|
||
export const readContract = async (req: Request, res: Response) => { | ||
try { | ||
const { methodName, args } = req.body; | ||
try { | ||
const { methodName, args } = req.body; | ||
|
||
const readResult = await readContractCall(methodName, args); | ||
const readResult = await readContractCall(methodName, args); | ||
|
||
return res.status(200).json({ result: readResult }); | ||
} catch (error) { | ||
return res.status(500).json({ | ||
error: true, | ||
message: "Something went wrong", | ||
}); | ||
} | ||
}; | ||
|
||
export const writeContract = async (req: Request, res: Response) => { | ||
try { | ||
const { methodName, args } = req.body; | ||
|
||
const transactionId = randomUUID(); | ||
return res.status(200).json({ result: readResult }); | ||
} catch (error) { | ||
return res.status(500).json({ | ||
error: true, | ||
message: "Something went wrong", | ||
}); | ||
} | ||
}; | ||
|
||
await writeContractCall(methodName, args, transactionId); | ||
|
||
return res.status(200).json({ transactionId }); | ||
} catch (error) { | ||
return res.status(500).json({ | ||
error: true, | ||
message: "Something went wrong", | ||
}); | ||
} | ||
}; | ||
export const writeContract = async (req: Request, res: Response) => { | ||
try { | ||
const { methodName, args } = req.body; | ||
|
||
export const txUrl = async (req: Request, res: Response) => { | ||
try { | ||
const { txId } = req.body; | ||
const transactionId = randomUUID(); | ||
|
||
const txUrl = getTransactionUrl(txId); | ||
const callResult = await writeContractCall(methodName, args, transactionId); | ||
|
||
return res.status(200).json({ transactionBlockUrl: txUrl }); | ||
} catch (error) { | ||
if (callResult !== "OK") { | ||
return res.status(500).json({ | ||
error: true, | ||
message: "Something went wrong", | ||
message: JSON.stringify(callResult) || "Something went wrong", | ||
}); | ||
} | ||
}; | ||
|
||
|
||
return res.status(200).json({ transactionId }); | ||
} catch (err) { | ||
return res.status(500).json({ | ||
error: true, | ||
message: JSON.stringify(err) || "Something went wrong", | ||
}); | ||
} | ||
}; | ||
|
||
export const txUrl = async (req: Request, res: Response) => { | ||
try { | ||
const { txId } = req.body; | ||
|
||
const txUrl = getTransactionUrl(txId); | ||
|
||
return res.status(200).json({ transactionBlockUrl: txUrl }); | ||
} catch (error) { | ||
return res.status(500).json({ | ||
error: true, | ||
message: "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