From 50ba25868b03d50516d7ecc040ac2e838b5f5ce8 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 28 Oct 2022 15:12:56 -0400 Subject: [PATCH] add configurable amount and fee --- server.js | 10 ++++++++-- validations.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 76644cb..d5645ea 100644 --- a/server.js +++ b/server.js @@ -204,6 +204,7 @@ const updateUnitMarketplaceIdentifierWithAssetId = async ( await request({ method: "post", url: `${CONFIG.REGISTRY_HOST}/v1/staging/commit`, + headers: { "Content-Type": "application/json" }, }); } catch (error) { console.log( @@ -220,6 +221,8 @@ const confirmTokenRegistrationOnWarehouse = async ( ) => { if (retry <= 60) { try { + await new Promise((resolve) => setTimeout(() => resolve(), 30000)); + const response = await request({ method: "get", url: `${CONFIG.REGISTRY_HOST}/v1/staging/hasPendingTransactions`, @@ -254,8 +257,9 @@ const registerTokenCreationOnClimateWarehouse = async ( url: `${CONFIG.REGISTRY_HOST}/v1/organizations/metadata`, method: "post", body: JSON.stringify({ - [token.asset_id]: token, + [token.asset_id]: JSON.stringify(token), }), + headers: { "Content-Type": "application/json" }, }); const data = JSON.parse(response); @@ -290,6 +294,8 @@ const confirmTokenCreationWithTransactionId = async ( ) => { if (retry <= 60) { try { + await new Promise((resolve) => setTimeout(() => resolve(), 30000)); + const response = await request({ method: "get", url: `${CONFIG.TOKENIZE_DRIVER_HOST}/v1/transactions/${transactionId}`, @@ -328,7 +334,7 @@ app.post("/tokenize", validator.body(tokenizeUnitSchema), async (req, res) => { sequence_num: req.body.sequence_num, }, payment: { - amount: 100, + amount: (req.body.amount || 1) * 1000, fee: 100, to_address: req.body.to_address, }, diff --git a/validations.js b/validations.js index ba93cbb..d8190a6 100644 --- a/validations.js +++ b/validations.js @@ -11,7 +11,8 @@ const tokenizeUnitSchema = Joi.object({ vintage_year: Joi.number().required(), sequence_num: Joi.number().required(), warehouseUnitId: Joi.string().required(), - to_address: Joi.string().required() + to_address: Joi.string().required(), + amount: Joi.number().required(), }); module.exports = { connectToOrgSchema, tokenizeUnitSchema };