0

Can I use MongoDB's public key to check the account's balance? This is the data for the user when he sign up

SignUp function

    module. exports.signUp= async(req,res)=>{
    const {pseudo,email,password}= req.body
    try{
        const pair = stellar.Keypair.random();
        const userData= await userModel.create(
            {
                pseudo,
                email,
                password,
                publicKey: pair.publicKey(),
                secret: pair.secret(),
            })
            
       // await userData.save()
        res.send(userData)
        res.status(201).json({userData:userData._id})
    }  

    catch(err){
  const errors= errorsSignUp(err)
    res.status(200).send({errors})
} 
}

Check balance function

// function without MongoDB // saving data in file.json

const stellar= require('stellar-sdk')
const accounts= require("./accounts")
const util = require("util")
const userModel = require('../models/user.model')
var server= new stellar.Server("https://horizon-testnet.stellar.org")

const checkAccount= async accounts=>{
const AccountsBalance= await Promise.all(
    accounts.map(async account=> await 
server.loadAccount(account.publicKey)))
return AccountsBalance.map(({id,balances})=>({
    id,
    balances,
 
}))
}

 checkAccount(accounts)
.then(account=>console.log(util.inspect(account,false, null)))
.catch(error=>{console.log(error)})

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.