Skip to content
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

release: 1.3.8 - assert no pending transactions when tokenizing #157

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,5 @@ jobs:

- name: Trigger apt repo update
run: |
curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"climate_tokenization_repo":"${{ steps.repo-name.outputs.REPO_NAME }}","application_name":"climate-tokenization-engine","release_version":"${{ steps.tag-name.outputs.TAGNAME }}","add_debian_version":"true","arm64":"available"}' ${{ secrets.GLUE_API_URL }}/api/v1/climate-tokenization/${{ github.sha }}/start
curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"climate_tokenization_repo":"${{ steps.repo-name.outputs.REPO_NAME }}","application_name":"climate-tokenization-engine","release_version":"${{ steps.tag-name.outputs.TAGNAME }}","add_debian_version":"true","arm64":"available"}' ${{ secrets.GLUE_API_URL }}/api/v1/climate-tokenization/${{ github.sha }}/success/deploy
curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"climate_tokenization_repo":"${{ steps.repo-name.outputs.REPO_NAME }}","application_name":"[\"climate-tokenization-engine\"]","release_version":"${{ steps.tag-name.outputs.TAGNAME }}","add_debian_version":"true","arm64":"available"}' ${{ secrets.GLUE_API_URL }}/api/v1/climate-tokenization/${{ github.sha }}/start
curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"climate_tokenization_repo":"${{ steps.repo-name.outputs.REPO_NAME }}","application_name":"[\"climate-tokenization-engine\"]","release_version":"${{ steps.tag-name.outputs.TAGNAME }}","add_debian_version":"true","arm64":"available"}' ${{ secrets.GLUE_API_URL }}/api/v1/climate-tokenization/${{ github.sha }}/success/deploy
14 changes: 14 additions & 0 deletions middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { hasUnconfirmedTransactions } = require("./chia/wallet");

export const assertNoPendingTransactions = async (req, res, next) => {
const hasPendingTransactions = await hasUnconfirmedTransactions();

if (hasPendingTransactions) {
return res.status(400).send({
success: false,
message: "Please wait for all transactions to confirm.",
});
}

next();
};
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "climate-tokenization-engine",
"version": "1.3.7",
"version": "1.3.8",
"bin": "./server.js",
"description": "",
"main": "proxy.js",
Expand Down
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const cors = require("cors");
const os = require("os");
const formData = require("express-form-data");
const scheduler = require("./tasks");
const { assertNoPendingTransactions } = require("./middleware");

const { getHomeOrgUid } = require("./utils/coreRegApi");

Expand Down Expand Up @@ -416,7 +417,7 @@ const confirmTokenCreationWithTransactionId = async (
return false;
};

app.post("/tokenize", validator.body(tokenizeUnitSchema), async (req, res) => {
app.post("/tokenize", validator.body(tokenizeUnitSchema), assertNoPendingTransactions(), async (req, res) => {
try {
console.log({
token: {
Expand All @@ -430,6 +431,7 @@ app.post("/tokenize", validator.body(tokenizeUnitSchema), async (req, res) => {
to_address: req.body.to_address,
},
});

const response = await superagent
.post(`${CONFIG.CLIMATE_TOKENIZATION_CHIA_HOST}/v1/tokens`)
.send({
Expand Down Expand Up @@ -661,7 +663,7 @@ app.use(async (req, res, next) => {
next();
});

const bindAddress = getConfig().BIND_ADDRESS || "localhost";
const bindAddress = CONFIG.BIND_ADDRESS || "localhost";

if (
(bindAddress !== "localhost" && CONFIG.CLIMATE_TOKENIZATION_ENGINE_API_KEY) ||
Expand Down
10 changes: 1 addition & 9 deletions utils/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ const yaml = require("js-yaml");
const fs = require("fs");
const os = require("os");
const path = require("path");

const getChiaRoot = () => {
if (process.env.CHIA_ROOT) {
return path.resolve(process.env.CHIA_ROOT);
} else {
const homeDir = os.homedir();
return path.resolve(`${homeDir}/.chia/mainnet`);
}
}
const { getChiaRoot } = require("chia-root-resolver");

const defaultConfig = require("./defaultConfig.json");
const chiaRoot = getChiaRoot();
Expand Down
Loading