Skip to content

Commit

Permalink
made changes on the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
uwezukwechibuzor committed Sep 22, 2023
1 parent 49a542a commit 24f1529
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/Model/bitcoin/Models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TxsSchema = new mongoose.Schema({
type: Object
},
outputs: {
type: Object
type: Array
},
});

Expand Down
20 changes: 2 additions & 18 deletions backend/data/chainQueries/bitcoin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ const fetchBitcoinTxs = async (api, txModel) => {
return;
}

// Convert inputs and outputs arrays to objects
const inputs = tx.inputs.map((input) => ({
prev_addresses: input.prev_addresses,
prev_position: input.prev_position,
prev_type: input.prev_type,
prev_value: input.prev_value,
sequence: input.sequence,
}));

const outputs = tx.outputs.map((output) => ({
addresses: output.addresses,
value: output.value,
type: output.type,
spent_by_tx_position: output.spent_by_tx_position,
}));

const transactionsData = new txModel({
block_height: tx.block_height,
hash: tx.hash,
Expand All @@ -71,8 +55,8 @@ const fetchBitcoinTxs = async (api, txModel) => {
is_double_spend: tx.is_double_spend,
outputs_count: tx.outputs_count,
outputs_value: tx.outputs_value,
inputs,
outputs,
inputs: tx.inputs,
outputs: tx.inputs,
});

// Save the data
Expand Down
8 changes: 5 additions & 3 deletions backend/data/chainQueries/cosmos/latestBlocksAndTxs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const fetchLatestBlocksAndTxs = async (api, txModel, blockModel) => {
// Attempt to find an existing transaction by txHash
const existingTx = await txModel.findOne({ txHash: tx.txhash });

if (existingTx) {
return;
} else {
if (!existingTx) {
const transactionsData = new txModel({
txHash: tx.txhash,
messages: tx.tx.body.messages,
Expand All @@ -42,6 +40,8 @@ const fetchLatestBlocksAndTxs = async (api, txModel, blockModel) => {

// Save the data
await transactionsData.save();
} else {
return;
}
} catch (error) {
return;
Expand Down Expand Up @@ -71,6 +71,8 @@ const fetchLatestBlocksAndTxs = async (api, txModel, blockModel) => {
});

await blockData.save();
} else {
return;
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 24f1529

Please sign in to comment.